public function getAllArticles() { $crit = $this->getCriteria(); $crit->addWhere(self::SCOPE, TBGContext::getScope()->getID()); $crit->addOrderBy(self::NAME); $res = $this->doSelect($crit); $articles = array(); if ($res) { while ($row = $res->getNextRow()) { $a_id = $row->get(self::ID); $articles[$a_id] = PublishFactory::article($a_id, $row); } } return $articles; }
protected function _populateCategoryArticles() { if ($this->_category_articles === null) { $this->_category_articles = array(); if ($res = TBGArticleCategoriesTable::getTable()->getCategoryArticles($this->getCategoryName())) { while ($row = $res->getNextRow()) { try { $this->_category_articles[$row->get(TBGArticleCategoriesTable::ARTICLE_NAME)] = PublishFactory::articleName($row->get(TBGArticleCategoriesTable::ARTICLE_NAME)); } catch (Exception $e) { } } } } }
/** * Configuration import page * * @param TBGRequest $request */ public function runImport(TBGRequest $request) { if ($request->isMethod(TBGRequest::POST)) { if ($request->getParameter('import_sample_data')) { $users = array(); $user1 = new TBGUser(); $user1->setUsername('john'); $user1->setPassword('john'); $user1->setBuddyname('John'); $user1->setRealname('John'); $user1->setActivated(); $user1->setEnabled(); $user1->save(); $users[] = $user1; $user2 = new TBGUser(); $user2->setUsername('jane'); $user2->setPassword('jane'); $user2->setBuddyname('Jane'); $user2->setRealname('Jane'); $user2->setActivated(); $user2->setEnabled(); $user2->save(); $users[] = $user2; $user3 = new TBGUser(); $user3->setUsername('jackdaniels'); $user3->setPassword('jackdaniels'); $user3->setBuddyname('Jack'); $user3->setRealname('Jack Daniels'); $user3->setActivated(); $user3->setEnabled(); $user3->save(); $users[] = $user3; $project1 = new TBGProject(); $project1->setName('Sample project 1'); $project1->setOwner($users[rand(0, 2)]); $project1->setLeader($users[rand(0, 2)]); $project1->setQaResponsible($users[rand(0, 2)]); $project1->setDescription('This is a sample project that is awesome. Try it out!'); $project1->setHomepage('http://www.google.com'); $project1->save(); $project2 = new TBGProject(); $project2->setName('Sample project 2'); $project2->setOwner($users[rand(0, 2)]); $project2->setLeader($users[rand(0, 2)]); $project2->setQaResponsible($users[rand(0, 2)]); $project2->setDescription('This is the second sample project. Not as awesome as the first one, but still worth a try!'); $project2->setHomepage('http://www.bing.com'); $project2->save(); foreach (array($project1, $project2) as $project) { for ($cc = 1; $cc <= 5; $cc++) { $milestone = new TBGMilestone(); $milestone->setName("Milestone {$cc}"); $milestone->setProject($project); $milestone->setType(TBGMilestone::TYPE_REGULAR); if ((bool) rand(0, 1)) { $milestone->setScheduledDate(NOW + 100000 * (20 * $cc)); } $milestone->save(); } } $p1_milestones = $project1->getMilestones(); $p2_milestones = $project2->getMilestones(); $issues = array(); $priorities = TBGPriority::getAll(); $categories = TBGCategory::getAll(); $severities = TBGSeverity::getAll(); $statuses = TBGStatus::getAll(); $reproducabilities = TBGReproducability::getAll(); $lorem_ipsum = TBGArticlesTable::getTable()->getArticleByName('LoremIpsum'); $lorem_ipsum = PublishFactory::article($lorem_ipsum->get(TBGArticlesTable::ID), $lorem_ipsum); $lorem_words = explode(' ', $lorem_ipsum->getContent()); foreach (array('bugreport', 'featurerequest', 'enhancement', 'idea') as $issuetype) { $issuetype = TBGIssuetype::getIssuetypeByKeyish($issuetype); for ($cc = 1; $cc <= 10; $cc++) { $issue1 = new TBGIssue(); $issue1->setProject($project1); $issue1->setPostedBy($users[rand(0, 2)]); $issue1->setPosted(NOW - 86400 * rand(1, 30)); $title_string = ''; $description_string = ''; $rand_length = rand(4, 15); $ucnext = true; for ($ll = 1; $ll <= $rand_length; $ll++) { $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]); $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : strtolower($word); $title_string .= $word; $ucnext = false; if ($ll == $rand_length || rand(1, 15) == 5) { $title_string .= '.'; $ucnext = true; } $title_string .= ' '; } $rand_length = rand(40, 500); $ucnext = true; for ($ll = 1; $ll <= $rand_length; $ll++) { $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]); $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : strtolower($word); $description_string .= $word; $ucnext = false; if ($ll == $rand_length || rand(1, 15) == 5) { $description_string .= '.'; $ucnext = true; $description_string .= $ll != $rand_length && rand(1, 15) == 8 ? "\n\n" : ' '; } else { $description_string .= ' '; } } $issue1->setTitle(ucfirst($title_string)); $issue1->setDescription($description_string); $issue1->setIssuetype($issuetype); $issue1->setMilestone($p1_milestones[array_rand($p1_milestones)]); $issue1->setPriority($priorities[array_rand($priorities)]); $issue1->setCategory($categories[array_rand($categories)]); $issue1->setSeverity($severities[array_rand($severities)]); $issue1->setReproducability($reproducabilities[array_rand($reproducabilities)]); $issue1->setPercentCompleted(rand(0, 100)); $issue1->save(); $issue1->setStatus($statuses[array_rand($statuses)]); if (rand(0, 1)) { $issue1->setAssignee($users[array_rand($users)]); } $issue1->save(); $issues[] = $issue1; $issue2 = new TBGIssue(); $issue2->setProject($project2); $issue2->setPostedBy($users[rand(0, 2)]); $issue2->setPosted(NOW - 86400 * rand(1, 30)); $title_string = ''; $description_string = ''; $rand_length = rand(4, 15); $ucnext = true; for ($ll = 1; $ll <= $rand_length; $ll++) { $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]); $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : strtolower($word); $title_string .= $word; $ucnext = false; if ($ll == $rand_length || rand(1, 15) == 5) { $title_string .= '.'; $ucnext = true; } $title_string .= ' '; } $rand_length = rand(40, 500); $ucnext = true; for ($ll = 1; $ll <= $rand_length; $ll++) { $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]); $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : strtolower($word); $description_string .= $word; $ucnext = false; if ($ll == $rand_length || rand(1, 15) == 5) { $description_string .= '.'; $ucnext = true; $description_string .= $ll != $rand_length && rand(1, 15) == 8 ? "\n\n" : ' '; } else { $description_string .= ' '; } } $issue2->setTitle(ucfirst($title_string)); $issue2->setDescription($description_string); $issue2->setIssuetype($issuetype); $issue2->setMilestone($p2_milestones[array_rand($p2_milestones)]); $issue2->setPriority($priorities[array_rand($priorities)]); $issue2->setCategory($categories[array_rand($categories)]); $issue2->setSeverity($severities[array_rand($severities)]); $issue2->setReproducability($reproducabilities[array_rand($reproducabilities)]); $issue2->setPercentCompleted(rand(0, 100)); if (rand(0, 1)) { $issue1->setAssignee($users[array_rand($users)]); } $issue2->save(); $issue2->setStatus($statuses[array_rand($statuses)]); $issue2->save(); $issues[] = $issue2; } } $rand_issues_to_close = rand(8, 40); $resolutions = TBGResolution::getAll(); for ($cc = 1; $cc <= $rand_issues_to_close; $cc++) { $issue = array_slice($issues, array_rand($issues), 1); $issue = $issue[0]; $issue->setResolution($resolutions[array_rand($resolutions)]); $issue->close(); $issue->save(); } $this->imported_data = true; $developer = TBGProjectAssigneesTable::getByType(TBGProjectAssigneesTable::TYPE_DEVELOPER); foreach (array($project1, $project2) as $project) { foreach ($users as $user) { $project->addAssignee($user, $developer->getID()); } } } } $project1 = TBGProject::getByKey('sampleproject1'); $project2 = TBGProject::getByKey('sampleproject2'); $this->canimport = !$project1 instanceof TBGProject && !$project2 instanceof TBGProject; }
public function getFrontpageArticle($type) { $article_name = $type == 'main' ? 'FrontpageArticle' : 'FrontpageLeftmenu'; if ($row = TBGArticlesTable::getTable()->getArticleByName($article_name)) { return PublishFactory::article($row->get(TBGArticlesTable::ID), $row); } return null; }
/** * Show an article * * @param TBGRequest $request */ public function runEditArticle(TBGRequest $request) { $article_name = $this->article instanceof TBGWikiArticle ? $this->article->getName() : $request->getParameter('article_name'); if (!TBGContext::getModule('publish')->canUserEditArticle($article_name)) { TBGContext::setMessage('publish_article_error', TBGContext::getI18n()->__('You do not have permission to edit this article')); $this->forward(TBGContext::getRouting()->generate('publish_article', array('article_name' => $article_name))); } if ($request->isMethod(TBGRequest::POST)) { if ($request->hasParameter('new_article_name') && $request->getParameter('new_article_name') != '') { if ($request->hasParameter('change_reason') && trim($request->getParameter('change_reason')) != '') { try { if ($request->getParameter('article_id')) { if (($article = PublishFactory::article($request->getParameter('article_id'))) && $article instanceof TBGWikiArticle) { if ($article->getLastUpdatedDate() != $request->getParameter('last_modified')) { $this->error = TBGContext::getI18n()->__('The file has been modified since you last opened it'); } else { try { $article->setName($request->getParameter('new_article_name')); $article->setContent($request->getRawParameter('new_article_content')); if ($request->getParameter('preview')) { $this->article = $article; } else { $article->doSave(array(), $request->getParameter('change_reason')); TBGContext::setMessage('publish_article_message', TBGContext::getI18n()->__('The article was saved')); $this->forward(TBGContext::getRouting()->generate('publish_article', array('article_name' => $article->getName()))); } } catch (Exception $e) { $this->error = $e->getMessage(); } } } } } catch (Exception $e) { } if (($article = TBGWikiArticle::getByName($request->getParameter('new_article_name'))) && $article instanceof TBGWikiArticle && $article->getID() != $request->getParameter('article_id')) { $this->error = TBGContext::getI18n()->__('An article with that name already exists. Please choose a different article name'); } elseif (!$article instanceof TBGWikiArticle) { if ($request->getParameter('preview')) { $article = new TBGWikiArticle(); $article->setContent($request->getRawParameter('new_article_content')); $article->setName($request->getParameter('new_article_name')); $this->article = $article; } else { $article_id = TBGWikiArticle::createNew($request->getParameter('new_article_name'), $request->getRawParameter('new_article_content', ''), true); $this->forward(TBGContext::getRouting()->generate('publish_article', array('article_name' => $request->getParameter('new_article_name')))); } } } else { $this->error = TBGContext::getI18n()->__('You have to provide a reason for the changes'); } } else { $this->error = TBGContext::getI18n()->__('You need to specify the article name'); } } $this->preview = (bool) $request->getParameter('preview'); $this->article_title = null; $this->article_content = null; $this->article_intro = null; $this->change_reason = null; if ($this->article instanceof TBGWikiArticle) { $this->article_title = $this->article->getTitle(); $this->article_content = $this->article->getContent(); if ($request->isMethod(TBGRequest::POST)) { if ($request->hasParameter('new_article_name')) { $this->article_title = $request->getParameter('new_article_name'); } if ($request->hasParameter('new_article_content')) { $this->article_content = $request->getRawParameter('new_article_content'); } if ($request->hasParameter('change_reason')) { $this->change_reason = $request->getParameter('change_reason'); } } } else { if ($request->hasParameter('new_article_content')) { $this->article_content = $request->getRawParameter('new_article_content'); } TBGContext::loadLibrary('publish'); $this->article_title = str_replace(array(':', '_'), array(' ', ' '), get_spaced_name($this->article_name)); } }
public function getArticles(TBGProject $project = null, $limit = 10) { $crit = $this->getCriteria(); $crit->addWhere(self::SCOPE, TBGContext::getScope()->getID()); $crit->addWhere('articles.article_type', TBGWikiArticle::TYPE_WIKI); if ($project instanceof TBGProject) { $crit->addWhere(self::NAME, "Category:" . ucfirst($project->getKey()) . "%", Criteria::DB_LIKE); $crit->addOr(self::NAME, ucfirst($project->getKey()) . ":%", Criteria::DB_LIKE); } else { foreach (TBGProjectsTable::getTable()->getAllIncludingDeleted() as $project) { $crit->addWhere(self::NAME, "Category:" . ucfirst($project->getKey()) . "%", Criteria::DB_NOT_LIKE); $crit->addWhere(self::NAME, ucfirst($project->getKey()) . ":%", Criteria::DB_NOT_LIKE); } } $crit->addOrderBy(self::DATE, 'desc'); $articles = array(); if ($res = self::getTable()->doSelect($crit)) { while (($row = $res->getNextRow()) && ($limit === null || count($articles) < $limit)) { try { $article = PublishFactory::article($row->get(self::ID), $row); } catch (Exception $e) { continue; } if ($article->hasAccess()) { $articles[] = $article; } } } return $articles; }
public function componentLogin() { $this->selected_tab = isset($this->section) ? $this->section : 'login'; $this->options = $this->getParameterHolder(); try { $this->article = null; $this->article = PublishFactory::articleName('LoginIntro'); } catch (Exception $e) { } if (TBGContext::getRequest()->getParameter('redirect') == true) { $this->mandatory = true; } }
public function getUserDrafts() { $articles = array(); if ($res = TBGArticlesTable::getTable()->getUnpublishedArticlesByUser(TBGContext::getUser()->getID())) { while ($row = $res->getNextRow()) { try { $article = PublishFactory::article($row->get(TBGArticlesTable::ID), $row); } catch (Exception $e) { continue; } if ($article->hasAccess()) { $articles[] = $article; } } } return $articles; }