本文整理汇总了PHP中TBGContext::setCurrentProject方法的典型用法代码示例。如果您正苦于以下问题:PHP TBGContext::setCurrentProject方法的具体用法?PHP TBGContext::setCurrentProject怎么用?PHP TBGContext::setCurrentProject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TBGContext
的用法示例。
在下文中一共展示了TBGContext::setCurrentProject方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preExecute
/**
* Pre-execute function for search functions
*
* @param TBGRequest $request
*/
public function preExecute(TBGRequest $request, $action)
{
$this->forward403unless(TBGContext::getUser()->hasPageAccess('search') && TBGContext::getUser()->canSearchForIssues());
if ($project_key = $request['project_key']) {
$project = TBGProject::getByKey($project_key);
} elseif (is_numeric($request['project_id']) && ($project_id = (int) $request['project_id'])) {
$project = TBGProjectsTable::getTable()->selectById($project_id);
} else {
$project = false;
}
if ($project instanceof TBGProject) {
$this->forward403unless(TBGContext::getUser()->hasProjectPageAccess('project_issues', $project));
TBGContext::getResponse()->setPage('project_issues');
TBGContext::setCurrentProject($project);
}
$this->search_object = TBGSavedSearch::getFromRequest($request);
$this->issavedsearch = $this->search_object instanceof TBGSavedSearch && $this->search_object->getB2DBID();
$this->show_results = $this->issavedsearch || $request->hasParameter('quicksearch') || $request->hasParameter('fs') || $request->getParameter('search', false) ? true : false;
$this->searchterm = $this->search_object->getSearchterm();
$this->searchtitle = $this->search_object->getTitle();
if ($this->issavedsearch) {
if (!($this->search_object instanceof TBGSavedSearch && TBGContext::getUser()->canAccessSavedSearch($this->search_object))) {
TBGContext::setMessage('search_error', TBGContext::getI18n()->__("You don't have access to this saved search"));
}
}
}
示例2: preExecute
/**
* 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) {
}
}
示例3: runProjectCommits
public function runProjectCommits(TBGRequest $request)
{
$this->selected_project = TBGProject::getByKey($request['project_key']);
TBGContext::setCurrentProject($this->selected_project);
if (TBGContext::getModule('vcs_integration')->getSetting('vcs_mode_' . TBGContext::getCurrentProject()->getID()) == TBGVCSIntegration::MODE_DISABLED) {
return $this->return404(TBGContext::getI18n()->__('VCS Integration has been disabled for this project'));
}
$offset = $request->getParameter('offset', 0);
$this->commits = TBGVCSIntegrationCommit::getByProject($this->selected_project->getID(), 40, $offset);
if ($offset) {
return $this->renderJSON(array('content' => $this->getTemplateHTML('vcs_integration/projectcommits', array('commits' => $this->commits, 'selected_project' => $this->selected_project)), 'offset' => $offset + 40));
}
}
示例4: preExecute
/**
* 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) {
}
}
示例5: preExecute
/**
* Pre-execute function
*
* @param TBGRequest $request
*/
public function preExecute(TBGRequest $request, $action)
{
$this->article = null;
$this->article_name = $request['article_name'];
$this->article_id = (int) $request['article_id'];
$this->special = false;
if ($request->hasParameter('article_name') && mb_strpos($request['article_name'], ':') !== false) {
$this->article_name = $this->_getArticleNameDetails($request['article_name']);
} else {
try {
if ($project_key = $request['project_key']) {
$this->selected_project = TBGProject::getByKey($project_key);
} elseif ($project_id = (int) $request['project_id']) {
$this->selected_project = TBGProjectsTable::getTable()->selectById($project_id);
}
} catch (Exception $e) {
}
}
if (!$this->special) {
if ($this->article_id) {
$this->article = TBGArticlesTable::getTable()->selectById($this->article_id);
} elseif ($this->article_name) {
$this->article = TBGArticlesTable::getTable()->getArticleByName($this->article_name);
}
if (!$this->article instanceof TBGWikiArticle) {
$this->article = new TBGWikiArticle();
if ($this->article_name) {
$this->article->setName($this->article_name);
} elseif ($request->hasParameter('parent_article_name')) {
$this->article->setParentArticle(TBGArticlesTable::getTable()->getArticleByName($request['parent_article_name']));
$this->_getArticleNameDetails($request['parent_article_name']);
if ($this->article->getParentArticle() instanceof TBGWikiArticle) {
if ($this->article->getParentArticle()->getArticleType() == TBGWikiArticle::TYPE_WIKI) {
$this->article->setName($this->article->getParentArticle()->getName() . ':');
}
$this->article->setArticleType($this->article->getParentArticle()->getArticleType());
}
}
$this->article->setContentSyntax($this->getUser()->getPreferredWikiSyntax(true));
}
}
if ($this->selected_project instanceof TBGProject) {
if (!$this->selected_project->hasAccess()) {
$this->forward403();
} else {
TBGContext::setCurrentProject($this->selected_project);
}
}
}
示例6: preExecute
/**
* Pre-execute function for search functions
*
* @param TBGRequest $request
*/
public function preExecute(TBGRequest $request, $action)
{
$this->forward403unless(TBGContext::getUser()->hasPageAccess('search') && TBGContext::getUser()->canSearchForIssues());
if ($request->hasParameter('project_key')) {
if (($project = TBGProject::getByKey($request->getParameter('project_key'))) instanceof TBGProject) {
$this->forward403unless(TBGContext::getUser()->hasProjectPageAccess('project_issues', $project->getID()));
TBGContext::getResponse()->setPage('project_issues');
TBGContext::setCurrentProject($project);
}
}
$filters = $request->getParameter('filters', array());
$this->searchterm = null;
if (array_key_exists('text', $filters) && array_key_exists('value', $filters['text'])) {
$this->searchterm = $filters['text']['value'];
}
}
示例7: preExecute
/**
* 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);
}
}
示例8: preExecute
/**
* Pre-execute function
*
* @param TBGRequest $request
* @param string $action
*/
public function preExecute(TBGRequest $request, $action)
{
if ($project_id = $request['project_id']) {
try {
$this->selected_project = TBGContext::factory()->TBGProject($project_id);
} catch (Exception $e) {
}
} elseif ($project_key = $request['project_key']) {
try {
$this->selected_project = TBGProject::getByKey($project_key);
} catch (Exception $e) {
}
}
if ($this->selected_project instanceof TBGProject) {
TBGContext::setCurrentProject($this->selected_project);
$this->project_key = $this->selected_project->getKey();
} else {
$this->return404(TBGContext::getI18n()->__('This project does not exist'));
}
}
示例9: runDashboardView
public function runDashboardView(TBGRequest $request)
{
$view = new TBGDashboardView($request['view_id']);
if ($view->getTargetType() == TBGDashboardView::TYPE_PROJECT) {
TBGContext::setCurrentProject(new TBGProject($view->getProjectID()));
}
return $this->renderJSON(array('content' => $this->returnComponentHTML($view->getTemplate(), array('view' => $view))));
}
示例10: processCommit
public static function processCommit(TBGProject $project, $commit_msg, $old_rev, $new_rev, $date = null, $changed, $author, $branch = null)
{
$output = '';
TBGContext::setCurrentProject($project);
if ($project->isArchived()) {
return;
}
try {
TBGContext::getI18n();
} catch (Exception $e) {
TBGContext::reinitializeI18n(null);
}
// Is VCS Integration enabled?
if (TBGSettings::get('vcs_mode_' . $project->getID(), 'vcs_integration') == TBGVCSIntegration::MODE_DISABLED) {
$output .= '[VCS ' . $project->getKey() . '] This project does not use VCS Integration' . "\n";
return $output;
}
// Parse the commit message, and obtain the issues and transitions for issues.
$parsed_commit = TBGIssue::getIssuesFromTextByRegex($commit_msg);
$issues = $parsed_commit["issues"];
$transitions = $parsed_commit["transitions"];
// If no issues exist, we may not be able to continue
// if (count($issues) == 0)
// {
// $output .= '[VCS '.$project->getKey().'] This project only accepts commits which affect issues' . "\n";
// return $output;
// }
// Build list of affected files
$file_lines = preg_split('/[\\n\\r]+/', $changed);
$files = array();
foreach ($file_lines as $aline) {
$action = mb_substr($aline, 0, 1);
if ($action == "A" || $action == "U" || $action == "D" || $action == "M") {
$theline = trim(mb_substr($aline, 1));
$files[] = array($action, $theline);
}
}
// Find author of commit, fallback is guest
/*
* Some VCSes use a different format of storing the committer's name. Systems like bzr, git and hg use the format
* Joe Bloggs <me@example.com>, instead of a classic username. Therefore a user will be found via 4 queries:
* a) First we extract the email if there is one, and find a user with that email
* b) If one is not found - or if no email was specified, then instead test against the real name (using the name part if there was an email)
* c) the username or full name is checked against the friendly name field
* d) and if we still havent found one, then we check against the username
* e) and if we STILL havent found one, we use the guest user
*/
if (preg_match("/(?<=<)(.*)(?=>)/", $author, $matches)) {
$email = $matches[0];
// a)
$user = TBGUsersTable::getTable()->getByEmail($email);
if (!$user instanceof TBGUser) {
// Not found by email
preg_match("/(?<=^)(.*)(?= <)/", $author, $matches);
$author = $matches[0];
}
}
// b)
if (!$user instanceof TBGUser) {
$user = TBGUsersTable::getTable()->getByRealname($author);
}
// c)
if (!$user instanceof TBGUser) {
$user = TBGUsersTable::getTable()->getByBuddyname($author);
}
// d)
if (!$user instanceof TBGUser) {
$user = TBGUsersTable::getTable()->getByUsername($author);
}
// e)
if (!$user instanceof TBGUser) {
$user = TBGSettings::getDefaultUser();
}
TBGContext::setUser($user);
TBGSettings::forceSettingsReload();
TBGContext::cacheAllPermissions();
$output .= '[VCS ' . $project->getKey() . '] Commit to be logged by user ' . $user->getName() . "\n";
if ($date == null) {
$date = NOW;
}
// Create the commit data
$commit = new TBGVCSIntegrationCommit();
$commit->setAuthor($user);
$commit->setDate($date);
$commit->setLog($commit_msg);
$commit->setPreviousRevision($old_rev);
$commit->setRevision($new_rev);
$commit->setProject($project);
if ($branch !== null) {
$data = 'branch:' . $branch;
$commit->setMiscData($data);
}
$commit->save();
$output .= '[VCS ' . $project->getKey() . '] Commit logged with revision ' . $commit->getRevision() . "\n";
// Iterate over affected issues and update them.
foreach ($issues as $issue) {
$inst = new TBGVCSIntegrationIssueLink();
$inst->setIssue($issue);
$inst->setCommit($commit);
$inst->save();
//.........这里部分代码省略.........
示例11: addNewCommit
public function addNewCommit($project, $commit_msg, $old_rev, $new_rev, $date = null, $changed, $author)
{
/* Find issues to update */
$fixes_grep = "#((bug|issue|ticket|fix|fixes|fixed|fixing|applies to|closes|references|ref|addresses|re|see|according to|also see)\\s\\#?(([A-Z0-9]+\\-)?\\d+))#ie";
$output = '';
$f_issues = array();
try {
TBGContext::getI18n();
} catch (Exception $e) {
TBGContext::reinitializei18n();
}
try {
$project = new TBGProject($project);
} catch (Exception $e) {
return TBGContext::getI18n()->__('Error: Invalid project ID');
}
if (preg_match_all($fixes_grep, $commit_msg, $f_issues)) {
// Github
if (is_array($changed)) {
$entries = $changed;
$changed = '';
// Now handle changed files
foreach ($entries[0] as $file) {
$changed .= 'M' . $file . "\n";
}
// Now handle new files
foreach ($entries[1] as $file) {
$changed .= 'A' . $file . "\n";
}
// Now handle deleted files
foreach ($entries[2] as $file) {
$changed .= 'D' . $file . "\n";
}
}
$f_issues = array_unique($f_issues[3]);
$file_lines = preg_split('/[\\n\\r]+/', $changed);
$files = array();
foreach ($file_lines as $aline) {
$action = substr($aline, 0, 1);
if ($action == "A" || $action == "U" || $action == "D" || $action == "M") {
$theline = trim(substr($aline, 1));
$files[] = array($action, $theline);
}
}
foreach ($f_issues as $issue_no) {
TBGContext::setCurrentProject($project);
$theIssue = TBGIssue::getIssueFromLink($issue_no, true);
if ($theIssue instanceof TBGIssue) {
$uid = 0;
/*
* Some VCSes use a different format of storing the committer's name. Systems like bzr, git and hg use the format
* Joe Bloggs <me@example.com>, instead of a classic username. Therefore a user will be found via 4 queries:
* a) First we extract the email if there is one, and find a user with that email
* b) If one is not found - or if no email was specified, then instead test against the real name (using the name part if there was an email)
* c) the username or full name is checked against the friendly name field
* d) and if we still havent found one, then we check against the username
* e) and if we STILL havent found one, we just say the user is id 0 (unknown user).
*/
if (preg_match("/(?<=<)(.*)(?=>)/", $author, $matches)) {
$email = $matches[0];
// a)
$crit = new B2DBCriteria();
$crit->setFromTable(TBGUsersTable::getTable());
$crit->addSelectionColumn(TBGUsersTable::ID);
$crit->addWhere(TBGUsersTable::EMAIL, $email);
$row = TBGUsersTable::getTable()->doSelectOne($crit);
if ($row != null) {
$uid = $row->get(TBGUsersTable::ID);
} else {
// Not found by email
preg_match("/(?<=^)(.*)(?= <)/", $author, $matches);
$author = $matches[0];
}
}
// b)
if ($uid == 0) {
$crit = new B2DBCriteria();
$crit->setFromTable(TBGUsersTable::getTable());
$crit->addSelectionColumn(TBGUsersTable::ID);
$crit->addWhere(TBGUsersTable::REALNAME, $author);
$row = TBGUsersTable::getTable()->doSelectOne($crit);
if ($row != null) {
$uid = $row->get(TBGUsersTable::ID);
}
}
// c)
if ($uid == 0) {
$crit = new B2DBCriteria();
$crit->setFromTable(TBGUsersTable::getTable());
$crit->addSelectionColumn(TBGUsersTable::ID);
$crit->addWhere(TBGUsersTable::BUDDYNAME, $author);
$row = TBGUsersTable::getTable()->doSelectOne($crit);
if ($row != null) {
$uid = $row->get(TBGUsersTable::ID);
}
}
// d)
if ($uid == 0) {
$crit = new B2DBCriteria();
$crit->setFromTable(TBGUsersTable::getTable());
//.........这里部分代码省略.........
示例12: _loadSelectedProjectAndIssueTypeFromRequestForReportIssueAction
protected function _loadSelectedProjectAndIssueTypeFromRequestForReportIssueAction(TBGRequest $request)
{
try {
if ($project_key = $request->getParameter('project_key')) {
$this->selected_project = TBGProject::getByKey($project_key);
} elseif ($project_id = $request->getParameter('project_id')) {
$this->selected_project = TBGContext::factory()->TBGProject($project_id);
}
} catch (Exception $e) {
}
if ($this->selected_project instanceof TBGProject) {
TBGContext::setCurrentProject($this->selected_project);
}
if ($this->selected_project instanceof TBGProject) {
$this->issuetypes = $this->selected_project->getIssuetypeScheme()->getIssuetypes();
} else {
$this->issuetypes = TBGIssuetype::getAll();
}
if ($request->hasParameter('issuetype')) {
$this->selected_issuetype = TBGIssuetype::getIssuetypeByKeyish($request->getParameter('issuetype'));
}
if (!$this->selected_issuetype instanceof TBGIssuetype) {
$this->issuetype_id = $request->getParameter('issuetype_id');
if ($this->issuetype_id) {
try {
$this->selected_issuetype = TBGContext::factory()->TBGIssuetype($this->issuetype_id);
} catch (Exception $e) {
}
}
} else {
$this->issuetype_id = $this->selected_issuetype->getID();
}
}