xref: /plugin/qc/admin.php (revision 6a7733deedd3256d91eadfb27619deb87ba04931)
1<?php
2if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
3if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
4
5require_once(DOKU_PLUGIN.'admin.php');
6require_once(DOKU_INC.'inc/pageutils.php');
7require_once(DOKU_INC.'inc/io.php');
8require_once(DOKU_INC.'inc/common.php');
9
10/**
11 * This plugin is used to display a summery of all FIXME pages
12 *
13 * @see http://dokuwiki.org/plugin:qc
14 * @author Dominik Eckelmann <dokuwiki@cosmocode.de>
15 */
16class admin_plugin_qc extends DokuWiki_Admin_Plugin {
17
18    var $data;
19    var $order;
20
21    function getMenuSort()      { return 999; }
22    function forAdminOnly()     { return false; }
23
24    /**
25     * handle the request befor html output
26     *
27     * @see html()
28     */
29    function handle() {
30        global $conf;
31
32        // load the quality data
33        if (is_file($conf['tmpdir'].'/qcgather')) {
34            $this->data = file_get_contents($conf['tmpdir'].'/qcgather');
35            $this->data = unserialize($this->data);
36        } else {
37            $this->data = array();
38        }
39
40        // order the data
41        if (!isset($_REQUEST['pluginqc']['order'])) {
42            $_REQUEST['pluginqc']['order'] = 'quality';
43        }
44
45        switch ($_REQUEST['pluginqc']['order']) {
46            case 'fixme':
47                uasort($this->data, array($this, 'sortFixme'));
48                $this->order = 'fixme';
49                break;
50            default:
51                uasort($this->data, array($this, 'sortQuality'));
52                $this->order = 'quality';
53        }
54    }
55
56    /**
57     * output html for the admin page
58     */
59    function html() {
60        global $ID;
61        $max = $this->getConf('maxshowen');
62        if (!$max || $max <= 0) $max = 25;
63
64        echo '<div id="plugin__qc_admin">';
65        echo '<h1>'.$this->getLang('admin_headline').'</h1>';
66
67        echo '<p>'.sprintf($this->getLang('admin_desc'),$max).'</p>';
68
69        echo '<table class="inline">';
70        echo '  <tr>';
71        echo '    <th>'.$this->getLang('admin_page').'</th>';
72        echo '    <th class="quality">'.$this->getOrderArrow('quality').'<a href="'.wl($ID,array('do'=>'admin','page'=>'qc','pluginqc[order]'=>'quality')).'">'.$this->getLang('admin_quality').'</a></th>';
73        echo '    <th class="fixme">'.$this->getOrderArrow('fixme').'<a href="'.wl($ID,array('do'=>'admin','page'=>'qc','pluginqc[order]'=>'fixme')).'">'.$this->getLang('admin_fixme').'</a></th>';
74        echo '  </tr>';
75
76        if ($this->data) {
77            foreach ($this->data as $id => $data) {
78                if ($max == 0) break;
79                echo '  <tr>';
80                echo '    <td>';
81                tpl_pagelink(':' . $id, $id);
82                echo '</td>';
83                echo '    <td class="centeralign">' . $data['score'] . ' <img src="'. $this->getImgUrl($data['score']) .'" /></td>';
84                echo '    <td class="centeralign">' . $data['err']['fixme'] . '</td>';
85                echo '  </tr>';
86                $max--;
87            }
88        }
89
90        echo '</table>';
91        echo '</div>';
92    }
93
94    function getOrderArrow($type) {
95        if ($type == $this->order) return '&darr; ';
96        return '';
97    }
98
99    function getImgUrl($score, $return = true) {
100        $maxerr = 10;
101        if ($score > $maxerr) {
102            $ico = DOKU_BASE . 'lib/plugins/qc/pix/'.$this->getConf('theme').'/status_red.png';
103        } elseif($score) {
104            $ico = DOKU_BASE . 'lib/plugins/qc/pix/'.$this->getConf('theme').'/status_yellow.png';
105        } else {
106            $ico = DOKU_BASE . 'lib/plugins/qc/pix/'.$this->getConf('theme').'/status_green.png';
107        }
108        if ($return) return $ico;
109        echo $ico;
110    }
111
112    /**
113     * order by quality
114     */
115    function sortQuality($a, $b) {
116        if ($a['score'] == $b['score']) return 0;
117        return ($a['score'] < $b['score']) ? 1 : -1;
118    }
119
120    /**
121     * order by fixmes
122     */
123    function sortFixme($a, $b) {
124        if ($a['err']['fixme'] == $b['err']['fixme']) return 0;
125        return ($a['err']['fixme'] < $b['err']['fixme']) ? 1 : -1;
126    }
127
128}
129
130?>
131