Exemple #1
0
/**
 * Return the current project id as stored in a cookie, in an Array
 * If no cookie exists, the user's default project is returned
 * If the current project is a subproject, the return value will include
 * any parent projects
 * @return array
 */
function helper_get_current_project_trace()
{
    $t_cookie_name = config_get('project_cookie');
    $t_project_id = gpc_get_cookie($t_cookie_name, null);
    if (null === $t_project_id) {
        $t_bottom = current_user_get_pref('default_project');
        $t_parent = $t_bottom;
        $t_project_id = array($t_bottom);
        while (true) {
            $t_parent = project_hierarchy_get_parent($t_parent);
            if (0 == $t_parent) {
                break;
            }
            array_unshift($t_project_id, $t_parent);
        }
    } else {
        $t_project_id = explode(';', $t_project_id);
        $t_bottom = $t_project_id[count($t_project_id) - 1];
    }
    if (!project_exists($t_bottom) || 0 == project_get_field($t_bottom, 'enabled') || !access_has_project_level(VIEWER, $t_bottom)) {
        $t_project_id = array(ALL_PROJECTS);
    }
    return $t_project_id;
}
 /**
  * Get the overall parent project by a given project/subproject
  *
  * @param $project_id
  * @return int
  */
 public function get_main_project_by_hierarchy($project_id)
 {
     if ($project_id != 0) {
         $parent_project = project_hierarchy_get_parent($project_id, false);
         if (project_hierarchy_is_toplevel($project_id)) {
             $parent_project_id = $project_id;
         } else {
             // selected project is subproject
             while (project_hierarchy_is_toplevel($parent_project, false) == false) {
                 $parent_project = project_hierarchy_get_parent($parent_project, false);
                 if (project_hierarchy_is_toplevel($parent_project)) {
                     break;
                 }
             }
             $parent_project_id = $parent_project;
         }
         return $parent_project_id;
     } else {
         return 0;
     }
 }