1<?php
2
3/**
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Andreas Gohr <andi@splitbrain.org>
7 */
8
9/**
10 * This inherits from the table syntax, because it's basically the
11 * same, just different output
12 */
13class syntax_plugin_data_list extends syntax_plugin_data_table
14{
15    /**
16     * Connect pattern to lexer
17     */
18    public function connectTo($mode)
19    {
20        $this->Lexer->addSpecialPattern('----+ *datalist(?: [ a-zA-Z0-9_]*)?-+\n.*?\n----+', $mode, 'plugin_data_list');
21    }
22
23    protected $before_item = '<li><div class="li">';
24    protected $after_item = '</div></li>';
25    protected $before_val = '';
26    protected $after_val = ' ';
27
28    /**
29     * Before value in listitem
30     *
31     * @param array $data instructions by handler
32     * @param int $colno column number
33     * @return string
34     */
35    protected function beforeVal(&$data, $colno)
36    {
37        if ($data['sepbyheaders'] && $colno === 0) {
38            return $data['headers'][$colno];
39        } else {
40            return $this->before_val;
41        }
42    }
43
44    /**
45     * After value in listitem
46     *
47     * @param array $data
48     * @param int $colno
49     * @return string
50     */
51    protected function afterVal(&$data, $colno)
52    {
53        if ($data['sepbyheaders']) {
54            return $data['headers'][$colno + 1];
55        } else {
56            return $this->after_val;
57        }
58    }
59
60    /**
61     * Create list header
62     *
63     * @param array $clist keys of the columns
64     * @param array $data instruction by handler
65     * @return string html of table header
66     */
67    public function preList($clist, $data)
68    {
69        return '<div class="dataaggregation"><ul class="dataplugin_list ' . $data['classes'] . '">';
70    }
71
72    /**
73     * Create an empty list
74     *
75     * @param array $data instruction by handler()
76     * @param array $clist keys of the columns
77     * @param Doku_Renderer $R
78     */
79    public function nullList($data, $clist, $R)
80    {
81        $R->doc .= '<div class="dataaggregation"><p class="dataplugin_list ' . $data['classes'] . '">';
82        $R->cdata($this->getLang('none'));
83        $R->doc .= '</p></div>';
84    }
85
86    /**
87     * Create list footer
88     *
89     * @param array $data instruction by handler()
90     * @param int $rowcnt number of rows
91     * @return string html of table footer
92     */
93    public function postList($data, $rowcnt)
94    {
95        return '</ul></div>';
96    }
97}
98