Example #1
0
 /**
  * Populate the planning with planned project tasks
  *
  * @since version 0.85
  *
  * @param $options   array of possible options:
  *    - who ID of the user (0 = undefined)
  *    - who_group ID of the group of users (0 = undefined)
  *    - begin Date
  *    - end Date
  *    - color
  *    - event_type_color
  *
  * @return array of planning item
  **/
 static function populatePlanning($options = array())
 {
     global $DB, $CFG_GLPI;
     $interv = array();
     $ttask = new self();
     if (!isset($options['begin']) || $options['begin'] == 'NULL' || !isset($options['end']) || $options['end'] == 'NULL') {
         return $interv;
     }
     if (!isset($options['color'])) {
         $options['color'] = '';
     }
     if (!isset($options['event_type_color'])) {
         $options['event_type_color'] = '';
     }
     $who = $options['who'];
     $who_group = $options['who_group'];
     $begin = $options['begin'];
     $end = $options['end'];
     // Get items to print
     $ASSIGN = "";
     if ($who_group === "mine") {
         if (count($_SESSION["glpigroups"])) {
             $groups = implode("','", $_SESSION['glpigroups']);
             $ASSIGN = "`glpi_projecttaskteams`.`itemtype` = 'Group'\n                       AND `glpi_projecttaskteams`.`items_id`\n                           IN (SELECT DISTINCT `groups_id`\n                               FROM `glpi_groups`\n                               WHERE `groups_id` IN ('{$groups}')\n                                     AND `glpi_groups`.`is_assign`)\n                                     AND ";
         } else {
             // Only personal ones
             $ASSIGN = "`glpi_projecttaskteams`.`itemtype` = 'User'\n                       AND `glpi_projecttaskteams`.`items_id` = '{$who}'\n                       AND ";
         }
     } else {
         if ($who > 0) {
             $ASSIGN = "`glpi_projecttaskteams`.`itemtype` = 'User'\n                       AND `glpi_projecttaskteams`.`items_id` = '{$who}'\n                       AND ";
         }
         if ($who_group > 0) {
             $ASSIGN = "`glpi_projecttaskteams`.`itemtype` = 'Group'\n                       AND `glpi_projecttaskteams`.`items_id`\n                           IN ('{$who_group}')\n                       AND ";
         }
     }
     if (empty($ASSIGN)) {
         $ASSIGN = "`glpi_projecttaskteams`.`itemtype` = 'User'\n                       AND `glpi_projecttaskteams`.`items_id`\n                        IN (SELECT DISTINCT `glpi_profiles_users`.`users_id`\n                            FROM `glpi_profiles`\n                            LEFT JOIN `glpi_profiles_users`\n                                 ON (`glpi_profiles`.`id` = `glpi_profiles_users`.`profiles_id`)\n                            WHERE `glpi_profiles`.`interface` = 'central' " . getEntitiesRestrictRequest("AND", "glpi_profiles_users", '', $_SESSION["glpiactive_entity"], 1) . ")\n                     AND ";
     }
     $query = "SELECT `glpi_projecttasks`.*\n                FROM `glpi_projecttaskteams`\n                INNER JOIN `glpi_projecttasks`\n                  ON (`glpi_projecttasks`.`id` = `glpi_projecttaskteams`.`projecttasks_id`)\n                WHERE {$ASSIGN}\n                      '{$begin}' < `glpi_projecttasks`.`plan_end_date`\n                      AND '{$end}' > `glpi_projecttasks`.`plan_start_date`\n                ORDER BY `glpi_projecttasks`.`plan_start_date`";
     $result = $DB->query($query);
     $interv = array();
     $task = new self();
     if ($DB->numrows($result) > 0) {
         for ($i = 0; $data = $DB->fetch_assoc($result); $i++) {
             if ($task->getFromDB($data["id"])) {
                 $key = $data["plan_start_date"] . "\$\$\$" . "ProjectTask" . "\$\$\$" . $data["id"];
                 $interv[$key]['color'] = $options['color'];
                 $interv[$key]['event_type_color'] = $options['event_type_color'];
                 $interv[$key]['itemtype'] = 'ProjectTask';
                 $interv[$key]["url"] = $CFG_GLPI["root_doc"] . "/front/project.form.php?id=" . $task->fields['projects_id'];
                 $interv[$key]["ajaxurl"] = $CFG_GLPI["root_doc"] . "/ajax/planning.php" . "?action=edit_event_form" . "&itemtype=ProjectTask" . "&id=" . $data['id'] . "&url=" . $interv[$key]["url"];
                 $interv[$key][$task->getForeignKeyField()] = $data["id"];
                 $interv[$key]["id"] = $data["id"];
                 $interv[$key]["users_id"] = $data["users_id"];
                 if (strcmp($begin, $data["plan_start_date"]) > 0) {
                     $interv[$key]["begin"] = $begin;
                 } else {
                     $interv[$key]["begin"] = $data["plan_start_date"];
                 }
                 if (strcmp($end, $data["plan_end_date"]) < 0) {
                     $interv[$key]["end"] = $end;
                 } else {
                     $interv[$key]["end"] = $data["plan_end_date"];
                 }
                 $interv[$key]["name"] = $task->fields["name"];
                 $interv[$key]["content"] = Html::resume_text($task->fields["content"], $CFG_GLPI["cut"]);
                 $interv[$key]["status"] = $task->fields["percent_done"];
                 $ttask->getFromDB($data["id"]);
                 $interv[$key]["editable"] = $ttask->canUpdateItem();
             }
         }
     }
     return $interv;
 }