Beispiel #1
0
 /**
  * getIssues($project=false)
  */
 static function getAll($args = array())
 {
     global $auth;
     $prefix = confGet('DB_TABLE_PREFIX');
     ### default params ###
     $order_by = "";
     $visible_only = true;
     # use project rights settings
     $alive_only = true;
     # ignore deleted
     $project = NULL;
     $search = NULL;
     ### filter params ###
     if ($args) {
         foreach ($args as $key => $value) {
             if (!isset(${$key}) && !is_null(${$key}) && !${$key} === "") {
                 trigger_error("unknown parameter", E_USER_NOTICE);
             } else {
                 ${$key} = $value;
             }
         }
     }
     $dbh = new DB_Mysql();
     $str_is_alive = $alive_only ? 'AND i.state=' . ITEM_STATE_OK : '';
     $AND_match = $search ? "AND (MATCH (iss.plattform,iss.os,iss.version,iss.production_build,iss.steps_to_reproduce,iss.expected_result,iss.suggested_solution) AGAINST ('" . asMatchString($search) . "*' IN BOOLEAN MODE))" : "";
     $AND_project1 = $project ? 'AND upp.project=' . intval($project) : '';
     $AND_project2 = $project ? 'AND i.project=' . intval($project) : '';
     if ($visible_only) {
         $str_query = "SELECT i.*, iss.* from {$prefix}item i, {$prefix}issue iss, {$prefix}projectperson upp\r\n            WHERE\r\n                    upp.person = {$auth->cur_user->id}\r\n                {$AND_project1}\r\n                AND upp.state = 1\r\n\r\n                AND i.type = '" . ITEM_ISSUE . "'\r\n                AND i.project = upp.project\r\n                {$AND_project2}\r\n                {$str_is_alive}\r\n                AND ( i.pub_level >= upp.level_view\r\n                      OR\r\n                      i.created_by = {$auth->cur_user->id}\r\n                )\r\n\r\n                AND iss.id = i.id\r\n                {$AND_match}\r\n           ";
     } else {
         $str_query = "SELECT i.*, iss.* from {$prefix}item i, {$prefix}issue iss\r\n            WHERE\r\n                    i.type = '" . ITEM_ISSUE . "'\r\n                {$AND_project2}\r\n                {$str_is_alive}\r\n\r\n                AND iss.id = i.id\r\n                {$AND_match}\r\n            ";
     }
     $sth = $dbh->prepare($str_query);
     $sth->execute("", 1);
     $tmp = $sth->fetchall_assoc();
     $issues = array();
     foreach ($tmp as $n) {
         $issue = new Issue($n);
         $issues[] = $issue;
     }
     return $issues;
 }
Beispiel #2
0
 /**
  * return tasks of project
  *
  *
  *
  * @params
  *   show_folders=true,
  *   order_by=NULL,
  *   status_min=2,
  *   status_max=4,
  *   visible_only=true,
  *   alive_only=true,
  *   parent_task=NULL)  # if NULL parent-task is ignored
  */
 static function getAll($args = NULL)
 {
     global $auth;
     $prefix = confGet('DB_TABLE_PREFIX');
     ### default params ###
     $project = NULL;
     $show_folders = true;
     $order_by = "is_folder DESC, parent_task, prio ASC,project,name";
     $status_min = STATUS_NEW;
     $status_max = STATUS_BLOCKED;
     $visible_only = NULL;
     # use project rights settings
     $alive_only = true;
     # ignore deleted
     $parent_task = NULL;
     #
     $sort_hierarchical = false;
     $use_collapsed = false;
     # by default ignore collapsed folders
     $issues_only = false;
     $folders_only = false;
     $level = 0;
     # hierarchical depth in trees
     $assigned_to_person = 0;
     # skip by default
     $search = NULL;
     $name = NULL;
     $is_milestone = NULL;
     $for_milestone = NULL;
     $resolved_version = NULL;
     $is_released_min = NULL;
     $is_released_max = NULL;
     $id = NULL;
     $modified_by = NULL;
     $not_modified_by = NULL;
     $resolve_reason_min = NULL;
     $category = NULL;
     $category_in = NULL;
     $label = NULL;
     $person = 0;
     $is_news = NULL;
     ### filter params ###
     if ($args) {
         foreach ($args as $key => $value) {
             if (!isset(${$key}) && !is_null(${$key}) && !${$key} === "") {
                 trigger_error("unknown parameter", E_USER_NOTICE);
             } else {
                 ${$key} = $value;
             }
         }
     }
     if ($sort_hierarchical && is_null($parent_task)) {
         $parent_task = 0;
     }
     $str_project = $project ? 'AND upp.project=' . intval($project) : '';
     $str_project2 = $project ? 'AND i.project=' . intval($project) : '';
     $str_is_alive = $alive_only ? 'AND i.state=' . ITEM_STATE_OK : '';
     $str_is_issue = $issues_only ? 'AND t.issue_report!=0' : '';
     $str_is_folder = $show_folders ? '' : 'AND t.is_folder=0';
     $str_modified_by = $modified_by ? 'AND i.modified_by =' . intval($modified_by) : '';
     $str_not_modified_by = $not_modified_by ? 'AND i.modified_by !=' . intval($not_modified_by) : '';
     $str_id = $id ? 'AND t.id=' . intval($id) : '';
     if (!is_null($label)) {
         $str_label = 'AND t.label=' . intval($label);
     } else {
         $str_label = '';
     }
     if (!is_null($is_milestone)) {
         $str_is_milestone = $is_milestone ? 'AND t.is_milestone=1' : 'AND t.is_milestone=0';
     } else {
         $str_is_milestone = '';
     }
     if (!is_null($category)) {
         $str_category = 'AND t.category=' . intval($category);
     } else {
         $str_category = '';
     }
     if (!is_null($category_in)) {
         $clean_array = array();
         foreach ($category_in as $c) {
             $clean_array[] = intval($c);
         }
         $str_category_in = 'AND t.category IN(' . join(",", $clean_array) . ')';
     } else {
         $str_category_in = '';
     }
     if (!is_null($is_news)) {
         $str_is_news = 'AND t.is_news=' . intval($is_news);
     } else {
         $str_is_news = '';
     }
     $str_is_released_min = $is_released_min ? 'AND t.is_released >= ' . intval($is_released_min) : '';
     if ($resolve_reason_min !== NULL) {
         $str_resolve_reason_min = $resolve_reason_min ? 'AND t.resovle_reason >= ' . intval($resolve_reason_min) : '';
     } else {
         $str_reasolve_reason_min = '';
     }
     $str_is_released_max = $is_released_max ? 'AND t.is_released <= ' . intval($is_released_max) : '';
     $str_has_name = $name ? "AND (t.name='" . asSecureString($name) . "' or t.short='" . asSecureString($name) . "')" : "";
     if (!is_null($for_milestone)) {
         $str_for_milestone = 'AND t.for_milestone=' . intval($for_milestone);
     } else {
         $str_for_milestone = '';
     }
     if (!is_null($resolved_version)) {
         $str_resolved_version = 'AND t.resolved_version=' . intval($resolved_version);
     } else {
         $str_resolved_version = '';
     }
     if ($folders_only) {
         $str_is_folder = 'AND t.is_folder=1';
     }
     $str_parent_task = !is_null($parent_task) ? 'AND t.parent_task=' . intval($parent_task) : '';
     $str_match = $search ? "AND MATCH (t.name,t.short,t.description) AGAINST ('" . asMatchString($search) . "*' IN BOOLEAN MODE)" : '';
     $str_person = $person ? $person : $auth->cur_user->id;
     if (is_null($visible_only)) {
         $visible_only = $auth->cur_user && $auth->cur_user->user_rights & RIGHT_VIEWALL ? false : true;
     }
     if ($visible_only) {
         ### only filter assigned to person ###
         if ($assigned_to_person) {
             $str_query = "SELECT i.*, t.* from {$prefix}item i, {$prefix}task t, {$prefix}taskperson tp, {$prefix}projectperson upp, {$prefix}item itp\r\n                WHERE\r\n\r\n                    upp.person = {$auth->cur_user->id}\r\n\t\t\t\t\t/*upp.person = {$str_person}*/\r\n                    {$str_project}\r\n                    AND i.type = '" . ITEM_TASK . "'\r\n                    AND i.project=upp.project\r\n                    {$str_is_alive}\r\n                    {$str_project2}\r\n                    {$str_modified_by}\r\n                    {$str_not_modified_by}\r\n\r\n                    {$str_is_issue}\r\n\r\n                    AND ( i.pub_level >= upp.level_view\r\n                          OR\r\n                          /*i.created_by = {$auth->cur_user->id}*/\r\n\t\t\t\t\t\t  i.created_by = {$str_person}\r\n                    )\r\n\r\n                    AND t.id = i.id\r\n                    {$str_id}\r\n                    {$str_category}\r\n                    {$str_category_in}\r\n                    {$str_is_folder}\r\n                    {$str_is_issue}\r\n                    {$str_label}\r\n                    {$str_parent_task}\r\n                    {$str_has_name}\r\n                    {$str_is_milestone}\r\n                    {$str_is_released_min}\r\n                    {$str_is_released_max}\r\n                    {$str_for_milestone}\r\n                    {$str_resolved_version}\r\n                    {$str_is_news}\r\n                    AND t.status >= " . intval($status_min) . "\r\n                    AND t.status <= " . intval($status_max) . "\r\n\r\n                    AND i.id = tp.task\r\n                           AND tp.person = " . intval($assigned_to_person) . "\r\n                           AND itp.id = tp.id\r\n                           AND itp.state = 1\r\n                           " . "\r\n                    {$str_match}\r\n\r\n                " . getOrderByString($order_by);
         } else {
             $str_query = "SELECT i.*, t.* from {$prefix}item i, {$prefix}task t, {$prefix}projectperson upp\r\n                WHERE\r\n                        /*upp.person = {$auth->cur_user->id}*/\r\n\t\t\t\t\t\tupp.person = {$str_person}\r\n                    {$str_project}\r\n                    AND i.type = '" . ITEM_TASK . "'\r\n                    AND i.project = upp.project\r\n                    {$str_is_alive}\r\n                    {$str_project2}\r\n                    {$str_category}\r\n                    {$str_category_in}\r\n                    {$str_modified_by}\r\n                    {$str_not_modified_by}\r\n                    {$str_is_issue}\r\n                    {$str_is_milestone}\r\n                    {$str_is_released_min}\r\n                    {$str_is_released_max}\r\n                    {$str_for_milestone}\r\n                    {$str_label}\r\n                    {$str_resolved_version}\r\n                    {$str_is_news}\r\n                    AND ( i.pub_level >= upp.level_view\r\n                          OR\r\n                          /*i.created_by = {$auth->cur_user->id}*/\r\n\t\t\t\t\t\t  i.created_by = {$str_person}\r\n                    )\r\n\r\n                    AND t.id = i.id\r\n                    {$str_is_folder}\r\n                    {$str_is_issue}\r\n                    {$str_parent_task}\r\n                    {$str_has_name}\r\n                    {$str_id}\r\n                    AND t.status >= " . intval($status_min) . "\r\n                    AND t.status <= " . intval($status_max) . "\r\n                    {$str_match}\r\n\r\n                " . getOrderByString($order_by);
         }
     } else {
         if ($assigned_to_person) {
             $str_query = "SELECT i.*, t.* from {$prefix}item i, {$prefix}task t, {$prefix}taskperson tp ,{$prefix}item itp\r\n                WHERE\r\n                    i.type = '" . ITEM_TASK . "'\r\n                {$str_project2}\r\n                {$str_is_alive}\r\n                {$str_modified_by}\r\n                {$str_not_modified_by}\r\n\r\n                AND t.id = i.id\r\n                {$str_id}\r\n                {$str_is_folder}\r\n                {$str_is_issue}\r\n                {$str_category}\r\n                {$str_category_in}\r\n                {$str_parent_task}\r\n                {$str_has_name}\r\n                {$str_label}\r\n                {$str_is_milestone}\r\n                {$str_is_released_min}\r\n                {$str_is_released_max}\r\n                {$str_for_milestone}\r\n                {$str_is_news}\r\n                {$str_resolved_version}\r\n                AND t.status >= " . intval($status_min) . "\r\n                AND t.status <= " . intval($status_max) . "\r\n                {$str_match}\r\n                AND i.id = tp.task\r\n                AND tp.person = " . intval($assigned_to_person) . "\r\n                       AND tp.id = itp.id\r\n                       AND itp.state = 1\r\n                " . getOrderByString($order_by);
         } else {
             $str_query = "SELECT i.*, t.* from {$prefix}item i, {$prefix}task t\r\n                WHERE\r\n                    i.type = '" . ITEM_TASK . "'\r\n                {$str_project2}\r\n                {$str_is_alive}\r\n                {$str_modified_by}\r\n                {$str_not_modified_by}\r\n\r\n                AND t.id = i.id\r\n                {$str_category}\r\n                {$str_category_in}\r\n                {$str_id}\r\n                {$str_is_folder}\r\n                {$str_is_issue}\r\n                {$str_is_milestone}\r\n                {$str_for_milestone}\r\n                {$str_label}\r\n                {$str_resolved_version}\r\n                {$str_is_news}\r\n\r\n                {$str_is_released_min}\r\n                {$str_is_released_max}\r\n                {$str_parent_task}\r\n                {$str_has_name}\r\n                AND t.status >= " . intval($status_min) . "\r\n                AND t.status <= " . intval($status_max) . "\r\n                {$str_match}\r\n\r\n                " . getOrderByString($order_by);
         }
     }
     $dbh = new DB_Mysql();
     $sth = $dbh->prepare($str_query);
     $sth->execute("", 1);
     $tmp = $sth->fetchall_assoc();
     $tasks = array();
     foreach ($tmp as $t) {
         $task = new Task($t);
         $task->level = $level;
         $tasks[] = $task;
         ### hierarchical / recursive sorting ###
         if ($sort_hierarchical && $task->is_folder && (!$use_collapsed || !$task->view_collapsed)) {
             if ($sub_tasks = Task::getAll(array('sort_hierarchical' => true, 'use_collapsed' => $use_collapsed, 'parent_task' => $task->id, 'order_by' => $order_by, 'visible_only' => $visible_only, 'alive_only' => $alive_only, 'issues_only' => $issues_only, 'status_min' => $status_min, 'status_max' => $status_max, 'level' => $level + 1, 'folders_only' => $folders_only, 'project' => $project))) {
                 foreach ($sub_tasks as &$st) {
                     $tasks[] = $st;
                 }
             }
         }
     }
     return $tasks;
 }
 public static function getAll($args = NULL)
 {
     global $auth;
     $prefix = confGet('DB_TABLE_PREFIX');
     ### default parameter ###
     $order_str = NULL;
     $has_id = NULL;
     $search = NULL;
     $visible_only = NULL;
     #$comcat=NULL;
     $ccategory_min = CCATEGORY_UNDEFINED;
     $ccategory_max = CCATEGORY_PARTNER;
     ### filter parameter ###
     if ($args) {
         foreach ($args as $key => $value) {
             if (!isset(${$key}) && !is_null(${$key}) && !${$key} === "") {
                 trigger_error("unknown parameter", E_USER_NOTICE);
             } else {
                 ${$key} = $value;
             }
         }
     }
     $str_has_id = $has_id ? 'AND c.id=' . intval($has_id) : '';
     if ($search) {
         $search = asMatchString($search);
         $AND_match = "AND (MATCH (c.name) AGAINST ('" . asMatchString($search) . "*') or MATCH (c.comments) AGAINST ('" . asMatchString($search) . "*'  IN BOOLEAN MODE))";
     } else {
         $AND_match = '';
     }
     /*if(is_null($comcat))
       {
           $str_comcat = '';
       }
       else
       {
           $str_comcat = 'AND c.category=' .intval($comcat);
       }*/
     if (!is_null($ccategory_min) && !is_null($ccategory_max)) {
         $str_ccategory = "AND (c.category BETWEEN " . $ccategory_min . " AND " . $ccategory_max . ")";
     } else {
         $str_ccategory = '';
     }
     ### show all ###
     if ($auth->cur_user->user_rights & RIGHT_COMPANY_VIEWALL) {
         $str = "SELECT c.*, ic.* from {$prefix}company c, {$prefix}item ic\r\n                WHERE\r\n                      c.state = 1\r\n                      {$str_has_id}\r\n                      AND c.id = ic.id\r\n                      {$AND_match}\r\n                      {$str_ccategory} " . getOrderByString($order_str, 'c.name');
     } else {
         $str = "SELECT DISTINCT c.*, ic.* from {$prefix}company c, {$prefix}project p, {$prefix}projectperson upp, {$prefix}item ic\r\n                 WHERE\r\n                        upp.person = {$auth->cur_user->id}\r\n                    AND upp.state = 1         /* upp all user projectpeople */\r\n\r\n                    AND  upp.project = p.id  /* all user projects */\r\n                       AND  p.company = c.id    /* all companies */\r\n                       AND  c.state = 1\r\n                       {$str_has_id}\r\n                         AND c.id = ic.id\r\n\r\n\r\n                      {$AND_match}\r\n                      {$str_ccategory} " . getOrderByString($order_str, 'c.name');
     }
     $companies = self::queryFromDb($str);
     # store in variable to return by reference
     return $companies;
 }
 /**
  * get all open & Visible projects from db
  */
 public static function getAll($args = NULL)
 {
     global $auth;
     $prefix = confGet('DB_TABLE_PREFIX');
     if ($args && !is_array($args)) {
         trigger_error("requires array as parameter", E_USER_WARNING);
         return;
     }
     ### default params ###
     $order_by = "prio, name";
     $status_min = STATUS_UNDEFINED;
     $status_max = STATUS_OPEN;
     $company = NULL;
     $visible_only = $auth->cur_user->user_rights & RIGHT_VIEWALL ? false : true;
     $search = NULL;
     $id = NULL;
     $person = NULL;
     $limit = NULL;
     ### filter params ###
     if ($args) {
         foreach ($args as $key => $value) {
             if (!isset(${$key}) && !is_null(${$key}) && !${$key} === "") {
                 trigger_error("unknown parameter", E_USER_NOTICE);
             } else {
                 ${$key} = $value;
             }
         }
     }
     $AND_id = $id ? 'AND p.id=' . intval($id) : '';
     $AND_match = $search ? "AND (MATCH (p.name,p.status_summary,p.description) AGAINST ('" . asMatchString($search) . "*' IN BOOLEAN MODE))" : '';
     if (!is_null($company)) {
         $AND_company = 'AND p.company=' . intval($company);
     } else {
         $AND_company = "";
     }
     if (!is_null($person)) {
         $AND_person_all_part1 = " {$prefix}projectperson upp, ";
         $AND_person_all_part2 = "AND upp.person = '" . intval($person) . "' \r\n                                     AND upp.state = 1\r\n                                     AND upp.project = p.id";
         $AND_person_visible_part1 = " {$prefix}projectperson upp2, ";
         $AND_person_visible_part2 = "AND upp.project = upp2.project\r\n                                         AND upp2.person = '" . intval($person) . "'";
     } else {
         $AND_person_all_part1 = "";
         $AND_person_all_part2 = "";
         $AND_person_visible_part1 = "";
         $AND_person_visible_part2 = "";
     }
     $str_limit = $limit ? " LIMIT " . intval($limit) . " " : "";
     /**
      * @@@ NOTE: using a distinct select here is not nice...
      */
     ### only assigned projects ###
     if ($visible_only) {
         $str = "SELECT DISTINCT i.*, p.* from {$prefix}item i, {$prefix}projectperson upp, {$AND_person_visible_part1} {$prefix}project p left join {$prefix}company c on p.company = c.id\r\n                WHERE\r\n                    upp.person = '{$auth->cur_user->id}'\r\n                    AND upp.state = 1\r\n                    AND upp.project = p.id\r\n                    {$AND_person_visible_part2}\r\n                    AND   p.status <= " . intval($status_max) . "\r\n                    AND   p.status >= " . intval($status_min) . "\r\n                    AND   p.state = 1\r\n                    AND   i.id = p.id\r\n                    AND (p.company = c.id OR p.company = 0)\r\n                    {$AND_company}\r\n                    {$AND_match}\r\n                    {$AND_id}\r\n                " . getOrderByString($order_by) . $str_limit;
     } else {
         $str = "SELECT DISTINCT i.*, p.* from {$prefix}item i, {$AND_person_all_part1} {$prefix}project p left join {$prefix}company c on p.company = c.id\r\n\r\n                WHERE\r\n                       p.status <= " . intval($status_max) . "\r\n                   AND p.status >= " . intval($status_min) . "\r\n                   AND p.state = 1\r\n                   AND i.id = p.id\r\n                   AND (p.company = 0 OR p.company = c.id)\r\n                  {$AND_company}\r\n                  {$AND_match}\r\n                  {$AND_id}\r\n                  {$AND_person_all_part2}\r\n                " . getOrderByString($order_by) . $str_limit;
     }
     $projects = self::queryFromDb($str);
     return $projects;
 }
 /**
  * return efforts depending on filter options
  * @@@ todo:
  * - refacture status_min/max evaluation only if !is_null
  *
  */
 static function getAll($args = NULL)
 {
     global $auth;
     $prefix = confGet('DB_TABLE_PREFIX');
     ### default params ###
     $project = NULL;
     $person = NULL;
     $order_by = 'e.time_start DESC';
     $visible_only = true;
     # use project rights settings
     $alive_only = true;
     # ignore deleted
     $task = NULL;
     # for a parent task?
     $date_min = NULL;
     $date_max = NULL;
     $search = NULL;
     # search query
     $effort_status_min = NULL;
     $effort_status_max = NULL;
     $effort_time_min = NULL;
     $effort_time_max = NULL;
     ### filter params ###
     if ($args) {
         foreach ($args as $key => $value) {
             if (!isset(${$key}) && !is_null(${$key}) && !${$key} === "") {
                 trigger_error("unknown parameter", E_USER_NOTICE);
             } else {
                 ${$key} = $value;
             }
         }
     }
     $str_project = $project ? 'AND i.project=' . intval($project) : '';
     $str_project2 = $project ? 'AND upp.project=' . intval($project) : '';
     $str_is_alive = $alive_only ? 'AND i.state=' . ITEM_STATE_OK : '';
     $str_date_min = $date_min ? "AND i.modified >= '" . asCleanString($date_min) . "'" : '';
     $str_date_max = $date_max ? "AND i.modified <= ' " . asCleanString($date_max) . "'" : '';
     $str_status_min = $effort_status_min ? "AND e.status >= '" . asCleanString($effort_status_min) . "'" : '';
     $str_status_max = $effort_status_max ? "AND e.status <= ' " . asCleanString($effort_status_max) . "'" : '';
     $str_effort_time_min = $effort_time_min ? "AND e.time_start >= ' " . asCleanString($effort_time_min) . "'" : '';
     $str_effort_time_max = $effort_time_max ? "AND e.time_end <= ' " . asCleanString($effort_time_max) . "'" : '';
     $str_task = !is_null($task) ? 'AND e.task=' . intval($task) : '';
     $str_person = $person ? 'AND e.person=' . intval($person) : '';
     if ($auth->cur_user->user_rights & RIGHT_VIEWALL) {
         $str_projectperson = "";
     } else {
         $str_projectperson = "AND upp.person = {$auth->cur_user->id}";
     }
     $str_match = $search ? "AND MATCH (e.description) AGAINST ('" . asMatchString($search) . "*' IN BOOLEAN MODE)" : '';
     /**
      * note: project p required for sorting
      */
     if ($visible_only) {
         $str_query = "SELECT DISTINCT i.*, e.* from {$prefix}item i, {$prefix}effort e, {$prefix}project p, {$prefix}projectperson upp\r\n            WHERE\r\n\r\n                i.type = '" . ITEM_EFFORT . "'\r\n                {$str_project}\r\n                {$str_projectperson}\r\n                {$str_project2}\r\n                {$str_person}\r\n                {$str_is_alive}\r\n                AND ( i.pub_level >= upp.level_view\r\n                      OR\r\n                      i.created_by = {$auth->cur_user->id}\r\n                )\r\n                AND i.project = p.id\r\n\r\n                AND i.id = e.id\r\n                 {$str_task}\r\n                 {$str_date_max}\r\n                 {$str_date_min}\r\n                 {$str_status_max}\r\n                 {$str_status_min}\r\n                 {$str_effort_time_min}\r\n                 {$str_effort_time_max}\r\n                 {$str_match}\r\n\r\n            " . getOrderByString($order_by);
     } else {
         $str_query = "SELECT i.*, e.* from {$prefix}item i, {$prefix}effort e, {$prefix}project p\r\n            WHERE\r\n                i.type = '" . ITEM_EFFORT . "'\r\n            {$str_project}\r\n            {$str_is_alive}\r\n\r\n            AND i.project = p.id\r\n\r\n            AND i.id = e.id\r\n             {$str_task}\r\n             {$str_date_max}\r\n             {$str_date_min}\r\n             {$str_match}\r\n\r\n            " . getOrderByString($order_by);
     }
     $dbh = new DB_Mysql();
     $sth = $dbh->prepare($str_query);
     $sth->execute("", 1);
     $tmp = $sth->fetchall_assoc();
     $efforts = array();
     foreach ($tmp as $t) {
         $effort = new Effort($t);
         $efforts[] = $effort;
     }
     return $efforts;
 }
 /**
  * getComments($project=false)
  */
 static function getAll($args = array())
 {
     global $auth;
     $prefix = confGet('DB_TABLE_PREFIX');
     require_once confGet('DIR_STREBER') . 'db/class_comment.inc.php';
     ### default params ###
     $order_by = 'c.name';
     $visible_only = true;
     # use project rights settings
     $alive_only = true;
     # ignore deleted
     $project = NULL;
     $task = NULL;
     $person = NULL;
     $date_min = NULL;
     $date_max = NULL;
     $search = NULL;
     $parent_comment = NULL;
     ### filter params ###
     if ($args) {
         foreach ($args as $key => $value) {
             if (!isset(${$key}) && !is_null(${$key}) && !${$key} === "") {
                 trigger_error("unknown parameter", E_USER_NOTICE);
             } else {
                 ${$key} = $value;
             }
         }
     }
     $dbh = new DB_Mysql();
     $str_is_alive = $alive_only ? 'AND i.state=1' : '';
     $AND_person = $person ? 'AND i.created_by=' . intval($person) : '';
     $AND_task = $task ? 'AND c.task=' . intval($task) : '';
     $AND_match = $search ? "AND (MATCH (c.name,c.description) AGAINST ('" . asMatchString($search) . "*'  IN BOOLEAN MODE))" : '';
     $AND_project1 = $project ? "AND upp.project= {$project}" : "";
     $AND_project2 = $project ? "AND i.project= {$project}" : "";
     $AND_date_min = $date_min ? "AND i.modified >= '" . asCleanString($date_min) . "'" : '';
     $AND_date_max = $date_max ? "AND i.modified <= '" . asCleanString($date_max) . "'" : '';
     if (!is_null($parent_comment)) {
         $AND_comment = 'AND c.comment = ' . intval($parent_comment);
     } else {
         $AND_comment = '';
     }
     if ($visible_only) {
         $str_query = "SELECT i.*, c.* from {$prefix}item i, {$prefix}comment c, {$prefix}projectperson upp\r\n            WHERE\r\n                    upp.person = {$auth->cur_user->id}\r\n                {$AND_project1}\r\n                AND upp.state = 1\r\n\r\n                AND i.type = '" . ITEM_COMMENT . "'\r\n                AND i.project = upp.project\r\n                {$AND_project2}\r\n                {$str_is_alive}\r\n                {$AND_person}\r\n                {$AND_date_min}\r\n                {$AND_date_max}\r\n                AND ( i.pub_level >= upp.level_view\r\n                      OR\r\n                      i.created_by = {$auth->cur_user->id}\r\n                )\r\n\r\n                AND c.id = i.id\r\n                {$AND_task}\r\n                {$AND_match}\r\n                {$AND_comment}\r\n\r\n            " . getOrderByString($order_by);
     } else {
         $str_query = "SELECT i.*, c.* from {$prefix}item i, {$prefix}comment c\r\n            WHERE\r\n                    i.type = '" . ITEM_COMMENT . "'\r\n                {$AND_project2}\r\n                {$str_is_alive}\r\n                {$AND_person}\r\n                {$AND_date_min}\r\n                {$AND_date_max}\r\n\r\n                AND c.id = i.id\r\n                {$AND_task}\r\n                {$AND_comment}\r\n                {$AND_match}\r\n\r\n            " . getOrderByString($order_by);
     }
     $sth = $dbh->prepare($str_query);
     $sth->execute("", 1);
     $tmp = $sth->fetchall_assoc();
     $comments = array();
     foreach ($tmp as $n) {
         $comment = new Comment($n);
         $comments[] = $comment;
     }
     return $comments;
 }
Beispiel #7
0
 static function RateTitle($item, $search)
 {
     $rate = 1;
     $strings = array();
     foreach (explode(" ", $search) as $s) {
         if ($s = trim($s)) {
             $s = str_replace('+', '', $s);
             $s = str_replace('*', '', $s);
             $s = asMatchString($s);
             $strings[] = $s;
         }
     }
     if (isset($item->name)) {
         foreach ($strings as $s) {
             if (preg_match("/\\A{$s}\\b/i", $item->name)) {
                 $rate *= RATE_MATCHES_NAME;
             } else {
                 if (preg_match("/\\A{$s}/i", $item->name)) {
                     $rate *= RATE_IN_NAME_START;
                 } else {
                     if (preg_match("/\\b{$s}\\b/i", $item->name)) {
                         $rate *= RATE_MATCHES_NAME_WORD;
                     }
                 }
             }
         }
     }
     if (isset($item->short)) {
         foreach ($strings as $s) {
             if (preg_match("/\\A{$s}\\b/i", $item->short)) {
                 $rate *= RATE_MATCHES_NAME;
             } else {
                 if (preg_match("/\\A{$s}/i", $item->short)) {
                     $rate *= RATE_IN_NAME_START;
                 } else {
                     if (preg_match("/\\b{$s}\\b/i", $item->short)) {
                         $rate *= RATE_MATCHES_NAME_WORD;
                     }
                 }
             }
         }
     }
     return $rate;
 }
 public static function getPeople($args = NULL)
 {
     global $auth;
     $prefix = confGet('DB_TABLE_PREFIX');
     ### default params ###
     $order_by = 'name';
     $visible_only = 'auto';
     #
     $can_login = NULL;
     $id = NULL;
     $search = NULL;
     $identifier = NULL;
     $cookie_string = NULL;
     $project = NULL;
     # all user projects
     $is_alive = true;
     #$perscat            = NULL;
     $pcategory_min = PCATEGORY_UNDEFINED;
     $pcategory_max = PCATEGORY_PARTNER;
     ### filter params ###
     if ($args) {
         foreach ($args as $key => $value) {
             if (!isset(${$key}) && !is_null(${$key}) && !${$key} === "") {
                 trigger_error("unknown parameter", E_USER_NOTICE);
             } else {
                 ${$key} = $value;
             }
         }
     }
     if (!is_null($can_login)) {
         if ($can_login == '0') {
             $str_can_login = "******";
         } else {
             $str_can_login = "******";
         }
     } else {
         $str_can_login = '';
     }
     if (!is_null($project)) {
         $str_project = "p.id";
     } else {
         $str_project = intVal($project);
     }
     $str_id = $id ? 'AND pers.id=' . intval($id) : '';
     $AND_match = $search ? "AND MATCH (pers.name,pers.nickname,pers.tagline,pers.description) AGAINST ('" . asMatchString($search) . "*' IN BOOLEAN MODE)" : "";
     if ($visible_only == 'auto') {
         $visible_only = $auth->cur_user->user_rights & RIGHT_PERSON_VIEWALL || $auth->cur_user->user_rights & RIGHT_VIEWALL ? false : true;
     }
     if (is_null($project)) {
         $str_project = "p.id";
     } else {
         $str_project = intVal($project);
         $visible_only = true;
         # project filtering only works in this mode
     }
     if (is_null($is_alive)) {
         # ignore
         $str_alive = "";
     } else {
         $str_alive = $is_alive ? "AND pers.state=1" : "AND pers.state=-1";
     }
     if (!is_null($pcategory_min) && !is_null($pcategory_max)) {
         $str_pcategory = "AND (pers.category BETWEEN " . $pcategory_min . " AND " . $pcategory_max . ")";
     } else {
         $str_pcategory = '';
     }
     ### all people ###
     if (!$visible_only) {
         $str = "SELECT i.*, pers.* from {$prefix}person pers, {$prefix}item i\r\n                WHERE 1\r\n                    {$str_alive}\r\n                    {$str_id}\r\n                    {$str_can_login}\r\n                    {$str_pcategory}\r\n                    AND i.id = pers.id\r\n                    {$AND_match}\r\n\r\n\r\n               " . getOrderByString($order_by);
     } else {
         $str = "SELECT DISTINCT pers.*, ipers.* from {$prefix}person pers, {$prefix}project p, {$prefix}projectperson upp, {$prefix}projectperson pp, {$prefix}item ipp, {$prefix}item ipers\r\n                WHERE\r\n                        upp.person = {$auth->cur_user->id}\r\n                    AND upp.state = 1           /* upp all user projectpeople */\r\n                    AND upp.project = {$str_project}        /* all user projects */\r\n\r\n                    AND p.state = 1\r\n                    AND p.status > 0              /* ignore templates */\r\n                    AND p.id = pp.project         /* all projectpeople in user's project*/\r\n\r\n                    AND pp.state = 1\r\n                    AND pp.id = ipp.id\r\n\r\n                    AND ( ipp.pub_level >= upp.level_view\r\n                          OR\r\n                          ipp.created_by = {$auth->cur_user->id}\r\n                    )\r\n                    AND  pp.person = pers.id      /* all belonging person*/\r\n                    {$str_alive}\r\n                    {$str_id}\r\n                    {$str_can_login}\r\n                    {$str_pcategory}\r\n                    {$AND_match}\r\n                    AND pers.id = ipers.id\r\n\r\n               " . getOrderByString($order_by);
     }
     $people = self::queryFromDb($str);
     # store in variable to pass by reference
     /**
      * be sure that the current user is listed
      * NOTE:
      * - constructing a query that insures the visibility of the current user
      *   is very complex because this does not depend on existing projects
      */
     if (!$search && $auth && $auth->cur_user && $auth->cur_user->id && (!$id || $id == $auth->cur_user->id) && $is_alive !== false) {
         $flag_user_found = false;
         foreach ($people as $p) {
             if ($p->id == $auth->cur_user->id) {
                 $flag_user_found = true;
                 break;
             }
         }
         if (!$flag_user_found) {
             $people[] = $auth->cur_user;
         }
     }
     return $people;
 }