-
Notifications
You must be signed in to change notification settings - Fork 1
/
class.php
93 lines (85 loc) · 2.83 KB
/
class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* @version $Id$
* KunenaStats Module
* @package Kunena Stats
*
* @Copyright (C) 2010 www.kunena.com All rights reserved
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @link http://www.kunena.com
*/
defined ( '_JEXEC' ) or die ();
class ModuleKunenaStats {
protected $params = null;
protected $api = null;
protected $type = null;
protected $items = 0;
protected $stats = null;
protected $titleHeader = '';
protected $valueHeader = '';
protected $top = 0;
public function __construct($params) {
require_once KPATH_SITE . '/lib/kunena.link.class.php';
$this->params = $params;
$this->type = $this->params->get ( 'type', 'general' );
$this->items = ( int ) $this->params->get ( 'items', 5 );
// load Kunena main language file so we can leverage langaueg strings from it
KunenaFactory::loadLanguage();
// Initialize session
$session = KunenaFactory::getSession ();
$session->updateAllowedForums();
$this->api = Kunena::getStatsAPI();
}
function display() {
$this->stats = $this->getStats ();
require JModuleHelper::getLayoutPath ( 'mod_kunenastats' );
$this->document = JFactory::getDocument ();
$this->document->addStyleSheet ( JURI::root () . 'modules/mod_kunenastats/tmpl/css/kunenastats.css' );
}
function getBarWidth($count) {
if ($count == $this->top) {
$barwidth = 100;
} else {
$barwidth = round(($count * 100) / $this->top);
}
return $barwidth;
}
function getStats() {
switch ($this->type) {
case 'topics':
$this->titleHeader = JText::_('MOD_KUNENASTATS_TOPTOPICS');
$this->valueHeader = JText::_('MOD_KUNENASTATS_HITS');
$items = $this->api->getTopicsStats ( $this->items );
if (!empty($items)) $this->top = $items[0]->hits;
break;
case 'posters':
$this->titleHeader = JText::_('MOD_KUNENASTATS_TOPPOSTERS');
$this->valueHeader = JText::_('MOD_KUNENASTATS_POSTS');
$items = $this->api->getPostersStats ( $this->items );
if (!empty($items)) $this->top = $items[0]->posts;
break;
case 'profiles':
$this->titleHeader = JText::_('MOD_KUNENASTATS_TOPPROFILES');
$this->valueHeader = JText::_('MOD_KUNENASTATS_HITS');
$items = $this->api->getProfileStats ( $this->items );
if (!empty($items)) $this->top = $items[0]->hits;
break;
case 'polls':
$this->titleHeader = JText::_('MOD_KUNENASTATS_TOPPOLLS');
$this->valueHeader = JText::_('MOD_KUNENASTATS_VOTES');
$items = $this->api->getTopPollStats ( $this->items );
if (!empty($items)) $this->top = $items[0]->total;
break;
case 'thanks':
$this->titleHeader = JText::_('MOD_KUNENASTATS_TOPTHANKS');
$this->valueHeader = JText::_('MOD_KUNENASTATS_THANKS');
$items = $this->api->getTopThanks ( $this->items );
if (!empty($items)) $this->top = $items[0]->receivedthanks;
break;
default:
$items = array();
break;
}
return $items;
}
}