Added tag implications and suggestions to export
This commit is contained in:
parent
0bd0589e32
commit
790c3e10c6
2 changed files with 49 additions and 0 deletions
|
@ -77,7 +77,23 @@ class TagService
|
|||
'name' => $tag->getName(),
|
||||
'usages' => $tag->getUsages(),
|
||||
'banned' => $tag->isBanned(),
|
||||
'implications' => array_values(array_map(
|
||||
function ($subTag)
|
||||
{
|
||||
return $subTag->getName();
|
||||
},
|
||||
$tag->getImpliedTags())),
|
||||
'suggestions' => array_values(array_map(
|
||||
function ($subTag)
|
||||
{
|
||||
return $subTag->getName();
|
||||
},
|
||||
$tag->getSuggestedTags())),
|
||||
];
|
||||
if (empty($item['implications']))
|
||||
unset($item['implications']);
|
||||
if (empty($item['suggestions']))
|
||||
unset($item['suggestions']);
|
||||
$tags[] = $item;
|
||||
}
|
||||
$json = json_encode($tags);
|
||||
|
|
|
@ -69,6 +69,39 @@ final class TagServiceTest extends AbstractDatabaseTestCase
|
|||
$this->assertEquals('test3', $result[1]->getName());
|
||||
}
|
||||
|
||||
public function testExportRelations()
|
||||
{
|
||||
$fileDao = $this->getPublicFileDao();
|
||||
$tagService = $this->getTagService();
|
||||
|
||||
$tag1 = new Tag();
|
||||
$tag1->setName('test');
|
||||
$tag1->setCreationTime(date('c'));
|
||||
|
||||
$tag2 = new Tag();
|
||||
$tag2->setName('test 2');
|
||||
$tag3 = new Tag();
|
||||
$tag3->setName('test 3');
|
||||
$tag4 = new Tag();
|
||||
$tag4->setName('test 4');
|
||||
$tag5 = new Tag();
|
||||
$tag5->setName('test 5');
|
||||
$tagService->createTags([$tag2, $tag3, $tag4, $tag5]);
|
||||
|
||||
$tag1->setImpliedTags([$tag2, $tag3]);
|
||||
$tag1->setSuggestedTags([$tag4, $tag5]);
|
||||
|
||||
$tagService->createTags([$tag1]);
|
||||
$tagService->exportJson();
|
||||
$this->assertEquals('[' .
|
||||
'{"name":"test 2","usages":0,"banned":false},' .
|
||||
'{"name":"test 3","usages":0,"banned":false},' .
|
||||
'{"name":"test 4","usages":0,"banned":false},' .
|
||||
'{"name":"test 5","usages":0,"banned":false},' .
|
||||
'{"name":"test","usages":0,"banned":false,"implications":["test 2","test 3"],"suggestions":["test 4","test 5"]}]',
|
||||
$fileDao->load('tags.json'));
|
||||
}
|
||||
|
||||
public function testExportSingle()
|
||||
{
|
||||
$tag1 = new Tag();
|
||||
|
|
Loading…
Reference in a new issue