" . elgg_echo("koolielu:koolielu_statistics") . "";
// Time period filtering part
$timestamp_case = false;
$pb = get_input("pb");
$pe = get_input("pe");
$statistics_type_value = get_input("stat_type");
// See if we are dealing with timestamp case at all
if ((!empty($pb) and !empty($pe)) && $pb <= $pe) {
$timestamp_case = true;
// Adding one day, so that last day resources would be counted
$pe_mod = $pe + 86400;
}
$body .= "
";
$body .= elgg_view('koolielu/forms/filter_moderator_statistics');
$body .= "
";
function _analize_ke_user_role($roledata) {
$returened_role = array();
if (is_array($roledata)) {
return $roledata;
}
if (!empty($roledata) && is_string($roledata)) {
array_push($returned_role, $roledata);
}
return $returned_role;
}
if ($statistics_type_value == "users") {
// TODO See if we need to filter out some of the users
$all_koolielu_users = get_entities("user", "", 0, "", 9999, 0);
// Roles statistics part
$ke_roles_statistics = array('admin' => 0, 'editor' => 0, 'moderator' => 0, 'user' => 0, 'teacher' => 0, 'principal' => 0, 'interestmanager' => 0, 'scoutmaster' => 0, 'parent' => 0, 'student' => 0, 'other' => 0);
$ke_users_data = array();
foreach ($all_koolielu_users as $ke_user) {
$ke_user_row = array();
// Name
$ke_user_row['name'] = $ke_user->name;
// Approved and Rejected materials
if ($timestamp_case) {
$u_approved = get_data("SELECT COUNT(waramu_id) FROM {$CONFIG->dbprefix}koolielu_waramu_resources where user_guid = {$ke_user->guid} and time BETWEEN FROM_UNIXTIME({$pb}) and FROM_UNIXTIME({$pe_mod})");
// XXX Use moderation_time instead of time
$u_rejected = get_data("SELECT COUNT(ID) FROM {$CONFIG->dbprefix}koolielu_waramu_queue where user_guid = {$ke_user->guid} and status = 2 and time BETWEEN FROM_UNIXTIME({$pb}) and FROM_UNIXTIME({$pe_mod})");
// XXX Use moderation_time instead of time
$u_pending = get_data("SELECT COUNT(ID) FROM {$CONFIG->dbprefix}koolielu_waramu_queue where user_guid = {$ke_user->guid} and status = 0 and time BETWEEN FROM_UNIXTIME({$pb}) and FROM_UNIXTIME({$pe_mod})");
} else {
$u_approved = get_data("SELECT COUNT(waramu_id) FROM {$CONFIG->dbprefix}koolielu_waramu_resources where user_guid = {$ke_user->guid}");
$u_rejected = get_data("SELECT COUNT(ID) FROM {$CONFIG->dbprefix}koolielu_waramu_queue where user_guid = {$ke_user->guid} and status = 2");
$u_pending = get_data("SELECT COUNT(ID) FROM {$CONFIG->dbprefix}koolielu_waramu_queue where user_guid = {$ke_user->guid} and status = 0");
}
$u_approved = get_object_vars($u_approved[0]);
$u_approved = (int) array_pop($u_approved);
$u_rejected = get_object_vars($u_rejected[0]);
$u_rejected = (int) array_pop($u_rejected);
$u_pending = get_object_vars($u_pending[0]);
$u_pending = (int) array_pop($u_pending);
$ke_user_row['approved'] = $u_approved;
$ke_user_row['rejected'] = $u_rejected;
$ke_user_row['pending'] = $u_pending;
$ke_user_row['all'] = $u_approved + $u_rejected + $u_pending;
// Append row data to array
array_push($ke_users_data, $ke_user_row);
// System role case
if ($ke_user->admin || $ke_user->siteadmin) {
$ke_roles_statistics['admin'] = $ke_roles_statistics['admin'] + 1;
} else {
if ($ke_user->roles == "moderator") {
$ke_roles_statistics['moderator'] = $ke_roles_statistics['moderator'] + 1;
} else if ($ke_user->roles == "editor") {
$ke_roles_statistics['editor'] = $ke_roles_statistics['editor'] + 1;
} else {
$ke_roles_statistics['user'] = $ke_roles_statistics['user'] + 1;
}
}
// User role case
$ke_user_selfassigned_roles = _analize_ke_user_role($ke_user->role);
foreach ($ke_user_selfassigned_roles as $key => $s_role) {
$ke_roles_statistics[$s_role] = $ke_roles_statistics[$s_role] + 1;
}
}
if (is_array($ke_users_data) && sizeof($ke_users_data) > 0) {
//
$ke_users_rolestatistics = "";
// Now add some general stupid stuff
foreach ($ke_roles_statistics as $key => $row) {
if (!in_array($key, array('editor', 'moderator', 'user', 'admin'))) {
$named_trans = getRoleNameFromID($key);
} else if ($key == "admin") {
/*translation:Admin*/
$named_trans = elgg_echo("koolielu:statistics_user_role_admin");
} else if ($key == "editor") {
/*translation:Editor*/
$named_trans = elgg_echo("koolielu:statistics_user_role_editor");
} else if ($key == "moderator") {
/*translation:Moderator*/
$named_trans = elgg_echo("koolielu:statistics_user_role_moderator");
} else if ($key == "user") {
/*translation:User*/
$named_trans = elgg_echo("koolielu:statistics_user_role_user");
} else {
$named_trans = $key;
}
$ke_users_rolestatistics .= "" . $named_trans . ": " . $row . "
";
}
/*translation:Total*/
$ke_users_rolestatistics .= "" . elgg_echo("koolielu:statistics_users_total") . ": " . sizeof($all_koolielu_users) . "
";
$ke_users_statistics_table = "";
$ke_users_statistics_table .= "";
$ke_users_statistics_table .= "";
$ke_users_statistics_table .= "";
/*translation:Name*/
$ke_users_statistics_table .= "" . elgg_echo("koolielu:users_stats_heading_name") . " | ";
/*translation:Pending materials*/
$ke_users_statistics_table .= "" . elgg_echo("koolielu:users_stats_heading_pending") . " | ";
/*translation:Approved materials*/
$ke_users_statistics_table .= "" . elgg_echo("koolielu:users_stats_heading_approved") . " | ";
/*translation:Rejected materials*/
$ke_users_statistics_table .= "" . elgg_echo("koolielu:users_stats_heading_rejected") . " | ";
/*translation:All*/
$ke_users_statistics_table .= "" . elgg_echo("koolielu:users_stats_heading_all") . " | ";
$ke_users_statistics_table .= "
";
$ke_users_statistics_table .= "";
$ke_users_statistics_table .= "";
foreach ($ke_users_data as $row) {
// Do not show users with no resources at all
if ($row['all'] && $row['all'] != 0) {
$ke_users_statistics_table .= "";
$ke_users_statistics_table .= "" . $row['name'] . " | ";
$ke_users_statistics_table .= "" . $row['pending'] . " | ";
$ke_users_statistics_table .= "" . $row['approved'] . " | ";
$ke_users_statistics_table .= "" . $row['rejected'] . " | ";
$ke_users_statistics_table .= "" . $row['all'] . " | ";
$ke_users_statistics_table .= "
";
}
}
$ke_users_statistics_table .= "";
$ke_users_statistics_table .= "
";
$body .= $ke_users_statistics_table;
} else {
/*translation:No users statistics data to show.*/
$body .= elgg_echo("koolielu:no_users_statistics_data_to_show");
}
} else {
$all_moderators = getAllModerators();
// Array with moderation data, sorted by number of rejected
// array('name' => 'Juku', 'subjects' => 'INFORMAATIKA', 'added' => 10, 'reviewed' => 6, 'approved' => 4, 'rejected' => 2)
$moderation_data = array();
foreach ($all_moderators as $moderator) {
$moderation_row = array();
// Name
$moderation_row['name'] = $moderator->name;
// Subjects
$m_subjects = $moderator->subjects;
if (!empty($m_subjects) && !is_array($m_subjects)) {
$m_subjects = array($m_subjects);
}
$final_subjects = array();
foreach ($m_subjects as $m_subject) {
$subject_name = get_data("SELECT title FROM {$CONFIG->dbprefix}curriculum WHERE eid = $m_subject");
if ($subject_name) {
array_push($final_subjects, $subject_name[0]->title);
}
}
$moderation_row['subjects'] = implode(", ", $final_subjects);
// Added
if ($timestamp_case) {
// Using timestamps for additional filtering
$local_materials = get_data("SELECT COUNT(*) FROM {$CONFIG->dbprefix}koolielu_waramu_queue WHERE user_guid = {$moderator->guid} and time BETWEEN FROM_UNIXTIME({$pb}) and FROM_UNIXTIME({$pe_mod})");
$approved_materials = get_data("SELECT COUNT(*) FROM {$CONFIG->dbprefix}koolielu_waramu_resources WHERE user_guid = {$moderator->guid} and time BETWEEN FROM_UNIXTIME({$pb}) and FROM_UNIXTIME({$pe_mod})");
} else {
$local_materials = get_data("SELECT COUNT(*) FROM {$CONFIG->dbprefix}koolielu_waramu_queue WHERE user_guid = {$moderator->guid}");
$approved_materials = get_data("SELECT COUNT(*) FROM {$CONFIG->dbprefix}koolielu_waramu_resources WHERE user_guid = {$moderator->guid}");
}
$local_materials = get_object_vars($local_materials[0]);
$approved_materials = get_object_vars($approved_materials[0]);
$m_added = (int) array_pop($local_materials) + (int) array_pop($approved_materials);
$moderation_row['added'] = $m_added;
// Approved
if ($timestamp_case) {
// Using timestamps for additional filtering
//$m_approved = get_data("SELECT COUNT(waramu_id) FROM {$CONFIG->dbprefix}koolielu_waramu_resources where moderator_guid = {$moderator->guid} and time BETWEEN FROM_UNIXTIME({$pb}) and FROM_UNIXTIME({$pe_mod})");
// XXX This is a temporary HACK
$m_approved = get_data("SELECT COUNT(waramu_id) FROM {$CONFIG->dbprefix}koolielu_waramu_queue WHERE status = 1 AND moderator_guid = {$moderator->guid} and time BETWEEN FROM_UNIXTIME({$pb}) and FROM_UNIXTIME({$pe_mod})");
} else {
$m_approved = get_data("SELECT COUNT(waramu_id) FROM {$CONFIG->dbprefix}koolielu_waramu_resources where moderator_guid = {$moderator->guid}");
}
$m_approved = get_object_vars($m_approved[0]);
$m_approved = (int) array_pop($m_approved);
$moderation_row['approved'] = $m_approved;
// Rejected
if ($timestamp_case) {
// Using timestamps for additional filtering
// XXX USE moderation_time instead of time
$m_rejected = get_data("SELECT COUNT(ID) FROM {$CONFIG->dbprefix}koolielu_waramu_queue where moderator_guid = {$moderator->guid} and status = 2 and time BETWEEN FROM_UNIXTIME({$pb}) and FROM_UNIXTIME({$pe_mod})");
} else {
$m_rejected = get_data("SELECT COUNT(ID) FROM {$CONFIG->dbprefix}koolielu_waramu_queue where moderator_guid = {$moderator->guid} and status = 2");
}
$m_rejected = get_object_vars($m_rejected[0]);
$m_rejected = (int) array_pop($m_rejected);
$moderation_row['rejected'] = $m_rejected;
// Reviewed
$m_reviewed = $m_approved + $m_rejected;
$moderation_row["reviewed"] = $m_reviewed;
// Append row to data array
array_push($moderation_data, $moderation_row);
}
if (is_array($moderation_data) && sizeof($moderation_data) > 0) {
// Sort array by number of rejected elements
if (sizeof($moderation_data) > 1) {
function cmp($a, $b) {
if ($a['rejected'] == $b['rejected']) {
return 0;
}
return ($a['rejected'] > $b['rejected']) ? -1 : 1;
}
usort($moderation_data, 'cmp');
}
$moderation_statistics_table = "";
$moderation_statistics_table .= "";
$moderation_statistics_table .= "";
$moderation_statistics_table .= "";
/*translation:Moderator*/
$moderation_statistics_table .= "" . elgg_echo("koolielu:moderation_heading_moderator") . " | ";
/*translation:Subjects*/
$moderation_statistics_table .= "" . elgg_echo("koolielu:moderation_heading_subjects") . " | ";
/*translation:Added*/
$moderation_statistics_table .= "" . elgg_echo("koolielu:moderation_heading_added") . " | ";
/*translation:Moderated*/
$moderation_statistics_table .= "" . elgg_echo("koolielu:moderation_heading_moderated") . " | ";
/*translation:Approved*/
$moderation_statistics_table .= "" . elgg_echo("koolielu:moderation_heading_approved") . " | ";
/*translation:Rejected*/
$moderation_statistics_table .= "" . elgg_echo("koolielu:moderation_heading_rejected") . " | ";
$moderation_statistics_table .= "
";
$moderation_statistics_table .= "";
$moderation_statistics_table .= "";
foreach ($moderation_data as $row) {
$moderation_statistics_table .= "";
$moderation_statistics_table .= "". $row['name'] ." | ";
$moderation_statistics_table .= "". $row['subjects'] ." | ";
$moderation_statistics_table .= "". $row['added'] ." | ";
$moderation_statistics_table .= "". $row['reviewed'] ." | ";
$moderation_statistics_table .= "". $row['approved'] ." | ";
$moderation_statistics_table .= "". $row['rejected'] ." | ";
$moderation_statistics_table .= "
";
}
$moderation_statistics_table .= "";
$moderation_statistics_table .= "
";
$body .= $moderation_statistics_table;
} else {
/*translation:No moderation data to show.*/
$body .= elgg_echo("koolielu:no_moderation_data_to_show");
}
}
// Display main admin menu
/*translation:Koolielu management*/
page_draw(elgg_echo('koolielu:koolielu_management'),elgg_view_layout("two_column_left_sidebar", '', $title . $body));
?>