Skip to content

Commit

Permalink
Fixed some wrong comments in the REST service documentation.
Browse files Browse the repository at this point in the history
Fixed users being shown as offline.
Fixed user activity table always showing 'total' as stats type.
Removed channel kicks from channel status page since it makes little sense to show that there.
No more need to specify global as channel if global stats needed.
Chanstats type are now anope-style and are mapped in the Denora module for Denora compatibility.
  • Loading branch information
Hal9000 committed Dec 11, 2013
1 parent 0c2834b commit a583f9f
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 82 deletions.
3 changes: 3 additions & 0 deletions lib/magirc/objects/anope/User.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ class User extends UserBase {
function __construct() {
parent::__construct();

//TODO: Anope does not keep offline users, you need the seen module for that but MagIRC does not support it yet.
$this->online = true;

// Oper mode
if (!Protocol::oper_hidden_mode || !$this->hasMode(Protocol::oper_hidden_mode)) {
$levels = Protocol::$oper_levels;
Expand Down
34 changes: 7 additions & 27 deletions lib/magirc/services/Anope.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,6 @@ public function getChannelGlobalActivity($type, $datatables = false) {
FROM `%s`AS cs
JOIN `%s`AS c ON LOWER(cs.chan) = LOWER(c.channel)
WHERE cs.type=:type AND %s", TBL_CHANSTATS, TBL_CHAN, $sWhere);
$type = self::getChanstatsType($type);
if ($datatables) {
$iTotal = $this->db->datatablesTotal($sQuery, array(':type' => $type));
$sFiltering = $this->db->datatablesFiltering(array('cs.chan', 'c.topic'));
Expand Down Expand Up @@ -602,7 +601,6 @@ public function getChannelActivity($chan, $type, $datatables = false) {
. " FROM `%s` AS cs"
. " WHERE chan = :channel AND nick != '' AND type=:type AND letters > 0 ",
TBL_CHANSTATS);
$type = self::getChanstatsType($type);
if ($datatables) {
$iTotal = $this->db->datatablesTotal($sQuery, array(':type' => $type, ':channel' => $chan));
$sFiltering = $this->db->datatablesFiltering(array('uname'));
Expand Down Expand Up @@ -649,7 +647,7 @@ public function getChannelHourlyActivity($chan, $type) {
WHERE chan=:channel AND type=:type",
TBL_CHANSTATS);
$ps = $this->db->prepare($sQuery);
$ps->bindValue(':type', self::getChanstatsType($type), PDO::PARAM_INT);
$ps->bindValue(':type', $type, PDO::PARAM_INT);
$ps->bindValue(':channel', $chan, PDO::PARAM_STR);
$ps->execute();
$result = $ps->fetch(PDO::FETCH_NUM);
Expand Down Expand Up @@ -833,7 +831,6 @@ public function getUserGlobalActivity($type, $datatables = false) {
FROM `%s`AS cs
WHERE type=:type AND letters > 0 and chan=''",
TBL_CHANSTATS);
$type = self::getChanstatsType($type);
if ($datatables) {
$iTotal = $this->db->datatablesTotal($sQuery, array(':type' => $type));
$sFiltering = $this->db->datatablesFiltering(array('uname'));
Expand Down Expand Up @@ -885,8 +882,8 @@ public function getUserGlobalActivity($type, $datatables = false) {
*/
public function getUserActivity($mode, $user, $chan) {
$info = $this->getUserData($mode, $user);
if ($chan == 'global') {
$chan = ''; //TODO: this is dirty
if ($chan == null) {
$chan = ''; //TODO: this is dirty but should be fixed on the anope side
$sQuery = sprintf("SELECT type, letters, words, line AS 'lines', actions,
(smileys_happy + smileys_sad + smileys_other) AS smileys, kicks, cs.modes, topics
FROM `%s` AS cs
Expand Down Expand Up @@ -921,7 +918,7 @@ public function getUserActivity($mode, $user, $chan) {
}
foreach ($data as $key => $type) {
foreach ($type as $field => $val) {
$data[$key][$field] = (int) $val;
$data[$key][$field] = is_numeric($val) ? (int) $val : $val; //TODO: make int if digit
}
}
return $data;
Expand All @@ -938,8 +935,8 @@ public function getUserActivity($mode, $user, $chan) {
*/
public function getUserHourlyActivity($mode, $user, $chan, $type) {
$info = $this->getUserData($mode, $user);
//TODO: this is dirty
if ($chan == 'global'){
//TODO: this is dirty but should be fixed on the anope side
if ($chan == null){
$chan = '';
}
$sQuery = sprintf("SELECT time0,time1,time2,time3,time4,time5,time6,time7,time8,time9,time10,time11,
Expand All @@ -948,7 +945,7 @@ public function getUserHourlyActivity($mode, $user, $chan, $type) {
WHERE nick = :nick AND chan = :channel AND type = :type",
TBL_CHANSTATS);
$ps = $this->db->prepare($sQuery);
$ps->bindValue(':type', self::getChanstatsType($type), PDO::PARAM_INT);
$ps->bindValue(':type', $type, PDO::PARAM_INT);
$ps->bindValue(':channel', $chan, PDO::PARAM_STR);
$ps->bindValue(':nick', $info['uname'], PDO::PARAM_STR);
$ps->execute();
Expand Down Expand Up @@ -1058,22 +1055,5 @@ private function getUnameAliases($uname) {
$ps->execute();
return $ps->fetchAll(PDO::FETCH_COLUMN);
}

/**
* Maps the denora style chanstats type to the anope names
* @param type $type
* @return string
*/
private static function getChanstatsType($type) {
switch ($type) {
case 1:
return 'daily';
case 2:
return 'weekly';
case 3:
return 'monthly';
}
return 'total';
}

}
54 changes: 46 additions & 8 deletions lib/magirc/services/Denora.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ public function getChannelGlobalActivity($type, $datatables = false) {

$sQuery = sprintf("SELECT SQL_CALC_FOUND_ROWS chan AS name,letters,words,line AS 'lines',actions,smileys,kicks,modes,topics FROM cstats
JOIN chan ON BINARY LOWER(cstats.chan)=LOWER(chan.channel) WHERE cstats.type=:type AND %s", $sWhere);
$type = self::getDenoraChanstatsType($type);
if ($datatables) {
$iTotal = $this->db->datatablesTotal($sQuery, array(':type' => (int) $type));
$sFiltering = $this->db->datatablesFiltering(array('cstats.chan', 'chan.topic'));
Expand Down Expand Up @@ -696,6 +697,7 @@ public function getChannelGlobalActivity($type, $datatables = false) {
public function getChannelActivity($chan, $type, $datatables = false) {
$aaData = array();
$sQuery = "SELECT SQL_CALC_FOUND_ROWS uname,letters,words,line AS 'lines',actions,smileys,kicks,modes,topics FROM ustats WHERE chan=:channel AND type=:type AND letters > 0 ";
$type = self::getDenoraChanstatsType($type);
if ($datatables) {
$iTotal = $this->db->datatablesTotal($sQuery, array(':type' => (int) $type, ':channel' => $chan));
$sFiltering = $this->db->datatablesFiltering(array('uname'));
Expand Down Expand Up @@ -739,13 +741,13 @@ public function getChannelHourlyActivity($chan, $type) {
$sQuery = "SELECT time0,time1,time2,time3,time4,time5,time6,time7,time8,time9,time10,time11,time12,time13,time14,time15,time16,time17,time18,time19,time20,time21,time22,time23
FROM cstats WHERE chan=:channel AND type=:type";
$ps = $this->db->prepare($sQuery);
$ps->bindValue(':type', $type, PDO::PARAM_INT);
$ps->bindValue(':channel', $chan, PDO::PARAM_STR);
$ps->bindValue(':type', self::getDenoraChanstatsType($type), PDO::PARAM_INT);
$ps->bindValue(':channel', $chan == null ? 'global' : $chan, PDO::PARAM_STR);
$ps->execute();
$result = $ps->fetch(PDO::FETCH_NUM);
if (is_array($result)) {
foreach ($result as $key => $val) {
$result[$key] = (int) $val;
$result[$key] = self::getAnopeChanstatsType($val);
}
return $result;
} else {
Expand All @@ -766,6 +768,7 @@ public function getUserGlobalActivity($type, $datatables = false) {
$sQuery = "SELECT SQL_CALC_FOUND_ROWS uname,letters,words,line AS 'lines',
actions,smileys,kicks,modes,topics FROM ustats
WHERE type=:type AND letters>0 and chan='global'";
$type = self::getDenoraChanstatsType($type);
if ($datatables) {
$iTotal = $this->db->datatablesTotal($sQuery, array(':type' => $type));
$sFiltering = $this->db->datatablesFiltering(array('uname'));
Expand Down Expand Up @@ -821,14 +824,14 @@ public function getUserHourlyActivity($mode, $user, $chan, $type) {
$sQuery = "SELECT time0,time1,time2,time3,time4,time5,time6,time7,time8,time9,time10,time11,time12,time13,time14,time15,time16,time17,time18,time19,time20,time21,time22,time23
FROM ustats WHERE uname=:uname AND chan=:channel AND type=:type";
$ps = $this->db->prepare($sQuery);
$ps->bindValue(':type', $type, PDO::PARAM_INT);
$ps->bindValue(':channel', $chan, PDO::PARAM_STR);
$ps->bindValue(':type', self::getDenoraChanstatsType($type), PDO::PARAM_INT);
$ps->bindValue(':channel', $chan == null ? 'global' : $chan, PDO::PARAM_STR);
$ps->bindValue(':uname', $info['uname'], PDO::PARAM_STR);
$ps->execute();
$result = $ps->fetch(PDO::FETCH_NUM);
if (is_array($result)) {
foreach ($result as $key => $val) {
$result[$key] = (int) $val;
$result[$key] = self::getAnopeChanstatsType($val);
}
return $result;
} else {
Expand Down Expand Up @@ -962,7 +965,8 @@ public function getUserChannels($mode, $user) {
*/
public function getUserActivity($mode, $user, $chan) {
$info = $this->getUserData($mode, $user);
if ($chan == 'global') {
if ($chan == null) {
$chan = 'global';
$sQuery = "SELECT type,letters,words,line AS 'lines',actions,smileys,kicks,modes,topics
FROM ustats WHERE uname=:uname AND chan=:chan ORDER BY ustats.letters DESC";
} else {
Expand All @@ -987,7 +991,7 @@ public function getUserActivity($mode, $user, $chan) {
if (is_array($data)) {
foreach ($data as $key => $type) {
foreach ($type as $field => $val) {
$data[$key][$field] = (int) $val;
$data[$key][$field] = $field == 'type' ? self::getAnopeChanstatsType ($field) : (int) $val;
}
}
return $data;
Expand Down Expand Up @@ -1024,6 +1028,40 @@ private function getUnameAliases($uname) {
$ps->execute();
return $ps->fetchAll(PDO::FETCH_COLUMN);
}

/**
* Maps the anope style chanstats type to the denora numbers
* @param string $type
* @return int
*/
private static function getDenoraChanstatsType($type) {
switch ($type) {
case 'daily':
return 1;
case 'weekly':
return 2;
case 'monthly':
return 3;
}
return 0;
}

/**
* Maps the denora style chanstats type to the anope values
* @param int $type
* @return string
*/
private static function getAnopeChanstatsType($type) {
switch ($type) {
case 1:
return 'daily';
case 2:
return 'weekly';
case 3:
return 'monthly';
}
return 'total';
}

}

Expand Down
20 changes: 10 additions & 10 deletions rest/service.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@
/**
* Get Channels Acticity Stats
*
* This will get a list of channels and their activity stats. The activity types
* are topics, smileys, kicks, actions, modes, words, and letters.
* This will get a list of channels and their activity stats.
* Type can be total, monthly, weekly, daily.
*
* Example: http://www.denorastats.org/magirc/rest/service.php/channels/activity/<type>
**/
Expand Down Expand Up @@ -249,8 +249,8 @@
/**
* Get Activity Stats in a Specific Channel
*
* This will show the activity stats for a specific channel. The activity types
* are topics, smileys, kicks, actions, modes, words, and letters.
* This will show the activity stats for a specific channel.
* Type can be total, monthly, weekly, daily.
*
* Example: http://www.denorastats.org/magirc/rest/service.php/channels/%23<channel>/activity/<type>
*
Expand All @@ -263,8 +263,8 @@
/**
* Get Hourly Activity Stats in a Specific Channel
*
* This will show the hourly activity stats for a specific channel. The activity types
* are topics, smileys, kicks, actions, modes, words, and letters.
* This will show the hourly activity stats for a specific channel.
* Type can be total, monthly, weekly, daily.
*
* Example: http://www.denorastats.org/magirc/rest/service.php/channels/%23<channel>/hourly/activity/<type>
*
Expand Down Expand Up @@ -347,8 +347,8 @@
/**
* Get User Activity Stats
*
* This will show the activity stats for a specific user. The activity types
* are topics, smileys, kicks, actions, modes, words, and letters.
* This will show the activity stats for a specific user.
* Type can be total, monthly, weekly, daily.
*
* Example: http://www.denorastats.org/magirc/rest/service.php/users/activity/<type>
*
Expand Down Expand Up @@ -400,7 +400,7 @@
* Example: http://www.denorastats.org/magirc/rest/service.php/users/stats/<nick>/channels
*
**/
$magirc->slim->get('/users/:mode/:user/activity(/:chan)', function($mode, $user, $chan = 'global') use($magirc) {
$magirc->slim->get('/users/:mode/:user/activity(/:chan)', function($mode, $user, $chan = null) use($magirc) {
$magirc->jsonOutput($magirc->service->getUserActivity($mode, $user, $chan), true);
});

Expand All @@ -413,7 +413,7 @@
* Example: http://www.denorastats.org/magirc/rest/service.php/users/stats/<nick>/hourly/<channel>/<type>
*
**/
$magirc->slim->get('/users/:mode/:user/hourly/:chan/:type', function($mode, $user, $chan, $type) use($magirc) {
$magirc->slim->get('/users/:mode/:user/hourly/(:chan/):type', function($mode, $user, $chan = null, $type) use($magirc) {
$magirc->jsonOutput($magirc->service->getUserHourlyActivity($mode, $user, $chan, $type));
});

Expand Down
12 changes: 6 additions & 6 deletions theme/default/tpl/channel_activity.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

<form>
<div id="radio" class="choser">
<input type="radio" id="radio0" name="radio" /><label for="radio0">{t}Total{/t}</label>
<input type="radio" id="radio1" name="radio" /><label for="radio1">{t}Today{/t}</label>
<input type="radio" id="radio2" name="radio" /><label for="radio2">{t}This Week{/t}</label>
<input type="radio" id="radio3" name="radio" checked="checked" /><label for="radio3">{t}This Month{/t}</label>
<input type="radio" id="radio0" name="radio" value="total" /><label for="radio0">{t}Total{/t}</label>
<input type="radio" id="radio1" name="radio" value="daily" /><label for="radio1">{t}Today{/t}</label>
<input type="radio" id="radio2" name="radio" value="weekly" /><label for="radio2">{t}This Week{/t}</label>
<input type="radio" id="radio3" name="radio" value="monthly" checked="checked" /><label for="radio3">{t}This Month{/t}</label>
</div>
</form>

Expand All @@ -25,7 +25,7 @@
var target = '{$target|escape:'url'}';
{literal}
$(document).ready(function() {
var type = 3;
var type = 'monthly';
var chart_activity = new Highcharts.Chart({
chart: { renderTo: 'chart_activity', type: 'column' },
xAxis: { type: 'linear', categories: [ 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 ], title: { text: 'Hour' } },
Expand Down Expand Up @@ -62,7 +62,7 @@ $(document).ready(function() {
});
$("#radio").buttonset();
$("#radio").change(function(event) {
type = $('input[name=radio]:checked').index() / 2;
type = $('input[name=radio]:checked').val();
oTable.fnSettings().sAjaxSource = "rest/service.php/channels/"+target+"/activity/"+type+"?format=datatables",
oTable.fnDraw();
updateChart();
Expand Down
12 changes: 6 additions & 6 deletions theme/default/tpl/channel_globalactivity.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

<form>
<div id="radio" class="choser">
<input type="radio" id="radio0" name="radio" /><label for="radio0">{t}Total{/t}</label>
<input type="radio" id="radio1" name="radio" /><label for="radio1">{t}Today{/t}</label>
<input type="radio" id="radio2" name="radio" /><label for="radio2">{t}This Week{/t}</label>
<input type="radio" id="radio3" name="radio" checked="checked" /><label for="radio3">{t}This Month{/t}</label>
<input type="radio" id="radio0" name="radio" value="total" /><label for="radio0">{t}Total{/t}</label>
<input type="radio" id="radio1" name="radio" value="daily" /><label for="radio1">{t}Today{/t}</label>
<input type="radio" id="radio2" name="radio" value="weekly" /><label for="radio2">{t}This Week{/t}</label>
<input type="radio" id="radio3" name="radio" value="monthly" checked="checked" /><label for="radio3">{t}This Month{/t}</label>
</div>
</form>

Expand All @@ -22,7 +22,7 @@
<script type="text/javascript">
{literal}
$(document).ready(function() {
var type = 3;
var type = 'monthly';
var oTable = $('#tbl_activity').dataTable({
"bServerSide": true,
"iDisplayLength": 25,
Expand Down Expand Up @@ -51,7 +51,7 @@ $(document).ready(function() {
});
$("#radio").buttonset();
$("#radio").change(function(event) {
type = $('input[name=radio]:checked').index() / 2;
type = $('input[name=radio]:checked').val();
oTable.fnSettings().sAjaxSource = "rest/service.php/channels/activity/"+type+"?format=datatables";
oTable.fnDraw();
});
Expand Down
4 changes: 1 addition & 3 deletions theme/default/tpl/channel_status.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<tr><th>{t}Current users{/t}:</th><td><span id="chan_users" class="val"></span></td></tr>
<tr><th>{t}User peak{/t}:</th><td><span id="chan_users_max" class="val"></span> {t}on{/t} <span id="chan_users_max_time"></span></td></tr>
<tr><th>{t}Modes{/t}:</th><td><span id="chan_modes" class="val"></span></td></tr>
<tr><th>{t}Kicks{/t}:</th><td><span id="chan_kicks" class="val"></span></td></tr>
</table>
{if $cfg->net_roundrobin || $cfg->service_webchat}
<h2>{t}Join this channel{/t}</h2>
Expand Down Expand Up @@ -64,7 +63,6 @@ $(document).ready(function() {
$("#chan_users_max").html(result.users_max);
$("#chan_users_max_time").html($.format.date(result.users_max_time, format_datetime));
$("#chan_modes").html(result.modes ? "+"+result.modes : mLang.None);
$("#chan_kicks").html(result.kicks);
});
$('#tbl_users').dataTable({
"iDisplayLength": 10,
Expand All @@ -76,7 +74,7 @@ $(document).ready(function() {
return getUserStatus(oObj.aData) + ' ' + getCountryFlag(oObj.aData) + ' ' + oObj.aData['nickname'] + getUserExtra(oObj.aData);
} },
{ "mDataProp": "cmodes", "fnRender": function(oObj) {
return '+' + oObj.aData['cmodes'];
return oObj.aData['cmodes'] ? '+' + oObj.aData['cmodes'] : null;
} }
]
});
Expand Down
Loading

0 comments on commit a583f9f

Please sign in to comment.