Exemplo n.º 1
0
 /**
  *
  * @param boolean $hasDetail if true, add [Progress, EffortEstim, Elapsed, Backlog, Drift]
  * @param boolean $isManager
  * @param int $userid
  * @return array
  */
 public function getDynatreeData($hasDetail = false, $isManager = false, $teamid = 0)
 {
     // TODO AND root_id = $this->getRootId()
     $query = "SELECT * FROM `codev_wbs_table` WHERE `parent_id` = " . $this->getId() . " ORDER BY `order`";
     $result = SqlWrapper::getInstance()->sql_query($query);
     //file_put_contents('/tmp/loadWBS.txt', "$query \n", FILE_APPEND);
     if ($result) {
         $parentArray = array();
         while ($row = SqlWrapper::getInstance()->sql_fetch_object($result)) {
             $wbselement = new WBSElement($row->id, $this->getRootId());
             $childArray = array();
             if ($wbselement->isFolder()) {
                 $childArray['isFolder'] = true;
                 $childArray['expand'] = $wbselement->isExpand();
                 $childArray['key'] = $wbselement->getId();
                 $detail = '';
                 if ($hasDetail) {
                     $bugids = $this->getBugidList($wbselement->getId());
                     $isel = new IssueSelection("wbs_" . $wbselement->getId());
                     foreach ($bugids as $bugid) {
                         try {
                             $isel->addIssue($bugid);
                         } catch (Exception $e) {
                             self::$logger->error("Issue {$bugid} does not exist in Mantis DB.");
                         }
                     }
                     if ($isManager) {
                         $effortEstim = $isel->getMgrEffortEstim();
                         $driftInfo = $isel->getDriftMgr();
                         $reestimated = $isel->getReestimated();
                     } else {
                         $effortEstim = $isel->getEffortEstim();
                         $driftInfo = $isel->getDrift();
                         $reestimated = '0';
                     }
                     $detail = '~' . round(100 * $isel->getProgress()) . '~' . $effortEstim . '~' . $reestimated . '~' . $isel->getElapsed() . '~' . $isel->duration . '~' . $driftInfo['nbDays'] . '~' . $isel->getDriftColor($driftInfo['nbDays']);
                 }
                 $childArray['title'] = $wbselement->getTitle() . $detail;
                 $childArray['children'] = $wbselement->getDynatreeData($hasDetail, $isManager, $teamid);
             } else {
                 try {
                     // avoid logging an exception...
                     if (!Issue::exists($wbselement->getBugId())) {
                         $e = new Exception("Issue with id=" . $wbselement->getBugId() . " not found.");
                         throw $e;
                     }
                     $issue = IssueCache::getInstance()->getIssue($wbselement->getBugId());
                     $detail = '';
                     if ($hasDetail) {
                         if ($isManager) {
                             $effortEstim = $issue->getMgrEffortEstim();
                             $drift = $issue->getDriftMgr();
                             $reestimated = $issue->getReestimated();
                         } else {
                             $effortEstim = $issue->getEffortEstim();
                             $drift = $issue->getDrift();
                             $reestimated = '0';
                         }
                         $detail = '~' . round(100 * $issue->getProgress()) . '~' . $effortEstim . '~' . $reestimated . '~' . $issue->getElapsed() . '~' . $issue->getBacklog() . '~' . $drift . '~' . $issue->getDriftColor($drift);
                     }
                     $formattedSummary = '<b>' . $issue->getId() . '</b> ' . $issue->getSummary();
                     //                  if ($hasDetail) {
                     //                     mb_internal_encoding("UTF-8");
                     //                     $formattedSummary = mb_strimwidth($formattedSummary, 0, 70, "...");
                     //                  }
                     $childArray['title'] = $formattedSummary . $detail;
                     $childArray['isFolder'] = false;
                     $childArray['key'] = $issue->getId();
                     // yes, bugid !
                     // add tooltip
                     $user = UserCache::getInstance()->getUser($issue->getHandlerId());
                     $titleAttr = array(T_('Project') => $issue->getProjectName(), T_('Category') => $issue->getCategoryName(), T_('Status') => Constants::$statusNames[$issue->getStatus()], T_('Assigned to') => $user->getRealname(), T_('Tags') => implode(',', $issue->getTagList()));
                     $childArray['href'] = Constants::$codevURL . '/reports/issue_info.php?bugid=' . $issue->getId();
                     #$childArray['htmlTooltip'] = Tools::getTooltip($issue->getTooltipItems($teamid, 0, $isManager));
                     $childArray['htmlTooltip'] = Tools::getTooltip($titleAttr);
                     #$childArray['icon'] = 'mantis_ico.gif';
                 } catch (Exception $e) {
                     //$childArray['title'] = $wbselement->getBugId().' - '.T_('Error: Task not found in Mantis DB !');
                     //$childArray['isFolder'] = false;
                     self::$logger->warn("Issue {$bugid} does not exist in Mantis DB: calling checkWBS()");
                     $childArray = array();
                     // remove from WBS
                     self::checkWBS();
                 }
             }
             if (sizeof($childArray) > 0) {
                 array_push($parentArray, $childArray);
             }
         }
         // root element not only has children !
         if ($this->id === $this->getRootId()) {
             $detail = '';
             if ($hasDetail) {
                 $bugids = $this->getBugidList($this->id);
                 $isel = new IssueSelection("wbs_" . $this->id);
                 foreach ($bugids as $bugid) {
                     try {
                         $isel->addIssue($bugid);
                     } catch (Exception $e) {
                         self::$logger->error("Issue {$bugid} does not exist in Mantis DB.");
                     }
                 }
                 if ($isManager) {
                     $effortEstim = $isel->getMgrEffortEstim();
                     $driftInfo = $isel->getDriftMgr();
                     $reestimated = $isel->getReestimated();
                 } else {
                     $effortEstim = $isel->getEffortEstim();
                     $driftInfo = $isel->getDrift();
                     $reestimated = '0';
                 }
                 $mgrDriftInfo = $isel->getDriftMgr();
                 $detail = '~' . round(100 * $isel->getProgress()) . '~' . $effortEstim . '~' . $reestimated . '~' . $isel->getElapsed() . '~' . $isel->duration . '~' . $driftInfo['nbDays'] . '~' . $isel->getDriftColor($driftInfo['nbDays']);
             }
             $rootArray = array('title' => $this->getTitle() . $detail, 'isFolder' => true, 'expand' => $this->isExpand(), 'key' => $this->getId(), 'children' => $parentArray);
             return $rootArray;
         } else {
             return $parentArray;
         }
     } else {
         self::$logger->error("Query failed!");
     }
 }