/**
  * Return all the roles in an array and their relations if exists.
  *
  * @param integer $projectId The Project ID.
  *
  * @return array Array with 'id', 'name' and 'users'.
  */
 function getProjectRoleUserPermissions($projectId)
 {
     $roles = array();
     $model = new Phprojekt_Role_Role();
     foreach ($model->fetchAll(null, 'name ASC') as $role) {
         $roles['data'][$role->id] = array();
         $roles['data'][$role->id]['id'] = (int) $role->id;
         $roles['data'][$role->id]['name'] = $role->name;
         $roles['data'][$role->id]['users'] = array();
     }
     $select = Phprojekt::getInstance()->getDb()->select();
     $select->from(array('prup' => 'project_role_user_permissions'), array('roleId' => 'role_id', 'userId' => 'user_id'))->where('prup.project_id = ?', (int) $projectId)->joinLeft(array('u' => 'user'), 'u.id = prup.user_id', array('username', 'firstname', 'lastname'))->order('prup.user_id ASC');
     $display = Phprojekt_User_User::getDisplay();
     foreach ($select->query()->fetchAll(Zend_Db::FETCH_OBJ) as $right) {
         $userDisplay = Phprojekt_User_User::applyDisplay($display, $right);
         $roles['data'][$right->roleId]['users'][] = array('id' => (int) $right->userId, 'display' => $userDisplay);
     }
     return $roles;
 }
 /**
  * Return all the roles in an array and their relations if exists.
  *
  * @param integer $projectId The Project ID.
  *
  * @return array Array with 'id', 'name' and 'users'.
  */
 function getProjectRoleUserPermissions($projectId)
 {
     $roles = array();
     $model = Phprojekt_Loader::getLibraryClass('Phprojekt_Role_Role');
     foreach ($model->fetchAll(null, 'name ASC') as $role) {
         $roles['data'][$role->id] = array();
         $roles['data'][$role->id]['id'] = (int) $role->id;
         $roles['data'][$role->id]['name'] = $role->name;
         $roles['data'][$role->id]['users'] = array();
     }
     $where = sprintf('project_role_user_permissions.project_id = %d', (int) $projectId);
     $order = 'project_role_user_permissions.user_id ASC';
     $select = ' user.username, user.firstname, user.lastname ';
     $join = ' LEFT JOIN user ON user.id = project_role_user_permissions.user_id ';
     $display = Phprojekt_User_User::getDisplay();
     foreach ($this->fetchAll($where, $order, null, null, $select, $join) as $right) {
         $userDisplay = Phprojekt_User_User::applyDisplay($display, $right);
         $roles['data'][$right->roleId]['users'][] = array('id' => (int) $right->userId, 'display' => $userDisplay);
     }
     return $roles;
 }
Exemple #3
0
 /**
  * Test the display
  */
 public function testdisplay()
 {
     $user = new Phprojekt_User_User();
     $this->assertEquals(array('lastname', 'firstname'), $user->getDisplay());
     $user->find(2);
     $this->assertEquals('Solt, Gustavo', $user->applyDisplay(array('lastname', 'firstname'), $user));
     $this->assertEquals('gus, Solt, Gustavo', $user->applyDisplay(array('username', 'lastname', 'firstname'), $user));
     $this->assertEquals('gus', $user->applyDisplay(array('username'), $user));
 }
Exemple #4
0
 /**
  * Test the display
  */
 public function testdisplay()
 {
     $user = new Phprojekt_User_User();
     $this->assertEquals(array('lastname', 'firstname'), $user->getDisplay());
     $user->find(1);
     $this->assertEquals('Mustermann, Max', $user->applyDisplay(array('lastname', 'firstname'), $user));
     $this->assertEquals('Test, Mustermann, Max', $user->applyDisplay(array('username', 'lastname', 'firstname'), $user));
     $this->assertEquals('Test', $user->applyDisplay(array('username'), $user));
 }