4
0

update 2023-07-29 08:30:37

This commit is contained in:
Robot 2023-07-29 08:30:37 +02:00
parent cfdb0b906d
commit 6cbfb33301
Signed by: Robot
GPG Key ID: 14DECD44E7E1BB95
3 changed files with 231 additions and 47 deletions

View File

@ -16,10 +16,11 @@ class Tag << (F,LightGreen) >> #Green {
# Update $update
# Linker $linker
+ __construct(Load $load, Insert $insert, ...)
+ set(string $name) : ?array
+ delete(string $tag) : bool
+ create(string $name, ?string $description) : ?array
+ update(string $tag, string $name, ...) : ?array
+ delete(string $tag) : ?array
- get(string $linker, string $name) : ?array
- create(string $linker, string $name) : bool
- createTag(string $linker, string $name, ...) : bool
}
note right of Tag::__construct
@ -34,18 +35,30 @@ note right of Tag::__construct
Linker $linker
end note
note right of Tag::set
Set a tag
note right of Tag::create
Create a tag
since: 2.0.1
return: ?array
end note
note right of Tag::update
Update a tag
since: 2.0.1
return: ?array
arguments:
string $tag
string $name
?string $description
end note
note right of Tag::delete
Delete a tag
since: 2.0.1
return: bool
return: ?array
end note
note right of Tag::get
@ -55,11 +68,16 @@ note right of Tag::get
return: ?array
end note
note right of Tag::create
note right of Tag::createTag
Create a Tag
since: 2.0.1
return: bool
arguments:
string $linker
string $name
?string $description
end note
@enduml

View File

@ -82,14 +82,15 @@ final class Tag
}
/**
* Set a tag
* Create a tag
*
* @param string $name The tag name being created
* @param string $name The tag name being created
* @param string|null $description The tag description being created
*
* @return array|null Array of the tag values on success
* @since 2.0.1
**/
public function set(string $name): ?array
public function create(string $name, ?string $description): ?array
{
// make sure the linker has access
if (($linker = $this->linker->get()) === null)
@ -101,6 +102,7 @@ final class Tag
}
// get tag if it exist
$name = trim($name);
if (($tag = $this->get($linker, $name)) !== null)
{
// publish if not published
@ -111,15 +113,23 @@ final class Tag
];
}
// update the description if it does not match
$description = $description ?? '';
$description = trim($description);
if ($tag->description !== $description && $this->update->value($description, 'description', $tag->id, 'id', 'tag'))
{
$tag->description = $description;
}
$tag->published = 1;
$tag->success = Text::_('COM_GETBIBLE_THE_TAG_WAS_SUCCESSFULLY_SET');
$tag->success = Text::_('COM_GETBIBLE_THE_TAG_WAS_SUCCESSFULLY_REACTIVATED');
return (array) $tag;
}
// create a new tag
elseif ($this->create($linker, $name)
elseif (strlen($name) >= 2 && $this->createTag($linker, $name, $description)
&& ($tag = $this->get($linker, $name)) !== null)
{
$tag->success = Text::_('COM_GETBIBLE_THE_TAG_WAS_SUCCESSFULLY_SET');
$tag->success = Text::_('COM_GETBIBLE_THE_TAG_WAS_SUCCESSFULLY_CREATED');
return (array) $tag;
}
@ -127,35 +137,105 @@ final class Tag
}
/**
* Delete a tag
* Update a tag
*
* @param string $tag The tagged verse GUID value
* @param string $tag The tag GUID value
* @param string $name The tag name being created
* @param string|null $description The tag description being created
*
* @return bool True on success
* @return array|null Array of the tag values on success
* @since 2.0.1
**/
public function delete(string $tag): bool
public function update(string $tag, string $name, ?string $description): ?array
{
// make sure the linker has access
if (($linker = $this->linker->get()) === null)
{
return false;
return [
'error' => Text::_("COM_GETBIBLE_WITHOUT_SELECTING_THE_CORRECT_FAVOURITE_VERSEBR_YOU_CANT_PERFORM_THE_INITIAL_ACTION"),
'access_required' => true
];
}
// get tag if it exist
$name = trim($name);
$tag = trim($tag);
if (($_tag = $this->load->item(['linker' => $linker, 'guid' => $tag], 'tag')) !== null)
{
// publish if not published
if ($_tag->published != 1 && !$this->update->value(1, 'published', $_tag->id, 'id', 'tag'))
{
return [
'error' => Text::_('COM_GETBIBLE_TAG_FOUND_BUT_COULD_NOT_BE_REACTIVATED')
];
}
// update the description if it does not match
$description = $description ?? '';
$description = trim($description);
if ($_tag->description !== $description && $this->update->value($description, 'description', $_tag->id, 'id', 'tag'))
{
$_tag->description = $description;
}
// update the name if it does not match
if (strlen($name) >= 2 && $_tag->name !== $name && $this->update->value($name, 'name', $_tag->id, 'id', 'tag'))
{
$_tag->name = $name;
}
$_tag->published = 1;
$_tag->success = Text::_('COM_GETBIBLE_THE_TAG_WAS_SUCCESSFULLY_UPDATED');
return (array) $_tag;
}
//elseif (($_tag = $this->load->item(['guid' => $tag], 'tag')) !== null)
//{
// we may need to add this
//}
return [
'error' => Text::_("COM_GETBIBLE_THIS_TAG_DOESNT_BELONG_TO_YOU_THUS_YOU_CANNOT_EDIT_IT")
];
}
/**
* Delete a tag
*
* @param string $tag The tagged verse GUID value
*
* @return array|null Array of the message on success
* @since 2.0.1
**/
public function delete(string $tag): ?array
{
// make sure the linker has access
if (($linker = $this->linker->get()) === null)
{
return [
'error' => Text::_("COM_GETBIBLE_WITHOUT_SELECTING_THE_CORRECT_FAVOURITE_VERSEBR_YOU_CANT_PERFORM_THE_INITIAL_ACTION"),
'access_required' => true
];
}
// make sure the linker has access to delete this tag
if (($id = $this->load->value(['guid' => $tag, 'linker' => $linker], 'id', 'tag')) !== null && $id > 0)
if (($id = $this->load->value(['guid' => $tag, 'linker' => $linker], 'id', 'tag')) !== null && $id > 0
&& $this->update->value(-2, 'published', $id, 'id', 'tag'))
{
return $this->update->value(-2, 'published', $id, 'id', 'tag');
return [
'success' => Text::_('COM_GETBIBLE_TAG_SUCCESSFULLY_DELETED')
];
}
return false;
return [
'error' => Text::_("COM_GETBIBLE_THIS_TAG_DOESNT_BELONG_TO_YOU_THUS_YOU_CANNOT_DELETE_IT")
];
}
/**
* Get a tag
*
* @param string $linker The linker GUID value
* @param string $name The tag name
* @param string $linker The linker GUID value
* @param string $name The tag name
*
* @return array|null Array of the tagged verse values on success
* @since 2.0.1
@ -180,15 +260,17 @@ final class Tag
/**
* Create a Tag
*
* @param string $linker The linker GUID value
* @param string $name The tag name
* @param string $linker The linker GUID value
* @param string $name The tag name
* @param string|null $description The tag description being created
*
* @return bool True on success
* @since 2.0.1
**/
private function create(
private function createTag(
string $linker,
string $name
string $name,
?string $description
): bool
{
$guid = (string) GuidHelper::get();
@ -202,6 +284,7 @@ final class Tag
'access' => 0,
'linker' => $linker,
'name' => $name,
'description' => $description ?? '',
'guid' => $guid
], 'tag');
}

View File

@ -53,14 +53,15 @@
}
/**
* Set a tag
* Create a tag
*
* @param string $name The tag name being created
* @param string $name The tag name being created
* @param string|null $description The tag description being created
*
* @return array|null Array of the tag values on success
* @since 2.0.1
**/
public function set(string $name): ?array
public function create(string $name, ?string $description): ?array
{
// make sure the linker has access
if (($linker = $this->linker->get()) === null)
@ -72,6 +73,7 @@
}
// get tag if it exist
$name = trim($name);
if (($tag = $this->get($linker, $name)) !== null)
{
// publish if not published
@ -82,15 +84,23 @@
];
}
// update the description if it does not match
$description = $description ?? '';
$description = trim($description);
if ($tag->description !== $description && $this->update->value($description, 'description', $tag->id, 'id', 'tag'))
{
$tag->description = $description;
}
$tag->published = 1;
$tag->success = Text::_('The tag was successfully set.');
$tag->success = Text::_('The tag was successfully reactivated.');
return (array) $tag;
}
// create a new tag
elseif ($this->create($linker, $name)
elseif (strlen($name) >= 2 && $this->createTag($linker, $name, $description)
&& ($tag = $this->get($linker, $name)) !== null)
{
$tag->success = Text::_('The tag was successfully set.');
$tag->success = Text::_('The tag was successfully created.');
return (array) $tag;
}
@ -98,35 +108,105 @@
}
/**
* Delete a tag
* Update a tag
*
* @param string $tag The tagged verse GUID value
* @param string $tag The tag GUID value
* @param string $name The tag name being created
* @param string|null $description The tag description being created
*
* @return bool True on success
* @return array|null Array of the tag values on success
* @since 2.0.1
**/
public function delete(string $tag): bool
public function update(string $tag, string $name, ?string $description): ?array
{
// make sure the linker has access
if (($linker = $this->linker->get()) === null)
{
return false;
return [
'error' => Text::_("Without selecting the correct favourite verse,<br />you can't perform the initial action."),
'access_required' => true
];
}
// get tag if it exist
$name = trim($name);
$tag = trim($tag);
if (($_tag = $this->load->item(['linker' => $linker, 'guid' => $tag], 'tag')) !== null)
{
// publish if not published
if ($_tag->published != 1 && !$this->update->value(1, 'published', $_tag->id, 'id', 'tag'))
{
return [
'error' => Text::_('Tag found, but could not be reactivated.')
];
}
// update the description if it does not match
$description = $description ?? '';
$description = trim($description);
if ($_tag->description !== $description && $this->update->value($description, 'description', $_tag->id, 'id', 'tag'))
{
$_tag->description = $description;
}
// update the name if it does not match
if (strlen($name) >= 2 && $_tag->name !== $name && $this->update->value($name, 'name', $_tag->id, 'id', 'tag'))
{
$_tag->name = $name;
}
$_tag->published = 1;
$_tag->success = Text::_('The tag was successfully updated.');
return (array) $_tag;
}
//elseif (($_tag = $this->load->item(['guid' => $tag], 'tag')) !== null)
//{
// we may need to add this
//}
return [
'error' => Text::_("This tag doesn't belong to you, thus you cannot edit it.")
];
}
/**
* Delete a tag
*
* @param string $tag The tagged verse GUID value
*
* @return array|null Array of the message on success
* @since 2.0.1
**/
public function delete(string $tag): ?array
{
// make sure the linker has access
if (($linker = $this->linker->get()) === null)
{
return [
'error' => Text::_("Without selecting the correct favourite verse,<br />you can't perform the initial action."),
'access_required' => true
];
}
// make sure the linker has access to delete this tag
if (($id = $this->load->value(['guid' => $tag, 'linker' => $linker], 'id', 'tag')) !== null && $id > 0)
if (($id = $this->load->value(['guid' => $tag, 'linker' => $linker], 'id', 'tag')) !== null && $id > 0
&& $this->update->value(-2, 'published', $id, 'id', 'tag'))
{
return $this->update->value(-2, 'published', $id, 'id', 'tag');
return [
'success' => Text::_('Tag successfully deleted.')
];
}
return false;
return [
'error' => Text::_("This tag doesn't belong to you, thus you cannot delete it.")
];
}
/**
* Get a tag
*
* @param string $linker The linker GUID value
* @param string $name The tag name
* @param string $linker The linker GUID value
* @param string $name The tag name
*
* @return array|null Array of the tagged verse values on success
* @since 2.0.1
@ -151,15 +231,17 @@
/**
* Create a Tag
*
* @param string $linker The linker GUID value
* @param string $name The tag name
* @param string $linker The linker GUID value
* @param string $name The tag name
* @param string|null $description The tag description being created
*
* @return bool True on success
* @since 2.0.1
**/
private function create(
private function createTag(
string $linker,
string $name
string $name,
?string $description
): bool
{
$guid = (string) GuidHelper::get();
@ -173,6 +255,7 @@
'access' => 0,
'linker' => $linker,
'name' => $name,
'description' => $description ?? '',
'guid' => $guid
], 'tag');
}