/** * Adds a new milestone to the project * * @param string $m_name * @return TBGMilestone */ public function addMilestone($m_name, $type) { $this->_milestones = null; $milestone = new TBGMilestone(); $milestone->setName($m_name); $milestone->setType($type); $milestone->setProject($this); $milestone->save(); return $milestone; }
/** * 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 runBulkUpdateIssues(TBGRequest $request) { $issue_ids = $request['issue_ids']; $options = array('issue_ids' => array_values($issue_ids)); TBGContext::loadLibrary('common'); $options['last_updated'] = tbg_formatTime(time(), 20); if (!empty($issue_ids)) { $options['bulk_action'] = $request['bulk_action']; switch ($request['bulk_action']) { case 'assign_milestone': $milestone = null; if ($request['milestone'] == 'new') { $milestone = new TBGMilestone(); $milestone->setProject(TBGContext::getCurrentProject()); $milestone->setName($request['milestone_name']); $milestone->save(); $options['milestone_url'] = TBGContext::getRouting()->generate('project_planning_milestone', array('project_key' => $milestone->getProject()->getKey(), 'milestone_id' => $milestone->getID())); } elseif ($request['milestone']) { $milestone = new TBGMilestone($request['milestone']); } $milestone_id = $milestone instanceof TBGMilestone ? $milestone->getID() : null; foreach (array_keys($issue_ids) as $issue_id) { if (is_numeric($issue_id)) { $issue = new TBGIssue($issue_id); $issue->setMilestone($milestone_id); $issue->save(); } } $options['milestone_id'] = $milestone_id; $options['milestone_name'] = $milestone_id ? $milestone->getName() : '-'; break; case 'set_status': if (is_numeric($request['status'])) { $status = new TBGStatus($request['status']); foreach (array_keys($issue_ids) as $issue_id) { if (is_numeric($issue_id)) { $issue = new TBGIssue($issue_id); $issue->setStatus($status->getID()); $issue->save(); } } $options['status'] = array('color' => $status->getColor(), 'name' => $status->getName(), 'id' => $status->getID()); } break; case 'set_severity': if (is_numeric($request['severity'])) { $severity = $request['severity'] ? new TBGSeverity($request['severity']) : null; foreach (array_keys($issue_ids) as $issue_id) { if (is_numeric($issue_id)) { $issue = new TBGIssue($issue_id); $severity_id = $severity instanceof TBGSeverity ? $severity->getID() : 0; $issue->setSeverity($severity_id); $issue->save(); } } $options['severity'] = array('name' => $severity instanceof TBGSeverity ? $severity->getName() : '-', 'id' => $severity instanceof TBGSeverity ? $severity->getID() : 0); } break; case 'set_resolution': if (is_numeric($request['resolution'])) { $resolution = $request['resolution'] ? new TBGResolution($request['resolution']) : null; foreach (array_keys($issue_ids) as $issue_id) { if (is_numeric($issue_id)) { $issue = new TBGIssue($issue_id); $resolution_id = $resolution instanceof TBGResolution ? $resolution->getID() : 0; $issue->setResolution($resolution_id); $issue->save(); } } $options['resolution'] = array('name' => $resolution instanceof TBGResolution ? $resolution->getName() : '-', 'id' => $resolution instanceof TBGResolution ? $resolution->getID() : 0); } break; case 'set_priority': if (is_numeric($request['priority'])) { $priority = $request['priority'] ? new TBGPriority($request['priority']) : null; foreach (array_keys($issue_ids) as $issue_id) { if (is_numeric($issue_id)) { $issue = new TBGIssue($issue_id); $priority_id = $priority instanceof TBGPriority ? $priority->getID() : 0; $issue->setPriority($priority_id); $issue->save(); } } $options['priority'] = array('name' => $priority instanceof TBGPriority ? $priority->getName() : '-', 'id' => $priority instanceof TBGPriority ? $priority->getID() : 0); } break; case 'set_category': if (is_numeric($request['category'])) { $category = $request['category'] ? new TBGCategory($request['category']) : null; foreach (array_keys($issue_ids) as $issue_id) { if (is_numeric($issue_id)) { $issue = new TBGIssue($issue_id); $category_id = $category instanceof TBGCategory ? $category->getID() : 0; $issue->setCategory($category_id); $issue->save(); } } $options['category'] = array('name' => $category instanceof TBGCategory ? $category->getName() : '-', 'id' => $category instanceof TBGCategory ? $category->getID() : 0); } break; } } return $this->renderJSON($options); }
public function hasValidTarget() { if (!$this->_target_value) { return true; } switch ($this->_action_type) { case self::ACTION_ASSIGN_ISSUE: $target_details = explode('_', $this->_target_value); return (bool) ($target_details[0] == 'user') ? TBGUser::doesIDExist($target_details[1]) : TBGTeam::doesIDExist($target_details[1]); break; case self::ACTION_SET_PERCENT: return (bool) ($this->_target_value > -1); break; case self::ACTION_SET_MILESTONE: return (bool) TBGMilestone::doesIDExist($this->_target_value); break; case self::ACTION_SET_PRIORITY: return (bool) TBGPriority::has($this->_target_value); break; case self::ACTION_SET_STATUS: return (bool) TBGStatus::has($this->_target_value); break; case self::ACTION_SET_REPRODUCABILITY: return (bool) TBGReproducability::has($this->_target_value); break; case self::ACTION_SET_RESOLUTION: return (bool) TBGResolution::has($this->_target_value); break; default: return true; } }
public function runTransitionIssues(TBGRequest $request) { try { try { $transition = TBGContext::factory()->TBGWorkflowTransition($request['transition_id']); } catch (Exception $e) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => $this->getI18n()->__('This is not a valid transition'))); } $issue_ids = $request['issue_ids']; $status = null; $closed = false; foreach ($issue_ids as $issue_id) { $issue = TBGContext::factory()->TBGIssue($issue_id); if (!$issue->isWorkflowTransitionsAvailable() || !$transition->validateFromRequest($request)) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => TBGContext::getI18n()->__('The transition could not be applied to issue %issue_number because of %errors', array('%issue_number' => $issue->getFormattedIssueNo(), '%errors' => join(', ', $transition->getValidationErrors()))))); } try { $transition->transitionIssueToOutgoingStepFromRequest($issue, $request); } catch (Exception $e) { $this->getResponse()->setHttpStatus(400); TBGLogging::log(TBGLogging::LEVEL_WARNING, 'Transition ' . $transition->getID() . ' failed for issue ' . $issue_id); TBGLogging::log(TBGLogging::LEVEL_WARNING, $e->getMessage()); return $this->renderJSON(array('error' => $this->getI18n()->__('The transition failed because of an error in the workflow. Check your workflow configuration.'))); } if ($status === null) { $status = $issue->getStatus(); } $closed = $issue->isClosed(); } TBGContext::loadLibrary('common'); $options = array('issue_ids' => array_keys($issue_ids), 'last_updated' => tbg_formatTime(time(), 20), 'closed' => $closed); $options['status'] = array('color' => $status->getColor(), 'name' => $status->getName(), 'id' => $status->getID()); if ($request->hasParameter('milestone_id')) { $milestone = new TBGMilestone($request['milestone_id']); $options['milestone_id'] = $milestone->getID(); $options['milestone_name'] = $milestone->getName(); } foreach (array('resolution', 'priority', 'category', 'severity') as $item) { $class = "TBG" . ucfirst($item); if ($request->hasParameter($item . '_id')) { if ($item_id = $request[$item . '_id']) { $itemobject = new $class($item_id); $itemname = $itemobject->getName(); } else { $item_id = 0; $itemname = '-'; } $options[$item] = array('name' => $itemname, 'id' => $item_id); } else { $method = 'get' . ucfirst($item); $itemname = $issue->{$method}() instanceof $class ? $issue->{$method}()->getName() : '-'; $item_id = $issue->{$method}() instanceof $class ? $issue->{$method}()->getID() : 0; $options[$item] = array('name' => $itemname, 'id' => $item_id); } } return $this->renderJSON($options); } catch (Exception $e) { $this->getResponse()->setHttpStatus(400); TBGLogging::log(TBGLogging::LEVEL_WARNING, 'Transition ' . $transition->getID() . ' failed for issue ' . $issue_id); TBGLogging::log(TBGLogging::LEVEL_WARNING, $e->getMessage()); return $this->renderJSON(array('error' => $this->getI18n()->__('An error occured when trying to apply the transition'))); } }
/** * Add a new sprint type milestone to a project * * @param TBGRequest $request */ public function runScrumAddSprint(TBGRequest $request) { $this->forward403unless($this->_checkProjectPageAccess('project_scrum')); if (($sprint_name = $request->getParameter('sprint_name')) && trim($sprint_name) != '') { $sprint = new TBGMilestone(); $sprint->setName($sprint_name); $sprint->setType(TBGMilestone::TYPE_SCRUMSPRINT); $sprint->setProject($this->selected_project); $sprint->setStartingDate(mktime(0, 0, 1, $request->getParameter('starting_month'), $request->getParameter('starting_day'), $request->getParameter('starting_year'))); $sprint->setScheduledDate(mktime(23, 59, 59, $request->getParameter('scheduled_month'), $request->getParameter('scheduled_day'), $request->getParameter('scheduled_year'))); $sprint->save(); return $this->renderJSON(array('failed' => false, 'content' => $this->getTemplateHTML('sprintbox', array('sprint' => $sprint)), 'sprint_id' => $sprint->getID())); } return $this->renderJSON(array('failed' => true, 'error' => TBGContext::getI18n()->__('Please specify a sprint name'))); }
echo __('ID'); ?> </th> </tr> </thead> <tbody> <?php foreach (TBGIssuetypeScheme::getAll() as $item) { echo '<tr><td>' . __('Issue type scheme') . '</td><td>' . $item->getName() . '</td><td>' . $item->getID() . '</td></tr>'; } foreach (TBGWorkflowScheme::getAll() as $item) { echo '<tr><td>' . __('Workflow scheme') . '</td><td>' . $item->getName() . '</td><td>' . $item->getID() . '</td></tr>'; } foreach (TBGProject::getAll() as $item) { echo '<tr><td>' . __('Project') . '</td><td>' . $item->getName() . '</td><td>' . $item->getID() . '</td></tr>'; foreach (TBGMilestone::getAllByProjectID($item->getID()) as $item2) { echo '<tr><td>' . __('Milestone for project') . ' ' . $item->getID() . '</td><td>' . $item2->getName() . '</td><td>' . $item2->getID() . '</td></tr>'; } } foreach (TBGReproducability::getAll() as $item) { echo '<tr><td>' . __('Reproducability') . '</td><td>' . $item->getName() . '</td><td>' . $item->getID() . '</td></tr>'; } foreach (TBGSeverity::getAll() as $item) { echo '<tr><td>' . __('Severity') . '</td><td>' . $item->getName() . '</td><td>' . $item->getID() . '</td></tr>'; } foreach (TBGCategory::getAll() as $item) { echo '<tr><td>' . __('Category') . '</td><td>' . $item->getName() . '</td><td>' . $item->getID() . '</td></tr>'; } foreach (TBGPriority::getAll() as $item) { echo '<tr><td>' . __('Priority') . '</td><td>' . $item->getName() . '</td><td>' . $item->getID() . '</td></tr>'; }