aboutsummaryrefslogtreecommitdiff
path: root/mod/graphstats/lib
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2014-03-15 14:42:50 -0300
committerSilvio Rhatto <rhatto@riseup.net>2014-03-15 14:42:50 -0300
commit971b54fe719ed70704fb3bcac4ef1d5f093cb454 (patch)
tree26e090c444b1e34881bc088a9cd6f3223e26047a /mod/graphstats/lib
parent711dab09b5146e74dbeda56679c65e3b6bec71f3 (diff)
parent36102a094de700ee339f6eaeffb8ab16ba4f2f3b (diff)
downloadelgg-971b54fe719ed70704fb3bcac4ef1d5f093cb454.tar.gz
elgg-971b54fe719ed70704fb3bcac4ef1d5f093cb454.tar.bz2
Merge commit '36102a094de700ee339f6eaeffb8ab16ba4f2f3b' as 'mod/graphstats'
Diffstat (limited to 'mod/graphstats/lib')
-rw-r--r--mod/graphstats/lib/timestats.php83
1 files changed, 83 insertions, 0 deletions
diff --git a/mod/graphstats/lib/timestats.php b/mod/graphstats/lib/timestats.php
new file mode 100644
index 000000000..739cc79c5
--- /dev/null
+++ b/mod/graphstats/lib/timestats.php
@@ -0,0 +1,83 @@
+<?php
+
+function timestats($type, $subtype, $relative = false){
+
+ // Start date
+ $entities = elgg_get_entities(array('types' => $type,'subtypes'=>$subtype,'limit' => 1,'order_by'=>'e.time_created asc'));
+ $firstentity = $entities[0];
+ $initial_time = $firstentity->time_created;
+ $initial_date = getdate($initial_time);
+ $start_month = mktime(0, 0, 0, $initial_date["mon"], 1, $initial_date["year"]);
+ $current_date = $start_month;
+
+ // End date
+ $last_time = time();
+ $last_date = getdate($last_time);
+
+ // Interval (week)
+ $interval = 7*24*60*60;
+
+
+ $total = elgg_get_entities(array('types' => $type,'subtypes'=>$subtype,'limit' => 99999, 'count'=>true));
+
+ $timestats = array();
+ while($current_date<$last_time) {
+ $count = elgg_get_entities(array(
+ 'types' => $type,
+ 'subtypes' => $subtype,
+ 'limit' => 99999,
+ 'count' => true,
+ 'created_time_lower' => $current_date,
+ 'created_time_upper'=>$current_date+$interval
+ ));
+ if (empty($count))
+ $count = 0;
+ $accumulated += $count;
+ $timestats[$current_date] = $relative? $count : $accumulated;
+ $current_date += $interval;
+ }
+
+ return $timestats;
+}
+
+function timestats_setup_sidebar_menu(){
+ $tabs = array(
+ 'user' => array(
+ 'text' => elgg_echo('item:user'),
+ 'href' => 'graphs/timestats?type=user',
+ 'priority' => 200,
+ ),
+ 'group' => array(
+ 'text' => elgg_echo('groups'),
+ 'href' => 'graphs/timestats?type=group',
+ 'priority' => 300,
+ ),
+ );
+
+ $db_prefix = elgg_get_config('dbprefix');
+ $result = get_data("SELECT * from {$db_prefix}entity_subtypes");
+
+ foreach($result as $row){
+ $type = $row->type;
+ $subtype = $row->subtype;
+ $tabs[$type.':'.$subtype] = array(
+ 'text' => elgg_echo("item:$type:$subtype"),
+ 'href' => "graphs/timestats?type=$type&subtype=$subtype",
+ 'priority' => 400,
+ );
+ }
+
+ unset($tabs['object:plugin']);
+ unset($tabs['object:widget']);
+
+ // sets default selected item
+ if (strpos(full_url(), 'type') === false) {
+ $tabs['user']['selected'] = true;
+ }
+
+ foreach ($tabs as $name => $tab) {
+ $tab['name'] = $name;
+
+ elgg_register_menu_item('page', $tab);
+ }
+}