Added tag relationship management to backend
This commit is contained in:
parent
1b82504f08
commit
5815f156a8
8 changed files with 61 additions and 8 deletions
5
TODO
5
TODO
|
@ -33,11 +33,6 @@ everything related to tags:
|
||||||
- privileges
|
- privileges
|
||||||
- template
|
- template
|
||||||
- ajax
|
- ajax
|
||||||
- handle tag relations editing in backend
|
|
||||||
- tagservice::update
|
|
||||||
- tageditformdata
|
|
||||||
- tagcontroller
|
|
||||||
- privileges
|
|
||||||
- handle relations in autocomplete
|
- handle relations in autocomplete
|
||||||
|
|
||||||
refactors:
|
refactors:
|
||||||
|
|
|
@ -60,6 +60,8 @@ changePostFlags = regularUser, powerUser, moderator, administrator
|
||||||
listTags = regularUser, powerUser, moderator, administrator
|
listTags = regularUser, powerUser, moderator, administrator
|
||||||
massTag = powerUser, moderator, administrator
|
massTag = powerUser, moderator, administrator
|
||||||
changeTagName = moderator, administrator
|
changeTagName = moderator, administrator
|
||||||
|
changeTagImplications = moderator, administrator
|
||||||
|
changeTagSuggestions = moderator, administrator
|
||||||
banTags = moderator, administrator
|
banTags = moderator, administrator
|
||||||
|
|
||||||
listComments = regularUser, powerUser, moderator, administrator
|
listComments = regularUser, powerUser, moderator, administrator
|
||||||
|
|
|
@ -45,6 +45,8 @@ App.Auth = function(_, jQuery, util, api, appState, promise) {
|
||||||
listTags: 'listTags',
|
listTags: 'listTags',
|
||||||
massTag: 'massTag',
|
massTag: 'massTag',
|
||||||
changeTagName: 'changeTagName',
|
changeTagName: 'changeTagName',
|
||||||
|
changeTagImplications: 'changeTagImplications',
|
||||||
|
changeTagSuggestions: 'changeTagSuggestions',
|
||||||
banTags: 'banTags',
|
banTags: 'banTags',
|
||||||
|
|
||||||
viewHistory: 'viewHistory',
|
viewHistory: 'viewHistory',
|
||||||
|
|
|
@ -44,7 +44,7 @@ final class TagController extends AbstractController
|
||||||
$this->privilegeService->assertPrivilege(Privilege::LIST_TAGS);
|
$this->privilegeService->assertPrivilege(Privilege::LIST_TAGS);
|
||||||
|
|
||||||
$tag = $this->tagService->getByName($tagName);
|
$tag = $this->tagService->getByName($tagName);
|
||||||
return $this->tagViewProxy->fromEntity($tag);
|
return $this->tagViewProxy->fromEntity($tag, $this->getFullFetchConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTags()
|
public function getTags()
|
||||||
|
@ -84,7 +84,22 @@ final class TagController extends AbstractController
|
||||||
if ($formData->banned !== null)
|
if ($formData->banned !== null)
|
||||||
$this->privilegeService->assertPrivilege(Privilege::BAN_TAGS);
|
$this->privilegeService->assertPrivilege(Privilege::BAN_TAGS);
|
||||||
|
|
||||||
|
if ($formData->implications !== null)
|
||||||
|
$this->privilegeService->assertPrivilege(Privilege::CHANGE_TAG_IMPLICATIONS);
|
||||||
|
|
||||||
|
if ($formData->suggestions !== null)
|
||||||
|
$this->privilegeService->assertPrivilege(Privilege::CHANGE_TAG_SUGGESTIONS);
|
||||||
|
|
||||||
$tag = $this->tagService->updateTag($tag, $formData);
|
$tag = $this->tagService->updateTag($tag, $formData);
|
||||||
return $this->tagViewProxy->fromEntity($tag);
|
return $this->tagViewProxy->fromEntity($tag, $this->getFullFetchConfig());
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getFullFetchConfig()
|
||||||
|
{
|
||||||
|
return
|
||||||
|
[
|
||||||
|
TagViewProxy::FETCH_IMPLICATIONS => true,
|
||||||
|
TagViewProxy::FETCH_SUGGESTIONS => true,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,9 @@ namespace Szurubooru\Controllers\ViewProxies;
|
||||||
|
|
||||||
class TagViewProxy extends AbstractViewProxy
|
class TagViewProxy extends AbstractViewProxy
|
||||||
{
|
{
|
||||||
|
const FETCH_IMPLICATIONS = 'fetchImplications';
|
||||||
|
const FETCH_SUGGESTIONS = 'fetchSuggestions';
|
||||||
|
|
||||||
public function fromEntity($tag, $config = [])
|
public function fromEntity($tag, $config = [])
|
||||||
{
|
{
|
||||||
$result = new \StdClass;
|
$result = new \StdClass;
|
||||||
|
@ -11,6 +14,12 @@ class TagViewProxy extends AbstractViewProxy
|
||||||
$result->name = $tag->getName();
|
$result->name = $tag->getName();
|
||||||
$result->usages = $tag->getUsages();
|
$result->usages = $tag->getUsages();
|
||||||
$result->banned = $tag->isBanned();
|
$result->banned = $tag->isBanned();
|
||||||
|
|
||||||
|
if (!empty($config[self::FETCH_IMPLICATIONS]))
|
||||||
|
$result->implications = $this->fromArray($tag->getImpliedTags());
|
||||||
|
|
||||||
|
if (!empty($config[self::FETCH_SUGGESTIONS]))
|
||||||
|
$result->suggestions = $this->fromArray($tag->getSuggestedTags());
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,14 +7,20 @@ class TagEditFormData implements IValidatable
|
||||||
{
|
{
|
||||||
public $name;
|
public $name;
|
||||||
public $banned;
|
public $banned;
|
||||||
|
public $implications;
|
||||||
|
public $suggestions;
|
||||||
|
|
||||||
public function __construct($inputReader = null)
|
public function __construct($inputReader = null)
|
||||||
{
|
{
|
||||||
if ($inputReader !== null)
|
if ($inputReader !== null)
|
||||||
{
|
{
|
||||||
$this->name = $inputReader->name;
|
$this->name = $inputReader->name;
|
||||||
|
|
||||||
if ($inputReader->banned !== null)
|
if ($inputReader->banned !== null)
|
||||||
$this->banned = boolval($inputReader->banned);
|
$this->banned = boolval($inputReader->banned);
|
||||||
|
|
||||||
|
$this->implications = array_filter(array_unique(preg_split('/[\s+]/', $inputReader->implications)));
|
||||||
|
$this->suggestions = array_filter(array_unique(preg_split('/[\s+]/', $inputReader->suggestions)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +28,12 @@ class TagEditFormData implements IValidatable
|
||||||
{
|
{
|
||||||
if ($this->name !== null)
|
if ($this->name !== null)
|
||||||
$validator->validatePostTags([$this->name]);
|
$validator->validatePostTags([$this->name]);
|
||||||
|
|
||||||
|
if (!empty($this->implications))
|
||||||
|
$validator->validatePostTags($this->implications);
|
||||||
|
|
||||||
|
if (!empty($this->suggestions))
|
||||||
|
$validator->validatePostTags($this->suggestions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,8 @@ class Privilege
|
||||||
const LIST_TAGS = 'listTags';
|
const LIST_TAGS = 'listTags';
|
||||||
const MASS_TAG = 'massTag';
|
const MASS_TAG = 'massTag';
|
||||||
const CHANGE_TAG_NAME = 'changeTagName';
|
const CHANGE_TAG_NAME = 'changeTagName';
|
||||||
|
const CHANGE_TAG_IMPLICATIONS = 'changeTagImplications';
|
||||||
|
const CHANGE_TAG_SUGGESTIONS = 'changeTagSuggestions';
|
||||||
const BAN_TAGS = 'banTags';
|
const BAN_TAGS = 'banTags';
|
||||||
|
|
||||||
const LIST_COMMENTS = 'listComments';
|
const LIST_COMMENTS = 'listComments';
|
||||||
|
|
|
@ -90,7 +90,7 @@ class TagService
|
||||||
{
|
{
|
||||||
$tagNameGetter = function($tag)
|
$tagNameGetter = function($tag)
|
||||||
{
|
{
|
||||||
return strtolower($tag->getName());
|
return strtolower(is_string($tag) ? $tag : $tag->getName());
|
||||||
};
|
};
|
||||||
|
|
||||||
$tagsNotToCreate = [];
|
$tagsNotToCreate = [];
|
||||||
|
@ -105,6 +105,12 @@ class TagService
|
||||||
if (isset($tagsNotToCreate[$tagNameGetter($tag)]))
|
if (isset($tagsNotToCreate[$tagNameGetter($tag)]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (is_string($tag))
|
||||||
|
{
|
||||||
|
$tagName = $tag;
|
||||||
|
$tag = new Tag();
|
||||||
|
$tag->setName($tagName);
|
||||||
|
}
|
||||||
$tag->setCreationTime($this->timeService->getCurrentTime());
|
$tag->setCreationTime($this->timeService->getCurrentTime());
|
||||||
$tagsToCreate[$tagNameGetter($tag)] = $tag;
|
$tagsToCreate[$tagNameGetter($tag)] = $tag;
|
||||||
}
|
}
|
||||||
|
@ -169,4 +175,14 @@ class TagService
|
||||||
{
|
{
|
||||||
$tag->setName($newName);
|
$tag->setName($newName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function updateImplications(Tag $tag, array $relatedNames)
|
||||||
|
{
|
||||||
|
$tag->setImpliedTags($this->createTags($relatedNames));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function updateSuggestions(Tag $tag, array $relatedNames)
|
||||||
|
{
|
||||||
|
$tag->setSuggestedTags($this->createTags($relatedNames));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue