Exemple #1
0
 private function createRole($roleData)
 {
     try {
         $this->throwExceptionIfNotAvailableType($roleData['Type']);
         $this->currentClass = User_Service::getClassNameForType($roleData['Type']);
         $class = $this->currentClass;
         $oldRoleId = $roleData['Id'];
         $oldRoleParentId = $roleData['ParentId'];
         $roleName = $roleData['Name'];
         $parentId = $this->rolesMap[$oldRoleParentId] > 0 ? $this->rolesMap[$oldRoleParentId] : $this->rootId;
         if ($this->getAllowReplace() === true) {
             $this->deleteRoleIfExist($roleData);
         }
         $role = $class::create(array('name' => $roleName, 'parentId' => $parentId));
         $this->rolesMap[$oldRoleId] = $role->getId();
         foreach ($roleData as $property => $value) {
             if ($this->isAvailableProperty($property, $role) === false) {
                 continue;
             }
             $parseValue = $this->parseValue($value, $property, $role->getId());
             self::l('hola');
             $role->{'set' . $property}($parseValue);
         }
         $role->save();
     } catch (Exception $ex) {
         self::l($ex);
         throw $ex;
     }
 }
 public function addAction()
 {
     try {
         $className = User_Service::getClassNameForType($this->_getParam("type"));
         $user = $className::create(array("parentId" => intval($this->_getParam("parentId")), "name" => $this->_getParam("name"), "password" => md5(microtime()), "active" => $this->_getParam("active")));
         $this->_helper->json(array("success" => true, "id" => $user->getId()));
     } catch (Exception $e) {
         $this->_helper->json(array("success" => false, "message" => $e->getMessage()));
     }
     $this->_helper->json(false);
 }
 /**
  * @param integer $id
  * @return User
  */
 public static function getById($id)
 {
     try {
         $user = new static();
         $user->getResource()->getById($id);
         if (get_class($user) == "User_Abstract") {
             $className = User_Service::getClassNameForType($user->getType());
             $user = $className::getById($user->getId());
         }
         return $user;
     } catch (Exception $e) {
         return false;
     }
 }
 /**
  * Loads a list of users for the specifies parameters, returns an array of User elements
  * @return array
  */
 public function load()
 {
     $items = array();
     $usersData = $this->db->fetchAll("SELECT id,type FROM users" . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables());
     foreach ($usersData as $userData) {
         $className = User_Service::getClassNameForType($userData["type"]);
         $item = $className::getById($userData["id"]);
         if ($item) {
             $items[] = $item;
         }
     }
     $this->model->setItems($items);
     return $items;
 }