public function getScope() { if (!$this->_scope instanceof TBGScope) { $this->_scope = TBGContext::factory()->TBGScope($this->_scope); } return $this->_scope; }
/** * Return a custom data type option by value and key * * @param string|integer $value * @param string $key * * @return TBGCustomDatatypeOption */ public static function getByValueAndKey($value, $key) { $row = B2DB::getTable('TBGCustomFieldOptionsTable')->getByValueAndKey($value, $key); if ($row) { return TBGContext::factory()->TBGCustomDatatypeOption($row->get(TBGCustomFieldOptionsTable::ID), $row); } return null; }
/** * Create a new status * * @param string $name The status description * @param string $itemdata[optional] The color if any (default FFF) * * @return TBGStatus */ public static function createNew($name, $itemdata = null) { $itemdata = $itemdata === null || trim($itemdata) == '' ? '#FFF' : $itemdata; if (substr($itemdata, 0, 1) != '#') { $itemdata = '#' . $itemdata; } $res = parent::_createNew($name, self::STATUS, $itemdata); return TBGContext::factory()->TBGStatus($res->getInsertID()); }
public static function getAll() { if (self::$_groups === null) { self::$_groups = array(); if ($res = TBGGroupsTable::getTable()->getAll()) { while ($row = $res->getNextRow()) { self::$_groups[$row->get(TBGGroupsTable::ID)] = TBGContext::factory()->TBGGroup($row->get(TBGGroupsTable::ID), $row); } } } return self::$_groups; }
/** * Returns all categories available * * @return array */ public static function getAll() { if (self::$_items === NULL) { self::$_items = array(); if ($items = TBGListTypesTable::getTable()->getAllByItemType(self::CATEGORY)) { foreach ($items as $row_id => $row) { self::$_items[$row_id] = TBGContext::factory()->TBGCategory($row_id, $row); } } } return self::$_items; }
public function getProjectsByTeamID($team_id) { $projects = array(); $crit = $this->getCriteria(); $crit->addWhere(self::TID, $team_id); if ($res = $this->doSelect($crit)) { foreach ($res->getNextRow() as $row) { $projects[$row->get(TBGComponentsTable::PROJECT)] = TBGContext::factory()->TBGProject($row->get(TBGComponentsTable::PROJECT)); } } return $projects; }
/** * The currently selected project in actions where there is one * * @access protected * @property TBGProject $selected_project */ public function preExecute(TBGRequest $request, $action) { try { if ($project_key = $request->getParameter('project_key')) { $this->selected_project = TBGProject::getByKey($project_key); } elseif ($project_id = (int) $request->getParameter('project_id')) { $this->selected_project = TBGContext::factory()->TBGProject($project_id); } TBGContext::setCurrentProject($this->selected_project); } catch (Exception $e) { } }
public function getByTransitionID($transition_id) { $crit = $this->getCriteria(); $crit->addWhere(self::SCOPE, TBGContext::getScope()->getID()); $crit->addWhere(self::TRANSITION_ID, $transition_id); $actions = array('pre' => array(), 'post' => array()); if ($res = $this->doSelect($crit, false)) { while ($row = $res->getNextRow()) { $actions[$row->get(self::PRE_OR_POST)][$row->get(self::RULE)] = TBGContext::factory()->TBGWorkflowTransitionValidationRule($row->get(self::ID), $row); } } return $actions; }
protected function _getByTypeID($type, $id) { $crit = $this->getCriteria(); $crit->addWhere(self::SCOPE, TBGContext::getScope()->getID()); $crit->addWhere($type == 'step' ? self::OUTGOING_STEP_ID : self::WORKFLOW_ID, $id); $return_array = array(); if ($res = $this->doSelect($crit)) { while ($row = $res->getNextRow()) { $return_array[$row->get(self::ID)] = TBGContext::factory()->TBGWorkflowTransition($row->get(self::ID), $row); } } return $return_array; }
/** * The currently selected project in actions where there is one * * @access protected * @property TBGProject $selected_project */ public function preExecute(TBGRequest $request, $action) { try { if ($project_key = $request['project_key']) { $this->selected_project = TBGProject::getByKey($project_key); } elseif ($project_id = (int) $request['project_id']) { $this->selected_project = TBGContext::factory()->TBGProject($project_id); } if ($this->selected_project instanceof TBGProject) { TBGContext::setCurrentProject($this->selected_project); } } catch (Exception $e) { } }
public static function getAll() { if (self::$_userstates === null) { if (!($states = TBGCache::get(TBGCache::KEY_USERSTATES_CACHE))) { $res = TBGUserStateTable::getTable()->doSelectAll(); $states = array(); while ($row = $res->getNextRow()) { $states[$row->get(TBGUserStateTable::ID)] = TBGContext::factory()->TBGUserstate($row->get(TBGUserStateTable::ID), $row); } TBGCache::add(TBGCache::KEY_USERSTATES_CACHE, $states); } self::$_userstates = $states; } return self::$_userstates; }
public function getByIssueID($issue_id) { $crit = $this->getCriteria(); $crit->addWhere(self::ISSUE_ID, $issue_id); $res = $this->doSelect($crit); $ret_arr = array(); if ($res) { while ($row = $res->getNextRow()) { $file = TBGContext::factory()->TBGFile($row->get(TBGFilesTable::ID), $row); $file->setUploadedAt($row->get(self::ATTACHED_AT)); $ret_arr[$row->get(TBGFilesTable::ID)] = $file; } } return $ret_arr; }
protected static function _populateSchemes() { if (self::$_schemes === null) { self::$_schemes = array(); if ($res = TBGIssuetypeSchemesTable::getTable()->getAll()) { while ($row = $res->getNextRow()) { $scheme = TBGContext::factory()->TBGIssuetypeScheme($row->get(TBGIssuetypeSchemesTable::ID), $row); if (self::$_core_scheme === null) { self::$_core_scheme = $scheme; } self::$_schemes[$row->get(TBGIssuetypeSchemesTable::ID)] = $scheme; } } } }
protected static function _populateWorkflows() { if (self::$_workflows === null) { self::$_workflows = array(); if ($res = TBGWorkflowsTable::getTable()->getAll()) { while ($row = $res->getNextRow()) { $workflow = TBGContext::factory()->TBGWorkflow($row->get(TBGWorkflowsTable::ID), $row); if (self::$_core_workflow === null) { self::$_core_workflow = $workflow; } self::$_workflows[$row->get(TBGWorkflowsTable::ID)] = $workflow; } } } }
/** * Return the identifiable object for a specific field * * @param string $field * * @return TBGIdentifiable */ protected function _getIdentifiable($field) { if (is_numeric($this->{$field})) { $type_field = "{$field}_type"; try { if ($this->{$type_field} == TBGIdentifiableClass::TYPE_USER) { $this->{$field} = TBGContext::factory()->TBGUser($this->{$field}); } elseif ($this->{$type_field} == TBGIdentifiableClass::TYPE_TEAM) { $this->{$field} = TBGContext::factory()->TBGTeam($this->{$field}); } } catch (Exception $e) { $this->{$field} = null; $this->{$type_field} = null; } } return $this->{$field}; }
protected function _getByTypeID($type, $id) { $crit = $this->getCriteria(); $crit->addWhere(self::SCOPE, TBGContext::getScope()->getID()); $crit->addWhere($type == 'step' ? self::FROM_STEP_ID : self::TRANSITION_ID, $id); $crit->addJoin(TBGWorkflowTransitionsTable::getTable(), TBGWorkflowTransitionsTable::ID, self::TRANSITION_ID); $return_array = array(); if ($res = $this->doSelect($crit, false)) { while ($row = $res->getNextRow()) { if ($type == 'step') { $return_array[$row->get(self::TRANSITION_ID)] = TBGContext::factory()->TBGWorkflowTransition($row->get(self::TRANSITION_ID)); } else { $return_array[$row->get(self::FROM_STEP_ID)] = TBGContext::factory()->TBGWorkflowStep($row->get(self::FROM_STEP_ID)); } } } return $return_array; }
public function componentResults_view() { $request = new TBGRequest(); switch ($this->type) { case TBGDashboard::DASHBOARD_VIEW_PREDEFINED_SEARCH: $request->setParameter('predefined_search', $this->view); break; case TBGDashboard::DASHBOARD_VIEW_SAVED_SEARCH: $request->setParameter('saved_search', $this->view); break; } $request->setParameter('search', $this->search); $search = TBGContext::factory()->manufacture('searchActions', uniqid(rand(), true)); $search->runFindIssues($request); $this->issues = $search->issues; $this->title = $search->searchtitle; $this->parameters = $request->getParameters(); }
/** * Pre-execute function * * @param TBGRequest $request */ public function preExecute(TBGRequest $request, $action) { $this->getResponse()->setPage('wiki'); $i18n = TBGContext::getI18n(); $this->article = null; $this->article_name = $request->getParameter('article_name'); if ($request->hasParameter('article_name') && strpos($request->getParameter('article_name'), ':') !== false) { $namespace = substr($this->article_name, 0, strpos($this->article_name, ':')); $article_name = substr($this->article_name, strpos($this->article_name, ':') + 1); if ($namespace == 'Category') { $namespace = substr($article_name, 0, strpos($article_name, ':')); $article_name = substr($article_name, strpos($article_name, ':') + 1); } if ($namespace != '') { $key = strtolower($namespace); $row = TBGProjectsTable::getTable()->getByKey($key); if ($row instanceof B2DBRow) { $project = TBGContext::factory()->TBGProject($row->get(TBGProjectsTable::ID), $row); if ($project instanceof TBGProject) { $this->forward403unless($project->hasAccess()); } TBGContext::setCurrentProject($project); } } } else { try { if ($project_key = $request->getParameter('project_key')) { $row = TBGProjectsTable::getTable()->getByKey($project_key); $this->selected_project = TBGContext::factory()->TBGProject($row->get(TBGProjectsTable::ID), $row); } elseif ($project_id = (int) $request->getParameter('project_id')) { $this->selected_project = TBGContext::factory()->TBGProject($project_id); } if ($this->selected_project instanceof TBGProject) { $this->forward403unless($this->selected_project->hasAccess()); } TBGContext::setCurrentProject($this->selected_project); } catch (Exception $e) { } } if ($row = TBGArticlesTable::getTable()->getArticleByName($this->article_name)) { $this->article = PublishFactory::article($row->get(TBGArticlesTable::ID), $row); } }
public function getByIssuetypeSchemeID($issuetype_scheme_id) { $crit = $this->getCriteria(); $crit->addWhere(self::ISSUETYPE_SCHEME_ID, $issuetype_scheme_id); $crit->addWhere(self::SCOPE, TBGContext::getScope()->getID()); $return_array = array(); if ($res = $this->doSelect($crit)) { while ($row = $res->getNextRow()) { try { $i_id = $row->get(self::ISSUETYPE_ID); $issuetype = TBGContext::factory()->TBGIssuetype($i_id, $row); } catch (Exception $e) { $this->deleteByIssuetypeID($i_id); } $return_array[$row->get(self::ISSUETYPE_ID)] = array('reportable' => (bool) $row->get(self::REPORTABLE), 'redirect' => (bool) $row->get(self::REDIRECT_AFTER_REPORTING), 'issuetype' => $issuetype); } } return $return_array; }
public function getByArticleID($article_id) { $crit = $this->getCriteria(); $crit->addWhere(self::ARTICLE_ID, $article_id); $res = $this->doSelect($crit); $ret_arr = array(); if ($res) { while ($row = $res->getNextRow()) { try { $file = TBGContext::factory()->TBGFile($row->get(TBGFilesTable::ID), $row); $file->setUploadedAt($row->get(self::ATTACHED_AT)); $ret_arr[$row->get(TBGFilesTable::ID)] = $file; } catch (Exception $e) { $this->doDeleteById($row->get(self::ID)); } } } return $ret_arr; }
/** * Returns a list of changed items with a specified class * * @param string $class The class name * * @return array */ public static function getChangedItems($class) { $retarr = array(); if (isset($_SESSION['changeableitems'][$class]) && is_array($_SESSION['changeableitems'][$class])) { $function = $class . 'Lab'; foreach ($_SESSION['changeableitems'][$class] as $id => $changes) { if ($changes) { try { $retarr[$id] = TBGContext::factory()->{$function}($id); } catch (Exception $e) { TBGLogging::log("Changed item of type {$class}, id {$id} is invalid - unsetting", 'main', TBGLogging::LEVEL_NOTICE); unset($_SESSION['changeableitems'][$class][$id]); } } else { unset($_SESSION['changeableitems'][$class][$id]); } } } return $retarr; }
/** * Return this steps linked status if any * * @return TBGStatus */ public function getLinkedStatus() { if (is_numeric($this->_status_id)) { try { $this->_status_id = TBGContext::factory()->TBGStatus($this->_status_id); } catch (Exception $e) { $this->_status_id = null; } } return $this->_status_id; }
public static function getAllByProjectID($project_id) { $accounts = array(); if ($res = TBGIncomingEmailAccountTable::getTable()->getAllByProjectID($project_id)) { while ($row = $res->getNextRow()) { $accounts[] = TBGContext::factory()->TBGIncomingEmailAccount($row->get(TBGIncomingEmailAccountTable::ID), $row); } } return $accounts; }
public function hasAccess() { $namespaces = $this->getNamespaces(); if (count($namespaces) > 0) { $key = $namespaces[0]; $row = TBGProjectsTable::getTable()->getByKey($key); if ($row instanceof B2DBRow) { $project = TBGContext::factory()->TBGProject($row->get(TBGProjectsTable::ID), $row); if ($project instanceof TBGProject) { if (!$project->hasAccess()) { return false; } } } } return true; }
public function getAssignedTeams() { $this->_populateAssignees(); $teams = array(); foreach (array_keys($this->_assignees['teams']) as $team_id) { $teams[$team_id] = TBGContext::factory()->TBGTeam($team_id); } return $teams; }
public function runUnassignFromProject(TBGRequest $request) { try { $project = TBGContext::factory()->TBGProject($request->getParameter('project_id')); $project->removeAssignee($request->getParameter('assignee_type'), $request->getParameter('assignee_id')); return $this->renderJSON(array('failed' => false, 'message' => TBGContext::getI18n()->__('The assignee has been removed'))); } catch (Exception $e) { return $this->renderJSON(array('failed' => true, 'message' => $e->getMessage())); } }
public function isValid($input) { switch ($this->_rule) { case self::RULE_MAX_ASSIGNED_ISSUES: $num_issues = (int) $this->getRuleValue(); return $num_issues ? (bool) (count(TBGContext::getUser()->getUserAssignedIssues()) < $num_issues) : true; break; case self::RULE_STATUS_VALID: case self::RULE_PRIORITY_VALID: case self::RULE_RESOLUTION_VALID: case self::RULE_REPRODUCABILITY_VALID: $valid_items = explode(',', $this->getRuleValue()); $valid = false; foreach ($valid_items as $item) { if ($this->_rule == self::RULE_STATUS_VALID) { $fieldname = 'Status'; $fieldname_small = 'status'; } elseif ($this->_rule == self::RULE_RESOLUTION_VALID) { $fieldname = 'Resolution'; $fieldname_small = 'resolution'; } elseif ($this->_rule == self::RULE_REPRODUCABILITY_VALID) { $fieldname = 'Reproducability'; $fieldname_small = 'reproducability'; } elseif ($this->_rule == self::RULE_PRIORITY_VALID) { $fieldname = 'Priority'; $fieldname_small = 'priority'; } if ($input instanceof TBGIssue) { $type = "TBG{$fieldname}"; $getter = "get{$fieldname}"; if (TBGContext::factory()->{$type}((int) $item)->getID() == $issue->{$getter}()->getID()) { $valid = true; break; } } elseif ($input instanceof TBGRequest) { if ($input->getParameter("{$fieldname_small}_id") == $item) { $valid = true; break; } } } return $valid; break; } }
public function getIssuesByProjectID($id) { $crit = new Criteria(); $crit->addWhere(self::DELETED, false); $crit->addWhere(self::PROJECT_ID, $id); $results = $this->doSelect($crit); if (!is_object($results) || count($results) == 0) { return false; } $data = array(); /* Build revision details */ while ($results->next()) { $data[] = TBGContext::factory()->TBGIssue($results->get(TBGIssuesTable::ID)); } return $data; }
protected function _populateRecentIdeas() { if ($this->_recentideas === null) { $this->_recentideas = array(); if ($res = TBGIssuesTable::getTable()->getRecentByProjectIDandIssueType($this->getID(), array('idea'))) { while ($row = $res->getNextRow()) { $recentissue = TBGContext::factory()->TBGIssue($row->get(TBGIssuesTable::ID), $row); if ($recentissue->hasAccess()) { $this->_recentideas[$recentissue->getID()] = $recentissue; } } } } }
public function perform(TBGIssue $issue, $request = null) { switch ($this->_action_type) { case self::ACTION_ASSIGN_ISSUE_SELF: $issue->setAssignee(TBGContext::getUser()); break; case self::ACTION_SET_STATUS: if ($this->getTargetValue()) { $issue->setStatus(TBGContext::factory()->TBGStatus((int) $this->getTargetValue())); } else { $issue->setStatus($request['status_id']); } break; case self::ACTION_SET_MILESTONE: if ($this->getTargetValue()) { $issue->setMilestone(TBGContext::factory()->TBGMilestone((int) $this->getTargetValue())); } else { $issue->setMilestone($request['milestone_id']); } break; case self::ACTION_CLEAR_PRIORITY: $issue->setPriority(null); break; case self::ACTION_SET_PRIORITY: if ($this->getTargetValue()) { $issue->setPriority(TBGContext::factory()->TBGPriority((int) $this->getTargetValue())); } else { $issue->setPriority($request['priority_id']); } break; case self::ACTION_CLEAR_PERCENT: $issue->setPercentCompleted(0); break; case self::ACTION_SET_PERCENT: if ($this->getTargetValue()) { $issue->setPercentCompleted((int) $this->getTargetValue()); } else { $issue->setPercentCompleted((int) $request['percent_complete_id']); } break; case self::ACTION_CLEAR_DUPLICATE: $issue->setDuplicateOf(null); break; case self::ACTION_SET_DUPLICATE: $issue->setDuplicateOf($request['duplicate_issue_id']); break; case self::ACTION_CLEAR_RESOLUTION: $issue->setResolution(null); break; case self::ACTION_SET_RESOLUTION: if ($this->getTargetValue()) { $issue->setResolution(TBGContext::factory()->TBGResolution((int) $this->getTargetValue())); } else { $issue->setResolution($request['resolution_id']); } break; case self::ACTION_CLEAR_REPRODUCABILITY: $issue->setReproducability(null); break; case self::ACTION_SET_REPRODUCABILITY: if ($this->getTargetValue()) { $issue->setReproducability(TBGContext::factory()->TBGReproducability((int) $this->getTargetValue())); } else { $issue->setReproducability($request['reproducability_id']); } break; case self::ACTION_CLEAR_ASSIGNEE: $issue->clearAssignee(); break; case self::ACTION_ASSIGN_ISSUE: if ($this->getTargetValue()) { $target_details = explode('_', $this->_target_value); if ($target_details[0] == 'user') { $assignee = TBGUser::getB2DBTable()->selectById((int) $target_details[1]); } else { $assignee = TBGTeam::getB2DBTable()->selectById((int) $target_details[1]); } $issue->setAssignee($assignee); } else { $assignee = null; switch ($request['assignee_type']) { case 'user': $assignee = TBGUser::getB2DBTable()->selectById((int) $request['assignee_id']); break; case 'team': $assignee = TBGTeam::getB2DBTable()->selectById((int) $request['assignee_id']); break; } if ((bool) $request->getParameter('assignee_teamup', false) && $assignee instanceof TBGUser && $assignee->getID() != TBGContext::getUser()->getID()) { $team = new TBGTeam(); $team->setName($assignee->getBuddyname() . ' & ' . TBGContext::getUser()->getBuddyname()); $team->setOndemand(true); $team->save(); $team->addMember($assignee); $team->addMember(TBGContext::getUser()); $assignee = $team; } $issue->setAssignee($assignee); } break; case self::ACTION_USER_START_WORKING: $issue->clearUserWorkingOnIssue(); if ($issue->getAssignee() instanceof TBGTeam && $issue->getAssignee()->isOndemand()) { $members = $issue->getAssignee()->getMembers(); $issue->startWorkingOnIssue(array_shift($members)); } elseif ($issue->getAssignee() instanceof TBGUser) { $issue->startWorkingOnIssue($issue->getAssignee()); } break; case self::ACTION_USER_STOP_WORKING: if ($request->getParameter('did', 'nothing') == 'nothing') { $issue->clearUserWorkingOnIssue(); } elseif ($request->getParameter('did', 'nothing') == 'this') { $times = array(); if ($request['timespent_manual']) { $times = TBGIssue::convertFancyStringToTime($request['timespent_manual']); } elseif ($request['timespent_specified_type']) { $times = array('points' => 0, 'hours' => 0, 'days' => 0, 'weeks' => 0, 'months' => 0); $times[$request['timespent_specified_type']] = $request['timespent_specified_value']; } if (array_sum($times) > 0) { $times['hours'] *= 100; $spenttime = new TBGIssueSpentTime(); $spenttime->setIssue($issue); $spenttime->setUser(TBGContext::getUser()); $spenttime->setSpentPoints($times['points']); $spenttime->setSpentHours($times['hours']); $spenttime->setSpentDays($times['days']); $spenttime->setSpentWeeks($times['weeks']); $spenttime->setSpentMonths($times['months']); $spenttime->setActivityType($request['timespent_activitytype']); $spenttime->setComment($request['timespent_comment']); $spenttime->save(); } $issue->clearUserWorkingOnIssue(); } else { $issue->stopWorkingOnIssue(); } break; } }