diff options
author | Joas Schilling <coding@schilljs.com> | 2016-10-27 13:26:02 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2016-11-07 16:56:31 +0300 |
commit | dc5c7d2b0420dadbee31d2f2f42bdeb46d92f6a1 (patch) | |
tree | 98cefe997f56df7665067e96c3d483cebec23133 /apps/systemtags/lib | |
parent | 1857e50259e3cedffd9d9c24ce2a47bf08ebf782 (diff) |
First list tags the user used lately
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/systemtags/lib')
-rw-r--r-- | apps/systemtags/lib/Activity/Listener.php | 32 | ||||
-rw-r--r-- | apps/systemtags/lib/Controller/LastUsedController.php | 59 |
2 files changed, 91 insertions, 0 deletions
diff --git a/apps/systemtags/lib/Activity/Listener.php b/apps/systemtags/lib/Activity/Listener.php index 69ba888c4fb..915df0d6594 100644 --- a/apps/systemtags/lib/Activity/Listener.php +++ b/apps/systemtags/lib/Activity/Listener.php @@ -28,6 +28,7 @@ use OCP\App\IAppManager; use OCP\Files\Config\IMountProviderCollection; use OCP\Files\IRootFolder; use OCP\Files\Node; +use OCP\IConfig; use OCP\IGroup; use OCP\IGroupManager; use OCP\IUser; @@ -46,6 +47,8 @@ class Listener { protected $activityManager; /** @var IUserSession */ protected $session; + /** @var IConfig */ + protected $config; /** @var \OCP\SystemTag\ISystemTagManager */ protected $tagManager; /** @var \OCP\App\IAppManager */ @@ -61,6 +64,7 @@ class Listener { * @param IGroupManager $groupManager * @param IManager $activityManager * @param IUserSession $session + * @param IConfig $config * @param ISystemTagManager $tagManager * @param IAppManager $appManager * @param IMountProviderCollection $mountCollection @@ -69,6 +73,7 @@ class Listener { public function __construct(IGroupManager $groupManager, IManager $activityManager, IUserSession $session, + IConfig $config, ISystemTagManager $tagManager, IAppManager $appManager, IMountProviderCollection $mountCollection, @@ -76,6 +81,7 @@ class Listener { $this->groupManager = $groupManager; $this->activityManager = $activityManager; $this->session = $session; + $this->config = $config; $this->tagManager = $tagManager; $this->appManager = $appManager; $this->mountCollection = $mountCollection; @@ -124,6 +130,11 @@ class Listener { $this->activityManager->publish($activity); } } + + + if ($actor !== '' && ($event->getEvent() === ManagerEvent::EVENT_CREATE || $event->getEvent() === ManagerEvent::EVENT_UPDATE)) { + $this->updateLastUsedTags($actor, $event->getTag()); + } } /** @@ -211,6 +222,27 @@ class Listener { $this->activityManager->publish($activity); } } + + if ($actor !== '' && $event->getEvent() === MapperEvent::EVENT_ASSIGN) { + foreach ($tags as $tag) { + $this->updateLastUsedTags($actor, $tag); + } + } + } + + /** + * @param string $actor + * @param ISystemTag $tag + */ + protected function updateLastUsedTags($actor, ISystemTag $tag) { + $lastUsedTags = $this->config->getUserValue($actor, 'systemtags', 'last_used', '[]'); + $lastUsedTags = json_decode($lastUsedTags, true); + + array_unshift($lastUsedTags, $tag->getId()); + array_unique($lastUsedTags); + $lastUsedTags = array_slice($lastUsedTags, 0, 10); + + $this->config->setUserValue($actor, 'systemtags', 'last_used', json_encode($lastUsedTags)); } /** diff --git a/apps/systemtags/lib/Controller/LastUsedController.php b/apps/systemtags/lib/Controller/LastUsedController.php new file mode 100644 index 00000000000..cbd149d75fb --- /dev/null +++ b/apps/systemtags/lib/Controller/LastUsedController.php @@ -0,0 +1,59 @@ +<?php +/** + * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\SystemTags\Controller; + + +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\DataResponse; +use OCP\IConfig; +use OCP\IRequest; +use OCP\IUserSession; + +class LastUsedController extends Controller { + + /** @var IConfig */ + protected $config; + + /** @var IUserSession */ + protected $userSession; + + /** + * @param string $appName + * @param IRequest $request + * @param IConfig $config + * @param IUserSession $userSession + */ + public function __construct($appName, IRequest $request, IConfig $config, IUserSession $userSession) { + parent::__construct($appName, $request); + $this->config = $config; + $this->userSession = $userSession; + } + + /** + * @NoAdminRequired + */ + public function getLastUsedTagIds() { + $lastUsed = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'systemtags', 'last_used', '[]'); + $tagIds = json_decode($lastUsed, true); + return new DataResponse(array_map(function($id) { return (string) $id; }, $tagIds)); + } +} |