From 36102a094de700ee339f6eaeffb8ab16ba4f2f3b Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 15 Mar 2014 14:42:50 -0300 Subject: Squashed 'mod/graphstats/' content from commit b5d0461 git-subtree-dir: mod/graphstats git-subtree-split: b5d046138c5841d55b4497618d5678cb8027c245 --- lib/timestats.php | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 lib/timestats.php (limited to 'lib/timestats.php') diff --git a/lib/timestats.php b/lib/timestats.php new file mode 100644 index 000000000..739cc79c5 --- /dev/null +++ b/lib/timestats.php @@ -0,0 +1,83 @@ + $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); + } +} -- cgit v1.2.3