/**
* Returns list Role Categories
* @param bool $notEmpty Not empty categories only
* @param bool $checkRoleImages Count roles with no images
* @return array [id => name]
*/
public function listRoleCategories($notEmpty = false, $checkRoleImages = false)
{
$query = "SELECT c.*\n FROM role_categories c ";
$where = "WHERE (c.account_id IS NULL AND c.env_id IS NULL) OR (c.account_id = ? AND (c.env_id IS NULL OR c.env_id = ?)) ";
$args = [$this->user->getAccountId(), $this->environment->id];
if ($notEmpty) {
$query .= "INNER JOIN roles r ON c.id = r.cat_id ";
$where .= "AND (r.client_id IS NULL AND r.env_id IS NULL) OR (r.client_id = ? AND (r.env_id IS NULL OR r.env_id = ?)) ";
$args[] = $this->user->getAccountId();
$args[] = $this->environment->id;
if ($this->request->getScope() == ScopeInterface::SCOPE_ENVIRONMENT && $checkRoleImages) {
$query .= "INNER JOIN role_images ri ON ri.role_id = r.id ";
$where .= "AND ri.platform IN ('" . implode("','", array_keys(self::loadController('Platforms')->getEnabledPlatforms())) . "') ";
}
}
$query .= $where . "\n GROUP BY c.id\n ORDER BY IF(c.account_id OR c.env_id, 1, 0), IF(c.account_id OR c.env_id, c.name, c.id)\n ";
$result = [];
foreach ($this->db->GetAll($query, $args) as $c) {
$category = new RoleCategory();
$category->load($c);
$result[$category->id] = ['id' => $category->id, 'name' => $category->name, 'scope' => $category->getScope()];
}
return $result;
}