예제 #1
0
파일: Projects.php 프로젝트: dasklney/traq
 /**
  * Handles the changelog page.
  */
 public function changelogAction()
 {
     $this->title($this->translate('changelog'));
     // Fetch issues
     $issues = [];
     $query = Ticket::select('t.summary', 't.ticket_id', 't.milestone_id', 't.type_id')->leftJoin('t', PREFIX . 'types', 'type', 'type.id = t.type_id')->leftJoin('t', PREFIX . 'statuses', 'status', 'status.id = t.status_id')->where('t.project_id = ?')->andWhere('type.show_on_changelog = 1')->andWhere('status.show_on_changelog = 1')->orderBy('t.type_id', 'ASC')->setParameter(0, $this->currentProject['id'])->execute();
     // Index issues by milestone ID
     foreach ($query->fetchAll() as $row) {
         $issues[$row['milestone_id']][] = $row;
     }
     // Fetch complete milestones
     $milestones = Milestone::select('m.id', 'm.name', 'm.slug')->where('m.project_id = ?')->andWhere('m.status = 2')->orderBy('m.display_order', 'DESC')->setParameter(0, $this->currentProject['id'])->execute()->fetchAll();
     // Combine issues and milestones into a single array
     foreach ($milestones as $index => $milestone) {
         $milestones[$index]['changes'] = isset($issues[$milestone['id']]) ? $issues[$milestone['id']] : [];
     }
     // Fetch ticket types
     $types = [];
     $query = queryBuilder()->select('id', 'bullet')->from(PREFIX . 'types')->execute();
     foreach ($query->fetchAll() as $row) {
         $types[$row['id']] = $row['bullet'];
     }
     return $this->respondTo(function ($format) use($milestones, $types) {
         if ($format == 'html') {
             return $this->render('projects/changelog.phtml', ['milestones' => $milestones, 'types' => $types]);
         } elseif ($format == 'txt') {
             $resp = $this->render('projects/changelog.txt.php', ['_layout' => false, 'milestones' => $milestones]);
             $resp->contentType = 'text/plain';
             return $resp;
         }
     });
 }
예제 #2
0
 /**
  * Toggles the subscription.
  *
  * @param string  $type Subscription type (Project, Milestone, Ticket)
  * @param integer $id   Subscribed object ID
  */
 public function action_toggle($type, $id)
 {
     switch ($type) {
         // Project
         case 'project':
             // Delete subscription
             if (is_subscribed($this->user, $this->project)) {
                 $sub = Subscription::select()->where(array(array('project_id', $this->project->id), array('user_id', $this->user->id), array('type', 'project')))->exec()->fetch();
                 $sub->delete();
             } else {
                 $sub = new Subscription(array('type' => "project", 'project_id' => $this->project->id, 'user_id' => $this->user->id, 'object_id' => $this->project->id));
                 $sub->save();
             }
             Request::redirectTo($this->project->href());
             break;
             // Milestone
         // Milestone
         case 'milestone':
             // Get milestone
             $milestone = Milestone::select()->where(array(array('project_id', $this->project->id), array('slug', $id)))->exec()->fetch();
             // Delete subscription
             if (is_subscribed($this->user, $milestone)) {
                 $sub = Subscription::select()->where(array(array('project_id', $this->project->id), array('user_id', $this->user->id), array('type', 'milestone'), array('object_id', $milestone->id)))->exec()->fetch();
                 $sub->delete();
             } else {
                 $sub = new Subscription(array('type' => "milestone", 'project_id' => $this->project->id, 'user_id' => $this->user->id, 'object_id' => $milestone->id));
                 $sub->save();
             }
             Request::redirectTo($milestone->href());
             break;
             // Milestone
         // Milestone
         case 'ticket':
             // Get ticket
             $ticket = Ticket::select()->where(array(array('project_id', $this->project->id), array('ticket_id', $id)))->exec()->fetch();
             // Delete subscription
             if (is_subscribed($this->user, $ticket)) {
                 $sub = Subscription::select()->where(array(array('project_id', $this->project->id), array('user_id', $this->user->id), array('type', 'ticket'), array('object_id', $ticket->id)))->exec()->fetch();
                 $sub->delete();
             } else {
                 $sub = new Subscription(array('type' => "ticket", 'project_id' => $this->project->id, 'user_id' => $this->user->id, 'object_id' => $ticket->id));
                 $sub->save();
             }
             Request::redirectTo($ticket->href());
             break;
     }
 }
예제 #3
0
 /**
  * Override to only get the relevant projects milestones.
  *
  * @return array
  */
 protected function getAllRows()
 {
     return Milestone::select('id', 'name', 'codename', 'status')->where('project_id = ?')->orderBy('display_order', 'ASC')->setParameter(0, $this->currentProject['id'])->execute()->fetchAll();
 }