Ejemplo n.º 1
0
 /**
  * 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;
         }
     });
 }
Ejemplo n.º 2
0
 /**
  * @return array[]
  */
 public function memberSelectOptions()
 {
     $options = [];
     $query = queryBuilder()->select('ur.user_id', 'u.name AS user_name')->from(PREFIX . 'user_roles', 'ur')->leftJoin('ur', PREFIX . 'users', 'u', 'u.id = ur.user_id')->where('project_id = ?')->setParameter(0, $this->id);
     foreach ($query->execute()->fetchAll() as $row) {
         $options[] = ['label' => $row['user_name'], 'value' => $row['user_id']];
     }
     return $options;
 }
Ejemplo n.º 3
0
 /**
  * Returns an array containing the open, started and closed ticket count queries.
  *
  * @return array
  */
 protected function getTicketCountQueries()
 {
     // Open ticket count
     $openQuery = queryBuilder()->select('COUNT(ot.id)')->from(PREFIX . 'tickets', 'ot')->where('ot.milestone_id = m.id')->andWhere('ot.is_closed = 0');
     // Started ticket count
     $startedQuery = queryBuilder()->select('COUNT(st.id)')->from(PREFIX . 'tickets', 'st')->where('st.milestone_id = m.id')->andWhere('s.status = 2')->leftJoin('st', PREFIX . 'statuses', 's', 's.id = st.status_id');
     // Closed query count
     $closedQuery = queryBuilder()->select('COUNT(ct.id)')->from(PREFIX . 'tickets', 'ct')->where('ct.milestone_id = m.id')->andWhere('ct.is_closed = 1');
     return [$openQuery, $startedQuery, $closedQuery];
 }
Ejemplo n.º 4
0
 /**
  * @return \Avalon\Http\Response
  */
 public function indexAction()
 {
     $userRoles = queryBuilder()->select('u.id AS user_id', 'u.name AS user_name', 'r.id AS role_id', 'r.name AS role_name', 'ur.project_role_id')->from(PREFIX . 'user_roles', 'ur')->where('ur.project_id = ?')->leftJoin('ur', PREFIX . 'users', 'u', 'u.id = ur.user_id')->leftJoin('ur', PREFIX . 'project_roles', 'r', 'r.id = ur.project_role_id')->setParameter(0, $this->currentProject['id'])->execute()->fetchAll();
     return $this->respondTo(function ($format) use($userRoles) {
         if ($format == "html") {
             return $this->render("project_settings/members/index.phtml", ['userRoles' => $userRoles]);
         } elseif ($format == "json") {
             return $this->jsonResponse($userRoles);
         }
     });
 }
Ejemplo n.º 5
0
/**
 * Get the setting value.
 *
 * @param string $setting
 *
 * @return mixed
 */
function setting($setting)
{
    static $settings;
    if (!$settings) {
        $rows = queryBuilder()->select('setting', 'value')->from(PREFIX . 'settings')->execute()->fetchAll();
        foreach ($rows as $row) {
            $settings[$row['setting']] = $row['value'];
        }
        unset($rows, $row);
    }
    return $settings[$setting];
}
Ejemplo n.º 6
0
 protected function loadPlugins()
 {
     global $autoloader;
     $queue = [];
     $plugins = queryBuilder()->select('*')->from(PREFIX . 'plugins')->where('is_enabled = 1')->execute()->fetchAll();
     foreach ($plugins as $plugin) {
         $vendorDir = __DIR__ . '/../vendor';
         foreach (json_decode($plugin['autoload'], true) as $namespace => $directory) {
             $autoloader->addPsr4($namespace, $vendorDir . "/{$plugin['directory']}/{$directory}");
         }
         $class = $plugin['main'];
         if (class_exists($class)) {
             $class::init();
             $queue[] = $class;
         }
     }
     foreach ($queue as $plugin) {
         $plugin::enable();
     }
 }
Ejemplo n.º 7
0
 protected function fetchProjectRolesIds()
 {
     $ids = [];
     $roles = queryBuilder()->select('project_id', 'project_role_id')->from(PREFIX . 'user_roles')->where('user_id = ?')->setParameter(0, $this->id);
     foreach ($roles->execute()->fetchAll() as $row) {
         $ids[$row['project_id']] = $row['project_role_id'];
     }
     return $ids;
 }
Ejemplo n.º 8
0
 /**
  * View revision.
  *
  * @param string  $slug
  * @param integer $revision
  */
 public function revisionAction($slug, $id)
 {
     $page = queryBuilder()->select('p.*', 'r.content', 'r.revision')->from(PREFIX . 'wiki_pages', 'p')->where('p.project_id = :project_id')->andWhere('p.slug = :slug')->join('p', PREFIX . 'wiki_revisions', 'r', 'r.wiki_page_id = p.id AND r.revision = :revision')->setParameter('project_id', $this->currentProject['id'])->setParameter('slug', $slug)->setParameter('revision', $id)->execute()->fetch();
     $this->title($page['title']);
     $this->title($this->translate('revisions'));
     $this->title($this->translate('revision_x', $page['revision']));
     $this->set('page', $page);
     return $this->render('wiki/show.phtml');
 }
Ejemplo n.º 9
0
function getTicketList($filter, $order_by, $order_desc = null, $page = null, $rows_per_page = 10000, $query_type = 'filter')
{
    global $db, $c;
    $limit = $page * $rows_per_page . "," . $rows_per_page;
    // Лимиты
    $query_tickets = queryBuilder('helpdesk', '
                                       `id`,
                                       `status`,
                                       (SELECT `order` FROM helpdesk_statuses WHERE helpdesk.`status`=`id`) as `status_order`,
                                       `tags`,
                                       `title`,
                                       `area`,
                                       `performers`,
                                       `creator`,
                                       `changer`,
                                       `created`,
                                       `changed`,
                                       `deadline`,
                                       `rate`', $filter, $order_by, $order_desc, $limit, $query_type);
    if ($query_tickets_res = $db->query($query_tickets)) {
        while ($tickets_res = $db->fetch_assoc($query_tickets_res)) {
            $id = $tickets_res['id'];
            foreach ($tickets_res as $key => $value) {
                if ($value != '') {
                    $result[$id][$key] = $value;
                }
            }
            $performers = explode(',', $result[$id]['performers']);
            $result[$id]['performers'] = array();
            foreach ($performers as $performer_id) {
                $result[$id]['performers'][$performer_id] = $c['users'][$performer_id];
            }
        }
    }
    return $result;
}
Ejemplo n.º 10
0
 protected function savePermissions($type)
 {
     foreach (Request::$post['permissions'] as $group => $perms) {
         $permissions = [];
         if ($group == 'defaults') {
             foreach (PermissionsAPI::getPermissions() as $name => $default) {
                 if (isset($perms[$name])) {
                     $permissions[$name] = true;
                 } else {
                     $permissions[$name] = false;
                 }
             }
             $this->db->update(PREFIX . 'permissions', ['permissions' => json_encode($permissions)], ['type' => $type, 'type_id' => 0, 'project_id' => 0]);
         } else {
             // Ignore 'null' values
             foreach ($perms as $name => $value) {
                 if ($value == '1' || $value == '0') {
                     $permissions[$name] = (bool) $value;
                 }
             }
             // If there are no permissions, delete the row
             if (!count($permissions)) {
                 $this->db->delete(PREFIX . 'permissions', ['type' => $type, 'type_id' => $group, 'project_id' => 0]);
             } else {
                 // Check if the row exists already
                 $query = queryBuilder()->select('id')->from(PREFIX . 'permissions')->where('type = ?')->andWhere('type_id = ?')->andWhere('project_id = ?')->setParameter(0, $type)->setParameter(1, $group)->setParameter(2, 0)->execute();
                 // Update the row
                 if ($query->rowCount()) {
                     $this->db->update(PREFIX . 'permissions', ['permissions' => json_encode($permissions)], ['type' => $type, 'type_id' => $group, 'project_id' => 0]);
                 } else {
                     // Insert a new row
                     $this->db->insert(PREFIX . 'permissions', ['type' => $type, 'type_id' => $group, 'project_id' => 0, 'permissions' => json_encode($permissions)]);
                 }
             }
         }
     }
 }
Ejemplo n.º 11
0
 /**
  * Get rows from the specified table.
  *
  * @param array $ids
  *
  * @return array
  */
 protected function getRows($table, $ids)
 {
     if (!count($ids)) {
         return;
     }
     $query = queryBuilder()->select('*')->from(PREFIX . $table);
     $query->where($query->expr()->in('id', $ids));
     $rows = [];
     foreach ($query->execute()->fetchAll() as $row) {
         $rows[$row['id']] = $row;
     }
     return $rows;
 }
Ejemplo n.º 12
0
 /**
  * All closed statuses.
  */
 protected function allClosed()
 {
     $statuses = queryBuilder()->select('id', 'name')->from(PREFIX . 'statuses')->where('status <= 0')->execute();
     $ids = [];
     $names = [];
     foreach ($statuses->fetchAll() as $status) {
         $ids[] = $status['id'];
         $names[] = $status['name'];
     }
     $this->builder->andWhere($this->expr->in('t.status_id', $ids));
     $this->filters['status'] = ['cond' => true, 'values' => $names];
 }
Ejemplo n.º 13
0
 /**
  * Get rows from the specified table.
  *
  * @param array $ids
  *
  * @return array
  */
 protected function getRows($table, $ids)
 {
     if (!count($ids)) {
         return;
     }
     if ($table === 'tickets') {
         $query = ticketQuery();
         $query->andWhere($query->expr()->in('t.id', $ids));
     } else {
         $query = queryBuilder()->select('*')->from($this->db->prefix . $table);
         $query->where($query->expr()->in('id', $ids));
     }
     $rows = [];
     foreach ($query->execute()->fetchAll() as $row) {
         $rows[$row['id']] = $row;
     }
     return $rows;
 }
Ejemplo n.º 14
0
 /**
  * Handles the view ticket page.
  *
  * @param integer $ticket_id
  */
 public function showAction($id)
 {
     if (!$this->hasPermission('view_tickets')) {
         return $this->show403();
     }
     $ticket = ticketQuery()->addSelect('t.*')->where('t.project_id = ?')->andWhere('t.ticket_id = ?')->setParameter(0, $this->currentProject['id'])->setParameter(1, $id)->execute()->fetch();
     if (!$ticket) {
         return $this->show404();
     }
     $ticket['tasks'] = json_decode($ticket['tasks'], true);
     $this->title($this->translate('ticket.page-title', $ticket['ticket_id'], $ticket['summary']));
     $history = queryBuilder()->select('h.*', 'u.name AS user_name')->from(PREFIX . 'ticket_history', 'h')->where('h.ticket_id = :ticket_id')->leftJoin('h', PREFIX . 'users', 'u', 'u.id = h.user_id')->orderBy('h.created_at', 'ASC')->setParameter('ticket_id', $ticket['id'])->execute()->fetchAll();
     return $this->respondTo(function ($format) use($ticket, $history) {
         if ($format == 'html') {
             return $this->render('tickets/show.phtml', ['ticket' => $ticket, 'history' => $history]);
         } elseif ($format == 'json') {
             return $this->jsonResponse($ticket);
         }
     });
 }