* added toolbar to user screen # 56 * added filter for user role in user admin toolbar # 56 * added unit tests for queries # 56
This commit is contained in:
@@ -67,7 +67,7 @@ class BaseQuery
|
||||
*/
|
||||
public function setPage($page)
|
||||
{
|
||||
$this->page = $page;
|
||||
$this->page = (int)$page;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,4 +19,29 @@ namespace AppBundle\Repository\Query;
|
||||
class UserQuery extends BaseQuery implements VisibilityInterface
|
||||
{
|
||||
use VisibilityTrait;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $role;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRole()
|
||||
{
|
||||
return $this->role;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $role
|
||||
* @return UserQuery
|
||||
*/
|
||||
public function setRole($role)
|
||||
{
|
||||
if (strpos($role, 'ROLE_') !== false || $role === null) {
|
||||
$this->role = $role;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +21,26 @@ interface VisibilityInterface
|
||||
const SHOW_VISIBLE = 1;
|
||||
const SHOW_HIDDEN = 0;
|
||||
const SHOW_BOTH = 2;
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function getVisibility();
|
||||
|
||||
/**
|
||||
* @param int $visibility
|
||||
* @return $this
|
||||
*/
|
||||
public function setVisibility($visibility);
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isExclusiveVisibility();
|
||||
|
||||
/**
|
||||
* @param bool $exclusiveVisibility
|
||||
* @return $this
|
||||
*/
|
||||
public function setExclusiveVisibility($exclusiveVisibility);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ trait VisibilityTrait
|
||||
*/
|
||||
public function setVisibility($visibility)
|
||||
{
|
||||
if (in_array($visibility, [self::SHOW_BOTH, self::SHOW_VISIBLE, self::SHOW_HIDDEN])) {
|
||||
if (in_array($visibility, [self::SHOW_BOTH, self::SHOW_VISIBLE, self::SHOW_HIDDEN], true)) {
|
||||
$this->visibility = $visibility;
|
||||
}
|
||||
return $this;
|
||||
|
||||
@@ -57,10 +57,14 @@ class UserRepository extends AbstractRepository
|
||||
->from('AppBundle:User', 'u')
|
||||
->orderBy('u.' . $query->getOrderBy(), $query->getOrder());
|
||||
|
||||
if ($query->getVisibility() === UserQuery::SHOW_VISIBLE) {
|
||||
$qb->andWhere('u.visible = 1');
|
||||
} elseif ($query->getVisibility() === UserQuery::SHOW_HIDDEN) {
|
||||
$qb->andWhere('u.visible = 0');
|
||||
if ($query->getVisibility() == UserQuery::SHOW_VISIBLE) {
|
||||
$qb->andWhere('u.active = 1');
|
||||
} elseif ($query->getVisibility() == UserQuery::SHOW_HIDDEN) {
|
||||
$qb->andWhere('u.active = 0');
|
||||
}
|
||||
|
||||
if ($query->getRole() !== null) {
|
||||
$qb->andWhere('u.roles LIKE :role')->setParameter('role', '%' . $query->getRole() . '%');
|
||||
}
|
||||
|
||||
return $this->getPager($qb->getQuery(), $query->getPage(), $query->getPageSize());
|
||||
|
||||
Reference in New Issue
Block a user