看板初始化提交
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Decorator;
|
||||
|
||||
use Kanboard\Core\Cache\CacheInterface;
|
||||
use Kanboard\Model\ColumnMoveRestrictionModel;
|
||||
|
||||
/**
|
||||
* Class ColumnMoveRestrictionCacheDecorator
|
||||
*
|
||||
* @package Kanboard\Decorator
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class ColumnMoveRestrictionCacheDecorator
|
||||
{
|
||||
protected $cachePrefix = 'column_move_restriction:';
|
||||
|
||||
/**
|
||||
* @var CacheInterface
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* @var ColumnMoveRestrictionModel
|
||||
*/
|
||||
protected $columnMoveRestrictionModel;
|
||||
|
||||
/**
|
||||
* ColumnMoveRestrictionDecorator constructor.
|
||||
*
|
||||
* @param CacheInterface $cache
|
||||
* @param ColumnMoveRestrictionModel $columnMoveRestrictionModel
|
||||
*/
|
||||
public function __construct(CacheInterface $cache, ColumnMoveRestrictionModel $columnMoveRestrictionModel)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
$this->columnMoveRestrictionModel = $columnMoveRestrictionModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy method to get sortable columns
|
||||
*
|
||||
* @param int $project_id
|
||||
* @param string $role
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function getSortableColumns($project_id, $role)
|
||||
{
|
||||
$key = $this->cachePrefix.$project_id.$role;
|
||||
$columnIds = $this->cache->get($key);
|
||||
|
||||
if ($columnIds === null) {
|
||||
$columnIds = $this->columnMoveRestrictionModel->getSortableColumns($project_id, $role);
|
||||
$this->cache->set($key, $columnIds);
|
||||
}
|
||||
|
||||
return $columnIds;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Decorator;
|
||||
|
||||
use Kanboard\Core\Cache\CacheInterface;
|
||||
use Kanboard\Model\MetadataModel;
|
||||
|
||||
/**
|
||||
* Class MetadataCacheDecorator
|
||||
*
|
||||
* @package Kanboard\Decorator
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class MetadataCacheDecorator
|
||||
{
|
||||
/**
|
||||
* @var CacheInterface
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* @var MetadataModel
|
||||
*/
|
||||
protected $metadataModel;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $cachePrefix;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $entityId;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CacheInterface $cache
|
||||
* @param MetadataModel $metadataModel
|
||||
* @param string $cachePrefix
|
||||
* @param integer $entityId
|
||||
*/
|
||||
public function __construct(CacheInterface $cache, MetadataModel $metadataModel, $cachePrefix, $entityId)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
$this->metadataModel = $metadataModel;
|
||||
$this->cachePrefix = $cachePrefix;
|
||||
$this->entityId = $entityId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get metadata value by key
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key, $default)
|
||||
{
|
||||
$metadata = $this->cache->get($this->getCacheKey());
|
||||
|
||||
if ($metadata === null) {
|
||||
$metadata = $this->metadataModel->getAll($this->entityId);
|
||||
$this->cache->set($this->getCacheKey(), $metadata);
|
||||
}
|
||||
|
||||
return isset($metadata[$key]) ? $metadata[$key] : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set new metadata value
|
||||
*
|
||||
* @param $key
|
||||
* @param $value
|
||||
*/
|
||||
public function set($key, $value)
|
||||
{
|
||||
$this->metadataModel->save($this->entityId, array(
|
||||
$key => $value,
|
||||
));
|
||||
|
||||
$metadata = $this->metadataModel->getAll($this->entityId);
|
||||
$this->cache->set($this->getCacheKey(), $metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cache key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getCacheKey()
|
||||
{
|
||||
return $this->cachePrefix.$this->entityId;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Decorator;
|
||||
|
||||
use Kanboard\Core\Cache\CacheInterface;
|
||||
use Kanboard\Model\UserModel;
|
||||
|
||||
/**
|
||||
* Class UserCacheDecorator
|
||||
*
|
||||
* @package Kanboard\Decorator
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class UserCacheDecorator
|
||||
{
|
||||
protected $cachePrefix = 'user_model:';
|
||||
|
||||
/**
|
||||
* @var CacheInterface
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* @var UserModel
|
||||
*/
|
||||
private $userModel;
|
||||
|
||||
/**
|
||||
* UserCacheDecorator constructor.
|
||||
*
|
||||
* @param CacheInterface $cache
|
||||
* @param UserModel $userModel
|
||||
*/
|
||||
public function __construct(CacheInterface $cache, UserModel $userModel)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
$this->userModel = $userModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific user by the username
|
||||
*
|
||||
* @access public
|
||||
* @param string $username Username
|
||||
* @return array
|
||||
*/
|
||||
public function getByUsername($username)
|
||||
{
|
||||
$key = $this->cachePrefix.$username;
|
||||
$user = $this->cache->get($key);
|
||||
|
||||
if ($user === null) {
|
||||
$user = $this->userModel->getByUsername($username);
|
||||
$this->cache->set($key, $user);
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user