protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addForeignKeyColumn(self::ISSUETYPE_ID, TBGIssueTypesTable::getTable(), TBGIssueTypesTable::ID);
     parent::_addForeignKeyColumn(self::PROJECT_ID, TBGProjectsTable::getTable(), TBGProjectsTable::ID);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
 }
 public function __construct()
 {
     parent::__construct(self::B2DBNAME, self::ID);
     parent::_addForeignKeyColumn(self::ISSUETYPE_ID, TBGIssueTypesTable::getTable(), TBGIssueTypesTable::ID);
     parent::_addForeignKeyColumn(self::PROJECT_ID, TBGProjectsTable::getTable(), TBGProjectsTable::ID);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
 }
 public function __construct()
 {
     parent::__construct(self::B2DBNAME, self::ID);
     parent::_addForeignKeyColumn(self::ISSUETYPE_SCHEME_ID, TBGIssuetypeSchemesTable::getTable(), TBGIssuetypeSchemesTable::ID);
     parent::_addForeignKeyColumn(self::ISSUETYPE_ID, TBGIssueTypesTable::getTable(), TBGIssueTypesTable::ID);
     parent::_addBoolean(self::REPORTABLE, true);
     parent::_addBoolean(self::REDIRECT_AFTER_REPORTING, true);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
 }
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addForeignKeyColumn(self::ISSUETYPE_SCHEME_ID, TBGIssuetypeSchemesTable::getTable(), TBGIssuetypeSchemesTable::ID);
     parent::_addForeignKeyColumn(self::ISSUETYPE_ID, TBGIssueTypesTable::getTable(), TBGIssueTypesTable::ID);
     parent::_addBoolean(self::REPORTABLE, true);
     parent::_addBoolean(self::REDIRECT_AFTER_REPORTING, true);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
 }
 public function __construct()
 {
     parent::__construct(self::B2DBNAME, self::ID);
     parent::_addVarchar(self::FIELD_KEY, 20);
     parent::_addBoolean(self::REQUIRED);
     parent::_addBoolean(self::REPORTABLE);
     parent::_addBoolean(self::ADDITIONAL);
     parent::_addForeignKeyColumn(self::ISSUETYPE_ID, TBGIssueTypesTable::getTable(), TBGIssueTypesTable::ID);
     parent::_addForeignKeyColumn(self::ISSUETYPE_SCHEME_ID, TBGIssuetypeSchemesTable::getTable(), TBGIssuetypeSchemesTable::ID);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
 }
 public function loadFixtures(TBGScope $scope)
 {
     foreach (TBGIssueTypesTable::getTable()->getAllIDsByScopeID($scope->getID()) as $issuetype_id) {
         $crit = $this->getCriteria();
         $crit->addInsert(self::SCOPE, $scope->getID());
         $crit->addInsert(self::WORKFLOW_ID, TBGSettings::getCoreWorkflow()->getID());
         $crit->addInsert(self::WORKFLOW_SCHEME_ID, TBGSettings::getCoreWorkflowScheme()->getID());
         $crit->addInsert(self::ISSUETYPE_ID, $issuetype_id);
         $this->doInsert($crit);
     }
 }
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addVarchar(self::FIELD_KEY, 100);
     parent::_addBoolean(self::REQUIRED);
     parent::_addBoolean(self::REPORTABLE);
     parent::_addBoolean(self::ADDITIONAL);
     parent::_addForeignKeyColumn(self::ISSUETYPE_ID, TBGIssueTypesTable::getTable(), TBGIssueTypesTable::ID);
     parent::_addForeignKeyColumn(self::ISSUETYPE_SCHEME_ID, TBGIssuetypeSchemesTable::getTable(), TBGIssuetypeSchemesTable::ID);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
 }
 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, TBGContext::getScope()->getID());
     if (count($filters) > 0) {
         $crit->addJoin(TBGIssueCustomFieldsTable::getTable(), TBGIssueCustomFieldsTable::ISSUE_ID, TBGIssuesTable::ID);
         $crit->addJoin(TBGIssueAffectsComponentTable::getTable(), TBGIssueAffectsComponentTable::ISSUE, self::ID);
         $crit->addJoin(TBGIssueAffectsEditionTable::getTable(), TBGIssueAffectsEditionTable::ISSUE, self::ID);
         $crit->addJoin(TBGIssueAffectsBuildTable::getTable(), TBGIssueAffectsBuildTable::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(TBGListTypesTable::getTable(), TBGListTypesTable::ID, self::CATEGORY);
                     $crit->addSelectionColumn(TBGListTypesTable::NAME);
                     $crit->addOrderBy(TBGListTypesTable::NAME, $grouporder);
                     $crit3->addJoin(TBGListTypesTable::getTable(), TBGListTypesTable::ID, self::CATEGORY);
                     $crit3->addOrderBy(TBGListTypesTable::NAME, $grouporder);
                     break;
                 case 'status':
                     $crit->addJoin(TBGListTypesTable::getTable(), TBGListTypesTable::ID, self::STATUS);
                     $crit->addSelectionColumn(self::STATUS);
                     $crit->addOrderBy(TBGListTypesTable::ORDER, Criteria::SORT_DESC);
                     $crit3->addJoin(TBGListTypesTable::getTable(), TBGListTypesTable::ID, self::STATUS);
                     $crit3->addOrderBy(TBGListTypesTable::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(TBGListTypesTable::getTable(), TBGListTypesTable::ID, self::SEVERITY);
                     $crit->addSelectionColumn(self::SEVERITY);
                     $crit->addOrderBy(TBGListTypesTable::ORDER, $grouporder);
                     $crit3->addJoin(TBGListTypesTable::getTable(), TBGListTypesTable::ID, self::SEVERITY);
                     $crit3->addOrderBy(TBGListTypesTable::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(TBGListTypesTable::getTable(), TBGListTypesTable::ID, self::RESOLUTION);
                     $crit->addSelectionColumn(self::RESOLUTION);
                     $crit->addOrderBy(TBGListTypesTable::ORDER, $grouporder);
                     $crit3->addJoin(TBGListTypesTable::getTable(), TBGListTypesTable::ID, self::RESOLUTION);
                     $crit3->addOrderBy(TBGListTypesTable::ORDER, $grouporder);
                     break;
                 case 'priority':
                     $crit->addJoin(TBGListTypesTable::getTable(), TBGListTypesTable::ID, self::PRIORITY);
                     $crit->addSelectionColumn(self::PRIORITY);
                     $crit->addOrderBy(TBGListTypesTable::ORDER, $grouporder);
                     $crit3->addJoin(TBGListTypesTable::getTable(), TBGListTypesTable::ID, self::PRIORITY);
                     $crit3->addOrderBy(TBGListTypesTable::ORDER, $grouporder);
                     break;
                 case 'issuetype':
                     $crit->addJoin(TBGIssueTypesTable::getTable(), TBGIssueTypesTable::ID, self::ISSUE_TYPE);
                     $crit->addSelectionColumn(TBGIssueTypesTable::NAME);
                     $crit->addOrderBy(TBGIssueTypesTable::NAME, $grouporder);
                     $crit3->addJoin(TBGIssueTypesTable::getTable(), TBGIssueTypesTable::ID, self::ISSUE_TYPE);
                     $crit3->addOrderBy(TBGIssueTypesTable::NAME, $grouporder);
                     break;
                 case 'edition':
                     $crit->addJoin(TBGIssueAffectsEditionTable::getTable(), TBGIssueAffectsEditionTable::ISSUE, self::ID);
                     $crit->addJoin(TBGEditionsTable::getTable(), TBGEditionsTable::ID, TBGIssueAffectsEditionTable::EDITION, array(), Criteria::DB_LEFT_JOIN, TBGIssueAffectsEditionTable::getTable());
                     $crit->addSelectionColumn(TBGEditionsTable::NAME);
                     $crit->addOrderBy(TBGEditionsTable::NAME, $grouporder);
                     $crit3->addJoin(TBGIssueAffectsEditionTable::getTable(), TBGIssueAffectsEditionTable::ISSUE, self::ID);
                     $crit3->addJoin(TBGEditionsTable::getTable(), TBGEditionsTable::ID, TBGIssueAffectsEditionTable::EDITION, array(), Criteria::DB_LEFT_JOIN, TBGIssueAffectsEditionTable::getTable());
                     $crit3->addOrderBy(TBGEditionsTable::NAME, $grouporder);
                     break;
                 case 'build':
                     $crit->addJoin(TBGIssueAffectsBuildTable::getTable(), TBGIssueAffectsBuildTable::ISSUE, self::ID);
                     $crit->addJoin(TBGBuildsTable::getTable(), TBGBuildsTable::ID, TBGIssueAffectsBuildTable::BUILD, array(), Criteria::DB_LEFT_JOIN, TBGIssueAffectsBuildTable::getTable());
                     $crit->addSelectionColumn(TBGBuildsTable::NAME);
                     $crit->addOrderBy(TBGBuildsTable::NAME, $grouporder);
                     $crit3->addJoin(TBGIssueAffectsBuildTable::getTable(), TBGIssueAffectsBuildTable::ISSUE, self::ID);
                     $crit3->addJoin(TBGBuildsTable::getTable(), TBGBuildsTable::ID, TBGIssueAffectsBuildTable::BUILD, array(), Criteria::DB_LEFT_JOIN, TBGIssueAffectsBuildTable::getTable());
                     $crit3->addOrderBy(TBGBuildsTable::NAME, $grouporder);
                     break;
                 case 'component':
                     $crit->addJoin(TBGIssueAffectsComponentTable::getTable(), TBGIssueAffectsComponentTable::ISSUE, self::ID);
                     $crit->addJoin(TBGComponentsTable::getTable(), TBGComponentsTable::ID, TBGIssueAffectsComponentTable::COMPONENT, array(), Criteria::DB_LEFT_JOIN, TBGIssueAffectsComponentTable::getTable());
                     $crit->addSelectionColumn(TBGComponentsTable::NAME);
                     $crit->addOrderBy(TBGComponentsTable::NAME, $grouporder);
                     $crit3->addJoin(TBGIssueAffectsComponentTable::getTable(), TBGIssueAffectsComponentTable::ISSUE, self::ID);
                     $crit3->addJoin(TBGComponentsTable::getTable(), TBGComponentsTable::ID, TBGIssueAffectsComponentTable::COMPONENT, array(), Criteria::DB_LEFT_JOIN, TBGIssueAffectsComponentTable::getTable());
                     $crit3->addOrderBy(TBGComponentsTable::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());
     }
 }
 public function getLast15IssueCountsByProjectID($project_id)
 {
     $retarr = array();
     for ($cc = 15; $cc >= 0; $cc--) {
         $crit = $this->getCriteria();
         $joinedtable = $crit->addJoin(TBGIssuesTable::getTable(), TBGIssuesTable::ID, self::TARGET);
         $crit->addWhere(self::TARGET_TYPE, self::TYPE_ISSUE);
         $crit->addWhere(self::CHANGE_TYPE, array(self::LOG_ISSUE_CREATED, self::LOG_ISSUE_CLOSE), Criteria::DB_IN);
         $crit->addWhere(TBGIssuesTable::PROJECT_ID, $project_id);
         $crit->addWhere(TBGIssuesTable::DELETED, false);
         $crit->addJoin(TBGIssueTypesTable::getTable(), TBGIssueTypesTable::ID, TBGIssuesTable::ISSUE_TYPE, array(), Criteria::DB_LEFT_JOIN, $joinedtable);
         $crit->addWhere(TBGIssueTypesTable::ICON, 'bug_report');
         $crit->addWhere(self::SCOPE, TBGContext::getScope()->getID());
         $ctn = $crit->returnCriterion(self::TIME, NOW - 86400 * ($cc + 1), Criteria::DB_GREATER_THAN_EQUAL);
         $ctn->addWhere(self::TIME, NOW - 86400 * $cc, Criteria::DB_LESS_THAN_EQUAL);
         $crit->addWhere($ctn);
         $crit2 = clone $crit;
         $crit->addWhere(self::CHANGE_TYPE, self::LOG_ISSUE_CLOSE);
         $crit2->addWhere(self::CHANGE_TYPE, self::LOG_ISSUE_CREATED);
         $retarr[0][$cc] = $this->doCount($crit);
         $retarr[1][$cc] = $this->doCount($crit2);
     }
     return $retarr;
 }
 protected function doSearch(TBGRequest $request)
 {
     $i18n = TBGContext::getI18n();
     if ($this->searchterm) {
         preg_replace_callback(TBGTextParser::getIssueRegex(), array($this, 'extractIssues'), $this->searchterm);
         if (!count($this->foundissues)) {
             $issue = TBGIssue::getIssueFromLink($this->searchterm);
             if ($issue instanceof TBGIssue) {
                 $this->foundissues = array($issue);
                 $this->resultcount = 1;
             }
         }
     }
     if (count($this->foundissues) == 0) {
         if ($request->hasParameter('predefined_search')) {
             switch ((int) $request->getParameter('predefined_search')) {
                 case TBGContext::PREDEFINED_SEARCH_PROJECT_OPEN_ISSUES:
                     $this->filters['state'] = array('operator' => '=', 'value' => TBGIssue::STATE_OPEN);
                     $this->groupby = 'issuetype';
                     break;
                 case TBGContext::PREDEFINED_SEARCH_PROJECT_CLOSED_ISSUES:
                     $this->filters['state'] = array('operator' => '=', 'value' => TBGIssue::STATE_CLOSED);
                     $this->groupby = 'issuetype';
                     break;
                 case TBGContext::PREDEFINED_SEARCH_PROJECT_MILESTONE_TODO:
                     $this->groupby = 'milestone';
                     break;
                 case TBGContext::PREDEFINED_SEARCH_PROJECT_MOST_VOTED:
                     $this->filters['state'] = array('operator' => '=', 'value' => TBGIssue::STATE_OPEN);
                     $this->groupby = 'votes';
                     $this->grouporder = 'desc';
                     break;
                 case TBGContext::PREDEFINED_SEARCH_MY_REPORTED_ISSUES:
                     $this->filters['posted_by'] = array('operator' => '=', 'value' => TBGContext::getUser()->getID());
                     $this->groupby = 'issuetype';
                     break;
                 case TBGContext::PREDEFINED_SEARCH_MY_ASSIGNED_OPEN_ISSUES:
                     $this->filters['state'] = array('operator' => '=', 'value' => TBGIssue::STATE_OPEN);
                     $this->filters['assigned_type'] = array('operator' => '=', 'value' => TBGIdentifiableClass::TYPE_USER);
                     $this->filters['assigned_to'] = array('operator' => '=', 'value' => TBGContext::getUser()->getID());
                     $this->groupby = 'issuetype';
                     break;
                 case TBGContext::PREDEFINED_SEARCH_TEAM_ASSIGNED_OPEN_ISSUES:
                     $this->filters['state'] = array('operator' => '=', 'value' => TBGIssue::STATE_OPEN);
                     $this->filters['assigned_type'] = array('operator' => '=', 'value' => TBGIdentifiableClass::TYPE_TEAM);
                     foreach (TBGContext::getUser()->getTeams() as $team_id => $team) {
                         $this->filters['assigned_to'][] = array('operator' => '=', 'value' => $team_id);
                     }
                     $this->groupby = 'issuetype';
                     break;
             }
         } elseif (in_array($this->templatename, array('results_userpain_singlepainthreshold', 'results_userpain_totalpainthreshold'))) {
             $this->searchtitle = $i18n->__('Showing "bug report" issues sorted by user pain, threshold set at %threshold%', array('%threshold%' => $this->template_parameter));
             $this->ipp = 0;
             $this->groupby = 'user_pain';
             $this->grouporder = 'desc';
             $ids = TBGIssueTypesTable::getTable()->getBugReportTypeIDs();
             $this->filters['issuetype'] = array();
             foreach ($ids as $id) {
                 $this->filters['issuetype'][] = array('operator' => '=', 'value' => $id);
             }
         } elseif ($this->templatename == 'results_votes') {
             $this->searchtitle = $i18n->__('Showing issues ordered by number of votes');
             $this->ipp = $request->getParameter('issues_per_page', 100);
             $this->groupby = 'votes';
             $this->grouporder = 'desc';
         }
         list($this->foundissues, $this->resultcount) = TBGIssue::findIssues($this->filters, $this->ipp, $this->offset, $this->groupby, $this->grouporder);
     } elseif (count($this->foundissues) == 1 && !$request->getParameter('quicksearch')) {
         $issue = array_shift($this->foundissues);
         $this->forward(TBGContext::getRouting()->generate('viewissue', array('project_key' => $issue->getProject()->getKey(), 'issue_no' => $issue->getFormattedIssueNo())));
     } elseif ($request->hasParameter('sortby')) {
     } else {
         $this->resultcount = count($this->foundissues);
         if ($this->templatename == 'results_userpain_singlepainthreshold') {
             usort($this->foundissues, array('searchActions', 'userPainSort'));
         }
     }
     if ($request->hasParameter('predefined_search')) {
         switch ((int) $request->getParameter('predefined_search')) {
             case TBGContext::PREDEFINED_SEARCH_PROJECT_OPEN_ISSUES:
                 $this->searchtitle = TBGContext::isProjectContext() ? $i18n->__('Open issues for %project_name%', array('%project_name%' => TBGContext::getCurrentProject()->getName())) : $i18n->__('All open issues');
                 break;
             case TBGContext::PREDEFINED_SEARCH_PROJECT_CLOSED_ISSUES:
                 $this->searchtitle = TBGContext::isProjectContext() ? $i18n->__('Closed issues for %project_name%', array('%project_name%' => TBGContext::getCurrentProject()->getName())) : $i18n->__('All closed issues');
                 break;
             case TBGContext::PREDEFINED_SEARCH_PROJECT_MILESTONE_TODO:
                 $this->searchtitle = $i18n->__('Milestone todo-list for %project_name%', array('%project_name%' => TBGContext::getCurrentProject()->getName()));
                 $this->templatename = 'results_todo';
                 break;
             case TBGContext::PREDEFINED_SEARCH_PROJECT_MOST_VOTED:
                 $this->searchtitle = TBGContext::isProjectContext() ? $i18n->__('Most voted issues for %project_name%', array('%project_name%' => TBGContext::getCurrentProject()->getName())) : $i18n->__('Most voted issues');
                 $this->templatename = 'results_votes';
                 break;
             case TBGContext::PREDEFINED_SEARCH_MY_ASSIGNED_OPEN_ISSUES:
                 $this->searchtitle = $i18n->__('Open issues assigned to me');
                 break;
             case TBGContext::PREDEFINED_SEARCH_TEAM_ASSIGNED_OPEN_ISSUES:
                 $this->searchtitle = $i18n->__('Open issues assigned to my teams');
                 break;
             case TBGContext::PREDEFINED_SEARCH_MY_REPORTED_ISSUES:
                 $this->searchtitle = $i18n->__('Issues reported by me');
                 break;
         }
     }
 }
 /**
  * Returns an array of issue types
  *
  * @param integer $scope_id  The ID number of the scope to load issue types from
  * @return array
  */
 public static function getAll($scope_id = null)
 {
     if (self::$_issuetypes === null) {
         self::$_issuetypes = array();
         $crit = TBGIssueTypesTable::getTable()->getCriteria();
         if ($scope_id === null) {
             $crit->addWhere(TBGIssueTypesTable::SCOPE, TBGContext::getScope()->getID());
         } else {
             $crit->addWhere(TBGIssueTypesTable::SCOPE, $scope_id);
         }
         $issuetypes = array();
         if ($res = TBGIssueTypesTable::getTable()->doSelect($crit, 'none')) {
             while ($row = $res->getNextRow()) {
                 $issuetypes[$row->get(TBGIssueTypesTable::ID)] = TBGContext::factory()->TBGIssuetype($res->get(TBGIssueTypesTable::ID), $row);
             }
         } else {
             TBGLogging::log('There are no issue types', 'main', TBGLogging::LEVEL_NOTICE);
         }
         self::$_issuetypes = $issuetypes;
     }
     return self::$_issuetypes;
 }
 static function getTask()
 {
     try {
         $crit = new \b2db\Criteria();
         $crit->addWhere(TBGIssueTypesTable::ICON, 'task');
         $crit->addWhere(TBGIssueTypesTable::SCOPE, TBGContext::getScope()->getID());
         $row = TBGIssueTypesTable::getTable()->doSelectOne($crit);
         if ($row instanceof \b2db\Row) {
             return TBGContext::factory()->TBGIssuetype($row->get(TBGIssueTypesTable::ID), $row);
         } else {
             throw new Exception("Couldn't find any 'task' issue types");
         }
     } catch (Exception $e) {
         throw $e;
     }
 }
Beispiel #13
0
 protected function _upgradeFrom3dot1()
 {
     // Add classpath for existing old tables used for upgrade
     TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'installation' . DS . 'classes' . DS . 'upgrade_3.1');
     TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'mailing' . DS . 'classes' . DS . 'B2DB');
     TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'mailing' . DS . 'classes');
     TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'publish' . DS . 'classes' . DS . 'B2DB');
     TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'publish' . DS . 'classes');
     // Create new tables
     TBGDashboardViewsTable::getTable()->create();
     TBGOpenIdAccountsTable::getTable()->create();
     TBGProjectAssignedUsersTable::getTable()->create();
     TBGProjectAssignedTeamsTable::getTable()->create();
     TBGEditionAssignedUsersTable::getTable()->create();
     TBGEditionAssignedTeamsTable::getTable()->create();
     TBGComponentAssignedUsersTable::getTable()->create();
     TBGComponentAssignedTeamsTable::getTable()->create();
     TBGRolePermissionsTable::getTable()->create();
     TBGUserScopesTable::getTable()->create();
     // Upgrade existing tables
     TBGProjectsTable::getTable()->upgrade(TBGProjectsTable3dot1::getTable());
     TBGUsersTable::getTable()->upgrade(TBGUsersTable3dot1::getTable());
     TBGIssuesTable::getTable()->upgrade(TBGIssuesTable3dot1::getTable());
     TBGIssueTypesTable::getTable()->upgrade(TBGIssueTypesTable3dot1::getTable());
     TBGListTypesTable::getTable()->upgrade(TBGListTypesTable3dot1::getTable());
     TBGEditionsTable::getTable()->upgrade(TBGEditionsTable3dot1::getTable());
     TBGBuildsTable::getTable()->upgrade(TBGBuildsTable3dot1::getTable());
     TBGCommentsTable::getTable()->upgrade(TBGCommentsTable3dot1::getTable());
     TBGComponentsTable::getTable()->upgrade(TBGComponentsTable3dot1::getTable());
     TBGCustomFieldsTable::getTable()->upgrade(TBGCustomFieldsTable3dot1::getTable());
     TBGCustomFieldOptionsTable::getTable()->upgrade(TBGCustomFieldOptionsTable3dot1::getTable());
     TBGIssueCustomFieldsTable::getTable()->upgrade(TBGIssueCustomFieldsTable3dot1::getTable());
     // Create new module tables
     TBGIncomingEmailAccountTable::getTable()->create();
     // Add new indexes
     TBGArticlesTable::getTable()->createIndexes();
     TBGCommentsTable::getTable()->createIndexes();
     TBGIssueAffectsBuildTable::getTable()->createIndexes();
     TBGIssueAffectsComponentTable::getTable()->createIndexes();
     TBGIssueAffectsEditionTable::getTable()->createIndexes();
     TBGIssueFieldsTable::getTable()->createIndexes();
     TBGIssueFilesTable::getTable()->createIndexes();
     TBGIssuesTable::getTable()->createIndexes();
     TBGIssuetypeSchemesTable::getTable()->createIndexes();
     TBGPermissionsTable::getTable()->createIndexes();
     TBGProjectsTable::getTable()->createIndexes();
     TBGSettingsTable::getTable()->createIndexes();
     TBGTeamMembersTable::getTable()->createIndexes();
     TBGUserIssuesTable::getTable()->createIndexes();
     TBGUsersTable::getTable()->createIndexes();
     TBGUserScopesTable::getTable()->createIndexes();
     if (TBGContext::getRequest()->getParameter('fix_my_timestamps', false)) {
         $this->_fixTimestamps();
     }
     foreach (TBGScope::getAll() as $scope) {
         TBGRole::loadFixtures($scope);
         foreach (TBGDatatype::getTypes() as $type => $class) {
             TBGContext::setPermission('set_datatype_' . $type, 0, 'core', 0, 0, 0, true, $scope->getID());
         }
         TBGContext::setPermission('page_confirm_scope_access', 0, 'core', 0, 0, 0, true, $scope->getID());
         if (!TBGSettings::get(TBGSettings::SETTING_DEFAULT_WORKFLOW, 'core', $scope->getID())) {
             $workflow_id = TBGWorkflowsTable::getTable()->getFirstIdByScope($scope->getID());
             if ($workflow_id) {
                 TBGSettings::saveSetting(TBGSettings::SETTING_DEFAULT_WORKFLOW, $workflow_id, 'core', $scope->getID());
             } else {
                 TBGWorkflow::loadFixtures($scope);
             }
         }
         if (!TBGSettings::get(TBGSettings::SETTING_DEFAULT_WORKFLOWSCHEME, 'core', $scope->getID())) {
             $workflow_scheme_id = TBGWorkflowSchemesTable::getTable()->getFirstIdByScope($scope->getID());
             if ($workflow_scheme_id) {
                 TBGSettings::saveSetting(TBGSettings::SETTING_DEFAULT_WORKFLOWSCHEME, $workflow_scheme_id, 'core', $scope->getID());
             } else {
                 TBGWorkflowScheme::loadFixtures($scope);
             }
         }
         if (!TBGSettings::get(TBGSettings::SETTING_DEFAULT_ISSUETYPESCHEME, 'core', $scope->getID())) {
             $issuetype_scheme_id = TBGIssuetypeSchemesTable::getTable()->getFirstIdByScope($scope->getID());
             if ($issuetype_scheme_id) {
                 TBGSettings::saveSetting(TBGSettings::SETTING_DEFAULT_ISSUETYPESCHEME, $issuetype_scheme_id, 'core', $scope->getID());
             } else {
                 TBGIssuetypeScheme::loadFixtures($scope);
             }
         }
         TBGSettings::saveSetting(TBGSettings::SETTING_FAVICON_ID, 0, 'core', $scope->getID());
         TBGSettings::saveSetting(TBGSettings::SETTING_FAVICON_TYPE, 0, 'core', $scope->getID());
         TBGSettings::saveSetting(TBGSettings::SETTING_HEADER_ICON_ID, 0, 'core', $scope->getID());
         TBGSettings::saveSetting(TBGSettings::SETTING_HEADER_ICON_TYPE, 0, 'core', $scope->getID());
     }
     $linkstable = TBGLinksTable::getTable();
     $crit = $linkstable->getCriteria();
     $crit->addUpdate(TBGLinksTable::URL, 'http://issues.thebuggenie.com');
     $crit->addWhere(TBGLinksTable::URL, 'http://thebuggenie.com/thebuggenie');
     $crit->addOr(TBGLinksTable::URL, 'http://www.thebuggenie.com/thebuggenie');
     $linkstable->doUpdate($crit);
     $listtypestable = TBGListTypesTable::getTable();
     $crit = $listtypestable->getCriteria();
     $crit->addUpdate(TBGListTypesTable::ITEMTYPE, 'role');
     $crit->addWhere(TBGListTypesTable::ITEMTYPE, 'projectrole');
     $listtypestable->doUpdate($crit);
     $crit = $listtypestable->getCriteria();
     $crit->addUpdate(TBGListTypesTable::ITEMTYPE, 'priority');
     $crit->addWhere(TBGListTypesTable::ITEMTYPE, 'b2_prioritytypes');
     $listtypestable->doUpdate($crit);
     TBGWorkflowTransitionsTable::getTable()->upgradeFrom3dot1();
     TBGSettings::saveSetting(TBGSettings::SETTING_ICONSET, TBGSettings::get(TBGSettings::SETTING_THEME_NAME));
     TBGContext::setPermission('readarticle', 0, 'publish', 0, 0, 0, true);
     foreach (TBGProject::getAll() as $project) {
         TBGDashboardViewsTable::getTable()->setDefaultViews($project->getID(), TBGDashboardViewsTable::TYPE_PROJECT);
         if (!$project->getKey()) {
             $project->setName($project->getName());
         }
     }
     $this->upgrade_complete = true;
 }
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addInteger(self::ISSUE_NO, 10);
     parent::_addVarchar(self::TITLE, 200);
     parent::_addInteger(self::POSTED, 10);
     parent::_addInteger(self::LAST_UPDATED, 10);
     parent::_addForeignKeyColumn(self::PROJECT_ID, TBGProjectsTable::getTable(), TBGProjectsTable::ID);
     parent::_addText(self::DESCRIPTION, false);
     parent::_addBoolean(self::STATE);
     parent::_addForeignKeyColumn(self::POSTED_BY, TBGUsersTable::getTable(), TBGUsersTable::ID);
     parent::_addInteger(self::OWNER, 10);
     parent::_addInteger(self::OWNER_TYPE, 2);
     parent::_addFloat(self::USER_PAIN, 3);
     parent::_addInteger(self::PAIN_BUG_TYPE, 3);
     parent::_addInteger(self::PAIN_EFFECT, 3);
     parent::_addInteger(self::PAIN_LIKELIHOOD, 3);
     parent::_addInteger(self::ASSIGNED_TO, 10);
     parent::_addText(self::REPRODUCTION_STEPS, false);
     parent::_addForeignKeyColumn(self::RESOLUTION, TBGListTypesTable::getTable(), TBGListTypesTable::ID);
     parent::_addForeignKeyColumn(self::ISSUE_TYPE, TBGIssueTypesTable::getTable(), TBGIssueTypesTable::ID);
     parent::_addForeignKeyColumn(self::STATUS, TBGListTypesTable::getTable(), TBGListTypesTable::ID);
     parent::_addForeignKeyColumn(self::PRIORITY, TBGListTypesTable::getTable(), TBGListTypesTable::ID);
     parent::_addForeignKeyColumn(self::CATEGORY, TBGListTypesTable::getTable(), TBGListTypesTable::ID);
     parent::_addForeignKeyColumn(self::SEVERITY, TBGListTypesTable::getTable(), TBGListTypesTable::ID);
     parent::_addForeignKeyColumn(self::REPRODUCABILITY, TBGListTypesTable::getTable(), TBGListTypesTable::ID);
     parent::_addVarchar(self::SCRUMCOLOR, 7, '#FFFFFF');
     parent::_addInteger(self::ESTIMATED_MONTHS, 10);
     parent::_addInteger(self::ESTIMATED_WEEKS, 10);
     parent::_addInteger(self::ESTIMATED_DAYS, 10);
     parent::_addInteger(self::ESTIMATED_HOURS, 10);
     parent::_addInteger(self::ESTIMATED_POINTS);
     parent::_addInteger(self::SPENT_MONTHS, 10);
     parent::_addInteger(self::SPENT_WEEKS, 10);
     parent::_addInteger(self::SPENT_DAYS, 10);
     parent::_addInteger(self::SPENT_HOURS, 10);
     parent::_addInteger(self::VOTES_TOTAL, 10);
     parent::_addInteger(self::SPENT_POINTS);
     parent::_addInteger(self::PERCENT_COMPLETE, 2);
     parent::_addInteger(self::ASSIGNED_TYPE, 2);
     parent::_addInteger(self::DUPLICATE_OF, 10);
     parent::_addBoolean(self::DELETED);
     parent::_addBoolean(self::BLOCKING);
     parent::_addBoolean(self::LOCKED);
     parent::_addForeignKeyColumn(self::BEING_WORKED_ON_BY_USER, TBGUsersTable::getTable(), TBGUsersTable::ID);
     parent::_addInteger(self::BEING_WORKED_ON_BY_USER_SINCE, 10);
     parent::_addForeignKeyColumn(self::MILESTONE, TBGMilestonesTable::getTable(), TBGMilestonesTable::ID);
     parent::_addForeignKeyColumn(self::WORKFLOW_STEP_ID, TBGWorkflowStepsTable::getTable(), TBGWorkflowStepsTable::ID);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
 }
 public function setValuesFromRequest(TBGRequest $request)
 {
     if ($request->hasParameter('predefined_search')) {
         $this->setPredefinedVariables($request['predefined_search']);
     } else {
         $this->_templatename = $request->hasParameter('template') && self::isTemplateValid($request['template']) ? $request['template'] : 'results_normal';
         $this->_templateparameter = $request['template_parameter'];
         $this->_issues_per_page = $request->getParameter('issues_per_page', 50);
         $this->_offset = $request->getParameter('offset', 0);
         $this->_filters = TBGSearchFilter::getFromRequest($request, $this);
         $this->_applies_to_project = TBGContext::getCurrentProject();
         $this->_columns = $request->getParameter('columns');
         $this->_sortfields = $request->getParameter('sortfields');
         if ($request['quicksearch']) {
             $this->setSortFields(array(TBGIssuesTable::LAST_UPDATED => 'asc'));
         }
         $this->_groupby = $request['groupby'];
         $this->_grouporder = $request->getParameter('grouporder', 'asc');
         if (in_array($this->_templatename, array('results_userpain_singlepainthreshold', 'results_userpain_totalpainthreshold'))) {
             $this->_searchtitle = TBGContext::getI18n()->__('Showing "bug report" issues sorted by user pain, threshold set at %threshold', array('%threshold' => $this->_template_parameter));
             $this->_issues_per_page = 0;
             $this->_groupby = 'user_pain';
             $this->_grouporder = 'desc';
             $this->_filters['issuetype'] = TBGSearchFilter::createFilter('issuetype', join(',', TBGIssueTypesTable::getTable()->getBugReportTypeIDs()));
         } elseif ($this->_templatename == 'results_votes') {
             $this->_searchtitle = TBGContext::getI18n()->__('Showing issues ordered by number of votes');
             $this->_issues_per_page = $request->getParameter('issues_per_page', 100);
             $this->_groupby = 'votes';
             $this->_grouporder = 'desc';
         }
     }
     $this->_setupGenericFilters();
 }
 public function findIssues($filters = array(), $results_per_page = 30, $offset = 0, $groupby = null, $grouporder = null)
 {
     $crit = $this->getCriteria();
     $crit->addWhere(self::DELETED, false);
     if (count($filters) > 0) {
         $crit->addJoin(TBGIssueCustomFieldsTable::getTable(), TBGIssueCustomFieldsTable::ISSUE_ID, TBGIssuesTable::ID);
         foreach ($filters as $filter => $filter_info) {
             if (array_key_exists('value', $filter_info) && in_array($filter_info['operator'], array('=', '!=', '<=', '>=', '<', '>'))) {
                 if ($filter == 'text') {
                     if ($filter_info['value'] != '') {
                         $searchterm = strpos($filter_info['value'], '%') !== false ? $filter_info['value'] : "%{$filter_info['value']}%";
                         if ($filter_info['operator'] == '=') {
                             $ctn = $crit->returnCriterion(self::TITLE, $searchterm, B2DBCriteria::DB_LIKE);
                             $ctn->addOr(self::DESCRIPTION, $searchterm, B2DBCriteria::DB_LIKE);
                             $ctn->addOr(self::REPRODUCTION_STEPS, $searchterm, B2DBCriteria::DB_LIKE);
                             $ctn->addOr(TBGIssueCustomFieldsTable::OPTION_VALUE, $searchterm, B2DBCriteria::DB_LIKE);
                         } else {
                             $ctn = $crit->returnCriterion(self::TITLE, $searchterm, B2DBCriteria::DB_NOT_LIKE);
                             $ctn->addWhere(self::DESCRIPTION, $searchterm, B2DBCriteria::DB_NOT_LIKE);
                             $ctn->addWhere(self::REPRODUCTION_STEPS, $searchterm, B2DBCriteria::DB_NOT_LIKE);
                             $ctn->addOr(TBGIssueCustomFieldsTable::OPTION_VALUE, $searchterm, B2DBCriteria::DB_NOT_LIKE);
                         }
                         $crit->addWhere($ctn);
                     }
                 } elseif (in_array($filter, self::getValidSearchFilters())) {
                     $crit->addWhere($this->getB2DBName() . '.' . $filter, $filter_info['value'], $filter_info['operator']);
                 } elseif (TBGCustomDatatype::doesKeyExist($filter)) {
                     $customdatatype = TBGCustomDatatype::getByKey($filter);
                     $ctn = $crit->returnCriterion(TBGIssueCustomFieldsTable::CUSTOMFIELDS_ID, $customdatatype->getID());
                     $ctn->addWhere(TBGIssueCustomFieldsTable::OPTION_VALUE, $filter_info['value'], $filter_info['operator']);
                     $crit->addWhere($ctn);
                 }
             } else {
                 if (in_array($filter, self::getValidSearchFilters())) {
                     $first_val = array_shift($filter_info);
                     if ($filter == 'text') {
                         $filter_info = $first_val;
                         if ($filter_info['value'] != '') {
                             $searchterm = strpos($filter_info['value'], '%') !== false ? $filter_info['value'] : "%{$filter_info['value']}%";
                             if ($filter_info['operator'] == '=') {
                                 $ctn = $crit->returnCriterion(self::TITLE, $searchterm, B2DBCriteria::DB_LIKE);
                                 $ctn->addOr(self::DESCRIPTION, $searchterm, B2DBCriteria::DB_LIKE);
                                 $ctn->addOr(self::REPRODUCTION_STEPS, $searchterm, B2DBCriteria::DB_LIKE);
                             } else {
                                 $ctn = $crit->returnCriterion(self::TITLE, $searchterm, B2DBCriteria::DB_NOT_LIKE);
                                 $ctn->addWhere(self::DESCRIPTION, $searchterm, B2DBCriteria::DB_NOT_LIKE);
                                 $ctn->addWhere(self::REPRODUCTION_STEPS, $searchterm, B2DBCriteria::DB_NOT_LIKE);
                             }
                             $crit->addWhere($ctn);
                         }
                     } else {
                         $ctn = $crit->returnCriterion($this->getB2DBName() . '.' . $filter, $first_val['value'], $first_val['operator']);
                         if (count($filter_info) > 0) {
                             foreach ($filter_info as $single_filter) {
                                 if (in_array($single_filter['operator'], array('=', '<=', '>=', '<', '>'))) {
                                     $ctn->addOr($this->getB2DBName() . '.' . $filter, $single_filter['value'], $single_filter['operator']);
                                 } elseif ($single_filter['operator'] == '!=') {
                                     $ctn->addWhere($this->getB2DBName() . '.' . $filter, $single_filter['value'], $single_filter['operator']);
                                 }
                             }
                         }
                         $crit->addWhere($ctn);
                     }
                 } elseif (TBGCustomDatatype::doesKeyExist($filter)) {
                     $customdatatype = TBGCustomDatatype::getByKey($filter);
                     $first_val = array_shift($filter_info);
                     $ctn = $crit->returnCriterion(TBGIssueCustomFieldsTable::CUSTOMFIELDS_ID, $customdatatype->getID());
                     $ctn->addWhere(TBGIssueCustomFieldsTable::OPTION_VALUE, $first_val['value'], $first_val['operator']);
                     if (count($filter_info) > 0) {
                         foreach ($filter_info as $single_filter) {
                             if (in_array($single_filter['operator'], array('=', '!=', '<=', '>=', '<', '>'))) {
                                 $ctn->addOr(TBGIssueCustomFieldsTable::OPTION_VALUE, $single_filter['value'], $single_filter['operator']);
                             }
                         }
                     }
                     $crit->addWhere($ctn);
                 }
             }
         }
     }
     $crit->addSelectionColumn(self::ID);
     $crit->setDistinct();
     if ($offset != 0) {
         $crit->setOffset($offset);
     }
     $crit2 = clone $crit;
     $count = $this->doCount($crit2);
     if ($count > 0) {
         if ($results_per_page != 0) {
             $crit->setLimit($results_per_page);
         }
         if ($offset != 0) {
             $crit->setOffset($offset);
         }
         if ($groupby !== null) {
             $grouporder = $grouporder !== null ? $grouporder == 'asc' ? B2DBCriteria::SORT_ASC : B2DBCriteria::SORT_DESC : B2DBCriteria::SORT_ASC;
             switch ($groupby) {
                 case 'category':
                     $crit->addSelectionColumn(TBGListTypesTable::NAME);
                     $crit->addOrderBy(TBGListTypesTable::NAME, $grouporder);
                     break;
                 case 'status':
                     $crit->addSelectionColumn(self::STATUS);
                     $crit->addOrderBy(self::STATUS, $grouporder);
                     break;
                 case 'milestone':
                     $crit->addSelectionColumn(self::MILESTONE);
                     $crit->addSelectionColumn(self::PERCENT_COMPLETE);
                     $crit->addOrderBy(self::MILESTONE, $grouporder);
                     $crit->addOrderBy(self::PERCENT_COMPLETE, 'desc');
                     break;
                 case 'assignee':
                     $crit->addSelectionColumn(self::ASSIGNED_TYPE);
                     $crit->addSelectionColumn(self::ASSIGNED_TO);
                     $crit->addOrderBy(self::ASSIGNED_TYPE);
                     $crit->addOrderBy(self::ASSIGNED_TO, $grouporder);
                     break;
                 case 'state':
                     $crit->addSelectionColumn(self::STATE);
                     $crit->addOrderBy(self::STATE, $grouporder);
                     break;
                 case 'severity':
                     $crit->addSelectionColumn(self::SEVERITY);
                     $crit->addOrderBy(self::SEVERITY, $grouporder);
                     break;
                 case 'user_pain':
                     $crit->addSelectionColumn(self::USER_PAIN);
                     $crit->addOrderBy(self::USER_PAIN, $grouporder);
                     break;
                 case 'votes':
                     $crit->addSelectionColumn(self::VOTES_TOTAL);
                     $crit->addOrderBy(self::VOTES_TOTAL, $grouporder);
                     break;
                 case 'resolution':
                     $crit->addSelectionColumn(self::RESOLUTION);
                     $crit->addOrderBy(self::RESOLUTION, $grouporder);
                     break;
                 case 'priority':
                     $crit->addSelectionColumn(self::PRIORITY);
                     $crit->addOrderBy(self::PRIORITY, $grouporder);
                     break;
                 case 'issuetype':
                     $crit->addJoin(TBGIssueTypesTable::getTable(), TBGIssueTypesTable::ID, self::ISSUE_TYPE);
                     $crit->addSelectionColumn(TBGIssueTypesTable::NAME);
                     $crit->addOrderBy(TBGIssueTypesTable::NAME, $grouporder);
                     break;
                 case 'edition':
                     $crit->addJoin(TBGIssueAffectsEditionTable::getTable(), TBGIssueAffectsEditionTable::ISSUE, self::ID);
                     $crit->addJoin(TBGEditionsTable::getTable(), TBGEditionsTable::ID, TBGIssueAffectsEditionTable::EDITION, array(), B2DBCriteria::DB_LEFT_JOIN, TBGIssueAffectsEditionTable::getTable());
                     $crit->addSelectionColumn(TBGEditionsTable::NAME);
                     $crit->addOrderBy(TBGEditionsTable::NAME, $grouporder);
                     break;
                 case 'build':
                     $crit->addJoin(TBGIssueAffectsBuildTable::getTable(), TBGIssueAffectsBuildTable::ISSUE, self::ID);
                     $crit->addJoin(TBGBuildsTable::getTable(), TBGBuildsTable::ID, TBGIssueAffectsBuildTable::BUILD, array(), B2DBCriteria::DB_LEFT_JOIN, TBGIssueAffectsBuildTable::getTable());
                     $crit->addSelectionColumn(TBGBuildsTable::NAME);
                     $crit->addOrderBy(TBGBuildsTable::NAME, $grouporder);
                     break;
                 case 'component':
                     $crit->addJoin(TBGIssueAffectsComponentTable::getTable(), TBGIssueAffectsComponentTable::ISSUE, self::ID);
                     $crit->addJoin(TBGComponentsTable::getTable(), TBGComponentsTable::ID, TBGIssueAffectsComponentTable::COMPONENT, array(), B2DBCriteria::DB_LEFT_JOIN, TBGIssueAffectsComponentTable::getTable());
                     $crit->addSelectionColumn(TBGComponentsTable::NAME);
                     $crit->addOrderBy(TBGComponentsTable::NAME, $grouporder);
                     break;
             }
         }
         $crit->addSelectionColumn(self::LAST_UPDATED);
         $crit->addOrderBy(self::LAST_UPDATED, 'asc');
         $res = $this->doSelect($crit, 'none');
         $ids = array();
         while ($row = $res->getNextRow()) {
             $ids[] = $row->get(self::ID);
         }
         $ids = array_reverse($ids);
         $crit2 = $this->getCriteria();
         $crit2->addWhere(self::ID, $ids, B2DBCriteria::DB_IN);
         $crit2->addOrderBy(self::ID, $ids);
         $res = $this->doSelect($crit2);
         return array($res, $count);
     } else {
         return array(null, 0);
     }
 }