diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-09-18 21:19:48 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-09-18 21:19:48 -0400 |
commit | 3043163747b13ce1942b2e55977cf7c5417021de (patch) | |
tree | 31552d8bfdf3b7a6eedfaded116b863e980f86b4 /app/Decorator | |
parent | 4bc83646b0b15bff9ae55083121f66b7a89e433d (diff) |
Add column restrictions to custom project roles
Diffstat (limited to 'app/Decorator')
-rw-r--r-- | app/Decorator/ColumnMoveRestrictionCacheDecorator.php | 3 | ||||
-rw-r--r-- | app/Decorator/ColumnRestrictionCacheDecorator.php | 59 | ||||
-rw-r--r-- | app/Decorator/ProjectRoleRestrictionCacheDecorator.php | 59 |
3 files changed, 120 insertions, 1 deletions
diff --git a/app/Decorator/ColumnMoveRestrictionCacheDecorator.php b/app/Decorator/ColumnMoveRestrictionCacheDecorator.php index 2a3e9c2a..82140d16 100644 --- a/app/Decorator/ColumnMoveRestrictionCacheDecorator.php +++ b/app/Decorator/ColumnMoveRestrictionCacheDecorator.php @@ -40,7 +40,8 @@ class ColumnMoveRestrictionCacheDecorator /** * Proxy method to get sortable columns * - * @param int $project_id + * @param int $project_id + * @param string $role * @return array|mixed */ public function getSortableColumns($project_id, $role) diff --git a/app/Decorator/ColumnRestrictionCacheDecorator.php b/app/Decorator/ColumnRestrictionCacheDecorator.php new file mode 100644 index 00000000..a615030d --- /dev/null +++ b/app/Decorator/ColumnRestrictionCacheDecorator.php @@ -0,0 +1,59 @@ +<?php + +namespace Kanboard\Decorator; + +use Kanboard\Core\Cache\CacheInterface; +use Kanboard\Model\ColumnRestrictionModel; + +/** + * Class ColumnRestrictionCacheDecorator + * + * @package Kanboard\Decorator + * @author Frederic Guillot + */ +class ColumnRestrictionCacheDecorator +{ + protected $cachePrefix = 'column_restriction:'; + + /** + * @var CacheInterface + */ + protected $cache; + + /** + * @var ColumnRestrictionModel + */ + protected $columnRestrictionModel; + + /** + * ColumnMoveRestrictionDecorator constructor. + * + * @param CacheInterface $cache + * @param ColumnRestrictionModel $columnMoveRestrictionModel + */ + public function __construct(CacheInterface $cache, ColumnRestrictionModel $columnMoveRestrictionModel) + { + $this->cache = $cache; + $this->columnRestrictionModel = $columnMoveRestrictionModel; + } + + /** + * Proxy method to get sortable columns + * + * @param int $project_id + * @param string $role + * @return array|mixed + */ + public function getAllByRole($project_id, $role) + { + $key = $this->cachePrefix.$project_id.$role; + $columnRestrictions = $this->cache->get($key); + + if ($columnRestrictions === null) { + $columnRestrictions = $this->columnRestrictionModel->getAllByRole($project_id, $role); + $this->cache->set($key, $columnRestrictions); + } + + return $columnRestrictions; + } +} diff --git a/app/Decorator/ProjectRoleRestrictionCacheDecorator.php b/app/Decorator/ProjectRoleRestrictionCacheDecorator.php new file mode 100644 index 00000000..a6e24048 --- /dev/null +++ b/app/Decorator/ProjectRoleRestrictionCacheDecorator.php @@ -0,0 +1,59 @@ +<?php + +namespace Kanboard\Decorator; + +use Kanboard\Core\Cache\CacheInterface; +use Kanboard\Model\ProjectRoleRestrictionModel; + +/** + * Class ProjectRoleRestrictionCacheDecorator + * + * @package Kanboard\Decorator + * @author Frederic Guillot + */ +class ProjectRoleRestrictionCacheDecorator +{ + protected $cachePrefix = 'project_restriction:'; + + /** + * @var CacheInterface + */ + protected $cache; + + /** + * @var ProjectRoleRestrictionModel + */ + protected $projectRoleRestrictionModel; + + /** + * ColumnMoveRestrictionDecorator constructor. + * + * @param CacheInterface $cache + * @param ProjectRoleRestrictionModel $projectRoleRestrictionModel + */ + public function __construct(CacheInterface $cache, ProjectRoleRestrictionModel $projectRoleRestrictionModel) + { + $this->cache = $cache; + $this->projectRoleRestrictionModel = $projectRoleRestrictionModel; + } + + /** + * Proxy method to get sortable columns + * + * @param int $project_id + * @param string $role + * @return array|mixed + */ + public function getAllByRole($project_id, $role) + { + $key = $this->cachePrefix.$project_id.$role; + $projectRestrictions = $this->cache->get($key); + + if ($projectRestrictions === null) { + $projectRestrictions = $this->projectRoleRestrictionModel->getAllByRole($project_id, $role); + $this->cache->set($key, $projectRestrictions); + } + + return $projectRestrictions; + } +} |