Пример #1
0
 public function findIssues($filters = array(), $results_per_page = 30, $offset = 0, $groupby = null, $grouporder = null, $sortfields = array(self::LAST_UPDATED => 'asc'))
 {
     $crit = $this->getCriteria();
     $crit->addWhere(self::DELETED, false);
     $crit->addWhere(self::SCOPE, framework\Context::getScope()->getID());
     if (count($filters) > 0) {
         $crit->addJoin(IssueCustomFields::getTable(), IssueCustomFields::ISSUE_ID, Issues::ID);
         $crit->addJoin(IssueAffectsComponent::getTable(), IssueAffectsComponent::ISSUE, self::ID);
         $crit->addJoin(IssueAffectsEdition::getTable(), IssueAffectsEdition::ISSUE, self::ID);
         $crit->addJoin(IssueAffectsBuild::getTable(), IssueAffectsBuild::ISSUE, self::ID);
         $filter_keys = array_keys($filters);
         foreach ($filters as $filter) {
             self::parseFilter($crit, $filter, $filter_keys);
         }
     }
     $crit->addSelectionColumn(self::ID);
     $crit->setDistinct();
     if ($offset != 0) {
         $crit->setOffset($offset);
     }
     $crit2 = clone $crit;
     $count = $this->doCount($crit2);
     if ($count > 0) {
         $crit3 = $this->getCriteria();
         if ($results_per_page != 0) {
             $crit->setLimit($results_per_page);
         }
         if ($offset != 0) {
             $crit->setOffset($offset);
         }
         if ($groupby !== null) {
             $grouporder = $grouporder !== null ? $grouporder == 'asc' ? Criteria::SORT_ASC : Criteria::SORT_DESC : Criteria::SORT_ASC;
             switch ($groupby) {
                 case 'category':
                     $crit->addJoin(ListTypes::getTable(), ListTypes::ID, self::CATEGORY);
                     $crit->addSelectionColumn(ListTypes::NAME);
                     $crit->addOrderBy(ListTypes::NAME, $grouporder);
                     $crit3->addJoin(ListTypes::getTable(), ListTypes::ID, self::CATEGORY);
                     $crit3->addOrderBy(ListTypes::NAME, $grouporder);
                     break;
                 case 'status':
                     $crit->addJoin(ListTypes::getTable(), ListTypes::ID, self::STATUS);
                     $crit->addSelectionColumn(self::STATUS);
                     $crit->addOrderBy(ListTypes::ORDER, Criteria::SORT_DESC);
                     $crit3->addJoin(ListTypes::getTable(), ListTypes::ID, self::STATUS);
                     $crit3->addOrderBy(ListTypes::ORDER, Criteria::SORT_DESC);
                     break;
                 case 'milestone':
                     $crit->addSelectionColumn(self::MILESTONE);
                     $crit->addSelectionColumn(self::PERCENT_COMPLETE);
                     $crit->addOrderBy(self::MILESTONE, $grouporder);
                     $crit->addOrderBy(self::PERCENT_COMPLETE, 'desc');
                     $crit3->addOrderBy(self::MILESTONE, $grouporder);
                     $crit3->addOrderBy(self::PERCENT_COMPLETE, 'desc');
                     break;
                 case 'assignee':
                     $crit->addSelectionColumn(self::ASSIGNEE_TEAM);
                     $crit->addSelectionColumn(self::ASSIGNEE_USER);
                     $crit->addOrderBy(self::ASSIGNEE_TEAM);
                     $crit->addOrderBy(self::ASSIGNEE_USER, $grouporder);
                     $crit3->addOrderBy(self::ASSIGNEE_TEAM);
                     $crit3->addOrderBy(self::ASSIGNEE_USER, $grouporder);
                     break;
                 case 'state':
                     $crit->addSelectionColumn(self::STATE);
                     $crit->addOrderBy(self::STATE, $grouporder);
                     $crit3->addOrderBy(self::STATE, $grouporder);
                     break;
                 case 'severity':
                     $crit->addJoin(ListTypes::getTable(), ListTypes::ID, self::SEVERITY);
                     $crit->addSelectionColumn(self::SEVERITY);
                     $crit->addOrderBy(ListTypes::ORDER, $grouporder);
                     $crit3->addJoin(ListTypes::getTable(), ListTypes::ID, self::SEVERITY);
                     $crit3->addOrderBy(ListTypes::ORDER, $grouporder);
                     break;
                 case 'user_pain':
                     $crit->addSelectionColumn(self::USER_PAIN);
                     $crit->addOrderBy(self::USER_PAIN, $grouporder);
                     $crit3->addOrderBy(self::USER_PAIN, $grouporder);
                     break;
                 case 'votes':
                     $crit->addSelectionColumn(self::VOTES_TOTAL);
                     $crit->addOrderBy(self::VOTES_TOTAL, $grouporder);
                     $crit3->addOrderBy(self::VOTES_TOTAL, $grouporder);
                     break;
                 case 'resolution':
                     $crit->addJoin(ListTypes::getTable(), ListTypes::ID, self::RESOLUTION);
                     $crit->addSelectionColumn(self::RESOLUTION);
                     $crit->addOrderBy(ListTypes::ORDER, $grouporder);
                     $crit3->addJoin(ListTypes::getTable(), ListTypes::ID, self::RESOLUTION);
                     $crit3->addOrderBy(ListTypes::ORDER, $grouporder);
                     break;
                 case 'priority':
                     $crit->addJoin(ListTypes::getTable(), ListTypes::ID, self::PRIORITY);
                     $crit->addSelectionColumn(self::PRIORITY);
                     $crit->addOrderBy(ListTypes::ORDER, $grouporder);
                     $crit3->addJoin(ListTypes::getTable(), ListTypes::ID, self::PRIORITY);
                     $crit3->addOrderBy(ListTypes::ORDER, $grouporder);
                     break;
                 case 'issuetype':
                     $crit->addJoin(IssueTypes::getTable(), IssueTypes::ID, self::ISSUE_TYPE);
                     $crit->addSelectionColumn(IssueTypes::NAME);
                     $crit->addOrderBy(IssueTypes::NAME, $grouporder);
                     $crit3->addJoin(IssueTypes::getTable(), IssueTypes::ID, self::ISSUE_TYPE);
                     $crit3->addOrderBy(IssueTypes::NAME, $grouporder);
                     break;
                 case 'edition':
                     $crit->addJoin(IssueAffectsEdition::getTable(), IssueAffectsEdition::ISSUE, self::ID);
                     $crit->addJoin(Editions::getTable(), Editions::ID, IssueAffectsEdition::EDITION, array(), Criteria::DB_LEFT_JOIN, IssueAffectsEdition::getTable());
                     $crit->addSelectionColumn(Editions::NAME);
                     $crit->addOrderBy(Editions::NAME, $grouporder);
                     $crit3->addJoin(IssueAffectsEdition::getTable(), IssueAffectsEdition::ISSUE, self::ID);
                     $crit3->addJoin(Editions::getTable(), Editions::ID, IssueAffectsEdition::EDITION, array(), Criteria::DB_LEFT_JOIN, IssueAffectsEdition::getTable());
                     $crit3->addOrderBy(Editions::NAME, $grouporder);
                     break;
                 case 'build':
                     $crit->addJoin(IssueAffectsBuild::getTable(), IssueAffectsBuild::ISSUE, self::ID);
                     $crit->addJoin(Builds::getTable(), Builds::ID, IssueAffectsBuild::BUILD, array(), Criteria::DB_LEFT_JOIN, IssueAffectsBuild::getTable());
                     $crit->addSelectionColumn(Builds::NAME);
                     $crit->addOrderBy(Builds::NAME, $grouporder);
                     $crit3->addJoin(IssueAffectsBuild::getTable(), IssueAffectsBuild::ISSUE, self::ID);
                     $crit3->addJoin(Builds::getTable(), Builds::ID, IssueAffectsBuild::BUILD, array(), Criteria::DB_LEFT_JOIN, IssueAffectsBuild::getTable());
                     $crit3->addOrderBy(Builds::NAME, $grouporder);
                     break;
                 case 'component':
                     $crit->addJoin(IssueAffectsComponent::getTable(), IssueAffectsComponent::ISSUE, self::ID);
                     $crit->addJoin(Components::getTable(), Components::ID, IssueAffectsComponent::COMPONENT, array(), Criteria::DB_LEFT_JOIN, IssueAffectsComponent::getTable());
                     $crit->addSelectionColumn(Components::NAME);
                     $crit->addOrderBy(Components::NAME, $grouporder);
                     $crit3->addJoin(IssueAffectsComponent::getTable(), IssueAffectsComponent::ISSUE, self::ID);
                     $crit3->addJoin(Components::getTable(), Components::ID, IssueAffectsComponent::COMPONENT, array(), Criteria::DB_LEFT_JOIN, IssueAffectsComponent::getTable());
                     $crit3->addOrderBy(Components::NAME, $grouporder);
                     break;
             }
         }
         foreach ($sortfields as $field => $sortorder) {
             $crit->addSelectionColumn($field);
             $crit->addOrderBy($field, $sortorder);
         }
         $res = $this->doSelect($crit, 'none');
         $ids = array();
         if ($res) {
             while ($row = $res->getNextRow()) {
                 $ids[] = $row->get(self::ID);
             }
             $ids = array_reverse($ids);
             $crit3->addWhere(self::ID, $ids, Criteria::DB_IN);
             foreach ($sortfields as $field => $sortorder) {
                 $crit3->addOrderBy($field, $sortorder);
             }
             $res = $this->doSelect($crit3);
             $rows = $res->getAllRows();
         } else {
             $rows = array();
         }
         unset($res);
         return array($rows, $count, $ids);
     } else {
         return array(null, 0, array());
     }
 }
Пример #2
0
 /**
  * Set status for affected edition
  *
  * @see setAffectedItemStatus()
  * @see setAffectedBuildStatus()
  * @see setAffectedComponentStatus()
  *
  * @param \thebuggenie\core\entities\Edition $item The edition to set status for
  * @param \thebuggenie\core\entities\Datatype $status The status to set
  *
  * @return boolean
  */
 public function setAffectedEditionStatus($item, $status)
 {
     if (tables\IssueAffectsEdition::getTable()->setStatusByIssueIDandEditionID($this->getID(), $item->getID(), $status->getID())) {
         $this->touch();
         $this->addLogEntry(tables\Log::LOG_AFF_DELETE, framework\Context::getI18n()->__("'%item_name' -> '%status_name", array('%item_name' => $item->getName(), '%status_name' => $status->getName())));
         return true;
     }
     return false;
 }
Пример #3
0
 /**
  *
  * @param \b2db\Criteria $crit
  * @param array|\thebuggenie\core\entities\SearchFilter $filters
  * @param \b2db\Criterion $ctn
  * @return null
  */
 public function addToCriteria($crit, $filters, $ctn = null)
 {
     $filter_key = $this->getFilterKey();
     if (in_array($this['operator'], array('=', '!=', '<=', '>=', '<', '>'))) {
         if ($filter_key == 'text') {
             if ($this['value'] != '') {
                 $searchterm = mb_strpos($this['value'], '%') !== false ? $this['value'] : "%{$this['value']}%";
                 $issue_no = Issue::extractIssueNoFromNumber($this['value']);
                 if ($this['operator'] == '=') {
                     if ($ctn === null) {
                         $ctn = $crit->returnCriterion(tables\Issues::TITLE, $searchterm, Criteria::DB_LIKE);
                     }
                     $ctn->addOr(tables\Issues::DESCRIPTION, $searchterm, Criteria::DB_LIKE);
                     $ctn->addOr(tables\Issues::REPRODUCTION_STEPS, $searchterm, Criteria::DB_LIKE);
                     $ctn->addOr(tables\IssueCustomFields::OPTION_VALUE, $searchterm, Criteria::DB_LIKE);
                     if (is_numeric($issue_no)) {
                         $ctn->addOr(tables\Issues::ISSUE_NO, $issue_no, Criteria::DB_EQUALS);
                     }
                     $ctn->addOr(tables\IssueCustomFields::OPTION_VALUE, $searchterm, Criteria::DB_LIKE);
                     if (is_numeric($issue_no)) {
                         $ctn->addOr(tables\Issues::ISSUE_NO, $issue_no, Criteria::DB_EQUALS);
                     }
                     // $ctn->addOr(tables\IssueCustomFields::OPTION_VALUE, $searchterm, Criteria::DB_LIKE);
                 } else {
                     if ($ctn === null) {
                         $ctn = $crit->returnCriterion(tables\Issues::TITLE, $searchterm, Criteria::DB_NOT_LIKE);
                     }
                     $ctn->addWhere(tables\Issues::DESCRIPTION, $searchterm, Criteria::DB_NOT_LIKE);
                     $ctn->addWhere(tables\Issues::REPRODUCTION_STEPS, $searchterm, Criteria::DB_NOT_LIKE);
                     $ctn->addOr(tables\IssueCustomFields::OPTION_VALUE, $searchterm, Criteria::DB_NOT_LIKE);
                     if (is_numeric($issue_no)) {
                         $ctn->addWhere(tables\Issues::ISSUE_NO, $issue_no, Criteria::DB_EQUALS);
                     }
                     $ctn->addOr(tables\IssueCustomFields::OPTION_VALUE, $searchterm, Criteria::DB_NOT_LIKE);
                     if (is_numeric($issue_no)) {
                         $ctn->addWhere(tables\Issues::ISSUE_NO, $issue_no, Criteria::DB_EQUALS);
                     }
                     // $ctn->addOr(tables\IssueCustomFields::OPTION_VALUE, $searchterm, Criteria::DB_NOT_LIKE);
                 }
                 return $ctn;
             }
         } elseif (in_array($filter_key, self::getValidSearchFilters())) {
             if ($filter_key == 'subprojects') {
                 if (framework\Context::isProjectContext()) {
                     if ($ctn === null) {
                         $ctn = $crit->returnCriterion(tables\Issues::PROJECT_ID, framework\Context::getCurrentProject()->getID());
                     }
                     if ($this->hasValue()) {
                         foreach ($this->getValues() as $value) {
                             switch ($value) {
                                 case 'all':
                                     $subprojects = Project::getIncludingAllSubprojectsAsArray(framework\Context::getCurrentProject());
                                     foreach ($subprojects as $subproject) {
                                         if ($subproject->getID() == framework\Context::getCurrentProject()->getID()) {
                                             continue;
                                         }
                                         $ctn->addOr(tables\Issues::PROJECT_ID, $subproject->getID());
                                     }
                                     break;
                                 case 'none':
                                 case '':
                                     break;
                                 default:
                                     $ctn->addOr(tables\Issues::PROJECT_ID, (int) $value);
                                     break;
                             }
                         }
                     }
                     return $ctn;
                 }
             } elseif (in_array($filter_key, array('build', 'edition', 'component'))) {
                 switch ($filter_key) {
                     case 'component':
                         $tbl = tables\IssueAffectsComponent::getTable();
                         $fk = tables\IssueAffectsComponent::ISSUE;
                         break;
                     case 'edition':
                         $tbl = tables\IssueAffectsEdition::getTable();
                         $fk = tables\IssueAffectsEdition::ISSUE;
                         break;
                     case 'build':
                         $tbl = tables\IssueAffectsBuild::getTable();
                         $fk = tables\IssueAffectsBuild::ISSUE;
                         break;
                 }
                 $crit->addJoin($tbl, $fk, tables\Issues::ID, array(array($tbl->getB2DBAlias() . '.' . $filter_key, $this->getValues())), \b2db\Criteria::DB_INNER_JOIN);
                 return null;
             } else {
                 if ($filter_key == 'project_id' && in_array('subprojects', $filters)) {
                     return null;
                 }
                 $values = $this->getValues();
                 $num_values = 0;
                 if ($filter_key == 'status') {
                     if ($this->hasValue('open')) {
                         $c = $crit->returnCriterion(tables\Issues::STATE, Issue::STATE_OPEN);
                         $num_values++;
                     }
                     if ($this->hasValue('closed')) {
                         $num_values++;
                         if (isset($c)) {
                             $c->addWhere(tables\Issues::STATE, Issue::STATE_CLOSED);
                         } else {
                             $c = $crit->returnCriterion(tables\Issues::STATE, Issue::STATE_CLOSED);
                         }
                     }
                     if (isset($c)) {
                         if (count($values) == $num_values) {
                             return $c;
                         } else {
                             $crit->addWhere($c);
                         }
                     }
                 }
                 $dbname = tables\Issues::getTable()->getB2DBName();
                 foreach ($values as $value) {
                     $operator = $this['operator'];
                     $or = true;
                     if ($filter_key == 'status' && in_array($value, array('open', 'closed'))) {
                         continue;
                     } else {
                         $field = $dbname . '.' . $filter_key;
                         if ($operator == '!=' || in_array($filter_key, array('posted', 'last_updated'))) {
                             $or = false;
                         }
                     }
                     if ($ctn === null) {
                         $ctn = $crit->returnCriterion($field, $value, urldecode($operator));
                     } elseif ($or) {
                         $ctn->addOr($field, $value, urldecode($operator));
                     } else {
                         $ctn->addWhere($field, $value, urldecode($operator));
                     }
                 }
                 return $ctn;
             }
         } elseif (CustomDatatype::doesKeyExist($filter_key)) {
             $customdatatype = CustomDatatype::getByKey($filter_key);
             if (in_array($this->getFilterType(), CustomDatatype::getInternalChoiceFieldsAsArray())) {
                 $tbl = clone tables\IssueCustomFields::getTable();
                 $crit->addJoin($tbl, tables\IssueCustomFields::ISSUE_ID, tables\Issues::ID, array(array($tbl->getB2DBAlias() . '.customfields_id', $customdatatype->getID()), array($tbl->getB2DBAlias() . '.customfieldoption_id', $this->getValues())), \b2db\Criteria::DB_INNER_JOIN);
                 return null;
             } else {
                 foreach ($this->getValues() as $value) {
                     if ($customdatatype->hasCustomOptions()) {
                         if ($ctn === null) {
                             $ctn = $crit->returnCriterion(tables\IssueCustomFields::CUSTOMFIELDS_ID, $customdatatype->getID());
                             $ctn->addWhere(tables\IssueCustomFields::CUSTOMFIELDOPTION_ID, $value, $this['operator']);
                         } else {
                             $ctn->addOr(tables\IssueCustomFields::CUSTOMFIELDOPTION_ID, $value, $this['operator']);
                         }
                     } else {
                         if ($ctn === null) {
                             $ctn = $crit->returnCriterion(tables\IssueCustomFields::CUSTOMFIELDS_ID, $customdatatype->getID());
                             $ctn->addWhere(tables\IssueCustomFields::OPTION_VALUE, $value, $this['operator']);
                         } else {
                             $ctn->addOr(tables\IssueCustomFields::OPTION_VALUE, $value, $this['operator']);
                         }
                     }
                 }
                 return $ctn;
             }
         }
     }
 }
Пример #4
0
 public function runAddAffected(framework\Request $request)
 {
     framework\Context::loadLibrary('ui');
     try {
         $issue = entities\Issue::getB2DBTable()->selectById($request['issue_id']);
         $statuses = entities\Status::getAll();
         switch ($request['item_type']) {
             case 'edition':
                 if (!$issue->getProject()->isEditionsEnabled()) {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Editions are disabled')));
                 } elseif (!$issue->canEditAffectedEditions()) {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => framework\Context::getI18n()->__('You are not allowed to do this')));
                 }
                 $edition = entities\Edition::getB2DBTable()->selectById($request['which_item_edition']);
                 if (tables\IssueAffectsEdition::getTable()->getByIssueIDandEditionID($issue->getID(), $edition->getID())) {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => framework\Context::getI18n()->__('%item is already affected by this issue', array('%item' => $edition->getName()))));
                 }
                 $result = $issue->addAffectedEdition($edition);
                 if ($result !== false) {
                     $itemtype = 'edition';
                     $item = $result;
                     $itemtypename = framework\Context::getI18n()->__('Edition');
                     $content = get_component_html('main/affecteditem', array('item' => $item, 'itemtype' => $itemtype, 'itemtypename' => $itemtypename, 'issue' => $issue, 'statuses' => $statuses));
                 }
                 $message = framework\Context::getI18n()->__('Edition <b>%edition</b> is now affected by this issue', array('%edition' => $edition->getName()), true);
                 break;
             case 'component':
                 if (!$issue->getProject()->isComponentsEnabled()) {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Components are disabled')));
                 } elseif (!$issue->canEditAffectedComponents()) {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => framework\Context::getI18n()->__('You are not allowed to do this')));
                 }
                 $component = entities\Component::getB2DBTable()->selectById($request['which_item_component']);
                 if (tables\IssueAffectsComponent::getTable()->getByIssueIDandComponentID($issue->getID(), $component->getID())) {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => framework\Context::getI18n()->__('%item is already affected by this issue', array('%item' => $component->getName()))));
                 }
                 $result = $issue->addAffectedComponent($component);
                 if ($result !== false) {
                     $itemtype = 'component';
                     $item = $result;
                     $itemtypename = framework\Context::getI18n()->__('Component');
                     $content = get_component_html('main/affecteditem', array('item' => $item, 'itemtype' => $itemtype, 'itemtypename' => $itemtypename, 'issue' => $issue, 'statuses' => $statuses));
                 }
                 $message = framework\Context::getI18n()->__('Component <b>%component</b> is now affected by this issue', array('%component' => $component->getName()), true);
                 break;
             case 'build':
                 if (!$issue->getProject()->isBuildsEnabled()) {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Releases are disabled')));
                 } elseif (!$issue->canEditAffectedBuilds()) {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => framework\Context::getI18n()->__('You are not allowed to do this')));
                 }
                 $build = entities\Build::getB2DBTable()->selectById($request['which_item_build']);
                 if (tables\IssueAffectsBuild::getTable()->getByIssueIDandBuildID($issue->getID(), $build->getID())) {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => framework\Context::getI18n()->__('%item is already affected by this issue', array('%item' => $build->getName()))));
                 }
                 $result = $issue->addAffectedBuild($build);
                 if ($result !== false) {
                     $itemtype = 'build';
                     $item = $result;
                     $itemtypename = framework\Context::getI18n()->__('Release');
                     $content = get_component_html('main/affecteditem', array('item' => $item, 'itemtype' => $itemtype, 'itemtypename' => $itemtypename, 'issue' => $issue, 'statuses' => $statuses));
                 }
                 $message = framework\Context::getI18n()->__('Release <b>%build</b> is now affected by this issue', array('%build' => $build->getName()), true);
                 break;
             default:
                 throw new \Exception('Internal error');
         }
         $editions = array();
         $components = array();
         $builds = array();
         if ($issue->getProject()->isEditionsEnabled()) {
             $editions = $issue->getEditions();
         }
         if ($issue->getProject()->isComponentsEnabled()) {
             $components = $issue->getComponents();
         }
         if ($issue->getProject()->isBuildsEnabled()) {
             $builds = $issue->getBuilds();
         }
         $count = count($editions) + count($components) + count($builds);
         return $this->renderJSON(array('content' => $content, 'message' => $message, 'itemcount' => $count));
     } catch (\Exception $e) {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('error' => $e->getMessage()));
     }
 }