Esempio n. 1
0
 /**
  * Load permissions into roles.
  *
  * @param Event $e
  */
 public function loadPermissions(Event $e)
 {
     $rbac = $e->getRbac();
     $builder = new \Doctrine\DBAL\Query\QueryBuilder($this->connection);
     $options = $this->options;
     $builder->select("\n                    p.{$options->getPermissionNameColumn()} AS permission,\n                    r.{$options->getRoleNameColumn()} AS role\n                ")->from($options->getPermissionTable(), 'p')->leftJoin('p', $options->getRoleJoinTable(), 'rp', "rp.{$options->getPermissionJoinColumn()} = p.{$options->getPermissionIdColumn()}")->leftJoin('p', $options->getRoleTable(), 'r', "rp.{$options->getRoleJoinColumn()} = r.{$options->getRoleIdColumn()}");
     foreach ($builder->execute() as $row) {
         if ($rbac->hasRole($row['role'])) {
             $rbac->getRole($row['role'])->addPermission($row['permission']);
         }
     }
 }
Esempio n. 2
0
 public function getRoles()
 {
     // get roles associated with the logged in user
     $builder = new \Doctrine\DBAL\Query\QueryBuilder($this->em->getConnection());
     $builder->select($this->roleIdFieldName, $this->parentRoleFieldName)->from($this->tableName, $this->tableName);
     $result = $builder->execute();
     $roles = array();
     foreach ($result as $row) {
         $roles[] = new Role($row[$this->roleIdFieldName], $row[$this->parentRoleFieldName]);
     }
     return $roles;
 }
Esempio n. 3
0
 public function getResponse()
 {
     $query = new \Doctrine\DBAL\Query\QueryBuilder($this->connection);
     $query->from('response', 'response');
     foreach ($this->context->getParameters() as $filterIdentifier => $values) {
         if (0 === count($values)) {
             continue;
         }
         $filter = $this->filters->getFilter($filterIdentifier);
         $filter->alterQuery($query, $values);
     }
     return $query;
 }
Esempio n. 4
0
 /**
  * Load roles at RBAC creation.
  *
  * @param Event $e
  * @return array
  */
 public function loadRoles(Event $e)
 {
     $builder = new \Doctrine\DBAL\Query\QueryBuilder($this->connection);
     $options = $this->options;
     $builder->select("role.{$options->getNameColumn()} AS name, parent.{$options->getNameColumn()} AS parent")->from($options->getTable(), 'role')->leftJoin('role', $options->getTable(), 'parent', "role.{$options->getJoinColumn()} = parent.{$options->getIdColumn()}");
     $result = $builder->execute();
     $roles = array();
     foreach ($result as $row) {
         $parentName = isset($row['parent']) ? $row['parent'] : 0;
         unset($row['parent']);
         $roles[$parentName][] = $row['name'];
     }
     $this->recursiveRoles($e->getRbac(), $roles);
 }
Esempio n. 5
0
 public function getIdentityRoles()
 {
     $authService = $this->userService->getAuthService();
     if (!$authService->hasIdentity()) {
         // get default/guest role
         return $this->getDefaultRole();
     } else {
         // get roles associated with the logged in user
         $builder = new \Doctrine\DBAL\Query\QueryBuilder($this->em->getConnection());
         $builder->select("linker.role_id")->from($this->tableName, 'linker')->where('linker.user_id = :user_id')->setParameter('user_id', $authService->getIdentity()->getId());
         $result = $builder->execute();
         $roles = array();
         foreach ($result as $row) {
             $roles[] = $row['role_id'];
         }
         return $roles;
     }
 }
Esempio n. 6
0
 public function getRoles()
 {
     // get roles associated with the logged in user
     $builder = new \Doctrine\DBAL\Query\QueryBuilder($this->em->getConnection());
     $builder->select($this->roleIdFieldName, $this->parentRoleFieldName)->from($this->tableName, $this->tableName);
     $rowset = $builder->execute();
     $roles = array();
     // Pass One: Build each object
     foreach ($rowset as $row) {
         $roleId = $row[$this->roleIdFieldName];
         $roles[$roleId] = new Role($roleId, $row[$this->parentRoleFieldName]);
     }
     // Pass Two: Re-inject parent objects to preserve hierarchy
     foreach ($roles as $roleId => $roleObj) {
         $parentRoleObj = $roleObj->getParent();
         if ($parentRoleObj && $parentRoleObj->getRoleId()) {
             $roleObj->setParent($roles[$parentRoleObj->getRoleId()]);
         }
     }
     return array_values($roles);
 }
Esempio n. 7
0
 /**
  * 
  * @param RecordBase|array $object
  * @return string Description
  */
 function update($object)
 {
     if (!$this->primary_keys) {
         Exception::noPrimaryKey();
     }
     $builder = new \Doctrine\DBAL\Query\QueryBuilder($this->getConnection());
     $params = [];
     $param_types = [];
     if (is_object($object)) {
         $object->beforeUpdate();
         $data = $this->fetchDataFromOrmObject($object);
         $types = $this->getTypes();
     } else {
         $data = $object;
     }
     $data_index = 0;
     foreach ($data as $k => $v) {
         $builder->set($k, "?");
         $params[] = $v;
         $param_types[] = isset($types[$data_index]) ? $types[$data_index] : \PDO::PARAM_STR;
     }
     if ($this->where_statement) {
         $builder->where($this->where_statement);
         if ($this->where_params) {
             $params = array_merge($params, $this->where_params);
         }
         if ($this->where_types) {
             $param_types = array_merge($param_types, $this->where_types);
         }
     }
     $builder->setParameters($params, $param_types);
     $builder->update($this->table_name);
     if (is_object($object)) {
         $object->afterUpdate();
     }
     return $builder->execute();
 }