diff options
Diffstat (limited to 'app/Decorator/ColumnRestrictionCacheDecorator.php')
-rw-r--r-- | app/Decorator/ColumnRestrictionCacheDecorator.php | 59 |
1 files changed, 59 insertions, 0 deletions
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; + } +} |