Esempio n. 1
0
 /**
  * Filter action
  *
  * This action is called through ajax on filter change like tags & order
  *
  * @access public
  * @return void
  *
  * @author Ole Aass <*****@*****.**>
  */
 public function filterAction()
 {
     if ($this->request->isPost() && $this->request->isAjax()) {
         $tags = $this->request->getPost('tags');
         $currentPage = $this->request->getPost('page', 'int');
         $counter = $this->request->getPost('counter', 'int');
         $projects = new Projects();
         if (empty($tags)) {
             $list = $projects->findAll();
         } else {
             $tags = array_keys($tags);
             $list = $projects->findByTags($tags);
         }
         $page = $projects->paginate($list, $currentPage, $counter);
         $page->counter = $counter;
         $this->view->setVar('page', $page);
         $this->view->partial('index/projects');
     }
 }
Esempio n. 2
0
 /**
  * Return all completed projects
  *
  * @param void
  * @return null
  */
 function getCompletedProjects()
 {
     if (is_null($this->completed_projects)) {
         if ($this->isOwner()) {
             $this->completed_projects = Projects::findAll(array('conditions' => '`completed_on` > ' . DB::escape(EMPTY_DATETIME)));
             // findAll
         } else {
             $this->completed_projects = ProjectCompanies::getProjectsByCompany($this, '`completed_on` > ' . DB::escape(EMPTY_DATETIME));
         }
         // if
     }
     // if
     return $this->completed_projects;
 }
Esempio n. 3
0
 /**
  * Return all projects this user can access
  *
  * @param void
  * @return array
  */
 function getProjects()
 {
     if ($this->projects === false) {
         if ($this->isAdministrator() || $this->isProjectManager()) {
             $this->projects = Projects::findAll();
         } else {
             $this->projects = Projects::findByUser($this);
         }
         // if
     }
     // if
     return $this->projects;
 }
Esempio n. 4
0
 /**
  * Return all projects
  *
  * @param void
  * @return array
  */
 static function getAll($order_by = self::ORDER_BY_NAME)
 {
     return Projects::findAll(array('order' => $order_by));
     // findAll
 }
Esempio n. 5
0
 /**
  * returns first level child workspaces sorted by name
  * @param $active
  * @param $user
  * @param $allLevels
  * @return unknown_type
  */
 function getSubWorkspacesSorted($active = false, $user = null)
 {
     $allLevels = false;
     $key = ($active ? "active" : "closed") . "_" . ($user instanceof User ? $user->getId() : 0) . "_" . ($allLevels ? 'all' : 'single');
     if (!array_var($this->subWScache, $key)) {
         $depth = $this->getDepth();
         $conditions = array("id != " . $this->getId() . " AND `p" . $depth . "` = ?", $this->getId());
         if (!$allLevels && $depth < 9) {
             $conditions[0] .= ' AND `p' . ($depth + 2) . '` = 0 ';
         }
         if ($active) {
             $conditions[0] .= ' AND `completed_on` = ? ';
             $conditions[] = EMPTY_DATETIME;
         }
         if ($user instanceof User && !can_manage_workspaces($user)) {
             $pu_tbl = ProjectUsers::instance()->getTableName(true);
             $conditions[0] .= " AND `id` IN (SELECT `project_id` FROM {$pu_tbl} WHERE `user_id` = ?)";
             $conditions[] = $user->getId();
         }
         $this->subWScache[$key] = Projects::findAll(array('conditions' => $conditions, 'order' => 'name'));
     }
     return $this->subWScache[$key];
 }
Esempio n. 6
0
 /**
  * Return subprojects
  *
  * @access public
  * @param void
  * @return array
  */
 function getSubprojects()
 {
     if (logged_user()->isMemberOfOwnerCompany()) {
         return $this->getAllSubprojects();
     }
     if (is_null($this->subprojects)) {
         $this->subprojects = Projects::findAll(array('conditions' => array('`parent_id` = ?', $this->getId()), 'order' => 'name'));
         // findAll
     }
     // if
     return $this->subprojects;
 }
Esempio n. 7
0
 function getProjectFromPath($path, User $user = null)
 {
     $parents = explode("/", $path);
     $length = count($parents);
     // Clean up the array for empty places
     while ($parents[0] == "" && $length > 0) {
         array_shift($parents);
         $length = count($parents);
     }
     while ($length > 0 && $parents[$length - 1] == "") {
         array_pop($parents);
         $length = count($parents);
     }
     if ($length == 0) {
         // ERROR
         return null;
     } else {
         if ($length == 1) {
             // Level one workspace
             $name = $parents[0];
             // Loof for top level project
             $proj = Projects::findOne(array('conditions' => array('p2 = ? and `name` = ?', 0, $name)));
             if (!$proj) {
                 if (!$user instanceof User) {
                     // Not checking permissions and project is not top level, so the path is invalid
                     return null;
                 } else {
                     // User might not have permissions over workspace parent and other ancestors.
                     // This means current user might see workspace $proj in the root while it is really not top level.
                     $projs = Projects::findAll(array('conditions' => array('`name` = ?', $name)));
                     if (!$projs) {
                         //No project by that name
                         return null;
                     } else {
                         // Iterate through all projects with that name
                         foreach ($projs as $ws) {
                             // If $user has no permissions over $ws, it is not what we are looking for
                             if ($user->isProjectUser($ws)) {
                                 $is_candidate_project = true;
                                 // Iterate through all ancestors to check permissions
                                 foreach ($ws->getParentIds(false) as $ancestor_id) {
                                     $ancestor = Projects::findById($ancestor_id);
                                     if ($user->isProjectUser($ancestor)) {
                                         // If user has permission over an ancestor, path is wrong
                                         $is_candidate_project = false;
                                         break;
                                     }
                                     //if
                                 }
                                 //foreach $ancestor
                                 if ($is_candidate_project) {
                                     // No permissions over ancestors
                                     return $ws;
                                 }
                                 // if
                             }
                             // if
                         }
                         // foreach $project
                         // No project by that name should appear in the root
                         return null;
                     }
                 }
             }
             if ($user && (!$user instanceof User || !$user->isProjectUser($proj))) {
                 return null;
             } else {
                 return $proj;
             }
         } else {
             $currentName = array_pop($parents);
             $length = count($parents);
             $new_path = implode("/", $parents);
             $parent = Projects::getProjectFromPath($new_path, $user);
             if ($parent instanceof Project) {
                 $conditions = 'p' . $length . ' = ? and p' . ($length + 2) . ' = ? and `name` = ?';
                 $proj = Projects::findOne(array('conditions' => array($conditions, $parent->getId(), 0, $currentName)));
                 if ($user) {
                     //we are checking permissions
                     if ($proj && $user->isProjectUser($proj)) {
                         // User has permissions over workspace, found!
                         return $proj;
                     } else {
                         // child does not exist, or it exists and user has no permissions
                         // still have to check if there exists a descendant (child of child^n) with that name
                         // If we have permissions over that descendant and have no permissions for WS between, we found a valid WS
                         $conditions = 'p' . $length . ' = ? and `name` = ?';
                         $projs = Projects::findAll(array('conditions' => array($conditions, $parent->getId(), $currentName)));
                         if ($projs) {
                             //Iterate through all projects with that name
                             foreach ($projs as $ws) {
                                 if ($user->isProjectUser($ws)) {
                                     $is_candidate_project = true;
                                     // Iterate through all ancestors to check permissions
                                     $parent_depth = $parent->getDepth();
                                     $ws_depth = $ws->getDepth(false);
                                     $parent_ids = $ws->getParentIds(false);
                                     // Iterate through all descendants of $parent and ancestors of $ws
                                     for ($i = $parent_depth; $i < $ws_depth; $i++) {
                                         $ancestor_id = $parent_ids[$i];
                                         $ancestor = Projects::findById($ancestor_id);
                                         if ($user->isProjectUser($ancestor)) {
                                             // If user has permission over an ancestor, path is wrong
                                             $is_candidate_project = false;
                                             break;
                                         }
                                         //if
                                     }
                                     //foreach $ancestor
                                     if ($is_candidate_project) {
                                         // No permissions over ancestors
                                         return $ws;
                                     }
                                     // if
                                 }
                                 // else: not interested in this project
                             }
                         } else {
                             // There is no project by that name
                             return null;
                         }
                     }
                 } else {
                     //user is null
                     //not checking permissions
                     if (!$proj instanceof Project) {
                         // project not found, wrong path
                         return null;
                     } else {
                         return $proj;
                     }
                 }
                 if (!$proj && $user == null) {
                     return null;
                 }
             } else {
                 return null;
             }
         }
     }
 }