/**
  * @param string $userId
  * @param Website $website
  * @param boolean $isArchivedList - set true to list archived projects
  * @return array - the DTO array
  */
 public static function encode($userId, $website, $isArchivedList = false)
 {
     $user = new UserModel($userId);
     $canListAllProjects = $user->hasRight(Domain::PROJECTS + Operation::VIEW, $website);
     $projectList = new ProjectList_UserModel($website->domain);
     if ($canListAllProjects) {
         $projectList->readAll($isArchivedList);
     } else {
         $projectList->readUserProjects($userId);
     }
     $data = array();
     $data['entries'] = array();
     $count = 0;
     foreach ($projectList->entries as $entry) {
         $project = new ProjectModel($entry['id']);
         $role = ProjectRoles::NONE;
         if (count($project->users) > 0) {
             if (isset($project->users[$userId]) && isset($project->users[$userId]->role)) {
                 $role = $project->users[$userId]->role;
             }
         }
         $entry['role'] = $role;
         if (array_key_exists('ownerRef', $entry) and $entry['ownerRef']) {
             $entry['ownerId'] = $entry['ownerRef']->{'$id'};
         } else {
             $entry['ownerId'] = '';
             // for legacy projects that don't have an owner
         }
         unset($entry['ownerRef']);
         $entry['dateModified'] = $project->dateModified->format(\DateTime::RFC2822);
         $data['entries'][] = $entry;
         $count++;
     }
     $data['count'] = $count;
     // Default sort list on project names
     usort($data['entries'], function ($a, $b) {
         $sortOn = 'projectName';
         if (array_key_exists($sortOn, $a) && array_key_exists($sortOn, $b)) {
             return strtolower($a[$sortOn]) > strtolower($b[$sortOn]) ? 1 : -1;
         } else {
             return 0;
         }
     });
     return $data;
 }
Esempio n. 2
0
 public function listProjects($site)
 {
     $projectList = new ProjectList_UserModel($site);
     $projectList->readUserProjects($this->id->asString());
     return $projectList;
 }
 /**
  * @param string $site
  * @param string $userId
  * @return array - the DTO array
  */
 public static function getActivityForUser($site, $userId)
 {
     $projectList = new ProjectList_UserModel($site);
     $projectList->readUserProjects($userId);
     $activity = array();
     $unreadItems = array();
     foreach ($projectList->entries as $project) {
         $projectModel = new ProjectModel($project['id']);
         $activity = array_merge($activity, self::getActivityForProject($projectModel));
         $unreadItems = array_merge($unreadItems, self::getUnreadActivityForUserInProject($userId, $project['id']));
     }
     $unreadItems = array_merge($unreadItems, self::getGlobalUnreadActivityForUser($userId));
     uasort($activity, array('self', 'sortActivity'));
     $dto = array('activity' => $activity, 'unread' => $unreadItems);
     return $dto;
 }