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) { $this->foundissues = $this->search_object->getIssues(); $this->resultcount = $this->search_object->getTotalNumberOfIssues(); } elseif (count($this->foundissues) == 1 && !$request['quicksearch']) { $issue = array_shift($this->foundissues); $this->forward(TBGContext::getRouting()->generate('viewissue', array('project_key' => $issue->getProject()->getKey(), 'issue_no' => $issue->getFormattedIssueNo()))); } else { $this->resultcount = count($this->foundissues); if ($this->templatename == 'results_userpain_singlepainthreshold') { usort($this->foundissues, array('searchActions', 'userPainSort')); } } }
public function transform($text) { $text = parent::transform($text); $text = preg_replace_callback(TBGTextParser::getIssueRegex(), array($this, '_parse_issuelink'), $text); $text = preg_replace_callback(TBGTextParser::getMentionsRegex(), array($this, '_parse_mention'), $text); return $text; }
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; } } }
/** * Runs one or more regular expressions against a supplied text, extracts * issue numbers from it, and then obtains corresponding issues. The * function will also obtain information about transitions (if this was * specified in the text). This data can be used for transitioning the * issues through a workflow. * * Once the function finishes processing, it will return an array of format: * * array('issues' => tbg_issues, 'transitions' => transitions). * * tbgissues is an array consisting of TBGIssue instances. * * transitions is an array containing transition arrays. The transition * arrays are accessed with issue numbers as keys (e.g. 'PREFIX-1', * 'PREFIX-5' or '2', '3' etc). Each transition array has the following * format: * * array(0 => command, 1 => parameters) * * command is a string representing the transision command (for example * 'Resolve issue') from the workflow definition. parameters is an array * that contains parameters and their values that should be passed to the * transition step: * * array( 'PARAM1' => 'VALUE1', 'PARAM2' => 'VALUE2', ...) * * * @param text Text that should be parsed for issue numbers and transitions. * * @param preg An array of regular expressions that should be used for * matching issue numbers. If an empty array is provided (default), regular * expressions are obtained through TBGTextParser::getIssueRegex() call. The * regular expressions should contain two named parameters - 'issues' and * 'transitions'. These two will be used for extracting the issue number and * transition information. * * @return An array with two elements, one denoting the matched issues, one * denoting the transitions for issues. These elements can be accessed using * keys 'issues', and 'transitions'. The key 'issues' can be used for * accessing an array made-up of TBGIssue instances. The key 'transitions' * can be used for accessing an array containing transition information * about each issue. The 'transitions' array uses issue numbers as keys, * and contains ordered transition information (see above for detailed * description of format). */ public static function getIssuesFromTextByRegex($text, $preg = array()) { // Fetch the default regular expressions if required. if (!$preg) { $issue_match_regexes = TBGTextParser::getIssueRegex(); } $issue_numbers = array(); // Issue numbers $issues = array(); // Issue objects $transitions = array(); // Transition information // Iterate over all regular expressions that should be used for // issue/transition matching in commit message. foreach ($issue_match_regexes as $issue_match_regex) { $matched_issue_data = array(); // All data from regexp // If any match is found using the current regular expression, extract // the information. if (preg_match_all($issue_match_regex, $text, $matched_issue_data)) { // Identified issues are kept inside of named regex group. foreach ($matched_issue_data["issues"] as $key => $issue_number) { // Get the matched transitions for the issue. $matched_issue_transitions = $matched_issue_data["transitions"][$key]; // Create an empty array to store transitions for an issue. Don't // overwrite it. Use issue number as key for transitions. if (!array_key_exists($issue_number, $transitions)) { $transitions[$issue_number] = array(); } // Add the transition information (if any) for an issue. if ($matched_issue_transitions) { // Parse the transition information. Each transition string is in // format: // 'TRANSITION1: PARAM1_1=VALUE1_1 PARAM1_2=VALUE1_2; TRANSITION2: PARAM2_1=VALUE2_1 PARAM2_2=VALUE2_2' foreach (explode("; ", $matched_issue_transitions) as $transition) { // Split command from its parameters. $transition_data = explode(": ", $transition); $transition_command = $transition_data[0]; // Set-up array that will contain parameters $transition_parameters = array(); // Process parameters if they were present. if (count($transition_data) == 2) { // Split into induvidual parameters. foreach (explode(" ", $transition_data[1]) as $parameter) { // Only process proper parameters (of format 'PARAM=VALUE') if (mb_strpos($parameter, '=')) { list($param_key, $param_value) = explode('=', $parameter); $transition_parameters[$param_key] = $param_value; } } } // Append the transition information for the current issue number. $transitions[$issue_number][] = array($transition_command, $transition_parameters); } } // Add the issue number to the list. $issue_numbers[] = $issue_number; } } } // Make sure that each issue gets procssed only once for a single commit // (avoid duplication of commits). $issue_numbers = array_unique($issue_numbers); // Fetch all issues affected by the commit. foreach ($issue_numbers as $issue_no) { $issue = TBGIssue::getIssueFromLink($issue_no); if ($issue instanceof TBGIssue) { $issues[] = $issue; } } // Return array consisting out of two arrays - one with TBGIssue // instances, and the second one with transition information for those // issues. return array("issues" => $issues, "transitions" => $transitions); }