/** * 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; } }); }
function createTicket($project = null, $milestone = null, $user = null) { if (!$project) { $project = createProject(); } if (!$milestone) { $milestone = createMilestone($project); } if (!$user) { $user = createUser(); } $ticket = new Ticket(['ticket_id' => $project['next_ticket_id'], 'summary' => 'ticket-' . mkRandomHash(5) . '-summary', 'body' => 'ticket-' . mkRandomHash(5) . '-body', 'project_id' => $project['id'], 'user_id' => $user['id'], 'type_id' => 1, 'milestone_id' => $milestone['id']]); $ticket->save(); $project['next_ticket_id'] = $project['next_ticket_id'] + 1; $project->save(); return $ticket; }
/** * Toggles the state of a task. * * @param integer $ticket_id * @param integer $task_id */ public function action_toggle($ticket_id, $task_id) { if (current_user()->permission($this->project->id, 'ticket_properties_complete_tasks')) { // Get ticket, update task and save $ticket = Ticket::select()->where('project_id', $this->project->id)->where('ticket_id', $ticket_id)->exec()->fetch(); $ticket->toggle_task($task_id); $ticket->save(); } }
/** * Dashboard index page. */ public function indexAction() { // Check for update $lastUpdateCheck = Setting::find('setting', 'last_update_check'); if ($lastUpdateCheck->value <= time() - 86400) { $this->checkForUpdate(); $lastUpdateCheck->value = time(); $lastUpdateCheck->save(); } // Get information $info = ['users' => User::select('id')->rowCount(), 'newestUser' => User::select('id', 'name')->orderBy('id', 'DESC')->execute()->fetch(), 'projects' => User::select('id')->rowCount()]; // Issues $info['tickets'] = ['open' => Ticket::select('id')->where('is_closed = ?')->setParameter(0, 0)->rowCount(), 'closed' => Ticket::select('id')->where('is_closed = ?')->setParameter(0, 1)->rowCount()]; return $this->render('admin/dashboard/index.phtml', $info); }
/** * 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; } }
/** * Returns the subscribed object. * * @return object */ public function object() { if ($this->object !== null) { return $this->object; } switch ($this->type) { case 'project': $this->object = Project::find($this->object_id); break; case 'milestone': $this->object = Milestone::find($this->object_id); break; case 'ticket': $this->object = Ticket::find($this->object_id); break; } return $this->object; }
/** * Save ticket description form. * * @param integer $id ticket_id */ public function saveDescriptionAction($id) { $ticket = Ticket::select()->where('ticket_id = ?')->andWhere('project_id = ?')->setParameter(0, $id)->setParameter(1, $this->currentProject['id'])->fetch(); $ticket->body = Request::$post->get('body'); $ticket->save(); return $this->redirectTo('ticket', ['pslug' => $this->currentProject['slug'], 'id' => $ticket['ticket_id']]); }
/** * Get a query builder object pre-built with all the necessary ticket information. */ function ticketQuery() { // $ticket = queryBuilder()->select( $ticket = Ticket::select('t.id', 't.ticket_id', 't.summary', 't.user_id', 't.milestone_id', 't.version_id', 't.component_id', 't.type_id', 't.status_id', 't.priority_id', 't.severity_id', 't.assigned_to_id', 't.votes', 't.created_at', 't.updated_at', 'u.name AS user_name', 'm.name AS milestone_name', 'm.slug AS milestone_slug', 'v.name AS version_name', 'v.slug AS version_slug', 'c.name AS component_name', 'tp.name AS type_name', 's.name AS status_name', 'p.name AS priority_name', 'sv.name AS severity_name', 'at.name AS assigned_to_name')->leftJoin('t', PREFIX . 'users', 'u', 'u.id = t.user_id')->leftJoin('t', PREFIX . 'milestones', 'm', 'm.id = t.milestone_id')->leftJoin('t', PREFIX . 'milestones', 'v', 'v.id = t.version_id')->leftJoin('t', PREFIX . 'components', 'c', 'c.id = t.component_id')->leftJoin('t', PREFIX . 'types', 'tp', 'tp.id = t.type_id')->leftJoin('t', PREFIX . 'statuses', 's', 's.id = t.status_id')->leftJoin('t', PREFIX . 'priorities', 'p', 'p.id = t.priority_id')->leftJoin('t', PREFIX . 'severities', 'sv', 'sv.id = t.severity_id')->leftJoin('t', PREFIX . 'users', 'at', 'at.id = t.assigned_to_id'); $ticket->groupBy('t.id')->addGroupBy('u.name')->addGroupBy('m.name')->addGroupBy('m.slug')->addGroupBy('v.name')->addGroupBy('v.slug')->addGroupBy('c.name')->addGroupBy('tp.name')->addGroupBy('s.name')->addGroupBy('p.name')->addGroupBy('sv.name')->addGroupBy('at.name'); return $ticket; }
/** * @param Ticket $ticket * * @return string */ public static function severityClass(Ticket $ticket) { switch ($ticket->severity()->level) { case 1: return 'active'; break; case 2: return 'info'; break; case 3: return 'success'; break; case 4: return 'warning'; break; case 5: return 'danger'; break; } }
/** * Returns an array containing the open, started and closed ticket count queries. * * @return array */ protected function getTicketCountQueries() { // Open ticket count $openQuery = Ticket::select('COUNT(t.id)')->where('t.milestone_id = m.id')->andWhere('t.is_closed = :open_count_is_closed'); // Started ticket count $startedQuery = Ticket::select('COUNT(t.id)')->where('t.milestone_id = m.id')->andWhere('s.status = 2')->leftJoin('t', Status::tableName(), 's', 's.id = t.status_id'); // Closed query count $closedQuery = Ticket::select('COUNT(t.id)')->where('t.milestone_id = m.id')->andWhere('t.is_closed = :closed_count_is_closed'); return [$openQuery, $startedQuery, $closedQuery]; }
<?php /*! * Traq Lite * Copyright (c) 2009-2016 Jack P. * https://github.com/nirix/traq-lite * * Licensed under the BSD 3-Clause license. */ use Traq\Models\Ticket; $ticket = new Ticket(['status_id' => 1]); if (Request::$method == 'POST') { $ticketId = currentProject()->get('next_ticket_id'); $ticket->set(['ticket_id' => $ticketId, 'summary' => Request::$post['summary'], 'body' => Request::$post['body'], 'project_id' => currentProject()->get('id'), 'user_id' => currentUser()->get('id'), 'type_id' => Request::$post['type_id'], 'status_id' => Request::$post['status_id'], 'milestone_id' => Request::$post['milestone_id'], 'component_id' => Request::$post['component_id']]); if ($ticket->validate()) { db()->beginTransaction(); $query = db()->prepare(' INSERT INTO ' . PREFIX . 'tickets (ticket_id, summary, body, project_id, user_id, type_id, status_id, milestone_id, component_id, created_at) VALUES (:ticket_id, :summary, :body, :project_id, :user_id, :type_id, :status_id, :milestone_id, :component_id, NOW()) '); $query->bindValue(':ticket_id', $ticket['ticket_id'], PDO::PARAM_INT); $query->bindValue(':summary', $ticket['summary']); $query->bindValue(':body', $ticket['body']); $query->bindValue(':project_id', $ticket['project_id'], PDO::PARAM_INT); $query->bindValue(':user_id', $ticket['user_id'], PDO::PARAM_INT); $query->bindValue(':type_id', $ticket['type_id'], PDO::PARAM_INT); $query->bindValue(':status_id', $ticket['status_id'], PDO::PARAM_INT); $query->bindValue(':milestone_id', $ticket['milestone_id'], PDO::PARAM_INT); $query->bindValue(':component_id', $ticket['component_id'] ?: null); $query->execute();