1<?php
2class syntax_plugin_ac_action_tickets extends syntax_plugin_ac_action {
3    public function __construct($ac, $data) {
4        parent::__construct($ac);
5        global $ID;
6        if (is_null($data[0])) {
7            $data[0] = substr($ID, strpos($ID, 'projekt:') + 8);
8        }
9        $this->project = $data[0];
10    }
11
12    public function exec() {
13        $projectid = 0;
14        if ((int) $this->project !== 0) {
15            $projectid = $this->project;
16        } else {
17            $project = $this->ac->fetchSingle('projects', array('name' => $this->project));
18            if ($project === false) {
19                return '<p>Project not found!</p>';
20            }
21            $projectid = $project->id;
22        }
23
24        $tickets = $this->ac->get('projects/' . $projectid . '/tickets');
25        if (!$tickets) {
26            return '<p>No active tickets found!</p>';
27        }
28
29        $output = '<ul>';
30        foreach ($tickets as $ticket) {
31            $output .= '<li><div class="li">' . $this->ac->objToString($ticket) . '</div>' .
32                       ajax_loader::getLoader('ac', array('tasks', $projectid, $ticket->ticket_id)) . '</li>' . DOKU_LF;
33        }
34        $output .= '</ul>';
35
36        return $output;
37    }
38}
39