diff --git a/components/Left/Left.php b/components/Left/Left.php new file mode 100644 index 0000000000..6e5d65e7b9 --- /dev/null +++ b/components/Left/Left.php @@ -0,0 +1,41 @@ +. +// }}} + +namespace Component\Left; + +use App\Core\Event; +use App\Core\Module; +use App\Util\Common; +use Exception; + +class Left extends Module +{ + public function onEndTwigPopulateVars(array &$vars) + { + try { + $user = Common::user(); + if ($user != null) { + $vars['user_nickname'] = $user->getNickname(); + $vars['user_tags'] = $user->getActor()->getSelfTags(); + } + } catch (Exception $e) { + } + return Event::next; + } +} diff --git a/src/Entity/GSActor.php b/src/Entity/GSActor.php index 047964d263..017e5a2e8a 100644 --- a/src/Entity/GSActor.php +++ b/src/Entity/GSActor.php @@ -222,14 +222,14 @@ class GSActor extends Entity return DB::findBy('gsactor_tag', ['tagger' => $this->id, 'tagged' => $this->id]); } - public function setSelfTags(array $tags, array $pt_existing): void + public function setSelfTags(array $tags, array $existing): void { - $tag_existing = F\map($pt_existing, function ($pt) { return $pt->getTag(); }); + $tag_existing = F\map($existing, function ($pt) { return $pt->getTag(); }); $tag_to_add = array_diff($tags, $tag_existing); $tag_to_remove = array_diff($tag_existing, $tags); - $pt_to_remove = F\filter($pt_existing, function ($pt) use ($tag_to_remove) { return in_array($pt->getTag(), $tag_to_remove); }); + $pt_to_remove = F\filter($existing, function ($pt) use ($tag_to_remove) { return in_array($pt->getTag(), $tag_to_remove); }); foreach ($tag_to_add as $tag) { - $pt = new GSActorTag($this->id, $this->id, $tag); + $pt = GSActorTag::create(['tagger' => $this->id, 'tagged' => $this->id, 'tag' => $tag]); DB::persist($pt); } foreach ($pt_to_remove as $pt) { diff --git a/src/Entity/GSActorTag.php b/src/Entity/GSActorTag.php index c2c73c4048..981efc66dc 100644 --- a/src/Entity/GSActorTag.php +++ b/src/Entity/GSActorTag.php @@ -19,6 +19,7 @@ namespace App\Entity; +use App\Core\Entity; use DateTimeInterface; /** @@ -35,7 +36,7 @@ use DateTimeInterface; * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ -class GSActorTag +class GSActorTag extends Entity { // {{{ Autocode diff --git a/templates/left/left.html.twig b/templates/left/left.html.twig index 55b50cff63..af99f93fbe 100644 --- a/templates/left/left.html.twig +++ b/templates/left/left.html.twig @@ -18,12 +18,13 @@

- Your avatar. + Your avatar.
- {{ app.user.username }} + {{ user_nickname }}
- coffee addict - lazy + {% for tag in user_tags %} + {{ tag }} + {% endfor %}