function getPermissions()
 {
     trace(__FILE__, 'getPermissions()');
     if (count($this->permissions) == 0) {
         $this->permissions = ProjectUserPermissions::getPermissionsForProjectUser($this);
     }
     return $this->permissions;
 }
 function getPermissionsForProjectUser(ProjectUser $project_user)
 {
     $permissions = array();
     $pups = ProjectUserPermissions::findAll(array('conditions' => '`project_id` = ' . $project_user->getProjectId() . ' and `user_id` = ' . $project_user->getUserId()));
     if (is_array($pups)) {
         foreach ($pups as $pup) {
             $permissions[] = Permissions::getPermissionString($pup->getPermissionId());
         }
     }
     //if
     return $permissions;
 }
Exemple #3
0
 function setProjectPermission(Project $project, $permission_name, $granted) {
   trace(__FILE__, "setProjectPermission(project, $permission_name, $granted):begin");
   $permission_id = Permissions::getPermissionId($permission_name);
   if (!isset($permission_id) || !$permission_id) {
     return false;
   }
   if ($granted) {
     trace(__FILE__, "setProjectPermission(project, $permission_name, $granted):granted");
     $pup = new ProjectUserPermission();
     $pup->setProjectId($project->getId());
     $pup->setUserId($this->getId());
     $pup->setPermissionId($permission_id);
     $pup->save();
   } else {
     $pup = ProjectUserPermissions::findOne(array('conditions' => '`project_id` = '.$project->getId().' and `user_id` = '.$this->getId().' and `permission_id` = '.$permission_id));
     if (isset($pup) && ($pup instanceOf ProjectUserPermission)) {
       $pup->delete();
     } // if
   } // if
 } // setProjectPermission
 /**
  * This function will return paginated result. Result is an array where first element is 
  * array of returned object and second populated pagination object that can be used for 
  * obtaining and rendering pagination data using various helpers.
  * 
  * Items and pagination array vars are indexed with 0 for items and 1 for pagination
  * because you can't use associative indexing with list() construct
  *
  * @access public
  * @param array $arguments Query argumens (@see find()) Limit and offset are ignored!
  * @param integer $items_per_page Number of items per page
  * @param integer $current_page Current page number
  * @return array
  */
 function paginate($arguments = null, $items_per_page = 10, $current_page = 1)
 {
     if (isset($this) && instance_of($this, 'ProjectUserPermissions')) {
         return parent::paginate($arguments, $items_per_page, $current_page);
     } else {
         return ProjectUserPermissions::instance()->paginate($arguments, $items_per_page, $current_page);
         //$instance =& ProjectUserPermissions::instance();
         //return $instance->paginate($arguments, $items_per_page, $current_page);
     }
     // if
 }
 static function removeUserPermissions($permission)
 {
     $user_permissions = ProjectUserPermissions::findAll(array('conditions' => "`permission_id` = '" . $permission->getId() . "'"));
     foreach ($user_permissions as $user_permission) {
         $user_permission->delete();
     }
 }
 /**
  * Clear permission by user
  *
  * @param User $user
  * @return boolean
  */
 static function clearByUser(User $user)
 {
     // project_id 0 means permission outside any project like can manage projects
     ProjectUserPermissions::delete(array('`user_id` = ? AND `project_id` > 0', $user->getId()));
     return self::delete(array('`user_id` = ?', $user->getId()));
 }
 static function removeSource($source)
 {
     $permissions = Permissions::findAll(array('conditions' => "`source` = '" . $source . "'"));
     if (is_array($permissions)) {
         foreach ($permissions as $permission) {
             $userpermissions = ProjectUserPermissions::findAll(array('conditions' => "`permission_id` = '" . $permission->getId() . "'"));
             foreach ($userpermissions as $userpermission) {
                 $userpermission->delete();
             }
             $permission->delete();
         }
         return true;
         // permission already exists
     }
     return false;
     // permission source does not exist
 }
 /**
  * Return manager instance
  *
  * @access protected
  * @param void
  * @return ProjectUsers 
  */
 function manager()
 {
     if (!$this->manager instanceof ProjectUserPermissions) {
         $this->manager = ProjectUserPermissions::instance();
     }
     return $this->manager;
 }