/**
  * Список всех ролей, которыми пользователь обладает
  *
  * @return CArrayList
  */
 public function getRoles()
 {
     if (is_null($this->_roles)) {
         $this->_roles = new CArrayList();
         // сначала глянем, в какие группы входит пользователь и какие роли он получил от них
         foreach ($this->getGroups()->getItems() as $group) {
             foreach ($group->getRoles()->getItems() as $role) {
                 $this->_roles->add($role->getId(), $role);
             }
         }
         // теперь смотрим, какие личные права он имеет
         if (!is_null($this->getId())) {
             foreach (CActiveRecordProvider::getWithCondition(TABLE_USER_HAS_ROLES, "user_id=" . $this->getId())->getItems() as $ar) {
                 $role = CStaffManager::getUserRole($ar->getItemValue("task_id"));
                 if (!is_null($role)) {
                     $role->level = $ar->getItemValue("task_rights_id");
                     /**
                     * Можно запретить доступ пользователю к конкретной задаче
                     
                                             if ($role->level == ACCESS_LEVEL_NO_ACCESS) {
                        $role->level = ACCESS_LEVEL_READ_OWN_ONLY;
                                             }
                     */
                     $this->_roles->add($role->getId(), $role);
                 }
             }
         }
     }
     return $this->_roles;
 }
 public function actionEdit()
 {
     /**
      * Собираем форму для редактирования
      */
     $form = new CUserForm();
     $user = CStaffManager::getUser(CRequest::getInt("id"));
     $form->user = $user;
     /**
      * Получаем список групп
      */
     $groups = array();
     foreach (CStaffManager::getAllUserGroups()->getItems() as $group) {
         $groups[$group->getId()] = $group->comment;
     }
     /**
      * Получаем список ролей, полученных от участия
      * в группах
      */
     $fromGroups = array();
     foreach ($user->getGroups()->getItems() as $group) {
         foreach ($group->getRoles()->getItems() as $role) {
             $fromGroups[$role->getId()] = $group->comment;
         }
     }
     /**
      * Исключаем оттуда личные права
      */
     foreach (CActiveRecordProvider::getWithCondition(TABLE_USER_HAS_ROLES, "user_id=" . $user->getId())->getItems() as $ar) {
         $role = CStaffManager::getUserRole($ar->getItemValue("task_id"));
         if (!is_null($role)) {
             if (array_key_exists($role->getId(), $fromGroups)) {
                 unset($fromGroups[$role->getId()]);
             }
         }
     }
     /**
      * Все передаем в представление
      */
     $this->setData("fromGroups", json_encode($fromGroups));
     $this->setData("groups", $groups);
     $this->setData("form", $form);
     $this->renderView("_users/users/edit.tpl");
 }
 /**
  * Роли, которые связаны с данной группой
  *
  * @return CArrayList
  */
 public function getRoles()
 {
     if (is_null($this->_roles)) {
         $this->_roles = new CArrayList();
         if (!is_null($this->getId())) {
             foreach (CActiveRecordProvider::getWithCondition(TABLE_USER_GROUP_HAS_ROLES, "user_group_id=" . $this->getId())->getItems() as $ar) {
                 $role = CStaffManager::getUserRole($ar->getItemValue("task_id"));
                 if (!is_null($role)) {
                     $role->level = $ar->getItemValue("task_rights_id");
                     if ($role->level == ACCESS_LEVEL_NO_ACCESS) {
                         $role->level = ACCESS_LEVEL_READ_OWN_ONLY;
                     }
                     $this->_roles->add($role->getId(), $role);
                 }
             }
         }
     }
     return $this->_roles;
 }
 public function actionDelete()
 {
     $task = CStaffManager::getUserRole(CRequest::getInt("id"));
     $task->remove();
     $this->redirect("?action=index");
 }
 /**
  * Лист ролей, которыми должен обладать пользователь, чтобы
  * видеть данный пункт меню (как минимум, одной)
  *
  * @return CArrayList
  */
 public function getRoles()
 {
     if (is_null($this->_roles)) {
         if (!CApp::getApp()->cache->hasCache("menu_item_access_" . $this->getId())) {
             $this->_roles = new CArrayList();
             foreach (CActiveRecordProvider::getWithCondition(TABLE_MENU_ITEMS_ACCESS, "item_id = " . $this->getId())->getItems() as $item) {
                 $role = CStaffManager::getUserRole($item->getItemValue("role_id"));
                 if (!is_null($role)) {
                     $this->_roles->add($role->getId(), $role);
                 }
             }
             CApp::getApp()->cache->set("menu_item_access_" . $this->getId(), $this->_roles, 300);
         }
         $this->_roles = CApp::getApp()->cache->get("menu_item_access_" . $this->getId());
     }
     return $this->_roles;
 }