http://www.mediawiki.org/wiki/Special:Code/MediaWiki/56337

Revision: 56337
Author:   nimishg
Date:     2009-09-14 21:31:09 +0000 (Mon, 14 Sep 2009)

Log Message:
-----------
Special:ClickTracking page to visualize the data in some way-- NOTE: very rough 
form, will be cleaned up extensively, just wanted to get some version of it in 
to SVN

Modified Paths:
--------------
    trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.i18n.php
    trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.php
    trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.php

Added Paths:
-----------
    
trunk/extensions/UsabilityInitiative/ClickTracking/ApiSpecialClickTracking.php
    trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.css
    trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.js

Added: 
trunk/extensions/UsabilityInitiative/ClickTracking/ApiSpecialClickTracking.php
===================================================================
--- 
trunk/extensions/UsabilityInitiative/ClickTracking/ApiSpecialClickTracking.php  
                            (rev 0)
+++ 
trunk/extensions/UsabilityInitiative/ClickTracking/ApiSpecialClickTracking.php  
    2009-09-14 21:31:09 UTC (rev 56337)
@@ -0,0 +1,116 @@
+<?php
+/**
+ * Extend the API for click tracking visualization in the 
special:clicktracking page
+ *
+ * @file
+ * @ingroup API
+ */
+
+class ApiSpecialClickTracking extends ApiBase {
+
+       /**
+        * runs when the API is called with "specialclicktracking", takes in 
"startdate" and "enddate" as YYYYMMDD , "eventid" as the event ID,
+        *     and "increment" as how many days to increment
+        * @see includes/api/ApiBase#execute()
+        */
+       public function execute(){
+               
+               $params = $this->extractRequestParams();
+               $this->validateParams( $params );
+               $event_id = $params['eventid'];
+               $startdate = $params['startdate'];
+               $enddate = $params['enddate'];
+               $increment = $params['increment'];
+               
+               $click_data = array();
+               try{
+                       $click_data = 
SpecialClickTracking::getChartData($event_id, $startdate, $enddate, $increment);
+                       $this->getResult()->addValue(array('datapoints'), 
'expert', $click_data['expert']);
+                       $this->getResult()->addValue(array('datapoints'), 
'basic', $click_data['basic']);
+                       $this->getResult()->addValue(array('datapoints'), 
'intermediate', $click_data['intermediate']);
+               }
+               catch(Exception $e){ /* no result */   }
+               
+       }
+
+       /**
+        * Required parameter check
+        * @param $params params extracted from the POST
+        */
+       protected function validateParams( $params ) {
+               $required = array( 'eventid', 'startdate', 'enddate', 
'increment' );
+               foreach( $required as $arg ) {
+                       if ( !isset( $params[$arg] ) ) {
+                               $this->dieUsageMsg( array( 'missingparam', $arg 
) );
+                       }
+               }
+               
+               //check if event id parses to an int greater than zero
+               if( (int) $params['eventid'] <= 0){
+                       $this->dieUsage("Invalid event ID", "badeventid"); 
+               }
+               
+               //check start and end date are of proper format
+               if(strptime(  $this->space_out_date($params['startdate']), "%Y 
%m %d") === false){
+                       $this->dieUsage("startdate not in YYYYMMDD format: 
<<{$params['startdate']}>>", "badstartdate");
+               }
+               if(strptime( $this->space_out_date($params['enddate']), "%Y %m 
%d") === false){
+                       $this->dieUsage("enddate not in YYYYMMDD format", 
"badenddate");
+               }
+               
+               //check if increment is a positive int
+               if( (int) $params['increment'] <= 0){
+                       $this->dieUsage("Invalid increment", "badincrement"); 
+               }
+       }
+
+       /**
+        * Space out the dates, 
+        * @param $datewithnospaces date with no spaces
+        * @return date with spaces
+        */
+       public function space_out_date($datewithnospaces){
+               return (substr($datewithnospaces, 0, 4) . " " 
.substr($datewithnospaces, 4, 2) . " " . substr($datewithnospaces, 6, 2));
+       }
+       
+       public function getParamDescription() {
+               return array(
+                       'eventid' => 'event ID (number)',
+                       'startdate'  => 'start date for data in YYYYMMDD 
format',
+                       'enddate' =>'end date for the data in YYYYMMDD format',
+                       'increment' => 'increment interval (in days) for data 
points',
+               );
+       }
+
+       public function getDescription() {
+               return array(
+                       'Returns data to the special:clicktracking 
visualization page'
+               );
+       }
+
+       public function getAllowedParams() {
+               return array(
+                       'eventid' => array(
+                               ApiBase::PARAM_TYPE => 'integer',
+                               ApiBase::PARAM_MIN => 1
+                       ),
+                       'startdate' => array(
+                               ApiBase::PARAM_TYPE => 'integer'
+                       ),
+                       'enddate' => array(
+                               ApiBase::PARAM_TYPE => 'integer'
+                       ),
+                       'increment' => array(
+                               ApiBase::PARAM_TYPE => 'integer',
+                               ApiBase::PARAM_MIN => 1,
+                               ApiBase::PARAM_MAX => 365 //1 year
+                       )
+               );
+       }
+
+       // TODO: create a more useful 'version number'
+       public function getVersion() {
+               return __CLASS__ . ': $Id: $';
+       }
+
+}
\ No newline at end of file


Property changes on: 
trunk/extensions/UsabilityInitiative/ClickTracking/ApiSpecialClickTracking.php
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: 
trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.i18n.php
===================================================================
--- trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.i18n.php   
2009-09-14 21:30:01 UTC (rev 56336)
+++ trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.i18n.php   
2009-09-14 21:31:09 UTC (rev 56337)
@@ -14,7 +14,19 @@
 $messages['en'] = array(
        'clicktracking' => 'Usability Initiative click tracking',
        'clicktracking-desc' => 'Click tracking, intended for tracking events 
that do not cause a page refresh',
-       'clicktracking-title' => 'Aggregated user clicks'
+       'clicktracking-title' => 'Aggregated user clicks',
+       'event-name' => 'Event Name',
+       'expert-header' => '"Expert" clicks',
+       'intermediate-header' => '"Intermediate" clicks',
+       'beginner-header' => '"Beginner" clicks',
+       'total-header' => 'Total clicks',
+       'start-date' => 'Start Date (YYYYMMDD)', 
+       'end-date' => 'End Date (YYYYMMDD)',
+       'increment-by' =>'Number of days each data point represents', 
+       'change-graph' =>'Change Graph',
+       'beginner' => 'Beginner',
+       'intermediate' => 'Intermediate',
+       'expert' => 'Expert',
 );
 
 /** Message documentation (Message documentation)
@@ -22,6 +34,15 @@
  */
 $messages['qqq'] = array(
        'clicktracking-desc' => '{{desc}}',
+       'expert-header' => '"Expert" is a user-definable category, these will 
show the number of clicks that fall into that category',
+       'intermediate-header' => '"Intermediate" is a user-definable category, 
these will show the number of clicks that fall into that category',
+       'beginner-header' => '"Beginner" is a user-definable category, these 
will show the number of clicks that fall into that category',
+       'total-header' => 'total',
+       'start-date' => 'YYYYMMDD refers to the date format (4-digit year, 
2-digit month, 2-digit day)', 
+       'end-date' => 'YYYYMMDD  refers to the date format (4-digit year, 
2-digit month, 2-digit day)',
+       'beginner' => 'label for a user at beginner skill level',
+       'intermediate' => 'label for a user at intermediate skill level',
+       'expert' => 'label for a user at expert skill level',
 );
 
 /** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца))

Modified: trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.php
===================================================================
--- trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.php        
2009-09-14 21:30:01 UTC (rev 56336)
+++ trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.php        
2009-09-14 21:31:09 UTC (rev 56337)
@@ -23,6 +23,7 @@
 
 // click throttle, should be seen as "1 out of every $wgClickTrackThrottle 
users will have it enabled"
 // setting this to 1 means all users will have it enabled
+// setting to a negative number will disable it for all users
 $wgClickTrackThrottle = 1;
 
 // set the time window for what we consider 'recent' contributions, in days
@@ -48,8 +49,8 @@
 $wgAutoloadClasses['ClickTrackingHooks'] = $dir . 'ClickTracking.hooks.php';
 $wgAutoloadClasses['ApiClickTracking'] = $dir . 'ApiClickTracking.php';
 $wgAutoloadClasses['SpecialClickTracking'] = $dir . 'SpecialClickTracking.php';
+$wgAutoloadClasses['ApiSpecialClickTracking'] = $dir 
.'ApiSpecialClickTracking.php';
 
-
 // Hooked functions
 $wgHooks['LoadExtensionSchemaUpdates'][] = 'ClickTrackingHooks::schema';
 $wgHooks['ArticleSaveComplete'][] = 'ClickTrackingHooks::storeNewContrib';
@@ -57,12 +58,12 @@
 
 // Set up the new API module
 $wgAPIModules['clicktracking'] = 'ApiClickTracking';
+$wgAPIModules['specialclicktracking'] = 'ApiSpecialClickTracking';
 
 //Special page setup
 $wgSpecialPages['ClickTracking'] = 'SpecialClickTracking';
+$wgSpecialPageGroups['ClickTracking'] = 'admin';
 
-
-
 // Adds Internationalized Messages
 $wgExtensionMessagesFiles['ClickTracking'] = $dir . 'ClickTracking.i18n.php';
 $wgExtensionAliasesFiles['ClickTracking'] = $dir . 'ClickTracking.alias.php';
\ No newline at end of file

Added: 
trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.css
===================================================================
--- trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.css 
                        (rev 0)
+++ trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.css 
2009-09-14 21:31:09 UTC (rev 56337)
@@ -0,0 +1,28 @@
+...@charset "UTF-8";
+
+.table_headers{
+       font-weight: bold;
+       border: bottom;
+}
+
+.table_data_row{
+       text-align: center;
+}
+
+.table_data_row .event_name{
+       text-align: left;
+       font-weight: bold;
+}
+
+#clicktrack_data_table {
+       float: left;
+}
+
+#chart_img {
+       float: left;
+       margin-left: 90px;
+}
+
+#change_graph_cell {
+       text-align: right;
+}
\ No newline at end of file


Property changes on: 
trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.css
___________________________________________________________________
Added: svn:eol-style
   + native

Added: 
trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.js
===================================================================
--- trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.js  
                        (rev 0)
+++ trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.js  
2009-09-14 21:31:09 UTC (rev 56337)
@@ -0,0 +1,127 @@
+(function($) {
+       
+       //functions
+       $.colorizeTable = function (){
+               
+                       //expert
+                       
+                       //get totals
+                       var expert_total = 0;
+                       
+                       $(".expert_data").each(function(){
+                               expert_total +=  parseInt($(this).attr( 
"value"));
+                       });
+                       
+                       //set proper red shade
+                       $(".expert_data").each(function(){
+                               var rval = 255;
+                               var gval = (expert_total == 0 ? 255 : 255 - 
(255 * $(this).attr("value") / expert_total));
+                               var bval = gval;
+                               rgbString = "rgb(" + parseInt(rval) + "," + 
parseInt(gval) + "," + parseInt(bval) + ")";
+                               $(this).css("color", rgbString);
+                               $(this).css("background-color", rgbString);
+                       });
+                                       
+
+                       //intermediate
+                       
+                       //total
+                       var intermediate_total = 0;
+                       $(".intermediate_data").each(function(){
+                               intermediate_total +=  parseInt($(this).attr( 
"value"));
+                       });
+                       
+                       
+                       //blue shade
+                       $(".intermediate_data").each(function(){
+                               var rval = (intermediate_total == 0 ? 255 : 255 
- (255 *  $(this).attr("value") / intermediate_total));
+                               var gval = rval;
+                               var bval = 255;
+                               rgbString = "rgb(" + parseInt(rval) + "," + 
parseInt(gval) + "," + parseInt(bval) + ")";
+                               $(this).css("color", rgbString);
+                               $(this).css("background-color", rgbString);
+                       });
+                       
+                       //total
+                       var basic_total = 0;
+                       $(".basic_data").each(function(){
+                               basic_total +=  parseInt($(this).attr( 
"value"));
+                       });
+                       
+                       //green shade
+                       $(".basic_data").each(function(){
+                               var rval = (basic_total == 0 ? 255 : 255 - (255 
* $(this).attr("value") / basic_total));
+                               var gval = 255;
+                               var bval = rval;
+                               rgbString = "rgb(" + parseInt(rval) + "," + 
parseInt(gval) + "," + parseInt(bval) + ")";
+                               $(this).css("color", rgbString);
+                               $(this).css("background-color", rgbString);
+                       });
+               
+       };
+       
+       
+       
+
+       $.changeDataLinks = function (){
+               $("#change_graph").click(function(){
+                       console.log($("#increment_date").val());
+               });
+               
+               $(".event_name").each(function(){
+                       $(this).click(function(){
+                       //$j.changeData( $(this).attr( "value" ));
+                       
+                       console.log($(this).attr( "value" ));
+                       
+                       event_name = $(this).text();
+                       console.log(event_name);
+                       
+                       var processChartJSON = function(data, status){
+                               
+                               var getMax = function(findMax){
+                                       var retval = Number.MIN_VALUE;
+                                       for(var i in findMax){
+                                               if(findMax[i] > retval) {
+                                                       retval = findMax[i];
+                                               }
+                                       }
+                                       return retval;
+                               };
+                               
+                               max1 = getMax(data['datapoints']['expert']);
+                               max2 = 
getMax(data['datapoints']['intermediate']);
+                               max3 = getMax(data['datapoints']['basic']);
+                               max = Math.max(max3, Math.max(max1,max2));
+                               chartURL = 
'http://chart.apis.google.com/chart?' +
+                                                       'chs=400x400&' +
+                                                       'cht=lc&' +
+                                                       
'chco=FF0000,0000FF,00FF00&' +
+                                                       'chtt=' + event_name + 
' from ' + $("#start_date").val() +' to ' +$("#end_date").val() + "&" +
+                                                       'chdl=' + 
'Expert|Intermediate|Beginner' + "&"+
+                                                       'chxt=x,y&' +
+                                                       'chd=t:' + 
data['datapoints']['expert'].join(',') + "|" + 
+                                                               
data['datapoints']['intermediate'].join(',') + "|" + 
data['datapoints']['basic'].join(',') + "&" +
+                                                       'chds=0,'+ max +',0,'+ 
max +',0,'+ max
+                               ;
+                               
+                               console.log(chartURL);
+                               $("#chart_img").attr( "src",chartURL);
+                       };
+                       
+                       //post relevant info
+                       $j.post( wgScriptPath + '/api.php', { 'action': 
'specialclicktracking', 'format': 'json', 'eventid': $(this).attr( "value" ), 
'increment': $("#increment_date").val(), 'startdate':$("#start_date").val(), 
'enddate':$("#end_date").val() } , processChartJSON, "json");
+                       
+                       
+                       
+                       });//click
+               });//each
+       };//adlink
+       
+
+return $(this);
+})(jQuery);
+
+//colorize the table on document.ready
+js2AddOnloadHook($j.colorizeTable);
+js2AddOnloadHook($j.changeDataLinks);


Property changes on: 
trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.js
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: 
trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.php
===================================================================
--- trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.php 
2009-09-14 21:30:01 UTC (rev 56336)
+++ trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.php 
2009-09-14 21:31:09 UTC (rev 56337)
@@ -7,18 +7,345 @@
  */
 
 class SpecialClickTracking extends SpecialPage {
+       
+       //set to zero for 'all'
+       private $top_results = 10;
+       private $normalize_top_results = false;
+       private $normalize_results = false;
+       private $use_timeframes = false;
+       private $begin_timeframe = '20090815'; //YYYYMMDD (+1 for today)
+       private $end_timeframe = '20090902';
+       
+       
+       //array of event_id => event_name
+       public static $join_conds = " LEFT JOIN click_tracking_events ON 
event_id=click_tracking_events.id";
+       public static $expert_user_conds = "user_total_contribs > 10 ";
+       public static $intermediate_user_conds = "user_total_contribs < 10 AND 
user_total_contribs > 1 ";
+       public static $basic_user_conds = "user_total_contribs <= 1";
+       
+       /*
+        * " DISTINCT session_id "
+        * 
+        * " select count(*), event_id from click_tracking group by event_id 
order by count(*) desc limit 10;"
+        * 
+        */
+       
+       private $event_id_to_name = array();
+       private $name_to_event_id = array();
+       private $time_constraint_sql = "";
+       
+       
+       
        function __construct() {
                parent::__construct( 'ClickTracking' );
                wfLoadExtensionMessages( 'ClickTracking' );
+               UsabilityInitiativeHooks::initialize();
+               UsabilityInitiativeHooks::addStyle( 
'ClickTracking/SpecialClickTracking.css' );
+               UsabilityInitiativeHooks::addScript( 
'ClickTracking/SpecialClickTracking.js' );
        }
-
+       
+       
+       
+       
+       
        function execute( $par ) {
-               global $wgOut;
+               global $wgOut, $wgUser;
+               
+               // Check permissions
+               if ( !$this->userCanExecute( $wgUser ) ) {
+                       $this->displayRestrictionError();
+                       return;
+               }
+               
                $this->setHeaders();
                $wgOut->setPageTitle( wfMsg( 'clicktracking-title' ) );
                
+               $outputTable ="";
+               
+               
+               //grab top N
+               $events = $this->getTopEvents();
+               
+               //open table
+               $outputTable .= Xml::openElement( "table", array( "class" 
=>"sortable click-data", "id" => "clicktrack_data_table" )  );
+               
+               //create a row for every event
+               $i = 0;
+               $db_result;
+               
+               //build row headers
+               $header_row = array();
+               
+               $header_row["event_header"] = wfMsg( 'event-name' );
+               $header_row["expert_header"] = wfMsg( 'expert-header' );
+               $header_row["intermediate_header"] = wfMsg( 
'intermediate-header' );
+               $header_row["beginner_header"] = wfMsg( 'beginner-header' );
+               $header_row["total_header"] = wfMsg( 'total-header' );
+               $outputTable .= Xml::buildTableRow( array( 
"class"=>"table_headers" ), $header_row );
+               
+               //foreach event, build a row
+               while(($db_result = $events->fetchRow()) != null){
+                       ++$i;
+                       $outputTable .= $this->buildRow( $db_result, $i );
+               }
+               
+               
+               //close table
+               $outputTable .= Xml::closeElement("table");
+               
+               $wgOut->addHTML( $outputTable );
+
+               
+               //build chart
+               $wgOut->addHTML($this->buildChart("advanced.hide",10, 
"20090815", "20090902", 1));
+               
+               $wgOut->addHTML($this->buildControlBox());
+               
        }
+       
 
+       /**
+        * Gets the data to build a chart for PHP or JS purposes
+        * @param $event_id  event id this chart is for
+        * @param $minTime minimum day
+        * @param $maxTime maximum day
+        * @param $increment number of day(s) to increment in units
+        * @return array with chart info
+        */
+       static function getChartData($event_id, $minTime, $maxTime, $increment){
+               //get data      
+               date_default_timezone_set('UTC');
+               
+               //FIXME: On PHP 5.3+, this will be MUCH cleaner
+               $currBeginDate = new DateTime( $minTime );
+               $currEndDate = new DateTime( $minTime );
+               $endDate = new DateTime( $maxTime );
+               
+               $basicUserData = array();
+               $intermediateUserData = array();
+               $expertUserData = array();
+               
+               // PHP 5.3...hurry!
+               $plural = ( $increment == 1 ? "" : "s" );
+               
+               while( $currEndDate->format( "U" )  < $endDate->format( "U" )  
){
+                       $currEndDate->modify( "+$increment day$plural" );
+                       $time_constraints_statement = 
self::getTimeConstraintsStatement( $currBeginDate->format("Ymd"), 
$currEndDate->format("Ymd") );
+                       $basicUserData[] = self::getTableValue( $event_id, 
self::$basic_user_conds, $time_constraints_statement );
+                       $intermediateUserData[] = self::getTableValue( 
$event_id, self::$intermediate_user_conds, $time_constraints_statement );
+                       $expertUserData[] = self::getTableValue( $event_id, 
self::$expert_user_conds, $time_constraints_statement );
+                       $currBeginDate->modify( "+$increment day$plural" );
+               }
+               return array("expert" => $expertUserData, "basic" => 
$basicUserData, "intermediate" => $intermediateUserData);
+       }               
+
+       function buildChart($event_name, $event_id, $minTime, $maxTime, 
$increment){
+               $chartData = self::getChartData($event_id, $minTime, $maxTime, 
$increment);
+               $chartSrc = $this->getGoogleChartParams( $event_id, 
$event_name, $minTime, $maxTime, $chartData["basic"], 
$chartData["intermediate"], $chartData["expert"]);
+               return Xml::element( 'img', array( 'src' => $chartSrc , 'id' => 
'chart_img' ) );
+       }
        
+       
+       function getGoogleChartParams( $event_id, $event_name, $minDate, 
$maxDate, $basicUserData, $intermediateUserData, $expertUserData ) {
+               $max = max( max($basicUserData), max($intermediateUserData), 
max($expertUserData));
+               return "http://chart.apis.google.com/chart?"; . wfArrayToCGI(
+               array(
+                       'chs' => '400x400', 
+                       'cht' => 'lc',
+                       'chco' => 'FF0000,0000FF,00FF00',
+                       'chtt' => "$event_name from $minDate to $maxDate",
+                       'chdl' => 'Expert|Intermediate|Beginner',
+                       'chxt' => 'x,y',
+                       'chd' => 't:' . implode( "," , $expertUserData ) . "|" 
. 
+                                               implode( "," , 
$intermediateUserData ) . "|" . implode( "," , $basicUserData ),
+                       'chds' => "0,$max,0,$max,0,$max"
+                       ));
+       }
+       
+       
+       function buildControlBox(){
+               
+               $control = Xml::openElement("form", array("id" => 
"control_box_form"));
+               $control .= Xml::openElement("table", array("id" => 
"control_box_table"));
+               $control .= Xml::openElement("tbody", array("id" => 
"control_box_tbody"));
+               
+               
+               $control .= Xml::openElement("tr", array("id" => 
"start_date_row"));
+               
+               $control .= Xml::openElement("td", array("id" => 
"start_date_label", "class" => "control_box_label"));
+               $control .= wfMsg( "start-date" );
+               $control .= Xml::closeElement("td");
+               
+               $control .= Xml::openElement("td", array("id" => 
"start_date_textarea"));
+               $control .= Xml::openElement("input", array("type" => "text", 
"id" => "start_date", "class" => "control_box_input"));
+               $control .= Xml::closeElement("input");
+               $control .= Xml::closeElement("td");
+               
+               $control .= Xml::closeElement("tr");
 
+               
+               
+               $control .= Xml::openElement("tr", array("id" => 
"end_date_row"));
+               
+               $control .= Xml::openElement("td", array("id" => 
"end_date_label", "class" => "control_box_label"));
+               $control .= wfMsg( "end-date" );
+               $control .= Xml::closeElement("td");
+               
+               $control .= Xml::openElement("td", array("id" => 
"end_date_textarea"));
+               $control .= Xml::openElement("input", array("type" => "text", 
"id" => "end_date", "class" => "control_box_input"));
+               $control .= Xml::closeElement("input");
+               $control .= Xml::closeElement("td");
+               
+               $control .= Xml::closeElement("tr");
+               
+               
+               
+               $control .= Xml::openElement("tr", array("id" => 
"increment_date_row"));
+               
+               $control .= Xml::openElement("td", array("id" => 
"increment_date_label", "class" => "control_box_label"));
+               $control .= wfMsg( "increment-by" );
+               $control .= Xml::closeElement("td");
+               
+               $control .= Xml::openElement("td", array("id" => 
"increment_date_textarea"));
+               $control .= Xml::openElement("input", array("type" => "text", 
"id" => "increment_date", "class" => "control_box_input"));
+               $control .= Xml::closeElement("input");
+               $control .= Xml::closeElement("td");
+               
+               $control .= Xml::closeElement("tr");
+               
+               
+               
+               $control .= Xml::openElement("tr", array("id" => 
"change_graph_row"));
+               $control .= Xml::openElement("td", array("id" => 
"change_graph_cell", "colspan" => 2));
+               
+               $control .= Xml::openElement("input", array("type" => "button", 
"id" => "change_graph", "value" => wfMsg( "change-graph" ) )  );
+               $control .= Xml::closeElement("input");
+               $control .= Xml::closeElement("td");
+               
+               $control .= Xml::closeElement("tr");
+                               
+               $control .= Xml::closeElement("tbody");
+               $control .= Xml::closeElement("table");
+               $control .= Xml::closeElement("form");
+               
+               return $control;
+       }
+       
+       
+       function buildRow($data_result, $row_count){
+                       
+                       $outputRow = Xml::openElement("tr", array("class" => 
"table_data_row"));
+                       
+                       //event name
+                       $outputRow .=Xml::openElement("td", 
+                                                                       
array("class" => "event_name", "id" => "event_name_$row_count", "value" 
=>$data_result['event_id']));
+                       $outputRow .= $data_result['event_name'];
+                       $outputRow .=Xml::closeElement("td");
+                       
+                       //advanced users
+                       $cellValue = 
self::getTableValue($data_result['event_id'], self::$expert_user_conds);
+                       $outputRow .=Xml::openElement("td", 
+                                                                       
array("class" => "event_data expert_data", "id" => "event_expert_$row_count",
+                                                                               
"value" => $cellValue));
+                       $outputRow .= $cellValue;
+                       $outputRow .=Xml::closeElement("td");
+                       
+                       //intermediate users
+                       $cellValue = 
self::getTableValue($data_result['event_id'], self::$intermediate_user_conds);
+                       $outputRow .=Xml::openElement("td", 
+                                                                       
array("class" => "event_data intermediate_data", "id" => 
"event_intermediate_$row_count", 
+                                                                               
"value" => $cellValue));
+                       $outputRow .= $cellValue;
+                       $outputRow .=Xml::closeElement("td");
+                       
+                       //basic users
+                       $cellValue = 
self::getTableValue($data_result['event_id'], self::$basic_user_conds);
+                       $outputRow .=Xml::openElement("td", 
+                                                                       
array("class" => "event_data basic_data", "id" => "event_basic_$row_count",
+                                                                       "value" 
=> $cellValue));
+                       $outputRow .= $cellValue;
+                       $outputRow .=Xml::closeElement("td");
+                       
+                       //totals
+                       $cellValue = $data_result["count(event_id)"];
+                       $outputRow .=Xml::openElement("td", 
+                                                                       
array("class" => "event_data total_data", "id" => "total_$row_count",
+                                                                       "value" 
=> $cellValue));
+                       $outputRow .= $cellValue;
+                       $outputRow .=Xml::closeElement("td");
+                       
+                       
+                       $outputRow .= Xml::closeElement("tr");
+                       
+                       return $outputRow;
+                       
+       }
+
+       /*
+        * get time constraints
+        * @param minTime minimum day (YYYYMMDD)
+        * @param maxTime max day (YYYYMMDD)
+        * NOTE: once some of the constraints have been finalized, this will 
use more of the Database functions and not raw SQL
+        */
+       static function getTimeConstraintsStatement( $minTime, $maxTime ){
+               if($minTime == 0 || $maxTime == 0){
+                       return '';              
+               }
+               else {
+                       return "WHERE action_time >= $minTime AND action_time 
<= $maxTime";     
+               }
+               
+       }
+       
+       
+       /**
+        * Gets the top N events as set in the page pref
+        * @param $time_constraint_statement
+        * @return unknown_type
+        * NOTE: once some of the constraints have been finalized, this will 
use more of the Database functions and not raw SQL
+        */
+       function getTopEvents($time_constraint_statement=''){
+               $normalize = "click_tracking";
+               $time_constraint = $time_constraint_statement;
+               if($this->normalize_top_results){
+                       $normalize = "(select distinct session_id, event_id 
from click_tracking $time_constraint_statement) as t1";
+                       $time_constraint = "";
+               }
+               $limit = $this->top_results;
+               $join = self::$join_conds;
+               $sql = "select count(event_id), event_id,event_name from 
$normalize $join $time_constraint group by event_id order by count(event_id) 
desc limit $limit";
+               
+               //returns count(event_id),event_id, event_name, top one first
+               $dbr = wfGetDB( DB_SLAVE );
+               $dbresult = $dbr->query($sql);
+               
+               return $dbresult;
+       }
+
+       /**
+        * Gets a table value for a given User ID
+        * NOTE: once some of the constraints have been finalized, this will 
use more of the Database functions and not raw SQL
+        */
+       static function getTableValue($event_id, $user_conditions, 
$time_constraint_statement = '', $normalize_results=false){
+               
+               $normalize = "click_tracking";
+               $time_constraint = $time_constraint_statement;
+               if($normalize_results){
+                       $normalize = "(select distinct session_id, event_id, 
user_total_contribs, user_contribs_span1, user_contribs_span2, 
user_contribs_span3, is_logged_in from click_tracking 
$time_constraint_statement) as t1";
+                       $time_constraint = "";
+               }
+               
+               
+               $where = ($time_constraint == "" ? "where" : "");
+               
+               $and = ($time_constraint == "" ? "": "and");
+               
+               $sql ="select count(*) from $normalize $where $time_constraint 
$and $user_conditions and event_id=$event_id";
+               
+               $dbr = wfGetDB( DB_SLAVE );
+               $result = $dbr->query($sql);
+               $resRow = $result->fetchRow();
+               return $resRow["count(*)"];
+       }
+       
 }
\ No newline at end of file



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to