} WBSElement::updateFromDynatree($rootArray, $root_id); echo $jsonDynatreeDict; } else { if ($_POST['action'] == 'loadWBS') { try { $root_id = Tools::getSecurePOSTIntValue('wbsRootId'); $hasDetail = 1 === Tools::getSecurePOSTIntValue('hasDetail') ? true : false; $userid = $_SESSION['userid']; $teamid = isset($_SESSION['teamid']) ? $_SESSION['teamid'] : 0; $session_user = UserCache::getInstance()->getUser($userid); // Managers & Observers have the same view (MEE,Reestimated, ...) $isManager = $session_user->isTeamManager($teamid); $isObserver = $session_user->isTeamObserver($teamid); $isManager = $isManager || $isObserver; $rootElement = new WBSElement($root_id); $dynatreeDict = $rootElement->getDynatreeData($hasDetail, $isManager, $teamid); if ($logger->isDebugEnabled()) { $aa = var_export($dynatreeDict, true); $logger->debug("loadWBS (root={$root_id}, hasDetail=" . $_POST['hasDetail'] . ") : \n{$aa}"); } $jsonDynatreeDict = json_encode($dynatreeDict); echo $jsonDynatreeDict; } catch (Exception $e) { $logger->error("loadWBS: " . $e->getMessage()); Tools::sendNotFoundAccess(); } } else { Tools::sendNotFoundAccess(); } }
/** * add Issue to command (in DB & current instance) * * @param int $bugid * @param bool $isDBonly if true, do not update current instance (PERF issue on) * * @return int insertion id if success, NULL on failure * @throws Exception */ public function addIssue($bugid, $isDBonly = false) { // security check if (!is_numeric($bugid)) { echo "<span style='color:red'>ERROR: Please contact your CodevTT administrator</span>"; $e = new Exception("SECURITY ALERT: Attempt to set non_numeric value ({$bugid})"); self::$logger->fatal("EXCEPTION addIssue: " . $e->getMessage()); self::$logger->fatal("EXCEPTION stack-trace:\n" . $e->getTraceAsString()); throw $e; } try { $issue = IssueCache::getInstance()->getIssue($bugid); } catch (Exception $e) { self::$logger->error("addIssue({$bugid}): issue {$bugid} does not exist !"); echo "<span style='color:red'>ERROR: issue '{$bugid}' does not exist !</span>"; return NULL; } $id = NULL; if (!array_key_exists($this->id, $issue->getCommandList())) { if (self::$logger->isDebugEnabled()) { self::$logger->debug("Add issue {$bugid} to command {$this->id}"); } $query = "INSERT INTO `codev_command_bug_table` (`command_id`, `bug_id`) VALUES ({$this->id}, {$bugid});"; $result = SqlWrapper::getInstance()->sql_query($query); if (!$result) { echo "<span style='color:red'>ERROR: Query FAILED</span>"; exit; } $id = SqlWrapper::getInstance()->sql_insert_id(); // add to WBS $wbsChild = new WBSElement(NULL, $this->wbsid, $bugid, $this->wbsid); if (self::$logger->isDebugEnabled()) { self::$logger->debug("Add issue {$bugid} from command {$this->id} to WBS root_id={$this->wbsid} wbse_id=" . $wbsChild->getId()); } } else { if (self::$logger->isDebugEnabled()) { self::$logger->debug("addIssue({$bugid}) to command {$this->id}: already in !"); } } if (!$isDBonly) { $this->getIssueSelection()->addIssue($bugid); } return $id; }
/** * * @param type $dynatreeDict */ public static function updateFromDynatree($dynatreeDict, $root_id = NULL, $parent_id = NULL, $order = 1) { $aa = var_export($dynatreeDict, true); if (self::$logger->isDebugEnabled()) { self::$logger->debug("updateFromDynatree(root={$root_id}, parent={$parent_id}, order={$order}) : \n{$aa}"); //self::$logger->debug($aa); } $id = NULL; $title = $dynatreeDict['title']; $icon = $dynatreeDict['icon']; $font = $dynatreeDict['font']; $color = $dynatreeDict['color']; $isExpand = $dynatreeDict['expand']; $isFolder = $dynatreeDict['isFolder']; if ($isFolder) { $id = $dynatreeDict['key']; // (null if new folder) // new created folders have an id starting with '_' if (substr($id, 0, 1) === '_') { $id = NULL; } $bug_id = NULL; } else { $bug_id = $dynatreeDict['key']; // find $id (if exists) // Note: parent_id may have changed (if issue moved) // Note: $root_id cannot be null because a WBS always starts with a folder (created at Command init) $query = "SELECT id FROM `codev_wbs_table` WHERE bug_id = {$bug_id} AND root_id = {$root_id}"; $result = SqlWrapper::getInstance()->sql_query($query); if (!$result) { echo "<span style='color:red'>ERROR: Query FAILED</span>"; exit; } $row = SqlWrapper::getInstance()->sql_fetch_object($result); if (!is_null($row)) { $id = $row->id; } } // create Element $wbse = new WBSElement($id, $root_id, $bug_id, $parent_id, $order, $title, $icon, $font, $color, $isExpand); // create children $children = $dynatreeDict['children']; if (!is_null($children)) { $childOrder = 1; foreach ($children as $childDict) { self::updateFromDynatree(get_object_vars($childDict), $root_id, $wbse->getId(), $childOrder); $childOrder += 1; } } }