xref: /plugin/bez/syntax/nav.php (revision 7e9a45a9f405a3132740045397380eea93e9690b)
1<?php
2/**
3 * Plugin Now: Inserts a timestamp.
4 *
5 * @license    GPL 3 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Szymon Olewniczak <szymon.olewniczak@rid.pl>
7 */
8
9// must be run within DokuWiki
10if(!defined('DOKU_INC')) die();
11
12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13require_once DOKU_PLUGIN.'syntax.php';
14include_once DOKU_PLUGIN."bez/models/tasks.php";
15include_once DOKU_PLUGIN."bez/models/issues.php";
16/**
17 * All DokuWiki plugins to extend the parser/rendering mechanism
18 * need to inherit from this class
19 */
20class syntax_plugin_bez_nav extends DokuWiki_Syntax_Plugin {
21
22    function getPType() { return 'block'; }
23    function getType() { return 'substition'; }
24    function getSort() { return 99; }
25
26
27    function connectTo($mode) {
28		$this->Lexer->addSpecialPattern('~~BEZNAV~~',$mode,'plugin_bez_nav');
29    }
30
31    function handle($match, $state, $pos, &$handler)
32    {
33		return true;
34    }
35
36    function render($mode, &$R, $pass) {
37		global $INFO;
38
39		$helper = $this->loadHelper('bez');
40		if ($mode != 'xhtml' || !$helper->user_viewer()) return false;
41
42        $R->info['cache'] = false;
43
44		$data = array(
45			'bez:start' => array('id' => 'bez:start', 'type' => 'd', 'level' => 1, 'title' => $this->getLang('bez')),
46		);
47
48		if ($helper->user_editor())
49			$data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issue_report'));
50
51		$isso = new Issues();
52		$no = count($isso->get_close_issue());
53		$title = str_replace('%d', $no, $this->getLang('menu_close_issue'));
54		$data['bez:close_issue'] = array('id' => 'bez:close_issue', 'type' => 'f', 'level' => 2, 'title' => $title);
55
56		$tasko = new Tasks();
57		$no = count($tasko->get_close_task());
58		$title = str_replace('%d', $no, $this->getLang('menu_close_task'));
59		$data['bez:close_task'] = array('id' => 'bez:close_task', 'type' => 'f', 'level' => 2, 'title' => $title);
60
61		$data['bez:issues'] = array('id' => 'bez:issues', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issues'));
62		$data['bez:tasks'] = array('id' => 'bez:tasks', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bez_tasks'));
63
64		$data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report'));
65
66
67
68
69		$oldest = $isso->get_oldest_date();
70		$year_old = (int)date('Y', $oldest);
71		$mon_old = (int)date('n', $oldest);
72		$year_now = (int)date('Y');
73		$mon_now = (int)date('n');
74
75		$id = $_GET['id'];
76		$ex = explode(':', $id);
77		$root = $ex[0];
78
79		for ($i = 0; $i < count($ex); $i += 2)
80			$value[urldecode($ex[$i])] = urldecode($ex[$i+1]);
81
82		$entity = '';
83		if (array_key_exists('entity', $value)) {
84			$entity = ':entity:'.$value['entity'];
85		}
86
87		$mon = $mon_old;
88		for ($year = $year_old; $year <= $year_now; $year++) {
89			$y_key = 'bez:report'.$entity.':year:'.$year;
90			$data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year);
91			if ($year == $year_now)
92				$mon_max = $mon_now;
93			else
94				$mon_max = 12;
95			for ( ; $mon <= $mon_max; $mon++) {
96				$m_key = $y_key.':month:'.$mon;
97				$data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4,
98				'title' => $mon < 10 ? '0'.$mon : $mon);
99			}
100			$mon = 1;
101		}
102
103		if ($helper->user_admin())
104			$data['bez:entity'] = array('id' => 'bez:entity', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('entity_manage'));
105
106
107
108		if ($root == 'bez') {
109			$data['bez:start']['open'] = true;
110		} else {
111			$data['bez:start']['open'] = false;
112			array_splice($data, 1);
113		}
114
115        $R->doc .= '<div class="plugin__bez">';
116        $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li'));
117        $R->doc .= '</div>';
118
119		return true;
120	}
121
122	function _bezlink($id, $title) {
123		$uri = wl($id);
124		return '<a href="'.$uri.'">'.($title).'</a>';
125	}
126
127    function _list($item){
128        global $INFO;
129
130        if(($item['type'] == 'd' && $item['open']) || $INFO['id'] == $item['id']){
131            return '<strong>'.$this->_bezlink($item['id'], $item['title']).'</strong>';
132        }else{
133            return $this->_bezlink($item['id'], $item['title']);
134        }
135
136    }
137
138    function _li($item){
139        if($item['type'] == "f"){
140            return '<li class="level'.$item['level'].'">';
141        }elseif($item['open']){
142            return '<li class="open">';
143        }else{
144            return '<li class="closed">';
145        }
146    }
147}
148