コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
ファイル: actions.class.php プロジェクト: oparoz/thebuggenie
 public function runMilestone(TBGRequest $request)
 {
     if ($request->isPost()) {
         if ($this->getUser()->canManageProject($this->selected_project) || $this->getUser()->canManageProjectReleases($this->selected_project)) {
             try {
                 if (!$request['name']) {
                     throw new Exception($this->getI18n()->__('You must provide a valid milestone name'));
                 }
                 $milestone = new TBGMilestone($request['milestone_id']);
                 $milestone->setName($request['name']);
                 $milestone->setProject($this->selected_project);
                 $milestone->setStarting((bool) $request['is_starting']);
                 $milestone->setScheduled((bool) $request['is_scheduled']);
                 $milestone->setDescription($request['description']);
                 $milestone->setVisibleRoadmap($request['visibility_roadmap']);
                 $milestone->setVisibleIssues($request['visibility_issues']);
                 $milestone->setType($request->getParameter('milestone_type', TBGMilestone::TYPE_REGULAR));
                 if ($request->hasParameter('sch_month') && $request->hasParameter('sch_day') && $request->hasParameter('sch_year')) {
                     $scheduled_date = mktime(23, 59, 59, TBGContext::getRequest()->getParameter('sch_month'), TBGContext::getRequest()->getParameter('sch_day'), TBGContext::getRequest()->getParameter('sch_year'));
                     $milestone->setScheduledDate($scheduled_date);
                 } else {
                     $milestone->setScheduledDate(0);
                 }
                 if ($request->hasParameter('starting_month') && $request->hasParameter('starting_day') && $request->hasParameter('starting_year')) {
                     $starting_date = mktime(0, 0, 1, TBGContext::getRequest()->getParameter('starting_month'), TBGContext::getRequest()->getParameter('starting_day'), TBGContext::getRequest()->getParameter('starting_year'));
                     $milestone->setStartingDate($starting_date);
                 } else {
                     $milestone->setStartingDate(0);
                 }
                 $milestone->save();
                 if ($request['milestone_id']) {
                     $message = TBGContext::getI18n()->__('Milestone updated');
                     $template = 'milestoneboxheader';
                 } else {
                     $message = TBGContext::getI18n()->__('Milestone created');
                     $template = 'milestonebox';
                 }
                 return $this->renderJSON(array('content' => $this->getTemplateHTML($template, array('milestone' => $milestone)), 'milestone_id' => $milestone->getID(), 'milestone_name' => $milestone->getName(), 'available' => $milestone->isVisibleRoadmap(), 'milestone_order' => array_keys($this->selected_project->getMilestonesForRoadmap())));
             } catch (Exception $e) {
                 $this->getResponse()->setHttpStatus(400);
                 return $this->renderJSON(array('error' => $e->getMessage()));
             }
         }
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array("error" => $this->getI18n()->__("You don't have access to modify milestones")));
     }
 }
コード例 #4
0
ファイル: actions.class.php プロジェクト: oparoz/thebuggenie
 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);
 }
コード例 #5
0
 /**
  * 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')));
 }