Index: trunk/extensions/UsabilityInitiative/ClickTracking/ApiClickTracking.php |
— | — | @@ -27,10 +27,10 @@ |
28 | 28 | $now = time(); |
29 | 29 | $granularity1 = $is_logged_in ? |
30 | 30 | ClickTrackingHooks::getEditCountSince( $now - $wgClickTrackContribGranularity1 ) : 0; |
31 | | - |
| 31 | + |
32 | 32 | $granularity2 = $is_logged_in ? |
33 | 33 | ClickTrackingHooks::getEditCountSince( $now - $wgClickTrackContribGranularity2 ) : 0; |
34 | | - |
| 34 | + |
35 | 35 | $granularity3 = $is_logged_in ? |
36 | 36 | ClickTrackingHooks::getEditCountSince( $now - $wgClickTrackContribGranularity3 ) : 0; |
37 | 37 | |
Index: trunk/extensions/UsabilityInitiative/ClickTracking/ApiSpecialClickTracking.php |
— | — | @@ -21,22 +21,19 @@ |
22 | 22 | $enddate = $params['enddate']; |
23 | 23 | $increment = $params['increment']; |
24 | 24 | $userDefString = $params['userdefs']; |
25 | | - |
26 | | - //this is if it's asking for tableData |
27 | | - if(isset($params['tabledata'])){ |
28 | | - $tableData = SpecialClickTracking::buildRowArray($startdate, $enddate, $userDefString); |
29 | | - $this->getResult()->addValue(array('tablevals'), 'vals', $tableData); |
30 | | - |
31 | | - } |
32 | | - else{ //chart data |
| 25 | + |
| 26 | + // this is if it's asking for tableData |
| 27 | + if( isset( $params['tabledata'] ) ) { |
| 28 | + $tableData = SpecialClickTracking::buildRowArray( $startdate, $enddate, $userDefString ); |
| 29 | + $this->getResult()->addValue( array( 'tablevals' ), 'vals', $tableData ); |
| 30 | + } else{ //chart data |
33 | 31 | $click_data = array(); |
34 | | - try{ |
35 | | - $click_data = SpecialClickTracking::getChartData($event_id, $startdate, $enddate, $increment, $userDefString); |
36 | | - $this->getResult()->addValue(array('datapoints'), 'expert', $click_data['expert']); |
37 | | - $this->getResult()->addValue(array('datapoints'), 'basic', $click_data['basic']); |
38 | | - $this->getResult()->addValue(array('datapoints'), 'intermediate', $click_data['intermediate']); |
39 | | - } |
40 | | - catch(Exception $e){ /* no result */ } |
| 32 | + try { |
| 33 | + $click_data = SpecialClickTracking::getChartData( $event_id, $startdate, $enddate, $increment, $userDefString ); |
| 34 | + $this->getResult()->addValue( array( 'datapoints' ), 'expert', $click_data['expert'] ); |
| 35 | + $this->getResult()->addValue( array( 'datapoints' ), 'basic', $click_data['basic'] ); |
| 36 | + $this->getResult()->addValue( array( 'datapoints' ), 'intermediate', $click_data['intermediate'] ); |
| 37 | + } catch( Exception $e ) { /* no result */ } |
41 | 38 | } |
42 | 39 | } |
43 | 40 | |
— | — | @@ -51,39 +48,39 @@ |
52 | 49 | $this->dieUsageMsg( array( 'missingparam', $arg ) ); |
53 | 50 | } |
54 | 51 | } |
55 | | - |
56 | | - //check if event id parses to an int greater than zero |
57 | | - if( (int) $params['eventid'] < 0){ |
58 | | - $this->dieUsage("Invalid event ID", "badeventid"); |
| 52 | + |
| 53 | + // check if event id parses to an int greater than zero |
| 54 | + if( (int) $params['eventid'] < 0 ) { |
| 55 | + $this->dieUsage( 'Invalid event ID', 'badeventid' ); |
59 | 56 | } |
60 | | - |
61 | | - //check start and end date are of proper format |
62 | | - if($params['startdate'] != 0 && strptime( $this->space_out_date($params['startdate']), "%Y %m %d") === false){ |
63 | | - $this->dieUsage("startdate not in YYYYMMDD format: <<{$params['startdate']}>>", "badstartdate"); |
| 57 | + |
| 58 | + // check start and end date are of proper format |
| 59 | + if( $params['startdate'] != 0 && strptime( $this->space_out_date( $params['startdate'] ), "%Y %m %d" ) === false ) { |
| 60 | + $this->dieUsage( "startdate not in YYYYMMDD format: <<{$params['startdate']}>>", 'badstartdate' ); |
64 | 61 | } |
65 | | - if($params['enddate'] != 0 && strptime( $this->space_out_date($params['enddate']), "%Y %m %d") === false){ |
66 | | - $this->dieUsage("enddate not in YYYYMMDD format:<<{$params['enddate']}>>", "badenddate"); |
| 62 | + if( $params['enddate'] != 0 && strptime( $this->space_out_date( $params['enddate'] ), "%Y %m %d" ) === false ) { |
| 63 | + $this->dieUsage( "enddate not in YYYYMMDD format:<<{$params['enddate']}>>", 'badenddate' ); |
67 | 64 | } |
68 | | - |
69 | | - //check if increment is a positive int |
70 | | - if( (int) $params['increment'] <= 0){ |
71 | | - $this->dieUsage("Invalid increment", "badincrement"); |
| 65 | + |
| 66 | + // check if increment is a positive int |
| 67 | + if( (int) $params['increment'] <= 0 ) { |
| 68 | + $this->dieUsage( 'Invalid increment', 'badincrement' ); |
72 | 69 | } |
73 | | - |
74 | | - if(json_decode($params['userdefs']) == null){ |
75 | | - $this->dieUsage("Invalid JSON encoding <<{$params['userdefs']}>>", "badjson"); |
| 70 | + |
| 71 | + if( json_decode( $params['userdefs'] ) == null ) { |
| 72 | + $this->dieUsage( "Invalid JSON encoding <<{$params['userdefs']}>>", 'badjson' ); |
76 | 73 | } |
77 | 74 | } |
78 | 75 | |
79 | 76 | /** |
80 | | - * Space out the dates, |
| 77 | + * Space out the dates |
81 | 78 | * @param $datewithnospaces date with no spaces |
82 | 79 | * @return date with spaces |
83 | 80 | */ |
84 | | - public function space_out_date($datewithnospaces){ |
85 | | - return (substr($datewithnospaces, 0, 4) . " " .substr($datewithnospaces, 4, 2) . " " . substr($datewithnospaces, 6, 2)); |
| 81 | + public function space_out_date( $datewithnospaces ) { |
| 82 | + return ( substr( $datewithnospaces, 0, 4 ) . ' ' .substr( $datewithnospaces, 4, 2 ) . ' ' . substr( $datewithnospaces, 6, 2 ) ); |
86 | 83 | } |
87 | | - |
| 84 | + |
88 | 85 | public function getParamDescription() { |
89 | 86 | return array( |
90 | 87 | 'eventid' => 'event ID (number)', |
— | — | @@ -97,7 +94,7 @@ |
98 | 95 | |
99 | 96 | public function getDescription() { |
100 | 97 | return array( |
101 | | - 'Returns data to the special:clicktracking visualization page' |
| 98 | + 'Returns data to the Special:ClickTracking visualization page' |
102 | 99 | ); |
103 | 100 | } |
104 | 101 | |
— | — | @@ -118,10 +115,12 @@ |
119 | 116 | ApiBase::PARAM_MIN => 1, |
120 | 117 | ApiBase::PARAM_MAX => 365 //1 year |
121 | 118 | ), |
122 | | - 'userdefs' => array ( |
123 | | - ApiBase::PARAM_TYPE => 'string'), |
124 | | - 'tabledata' => array ( |
125 | | - ApiBase::PARAM_TYPE => 'integer'), |
| 119 | + 'userdefs' => array( |
| 120 | + ApiBase::PARAM_TYPE => 'string' |
| 121 | + ), |
| 122 | + 'tabledata' => array( |
| 123 | + ApiBase::PARAM_TYPE => 'integer' |
| 124 | + ), |
126 | 125 | ); |
127 | 126 | } |
128 | 127 | |
Index: trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.php |
— | — | @@ -7,549 +7,579 @@ |
8 | 8 | */ |
9 | 9 | |
10 | 10 | class SpecialClickTracking extends SpecialPage { |
11 | | - |
12 | | - //set to zero for 'all' |
| 11 | + |
| 12 | + // set to zero for 'all' |
13 | 13 | private $top_results = 10; |
14 | 14 | private $normalize_top_results = false; |
15 | 15 | private $normalize_results = false; |
16 | 16 | private $end_timeframe = '20090902'; |
17 | | - private static $minimum_date = '20091009'; //YYYYMMDD (+1 for today) |
18 | | - |
19 | | - private static $userTypes = array("basic" => 0, "intermediate" => 1, "expert" => 2); |
| 17 | + private static $minimum_date = '20091009'; // YYYYMMDD (+1 for today) |
| 18 | + |
| 19 | + private static $userTypes = array( 'basic' => 0, 'intermediate' => 1, 'expert' => 2 ); |
20 | 20 | private $user_defs = array(); |
21 | | - |
22 | | - //array of event_id => event_name |
| 21 | + |
| 22 | + // array of event_id => event_name |
23 | 23 | public static $expert_user_conds = "user_total_contribs > 10 "; |
24 | 24 | public static $intermediate_user_conds = "user_total_contribs < 10 AND user_total_contribs > 1 "; |
25 | 25 | public static $basic_user_conds = "user_total_contribs <= 1"; |
26 | | - |
27 | | - /* |
| 26 | + |
| 27 | + /** |
28 | 28 | * " DISTINCT session_id " |
29 | | - * |
| 29 | + * |
30 | 30 | * " select count(*), event_id from click_tracking group by event_id order by count(*) desc limit 10;" |
31 | | - * |
| 31 | + * |
32 | 32 | */ |
33 | | - |
34 | 33 | private $event_id_to_name = array(); |
35 | 34 | private $name_to_event_id = array(); |
36 | | - private $time_constraint_sql = ""; |
37 | | - |
38 | | - |
39 | | - |
40 | | - function __construct() { |
41 | | - parent::__construct( 'ClickTracking' , 'clicktrack'); |
| 35 | + private $time_constraint_sql = ''; |
| 36 | + |
| 37 | + /** |
| 38 | + * Constructor -- set up the new special page |
| 39 | + */ |
| 40 | + public function __construct() { |
| 41 | + parent::__construct( 'ClickTracking' , 'clicktrack' ); |
42 | 42 | wfLoadExtensionMessages( 'ClickTracking' ); |
43 | 43 | UsabilityInitiativeHooks::initialize(); |
44 | 44 | UsabilityInitiativeHooks::addStyle( 'ClickTracking/SpecialClickTracking.css' ); |
45 | 45 | UsabilityInitiativeHooks::addScript( 'ClickTracking/SpecialClickTracking.js' ); |
46 | 46 | } |
47 | | - |
48 | | - |
49 | | - |
50 | | - |
51 | | - function setDefaults(){ |
52 | | - $this->user_defs["basic"] = array( |
53 | | - "anonymous" => "1", |
54 | | - "total_contribs" => array( |
55 | | - array("operation" => "<=", "value" => "1"), |
| 47 | + |
| 48 | + function setDefaults() { |
| 49 | + $this->user_defs['basic'] = array( |
| 50 | + 'anonymous' => '1', |
| 51 | + 'total_contribs' => array( |
| 52 | + array( 'operation' => '<=', 'value' => '1' ), |
56 | 53 | ), |
57 | 54 | ); |
58 | | - |
59 | | - $this->user_defs["intermediate"] = array( |
60 | | - "anonymous" => "0", |
61 | | - "total_contribs" => array( |
62 | | - array("operation" => "<", "value" => "10"), |
63 | | - array("operation" => ">", "value" => "1"), |
| 55 | + |
| 56 | + $this->user_defs['intermediate'] = array( |
| 57 | + 'anonymous' => '0', |
| 58 | + 'total_contribs' => array( |
| 59 | + array( 'operation' => '<', 'value' => '10' ), |
| 60 | + array( 'operation' => '>', 'value' => '1' ), |
64 | 61 | ), |
65 | 62 | ); |
66 | | - |
67 | | - $this->user_defs["expert"] = array( |
68 | | - "anonymous" => "0", |
69 | | - "total_contribs" => array( |
70 | | - array("operation" => ">=", "value" => "10"), |
| 63 | + |
| 64 | + $this->user_defs['expert'] = array( |
| 65 | + 'anonymous' => '0', |
| 66 | + 'total_contribs' => array( |
| 67 | + array( 'operation' => '>=', 'value' => '10' ), |
71 | 68 | ), |
72 | 69 | ); |
73 | | - |
74 | | - |
| 70 | + |
75 | 71 | } |
76 | | - |
77 | | - |
78 | | - |
79 | | - function execute( $par ) { |
| 72 | + |
| 73 | + /** |
| 74 | + * Show the special page |
| 75 | + * |
| 76 | + * @param $par Mixed: parameter passed to the page or null |
| 77 | + */ |
| 78 | + public function execute( $par ) { |
80 | 79 | global $wgOut, $wgUser; |
81 | | - |
| 80 | + |
82 | 81 | // Check permissions |
83 | 82 | if ( !$this->userCanExecute( $wgUser ) ) { |
84 | 83 | $this->displayRestrictionError(); |
85 | 84 | return; |
86 | 85 | } |
87 | | - |
88 | | - |
| 86 | + |
89 | 87 | $this->setHeaders(); |
90 | 88 | $this->setDefaults(); |
91 | | - |
92 | | - $wgOut->addScript('<script type="text/javascript">'. "var wgClickTrackUserDefs = ".json_encode($this->user_defs). '</script>'); |
93 | | - |
| 89 | + |
| 90 | + $wgOut->addScript( '<script type="text/javascript">' . "var wgClickTrackUserDefs = " . json_encode( $this->user_defs ) . '</script>' ); |
| 91 | + |
94 | 92 | $wgOut->setPageTitle( wfMsg( 'ct-title' ) ); |
95 | | - |
96 | | - $outputTable =""; |
97 | | - |
98 | | - |
99 | | - //grab top N |
| 93 | + |
| 94 | + $outputTable = ''; |
| 95 | + |
| 96 | + // grab top N |
100 | 97 | $events = $this->getTopEvents(); |
101 | | - |
102 | | - //open table |
103 | | - $outputTable .= Xml::openElement( "table", array( "class" =>"sortable click-data", "id" => "clicktrack_data_table" ) ); |
104 | | - |
105 | | - //create a row for every event |
| 98 | + |
| 99 | + // open table |
| 100 | + $outputTable .= Xml::openElement( 'table', array( 'class' => 'sortable click-data', 'id' => 'clicktrack_data_table' ) ); |
| 101 | + |
| 102 | + // create a row for every event |
106 | 103 | $i = 0; |
107 | 104 | $db_result; |
108 | | - |
109 | | - //build row headers |
| 105 | + |
| 106 | + // build row headers |
110 | 107 | $header_row = array(); |
111 | | - |
112 | | - $header_row["event_header"] = wfMsg( 'ct-event-name' ); |
113 | | - $header_row["expert_header"] = wfMsg( 'ct-expert-header' ); |
114 | | - $header_row["intermediate_header"] = wfMsg( 'ct-intermediate-header' ); |
115 | | - $header_row["basic_header"] = wfMsg( 'ct-beginner-header' ); |
116 | | - $header_row["total_header"] = wfMsg( 'ct-total-header' ); |
117 | | - $outputTable .= Xml::buildTableRow( array( "class"=>"table_headers" ), $header_row ); |
118 | | - |
119 | | - //foreach event, build a row |
120 | | - while(($db_result = $events->fetchRow()) != null){ |
| 108 | + |
| 109 | + $header_row['event_header'] = wfMsg( 'ct-event-name' ); |
| 110 | + $header_row['expert_header'] = wfMsg( 'ct-expert-header' ); |
| 111 | + $header_row['intermediate_header'] = wfMsg( 'ct-intermediate-header' ); |
| 112 | + $header_row['basic_header'] = wfMsg( 'ct-beginner-header' ); |
| 113 | + $header_row['total_header'] = wfMsg( 'ct-total-header' ); |
| 114 | + $outputTable .= Xml::buildTableRow( array( 'class' => 'table_headers' ), $header_row ); |
| 115 | + |
| 116 | + // foreach event, build a row |
| 117 | + while( ( $db_result = $events->fetchRow() ) != null ) { |
121 | 118 | ++$i; |
122 | | - $outputTable .= $this->buildRow( $db_result, $i, $this->user_defs); |
| 119 | + $outputTable .= $this->buildRow( $db_result, $i, $this->user_defs ); |
123 | 120 | } |
124 | | - |
125 | | - |
126 | | - //close table |
127 | | - $outputTable .= Xml::closeElement("table"); |
128 | | - |
| 121 | + |
| 122 | + // close table |
| 123 | + $outputTable .= Xml::closeElement( 'table' ); |
| 124 | + |
129 | 125 | $wgOut->addHTML( $outputTable ); |
130 | 126 | |
131 | | - $wgOut->addHTML($this->buildDateRange()); |
132 | | - |
133 | | - //build chart |
134 | | - $wgOut->addHTML($this->buildChart("advanced.hide",10, "20090815", "20090902", 1)); |
135 | | - |
136 | | - //$wgOut->addHTML($this->buildControlBox()); |
137 | | - |
138 | | - $wgOut->addHTML($this->buildChartDialog()); |
139 | | - $wgOut->addHTML($this->buildUserDefBlankDialog()); |
140 | | - |
| 127 | + $wgOut->addHTML( $this->buildDateRange() ); |
| 128 | + |
| 129 | + // build chart |
| 130 | + $wgOut->addHTML( $this->buildChart( 'advanced.hide', 10, '20090815', '20090902', 1 ) ); |
| 131 | + |
| 132 | + //$wgOut->addHTML( $this->buildControlBox() ); |
| 133 | + |
| 134 | + $wgOut->addHTML( $this->buildChartDialog() ); |
| 135 | + $wgOut->addHTML( $this->buildUserDefBlankDialog() ); |
141 | 136 | } |
142 | | - |
143 | 137 | |
144 | 138 | /** |
145 | 139 | * Gets the data to build a chart for PHP or JS purposes |
146 | | - * @param $event_id event id this chart is for |
| 140 | + * @param $event_id event id this chart is for |
147 | 141 | * @param $minTime minimum day |
148 | 142 | * @param $maxTime maximum day |
149 | 143 | * @param $increment number of day(s) to increment in units |
150 | | - * @param $userDefs user defintions |
151 | | - * @param $isUserDefsJSON true if userDefs is JSON |
| 144 | + * @param $userDefs user defintions |
| 145 | + * @param $isUserDefsJSON Boolean: true if userDefs is JSON |
152 | 146 | * @return array with chart info |
153 | 147 | */ |
154 | | - static function getChartData($event_id, $minTime, $maxTime, $increment, $userDefs, $isUserDefsJSON=true){ |
155 | | - //get data |
156 | | - date_default_timezone_set('UTC'); |
157 | | - |
158 | | - if($maxTime == 0){ |
159 | | - $maxTime = gmdate("Ymd",time()); //today |
| 148 | + static function getChartData( $event_id, $minTime, $maxTime, $increment, $userDefs, $isUserDefsJSON = true ) { |
| 149 | + // get data |
| 150 | + date_default_timezone_set( 'UTC' ); |
| 151 | + |
| 152 | + if( $maxTime == 0 ) { |
| 153 | + $maxTime = gmdate( 'Ymd', time() ); // today |
160 | 154 | } |
161 | | - if($minTime == 0){ |
| 155 | + if( $minTime == 0 ) { |
162 | 156 | $minTime = self::$minimum_date; |
163 | 157 | } |
164 | | - |
165 | | - |
166 | | - //FIXME: On PHP 5.3+, this will be MUCH cleaner |
| 158 | + |
| 159 | + // FIXME: On PHP 5.3+, this will be MUCH cleaner |
167 | 160 | $currBeginDate = new DateTime( $minTime ); |
168 | 161 | $currEndDate = new DateTime( $minTime ); |
169 | 162 | $endDate = new DateTime( $maxTime ); |
170 | | - |
171 | | - |
172 | | - //get user definitions |
173 | | - if($isUserDefsJSON){ |
174 | | - $userDefs = json_decode($userDefs, true); |
| 163 | + |
| 164 | + // get user definitions |
| 165 | + if( $isUserDefsJSON ) { |
| 166 | + $userDefs = json_decode( $userDefs, true ); |
175 | 167 | } |
176 | | - |
| 168 | + |
177 | 169 | $basicUserData = array(); |
178 | 170 | $intermediateUserData = array(); |
179 | 171 | $expertUserData = array(); |
180 | | - |
| 172 | + |
181 | 173 | // PHP 5.3...hurry! |
182 | | - $plural = ( $increment == 1 ? "" : "s" ); |
183 | | - |
184 | | - while( $currEndDate->format( "U" ) < $endDate->format( "U" ) ){ |
| 174 | + $plural = ( $increment == 1 ? '' : 's' ); |
| 175 | + |
| 176 | + while( $currEndDate->format( 'U' ) < $endDate->format( 'U' ) ) { |
185 | 177 | $currEndDate->modify( "+$increment day$plural" ); |
186 | | - |
187 | | - $minDate = $currBeginDate->format("Ymd"); |
188 | | - $maxDate = $currEndDate->format("Ymd"); |
189 | | - |
| 178 | + |
| 179 | + $minDate = $currBeginDate->format( 'Ymd' ); |
| 180 | + $maxDate = $currEndDate->format( 'Ymd' ); |
| 181 | + |
190 | 182 | $basicUserData[] = self::getTableValue( $event_id, $userDefs['basic'], $minDate, $maxDate ); |
191 | 183 | $intermediateUserData[] = self::getTableValue( $event_id, $userDefs['intermediate'], $minDate, $maxDate ); |
192 | 184 | $expertUserData[] = self::getTableValue( $event_id, $userDefs['expert'], $minDate, $maxDate ); |
193 | 185 | $currBeginDate->modify( "+$increment day$plural" ); |
194 | 186 | } |
195 | | - return array("expert" => $expertUserData, "basic" => $basicUserData, "intermediate" => $intermediateUserData); |
196 | | - } |
| 187 | + return array( 'expert' => $expertUserData, 'basic' => $basicUserData, 'intermediate' => $intermediateUserData ); |
| 188 | + } |
197 | 189 | |
198 | | - function buildChart($event_name, $event_id, $minTime, $maxTime, $increment){ |
199 | | - $chartData = self::getChartData($event_id, $minTime, $maxTime, $increment, $this->user_defs, false); |
200 | | - $chartSrc = $this->getGoogleChartParams( $event_id, $event_name, $minTime, $maxTime, $chartData["basic"], $chartData["intermediate"], $chartData["expert"]); |
| 190 | + function buildChart( $event_name, $event_id, $minTime, $maxTime, $increment ) { |
| 191 | + $chartData = self::getChartData( $event_id, $minTime, $maxTime, $increment, $this->user_defs, false ); |
| 192 | + $chartSrc = $this->getGoogleChartParams( |
| 193 | + $event_id, $event_name, $minTime, $maxTime, $chartData['basic'], |
| 194 | + $chartData['intermediate'], $chartData['expert'] |
| 195 | + ); |
201 | 196 | return Xml::element( 'img', array( 'src' => $chartSrc , 'id' => 'chart_img' ) ); |
202 | 197 | } |
203 | | - |
204 | | - |
| 198 | + |
205 | 199 | function getGoogleChartParams( $event_id, $event_name, $minDate, $maxDate, $basicUserData, $intermediateUserData, $expertUserData ) { |
206 | | - $max = max( max($basicUserData), max($intermediateUserData), max($expertUserData)); |
207 | | - return "http://chart.apis.google.com/chart?" . wfArrayToCGI( |
208 | | - array( |
209 | | - 'chs' => '400x400', |
210 | | - 'cht' => 'lc', |
211 | | - 'chco' => 'FF0000,0000FF,00FF00', |
212 | | - 'chtt' => "$event_name from $minDate to $maxDate", |
213 | | - 'chdl' => 'Expert|Intermediate|Beginner', |
214 | | - 'chxt' => 'x,y', |
215 | | - 'chd' => 't:' . implode( "," , $expertUserData ) . "|" . |
| 200 | + $max = max( max( $basicUserData ), max( $intermediateUserData ), max( $expertUserData ) ); |
| 201 | + return 'http://chart.apis.google.com/chart?' . wfArrayToCGI( |
| 202 | + array( |
| 203 | + 'chs' => '400x400', |
| 204 | + 'cht' => 'lc', |
| 205 | + 'chco' => 'FF0000,0000FF,00FF00', |
| 206 | + 'chtt' => "$event_name from $minDate to $maxDate", |
| 207 | + 'chdl' => 'Expert|Intermediate|Beginner', |
| 208 | + 'chxt' => 'x,y', |
| 209 | + 'chd' => 't:' . implode( "," , $expertUserData ) . "|" . |
216 | 210 | implode( "," , $intermediateUserData ) . "|" . implode( "," , $basicUserData ), |
217 | | - 'chds' => "0,$max,0,$max,0,$max" |
218 | | - )); |
| 211 | + 'chds' => "0,$max,0,$max,0,$max" |
| 212 | + ) |
| 213 | + ); |
219 | 214 | } |
220 | | - |
221 | | - |
| 215 | + |
222 | 216 | function buildUserDefBlankDialog(){ |
223 | | - $control = ""; |
224 | | - $control .= Xml::openElement("div", array("id" => "user_def_dialog", "class" => "dialog")); |
225 | | - |
| 217 | + $control = ''; |
| 218 | + $control .= Xml::openElement( 'div', array( 'id' => 'user_def_dialog', 'class' => 'dialog' ) ); |
| 219 | + |
226 | 220 | //currently editing...----| |
227 | | - $control .= Xml::openElement("form", array("id" => "user_definition_form", "class" => "user_def_form")); |
228 | | - $control .= Xml::openElement("fieldset", array("id" => "user_def_alter_fieldset")); |
229 | | - $control .= Xml::openElement("legend", array("id" => "user_def_alter_legend")); |
230 | | - $control .= wfMsg( "editing" ); |
231 | | - $control .= Xml::closeElement("legend"); |
232 | | - |
| 221 | + $control .= Xml::openElement( 'form', array( 'id' => 'user_definition_form', 'class' => 'user_def_form' ) ); |
| 222 | + $control .= Xml::openElement( 'fieldset', array( 'id' => 'user_def_alter_fieldset' ) ); |
| 223 | + $control .= Xml::openElement( 'legend', array( 'id' => 'user_def_alter_legend' ) ); |
| 224 | + $control .= wfMsg( 'editing' ); |
| 225 | + $control .= Xml::closeElement( 'legend' ); |
| 226 | + |
233 | 227 | //[] anonymous users? |
234 | | - $control .= Xml::openElement("div", array("id" => "anon_users_div", "class" => "checkbox_div control_div")); |
235 | | - $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "anon_users_checkbox", "class" => "user_def_checkbox")); |
236 | | - $control .= Xml::closeElement("input"); |
237 | | - $control .= wfMsg("anon-users"); |
238 | | - $control .= Xml::closeElement("div"); |
239 | | - |
| 228 | + $control .= Xml::openElement( 'div', array( 'id' => 'anon_users_div', 'class' => 'checkbox_div control_div' ) ); |
| 229 | + $control .= Xml::openElement( 'input', array( 'type' => 'checkbox', 'id' => 'anon_users_checkbox', 'class' => 'user_def_checkbox' ) ); |
| 230 | + $control .= Xml::closeElement( 'input' ); |
| 231 | + $control .= wfMsg( 'anon-users' ); |
| 232 | + $control .= Xml::closeElement( 'div' ); |
| 233 | + |
240 | 234 | // ---------------- |
241 | | - $control .= Xml::openElement("hr"); |
242 | | - $control .= Xml::closeElement("hr"); |
243 | | - $control .= Xml::openElement("div", array("id" => "contrib_opts_container")); |
244 | | - |
| 235 | + $control .= Xml::openElement( 'hr' ); |
| 236 | + $control .= Xml::closeElement( 'hr' ); |
| 237 | + $control .= Xml::openElement( 'div', array( 'id' => 'contrib_opts_container' ) ); |
| 238 | + |
245 | 239 | // [] users with contributions [>=V] [n ] |
246 | | - $control .= Xml::openElement("div", array("id" => "total_users_contrib_div", "class" => "checkbox_div control_div")); |
247 | | - $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "contrib_checkbox", "class" => "user_def_checkbox")); |
248 | | - $control .= Xml::closeElement("input"); |
249 | | - $control .= wfMsg("user-contribs"); |
250 | | - |
251 | | - |
252 | | - $control .= Xml::closeElement("div"); |
253 | | - |
| 240 | + $control .= Xml::openElement( 'div', array( 'id' => 'total_users_contrib_div', 'class' => 'checkbox_div control_div' ) ); |
| 241 | + $control .= Xml::openElement( 'input', array( 'type' => 'checkbox', 'id' => 'contrib_checkbox', 'class' => 'user_def_checkbox' ) ); |
| 242 | + $control .= Xml::closeElement( 'input' ); |
| 243 | + $control .= wfMsg( 'ct-user-contribs' ); |
| 244 | + |
| 245 | + $control .= Xml::closeElement( 'div' ); |
| 246 | + |
254 | 247 | // [] contributions in timespan 1 |
255 | | - $control .= Xml::openElement("div", array("id" => "contrib_span_1_div", "class" => "checkbox_div control_div")); |
256 | | - |
257 | | - $control .= Xml::openElement("div", array("id" => "contrib_span_1_text_div", "class" => "checkbox_div")); |
258 | | - $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "contrib_span_1_checkbox", "class" => "user_def_checkbox")); |
259 | | - $control .= Xml::closeElement("input"); |
260 | | - $control .= wfMsg("user-span") . " 1"; |
261 | | - $control .= Xml::closeElement("div"); |
262 | | - $control .= Xml::closeElement("div"); |
263 | | - |
| 248 | + $control .= Xml::openElement( 'div', array( 'id' => 'contrib_span_1_div', 'class' => 'checkbox_div control_div' ) ); |
| 249 | + |
| 250 | + $control .= Xml::openElement( 'div', array( 'id' => 'contrib_span_1_text_div', 'class' => 'checkbox_div' ) ); |
| 251 | + $control .= Xml::openElement( 'input', |
| 252 | + array( |
| 253 | + 'type' => 'checkbox', |
| 254 | + 'id' => 'contrib_span_1_checkbox', |
| 255 | + 'class' => 'user_def_checkbox' |
| 256 | + ) |
| 257 | + ); |
| 258 | + $control .= Xml::closeElement( 'input' ); |
| 259 | + $control .= wfMsg( 'ct-user-span' ) . ' 1'; |
| 260 | + $control .= Xml::closeElement( 'div' ); |
| 261 | + $control .= Xml::closeElement( 'div' ); |
| 262 | + |
264 | 263 | // [] contributions in timespan 2 |
265 | | - $control .= Xml::openElement("div", array("id" => "contrib_span_2_div", "class" => "checkbox_div control_div")); |
266 | | - |
267 | | - $control .= Xml::openElement("div", array("id" => "contrib_span_2_text_div", "class" => "checkbox_div")); |
268 | | - $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "contrib_span_2_checkbox", "class" => "user_def_checkbox")); |
269 | | - $control .= Xml::closeElement("input"); |
270 | | - $control .= wfMsg("user-span") . " 2"; |
271 | | - $control .= Xml::closeElement("div"); |
272 | | - $control .= Xml::closeElement("div"); |
273 | | - |
| 264 | + $control .= Xml::openElement( 'div', array( 'id' => 'contrib_span_2_div', 'class' => 'checkbox_div control_div' ) ); |
| 265 | + |
| 266 | + $control .= Xml::openElement( 'div', array( 'id' => 'contrib_span_2_text_div', 'class' => 'checkbox_div' ) ); |
| 267 | + $control .= Xml::openElement( 'input', array( 'type' => 'checkbox', 'id' => 'contrib_span_2_checkbox', 'class' => 'user_def_checkbox' ) ); |
| 268 | + $control .= Xml::closeElement( 'input' ); |
| 269 | + $control .= wfMsg( 'ct-user-span' ) . ' 2'; |
| 270 | + $control .= Xml::closeElement( 'div' ); |
| 271 | + $control .= Xml::closeElement( 'div' ); |
| 272 | + |
274 | 273 | // [] contributions in timespan 3 |
275 | | - $control .= Xml::openElement("div", array("id" => "contrib_span_3_div", "class" => "checkbox_div control_div")); |
276 | | - |
277 | | - $control .= Xml::openElement("div", array("id" => "contrib_span_3_text_div", "class" => "checkbox_div")); |
278 | | - $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "contrib_span_3_checkbox", "class" => "user_def_checkbox")); |
279 | | - $control .= Xml::closeElement("input"); |
280 | | - $control .= wfMsg("user-span") . " 3"; |
281 | | - $control .= Xml::closeElement("div"); |
282 | | - $control .= Xml::closeElement("div"); |
283 | | - |
284 | | - |
285 | | - |
286 | | - |
287 | | - $control .= Xml::closeElement("div");//close contrib opts |
288 | | - |
289 | | - $control .= Xml::closeElement("fieldset"); |
290 | | - $control .= Xml::closeElement("form"); |
291 | | - $control .= Xml::closeElement("div"); |
| 274 | + $control .= Xml::openElement( 'div', array( 'id' => 'contrib_span_3_div', 'class' => 'checkbox_div control_div' ) ); |
| 275 | + |
| 276 | + $control .= Xml::openElement( 'div', array( 'id' => 'contrib_span_3_text_div', 'class' => 'checkbox_div' ) ); |
| 277 | + $control .= Xml::openElement( 'input', array( 'type' => 'checkbox', 'id' => 'contrib_span_3_checkbox', 'class' => 'user_def_checkbox' ) ); |
| 278 | + $control .= Xml::closeElement( 'input' ); |
| 279 | + $control .= wfMsg( 'ct-user-span' ) . ' 3'; |
| 280 | + $control .= Xml::closeElement( 'div' ); |
| 281 | + $control .= Xml::closeElement( 'div' ); |
| 282 | + |
| 283 | + $control .= Xml::closeElement( 'div' ); // close contrib opts |
| 284 | + |
| 285 | + $control .= Xml::closeElement( 'fieldset' ); |
| 286 | + $control .= Xml::closeElement( 'form' ); |
| 287 | + $control .= Xml::closeElement( 'div' ); |
292 | 288 | return $control; |
293 | 289 | } |
294 | | - |
295 | | - |
296 | | - |
297 | | - function buildUserDefNumberSelect($include_checkbox, $include_and, $ids){ |
298 | | - $control = ""; |
299 | | - if($include_checkbox){ |
300 | | - $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "{$ids}_checkbox", "class" => "number_select_checkbox")); |
301 | | - $control .= Xml::closeElement("input"); |
| 290 | + |
| 291 | + function buildUserDefNumberSelect( $include_checkbox, $include_and, $ids ) { |
| 292 | + $control = ''; |
| 293 | + if( $include_checkbox ) { |
| 294 | + $control .= Xml::openElement( 'input', array( 'type' => 'checkbox', 'id' => "{$ids}_checkbox", 'class' => 'number_select_checkbox' ) ); |
| 295 | + $control .= Xml::closeElement( 'input' ); |
302 | 296 | } |
303 | | - |
304 | | - if($include_and){ |
305 | | - $control .= wfMsg("ct-and"); |
| 297 | + |
| 298 | + if( $include_and ) { |
| 299 | + $control .= wfMsg( 'ct-and' ); |
306 | 300 | } |
307 | | - |
308 | | - $control .= Xml::openElement("select", array("id" => "{$ids}_ltgt", "class" => "number_select_ltgt")); |
309 | | - $control .= Xml::openElement("option", array("id" => "{$ids}_lt", "class" => "number_select_ltgt_opt", "value" => "lt")); |
| 301 | + |
| 302 | + $control .= Xml::openElement( 'select', array( 'id' => "{$ids}_ltgt", 'class' => 'number_select_ltgt' ) ); |
| 303 | + $control .= Xml::openElement( 'option', array( 'id' => "{$ids}_lt", 'class' => 'number_select_ltgt_opt', 'value' => 'lt' ) ); |
310 | 304 | $control .= "<="; |
311 | | - $control .= Xml::closeElement("option"); |
312 | | - $control .= Xml::openElement("option", array("id" => "{$ids}_gt", "class" => "number_select_ltgt_opt", "value" => "gt")); |
| 305 | + $control .= Xml::closeElement( 'option' ); |
| 306 | + $control .= Xml::openElement( 'option', array( 'id' => "{$ids}_gt", 'class' => 'number_select_ltgt_opt', 'value' => 'gt' ) ); |
313 | 307 | $control .= ">="; |
314 | | - $control .= Xml::closeElement("option"); |
315 | | - $control .= Xml::closeElement("select"); |
316 | | - $control .= Xml::openElement("input", array("type" => "text", "id" => "{$ids}_text", "class" => "number_select_text")); |
317 | | - $control .= Xml::closeElement("input"); |
| 308 | + $control .= Xml::closeElement( 'option' ); |
| 309 | + $control .= Xml::closeElement( 'select' ); |
| 310 | + $control .= Xml::openElement( 'input', array( 'type' => 'text', 'id' => "{$ids}_text", 'class' => 'number_select_text' ) ); |
| 311 | + $control .= Xml::closeElement( 'input' ); |
318 | 312 | return $control; |
319 | 313 | } |
320 | | - |
321 | | - |
322 | | - function buildChartDialog(){ |
323 | | - $control = ""; |
324 | | - $control .= Xml::openElement("div", array("id" => "chart_dialog", "class" => "dialog")); |
325 | | - |
326 | | - $control .= Xml::openElement("form", array("id" => "chart_dialog_form", "class" => "chart_form")); |
327 | | - $control .= Xml::openElement("fieldset", array("id" => "chart_dialog_alter_fieldset")); |
328 | | - $control .= Xml::openElement("legend", array("id" => "chart_dialog_alter_legend")); |
329 | | - $control .= wfMsg( "ct-increment-by" ); |
330 | | - $control .= Xml::closeElement("legend"); |
331 | | - |
332 | | - $control .= Xml::openElement("table", array("id" => "chart_dialog_increment_table")); |
333 | | - $control .= Xml::openElement("tbody", array("id" => "chart_dialog_increment_tbody")); |
334 | | - |
335 | | - $control .= Xml::openElement("tr", array("id" => "chart_dialog_increment_row")); |
336 | | - |
337 | | - $control .= Xml::openElement("td", array("id" => "chart_dialog_increment_cell")); |
338 | | - $control .= Xml::openElement("input", array("type" => "text", "id" => "chart_increment", "class" => "chart_dialog_area", "value" => '1')); |
339 | | - $control .= Xml::closeElement("input"); |
340 | | - $control .= Xml::closeElement("td"); |
341 | | - |
342 | | - $control .= Xml::openElement("td", array("id" => "chart_dialog_button_cell")); |
343 | | - $control .= Xml::openElement("input", array("type" => "button", "id" => "change_graph", "value" => wfMsg( "ct-change-graph" ) ) ); |
344 | | - $control .= Xml::closeElement("input"); |
345 | | - $control .= Xml::closeElement("td"); |
346 | | - |
347 | | - $control .= Xml::closeElement("tr"); |
348 | | - |
349 | | - $control .= Xml::closeElement("tbody"); |
350 | | - $control .= Xml::closeElement("table"); |
351 | | - $control .= Xml::closeElement("fieldset"); |
352 | | - $control .= Xml::closeElement("form"); |
353 | | - $control .= Xml::closeElement("div"); |
| 314 | + |
| 315 | + function buildChartDialog() { |
| 316 | + $control = ''; |
| 317 | + $control .= Xml::openElement( 'div', array( 'id' => 'chart_dialog', 'class' => 'dialog' ) ); |
| 318 | + |
| 319 | + $control .= Xml::openElement( 'form', array( 'id' => 'chart_dialog_form', 'class' => 'chart_form' ) ); |
| 320 | + $control .= Xml::openElement( 'fieldset', array( 'id' => 'chart_dialog_alter_fieldset' ) ); |
| 321 | + $control .= Xml::openElement( 'legend', array( 'id' => 'chart_dialog_alter_legend' ) ); |
| 322 | + $control .= wfMsg( 'ct-increment-by' ); |
| 323 | + $control .= Xml::closeElement( 'legend' ); |
| 324 | + |
| 325 | + $control .= Xml::openElement( 'table', array( 'id' => 'chart_dialog_increment_table' ) ); |
| 326 | + $control .= Xml::openElement( 'tbody', array( 'id' => 'chart_dialog_increment_tbody' ) ); |
| 327 | + |
| 328 | + $control .= Xml::openElement( 'tr', array( 'id' => 'chart_dialog_increment_row' ) ); |
| 329 | + |
| 330 | + $control .= Xml::openElement( 'td', array( 'id' => 'chart_dialog_increment_cell' ) ); |
| 331 | + $control .= Xml::openElement( 'input', |
| 332 | + array( |
| 333 | + 'type' => 'text', |
| 334 | + 'id' => 'chart_increment', |
| 335 | + 'class' => 'chart_dialog_area', |
| 336 | + 'value' => '1' |
| 337 | + ) |
| 338 | + ); |
| 339 | + $control .= Xml::closeElement( 'input' ); |
| 340 | + $control .= Xml::closeElement( 'td' ); |
| 341 | + |
| 342 | + $control .= Xml::openElement( 'td', array( 'id' => 'chart_dialog_button_cell' ) ); |
| 343 | + $control .= Xml::openElement( 'input', |
| 344 | + array( |
| 345 | + 'type' => 'button', |
| 346 | + 'id' => 'change_graph', |
| 347 | + 'value' => wfMsg( 'ct-change-graph' ) |
| 348 | + ) |
| 349 | + ); |
| 350 | + $control .= Xml::closeElement( 'input' ); |
| 351 | + $control .= Xml::closeElement( 'td' ); |
| 352 | + |
| 353 | + $control .= Xml::closeElement( 'tr' ); |
| 354 | + |
| 355 | + $control .= Xml::closeElement( 'tbody' ); |
| 356 | + $control .= Xml::closeElement( 'table' ); |
| 357 | + $control .= Xml::closeElement( 'fieldset' ); |
| 358 | + $control .= Xml::closeElement( 'form' ); |
| 359 | + $control .= Xml::closeElement( 'div' ); |
354 | 360 | return $control; |
355 | 361 | } |
356 | | - |
357 | | - |
358 | | - function buildDateRange(){ |
359 | | - $control = Xml::openElement("form", array("id" => "date_range")); |
360 | | - |
361 | | - $control .= Xml::openElement("fieldset", array("id" => "date_range_fieldset")); |
362 | | - $control .= Xml::openElement("legend", array("id" => "date_range_legend")); |
363 | | - $control .= wfMsg('ct-date-range'); |
364 | | - $control .= Xml::closeElement("legend"); |
365 | | - |
366 | 362 | |
367 | | - |
368 | | - $control .= Xml::openElement("table", array("id" => "date_range_table")); |
369 | | - $control .= Xml::openElement("tbody", array("id" => "date_range_tbody")); |
370 | | - |
371 | | - |
372 | | - $control .= Xml::openElement("tr", array("id" => "start_date_row")); |
373 | | - |
374 | | - $control .= Xml::openElement("td", array("id" => "start_date_label", "class" => "date_range_label")); |
375 | | - $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "start_date_checkbox", "class" => "date_range_checkbox", "checked" => "")); |
376 | | - $control .= Xml::closeElement("input"); |
377 | | - $control .= wfMsg( "ct-start-date" ); |
378 | | - $control .= Xml::closeElement("td"); |
379 | | - |
380 | | - $control .= Xml::openElement("td", array("id" => "start_date_textarea")); |
381 | | - $control .= Xml::openElement("input", array("type" => "text", "id" => "start_date", "class" => "date_range_input")); |
382 | | - $control .= Xml::closeElement("input"); |
383 | | - $control .= Xml::closeElement("td"); |
384 | | - |
385 | | - $control .= Xml::closeElement("tr"); |
386 | | - |
387 | | - $control .= Xml::openElement("tr", array("id" => "end_date_row")); |
388 | | - |
389 | | - $control .= Xml::openElement("td", array("id" => "end_date_label", "class" => "date_range_label")); |
390 | | - $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "end_date_checkbox", "class" => "date_range_checkbox", "checked" => "")); |
391 | | - $control .= Xml::closeElement("input"); |
392 | | - $control .= wfMsg( "ct-end-date" ); |
393 | | - $control .= Xml::closeElement("td"); |
394 | | - |
395 | | - $control .= Xml::openElement("td", array("id" => "end_date_textarea")); |
396 | | - $control .= Xml::openElement("input", array("type" => "text", "id" => "end_date", "class" => "date_range_input")); |
397 | | - $control .= Xml::closeElement("input"); |
398 | | - $control .= Xml::closeElement("td"); |
399 | | - |
400 | | - $control .= Xml::closeElement("tr"); |
401 | | - |
| 363 | + function buildDateRange() { |
| 364 | + $control = Xml::openElement( 'form', array( 'id' => 'date_range' ) ); |
402 | 365 | |
403 | | - $control .= Xml::openElement("tr", array("id" => "update_row")); |
404 | | - |
405 | | - $control .= Xml::openElement("td"); |
406 | | - $control .= Xml::closeElement("td"); |
407 | | - |
408 | | - $control .= Xml::openElement("td", array("id" => "update_table_button_td")); |
409 | | - $control .= Xml::openElement("input", array("type" => "button", "id" => "update_table_button", "class" => "update_button", "value" =>wfMsg("ct-update-table"))); |
410 | | - $control .= Xml::closeElement("input"); |
411 | | - $control .= Xml::closeElement("td"); |
412 | | - |
413 | | - $control .= Xml::closeElement("tr"); |
414 | | - |
415 | | - $control .= Xml::closeElement("tbody"); |
416 | | - $control .= Xml::closeElement("table"); |
417 | | - $control .= Xml::closeElement("fieldset"); |
418 | | - |
419 | | - $control .= Xml::closeElement("form"); |
420 | | - |
| 366 | + $control .= Xml::openElement( 'fieldset', array( 'id' => 'date_range_fieldset' ) ); |
| 367 | + $control .= Xml::openElement( 'legend', array( 'id' => 'date_range_legend' ) ); |
| 368 | + $control .= wfMsg( 'ct-date-range' ); |
| 369 | + $control .= Xml::closeElement( 'legend' ); |
| 370 | + |
| 371 | + $control .= Xml::openElement( 'table', array( 'id' => 'date_range_table' ) ); |
| 372 | + $control .= Xml::openElement( 'tbody', array( 'id' => 'date_range_tbody' ) ); |
| 373 | + |
| 374 | + $control .= Xml::openElement( 'tr', array( 'id' => 'start_date_row' ) ); |
| 375 | + |
| 376 | + $control .= Xml::openElement( 'td', array( 'id' => 'start_date_label', 'class' => 'date_range_label' ) ); |
| 377 | + $control .= Xml::openElement( 'input', |
| 378 | + array( |
| 379 | + 'type' => 'checkbox', |
| 380 | + 'id' => 'start_date_checkbox', |
| 381 | + 'class' => 'date_range_checkbox', |
| 382 | + 'checked' => '' |
| 383 | + ) |
| 384 | + ); |
| 385 | + $control .= Xml::closeElement( 'input' ); |
| 386 | + $control .= wfMsg( 'ct-start-date' ); |
| 387 | + $control .= Xml::closeElement( 'td' ); |
| 388 | + |
| 389 | + $control .= Xml::openElement( 'td', array( 'id' => 'start_date_textarea' ) ); |
| 390 | + $control .= Xml::openElement( 'input', array( 'type' => 'text', 'id' => 'start_date', 'class' => 'date_range_input' ) ); |
| 391 | + $control .= Xml::closeElement( 'input' ); |
| 392 | + $control .= Xml::closeElement( 'td' ); |
| 393 | + |
| 394 | + $control .= Xml::closeElement( 'tr' ); |
| 395 | + |
| 396 | + $control .= Xml::openElement( 'tr', array( 'id' => 'end_date_row' ) ); |
| 397 | + |
| 398 | + $control .= Xml::openElement( 'td', array( 'id' => 'end_date_label', 'class' => 'date_range_label' ) ); |
| 399 | + $control .= Xml::openElement( 'input', |
| 400 | + array( |
| 401 | + 'type' => 'checkbox', |
| 402 | + 'id' => 'end_date_checkbox', |
| 403 | + 'class' => 'date_range_checkbox', |
| 404 | + 'checked' => '' |
| 405 | + ) |
| 406 | + ); |
| 407 | + $control .= Xml::closeElement( 'input' ); |
| 408 | + $control .= wfMsg( 'ct-end-date' ); |
| 409 | + $control .= Xml::closeElement( 'td' ); |
| 410 | + |
| 411 | + $control .= Xml::openElement( 'td', array( 'id' => 'end_date_textarea' ) ); |
| 412 | + $control .= Xml::openElement( 'input', array( 'type' => 'text', 'id' => 'end_date', 'class' => 'date_range_input' ) ); |
| 413 | + $control .= Xml::closeElement( 'input' ); |
| 414 | + $control .= Xml::closeElement( 'td' ); |
| 415 | + |
| 416 | + $control .= Xml::closeElement( 'tr' ); |
| 417 | + |
| 418 | + $control .= Xml::openElement( 'tr', array( 'id' => 'update_row' ) ); |
| 419 | + |
| 420 | + $control .= Xml::openElement( 'td' ); |
| 421 | + $control .= Xml::closeElement( 'td' ); |
| 422 | + |
| 423 | + $control .= Xml::openElement( 'td', array( 'id' => 'update_table_button_td' ) ); |
| 424 | + $control .= Xml::openElement( 'input', |
| 425 | + array( |
| 426 | + 'type' => 'button', |
| 427 | + 'id' => 'update_table_button', |
| 428 | + 'class' => 'update_button', |
| 429 | + 'value' => wfMsg( 'ct-update-table' ) |
| 430 | + ) |
| 431 | + ); |
| 432 | + $control .= Xml::closeElement( 'input' ); |
| 433 | + $control .= Xml::closeElement( 'td' ); |
| 434 | + |
| 435 | + $control .= Xml::closeElement( 'tr' ); |
| 436 | + |
| 437 | + $control .= Xml::closeElement( 'tbody' ); |
| 438 | + $control .= Xml::closeElement( 'table' ); |
| 439 | + $control .= Xml::closeElement( 'fieldset' ); |
| 440 | + |
| 441 | + $control .= Xml::closeElement( 'form' ); |
| 442 | + |
421 | 443 | return $control; |
422 | 444 | } |
423 | | - |
424 | | - |
425 | 445 | |
426 | | - public static function buildRowArray($minTime, $maxTime, $userDefs, $is_JSON= true){ |
427 | | - |
428 | | - |
429 | | - if($minTime == 0){ |
| 446 | + public static function buildRowArray( $minTime, $maxTime, $userDefs, $is_JSON = true) { |
| 447 | + if( $minTime == 0 ) { |
430 | 448 | $minTime = self::$minimum_date; |
431 | 449 | } |
432 | | - if($maxTime == 0){ |
433 | | - $maxTime = gmdate("Ymd",time()); //today |
| 450 | + |
| 451 | + if( $maxTime == 0 ) { |
| 452 | + $maxTime = gmdate( 'Ymd', time() ); // today |
434 | 453 | } |
435 | | - |
436 | | - if($is_JSON){ |
437 | | - $userDefs = json_decode($userDefs, true); |
| 454 | + |
| 455 | + if( $is_JSON ) { |
| 456 | + $userDefs = json_decode( $userDefs, true ); |
438 | 457 | } |
439 | | - |
440 | | - |
441 | | - $events = self::getTopEvents($minTime, $maxTime); |
442 | | - |
| 458 | + |
| 459 | + $events = self::getTopEvents( $minTime, $maxTime ); |
| 460 | + |
443 | 461 | $returnArray = array(); |
444 | | - |
445 | | - while(($data_result = $events->fetchRow()) != null){ |
| 462 | + |
| 463 | + while( ( $data_result = $events->fetchRow() ) != null ) { |
446 | 464 | $outputArray = array(); |
447 | 465 | $outputArray['event_name'] = $data_result['event_name']; |
448 | 466 | $outputArray['event_id'] = $data_result['event_id']; |
449 | | - $outputArray['expert'] = self::getTableValue($data_result['event_id'], $userDefs["expert"]); |
450 | | - $outputArray['intermediate'] = self::getTableValue($data_result['event_id'], $userDefs["intermediate"]); |
451 | | - $outputArray['basic'] = self::getTableValue($data_result['event_id'], $userDefs["basic"]); |
452 | | - $outputArray['total'] = $data_result["totalevtid"]; |
| 467 | + $outputArray['expert'] = self::getTableValue( $data_result['event_id'], $userDefs['expert'] ); |
| 468 | + $outputArray['intermediate'] = self::getTableValue( $data_result['event_id'], $userDefs['intermediate'] ); |
| 469 | + $outputArray['basic'] = self::getTableValue( $data_result['event_id'], $userDefs['basic']); |
| 470 | + $outputArray['total'] = $data_result['totalevtid']; |
453 | 471 | $returnArray[] = $outputArray; |
454 | 472 | } |
455 | | - |
| 473 | + |
456 | 474 | return $returnArray; |
457 | | - |
458 | 475 | } |
459 | | - |
460 | | - function buildRow($data_result, $row_count, $userDefs){ |
461 | | - |
462 | | - $outputRow = Xml::openElement("tr", array("class" => "table_data_row")); |
463 | | - |
464 | | - //event name |
465 | | - $outputRow .=Xml::openElement("td", |
466 | | - array("class" => "event_name", "id" => "event_name_$row_count", "value" =>$data_result['event_id'])); |
467 | | - $outputRow .= $data_result['event_name']; |
468 | | - $outputRow .=Xml::closeElement("td"); |
469 | | - |
470 | | - //advanced users |
471 | | - $cellValue = self::getTableValue($data_result['event_id'], $userDefs["expert"]); |
472 | | - $outputRow .=Xml::openElement("td", |
473 | | - array("class" => "event_data expert_data", "id" => "event_expert_$row_count", |
474 | | - "value" => $cellValue)); |
475 | | - $outputRow .= $cellValue; |
476 | | - $outputRow .=Xml::closeElement("td"); |
477 | | - |
478 | | - //intermediate users |
479 | | - $cellValue = self::getTableValue($data_result['event_id'], $userDefs["intermediate"]); |
480 | | - $outputRow .=Xml::openElement("td", |
481 | | - array("class" => "event_data intermediate_data", "id" => "event_intermediate_$row_count", |
482 | | - "value" => $cellValue)); |
483 | | - $outputRow .= $cellValue; |
484 | | - $outputRow .=Xml::closeElement("td"); |
485 | | - |
486 | | - //basic users |
487 | | - $cellValue = self::getTableValue($data_result['event_id'], $userDefs["basic"]); |
488 | | - $outputRow .=Xml::openElement("td", |
489 | | - array("class" => "event_data basic_data", "id" => "event_basic_$row_count", |
490 | | - "value" => $cellValue)); |
491 | | - $outputRow .= $cellValue; |
492 | | - $outputRow .=Xml::closeElement("td"); |
493 | | - |
494 | | - //totals |
495 | | - $cellValue = $data_result["totalevtid"]; |
496 | | - $outputRow .=Xml::openElement("td", |
497 | | - array("class" => "event_data total_data", "id" => "total_$row_count", |
498 | | - "value" => $cellValue)); |
499 | | - $outputRow .= $cellValue; |
500 | | - $outputRow .=Xml::closeElement("td"); |
501 | | - |
502 | | - |
503 | | - $outputRow .= Xml::closeElement("tr"); |
504 | | - |
505 | | - return $outputRow; |
506 | | - |
| 476 | + |
| 477 | + function buildRow( $data_result, $row_count, $userDefs ) { |
| 478 | + $outputRow = Xml::openElement( 'tr', array( 'class' => 'table_data_row' ) ); |
| 479 | + |
| 480 | + // event name |
| 481 | + $outputRow .= Xml::openElement( 'td', |
| 482 | + array( |
| 483 | + 'class' => 'event_name', |
| 484 | + 'id' => "event_name_$row_count", |
| 485 | + 'value' => $data_result['event_id'] |
| 486 | + ) |
| 487 | + ); |
| 488 | + $outputRow .= $data_result['event_name']; |
| 489 | + $outputRow .= Xml::closeElement( 'td' ); |
| 490 | + |
| 491 | + // advanced users |
| 492 | + $cellValue = self::getTableValue( $data_result['event_id'], $userDefs['expert'] ); |
| 493 | + $outputRow .=Xml::openElement( 'td', |
| 494 | + array( |
| 495 | + 'class' => 'event_data expert_data', |
| 496 | + 'id' => "event_expert_$row_count", |
| 497 | + 'value' => $cellValue |
| 498 | + ) |
| 499 | + ); |
| 500 | + $outputRow .= $cellValue; |
| 501 | + $outputRow .= Xml::closeElement( 'td' ); |
| 502 | + |
| 503 | + // intermediate users |
| 504 | + $cellValue = self::getTableValue( $data_result['event_id'], $userDefs['intermediate'] ); |
| 505 | + $outputRow .= Xml::openElement( 'td', |
| 506 | + array( |
| 507 | + 'class' => 'event_data intermediate_data', |
| 508 | + 'id' => "event_intermediate_$row_count", |
| 509 | + 'value' => $cellValue |
| 510 | + ) |
| 511 | + ); |
| 512 | + $outputRow .= $cellValue; |
| 513 | + $outputRow .= Xml::closeElement( 'td' ); |
| 514 | + |
| 515 | + // basic users |
| 516 | + $cellValue = self::getTableValue( $data_result['event_id'], $userDefs['basic'] ); |
| 517 | + $outputRow .= Xml::openElement( 'td', |
| 518 | + array( |
| 519 | + 'class' => 'event_data basic_data', |
| 520 | + 'id' => "event_basic_$row_count", |
| 521 | + 'value' => $cellValue |
| 522 | + ) |
| 523 | + ); |
| 524 | + $outputRow .= $cellValue; |
| 525 | + $outputRow .= Xml::closeElement( 'td' ); |
| 526 | + |
| 527 | + // totals |
| 528 | + $cellValue = $data_result['totalevtid']; |
| 529 | + $outputRow .=Xml::openElement( 'td', |
| 530 | + array( |
| 531 | + 'class' => 'event_data total_data', |
| 532 | + 'id' => "total_$row_count", |
| 533 | + 'value' => $cellValue |
| 534 | + ) |
| 535 | + ); |
| 536 | + $outputRow .= $cellValue; |
| 537 | + $outputRow .= Xml::closeElement( 'td' ); |
| 538 | + $outputRow .= Xml::closeElement( 'tr' ); |
| 539 | + |
| 540 | + return $outputRow; |
507 | 541 | } |
508 | 542 | |
509 | | - /* |
510 | | - * get time constraints |
| 543 | + /** |
| 544 | + * Get time constraints |
511 | 545 | * @param minTime minimum day (YYYYMMDD) |
512 | 546 | * @param maxTime max day (YYYYMMDD) |
513 | 547 | * NOTE: once some of the constraints have been finalized, this will use more of the Database functions and not raw SQL |
514 | 548 | */ |
515 | | - static function getTimeConstraintsStatement( $minTime, $maxTime ){ |
516 | | - if($minTime == 0 || $maxTime == 0){ |
517 | | - return ''; |
| 549 | + static function getTimeConstraintsStatement( $minTime, $maxTime ) { |
| 550 | + if( $minTime == 0 || $maxTime == 0 ) { |
| 551 | + return ''; |
| 552 | + } else { |
| 553 | + return "WHERE `action_time` >= '$minTime' AND `action_time` <= '$maxTime'"; |
518 | 554 | } |
519 | | - else { |
520 | | - |
521 | | - return "WHERE `action_time` >= '$minTime' AND `action_time` <= '$maxTime'"; |
522 | | - } |
523 | | - |
524 | 555 | } |
525 | | - |
526 | | - |
| 556 | + |
527 | 557 | /** |
528 | 558 | * Gets the top N events as set in the page pref |
529 | 559 | * @param $time_constraint_statement |
530 | 560 | * @return unknown_type |
531 | 561 | * NOTE: once some of the constraints have been finalized, this will use more of the Database functions and not raw SQL |
532 | 562 | */ |
533 | | - public static function getTopEvents($minTime = "", $maxTime = "", $normalize_top_results = false){ |
534 | | - |
535 | | - $normalize = "click_tracking"; |
536 | | - //escaped |
537 | | - |
538 | | - $time_constraint_statement = self::getTimeConstraintsStatement($minTime,$maxTime); |
| 563 | + public static function getTopEvents( $minTime = '', $maxTime = '', $normalize_top_results = false ) { |
| 564 | + $normalize = 'click_tracking'; |
| 565 | + // escaped |
| 566 | + |
| 567 | + $time_constraint_statement = self::getTimeConstraintsStatement( $minTime, $maxTime ); |
539 | 568 | $time_constraint = $time_constraint_statement; |
540 | | - |
541 | | - if($normalize_top_results){ |
542 | | - $normalize = "(select distinct session_id, event_id from click_tracking $time_constraint_statement) as t1"; |
543 | | - $time_constraint = ""; |
| 569 | + |
| 570 | + if( $normalize_top_results ) { |
| 571 | + $normalize = "(SELECT DISTINCT session_id, event_id FROM click_tracking $time_constraint_statement) AS t1"; |
| 572 | + $time_constraint = ''; |
544 | 573 | } |
545 | | - $join = " "; |
546 | | - $sql = "select count(event_id) as totalevtid, event_id,event_name from $normalize" . |
| 574 | + |
| 575 | + $join = ' '; |
| 576 | + $sql = "SELECT COUNT(event_id) AS totalevtid, event_id,event_name FROM $normalize" . |
547 | 577 | " LEFT JOIN click_tracking_events ON event_id=click_tracking_events.id". |
548 | | - " $time_constraint group by event_id order by totalevtid desc"; |
549 | | - |
550 | | - //returns count(event_id),event_id, event_name, top one first |
| 578 | + " $time_constraint GROUP BY event_id ORDER BY totalevtid DESC"; |
| 579 | + |
| 580 | + // returns count(event_id),event_id, event_name, top one first |
551 | 581 | $dbr = wfGetDB( DB_SLAVE ); |
552 | | - $dbresult = $dbr->query($sql); |
553 | | - |
| 582 | + $dbresult = $dbr->query( $sql, __METHOD__ ); |
| 583 | + |
554 | 584 | return $dbresult; |
555 | 585 | } |
556 | 586 | |
— | — | @@ -557,31 +587,30 @@ |
558 | 588 | * Gets a table value for a given User ID |
559 | 589 | * NOTE: once some of the constraints have been finalized, this will use more of the Database functions and not raw SQL |
560 | 590 | */ |
561 | | - static function getTableValue($event_id, $userDef, $minTime = '', $maxTime = '', $normalize_results = false){ |
562 | | - |
563 | | - $normalize = "click_tracking"; |
564 | | - //escaped |
565 | | - $time_constraint_statement = self::getTimeConstraintsStatement($minTime,$maxTime); |
| 591 | + static function getTableValue( $event_id, $userDef, $minTime = '', $maxTime = '', $normalize_results = false ) { |
| 592 | + $normalize = 'click_tracking'; |
| 593 | + // escaped |
| 594 | + $time_constraint_statement = self::getTimeConstraintsStatement( $minTime, $maxTime ); |
566 | 595 | $time_constraint = $time_constraint_statement; |
567 | | - if($normalize_results){ |
568 | | - $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"; |
569 | | - $time_constraint = ""; |
| 596 | + if( $normalize_results ) { |
| 597 | + $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"; |
| 598 | + $time_constraint = ''; |
570 | 599 | } |
571 | | - |
572 | | - $user_conditions = SpecialClickTracking::buildUserDefQuery($userDef); |
573 | | - |
574 | | - $where = ($time_constraint == "" ? "where" : ""); |
575 | | - |
576 | | - $and = ($time_constraint == "" ? "": "and"); |
577 | | - |
578 | | - $sql ="select count(*) as totalcount from $normalize $where $time_constraint $and ($user_conditions) and event_id=$event_id"; |
579 | | - |
| 600 | + |
| 601 | + $user_conditions = SpecialClickTracking::buildUserDefQuery( $userDef ); |
| 602 | + |
| 603 | + $where = ( $time_constraint == '' ? 'WHERE' : '' ); |
| 604 | + |
| 605 | + $and = ( $time_constraint == '' ? '' : 'AND' ); |
| 606 | + |
| 607 | + $sql = "SELECT COUNT(*) AS totalcount FROM $normalize $where $time_constraint $and ($user_conditions) AND event_id=$event_id"; |
| 608 | + |
580 | 609 | $dbr = wfGetDB( DB_SLAVE ); |
581 | | - $result = $dbr->query($sql); |
| 610 | + $result = $dbr->query( $sql, __METHOD__ ); |
582 | 611 | $resRow = $result->fetchRow(); |
583 | | - return $resRow["totalcount"]; |
| 612 | + return $resRow['totalcount']; |
584 | 613 | } |
585 | | - |
| 614 | + |
586 | 615 | /** |
587 | 616 | * Generates a query for a user type definition |
588 | 617 | * @param $include_anon_users boolean, include anon users or not |
— | — | @@ -591,74 +620,90 @@ |
592 | 621 | * @param $contrib_3 array, nonempty AND conditions for user_contribs_1 |
593 | 622 | * @return unknown_type query |
594 | 623 | */ |
595 | | - public static function buildUserDefQuery($def){ |
596 | | - |
597 | | - $include_anon_users = (empty($def['anonymous'])?array():$def['anonymous']); |
598 | | - $total_contribs = (empty($def['total_contribs'])?array():$def['total_contribs']); |
599 | | - $contrib_1 = (empty($def['contrib_1'])?array():$def['contrib_1']); |
600 | | - $contrib_2 = (empty($def['contrib_2'])?array():$def['contrib_2']); |
601 | | - $contrib_3 = (empty($def['contrib_3'])?array():$def['contrib_3']); |
602 | | - |
| 624 | + public static function buildUserDefQuery( $def ) { |
| 625 | + $include_anon_users = ( empty( $def['anonymous'] ) ? array() : $def['anonymous'] ); |
| 626 | + $total_contribs = ( empty( $def['total_contribs'] ) ? array() : $def['total_contribs'] ); |
| 627 | + $contrib_1 = ( empty( $def['contrib_1'] ) ? array() : $def['contrib_1'] ); |
| 628 | + $contrib_2 = ( empty( $def['contrib_2'] ) ? array() : $def['contrib_2'] ); |
| 629 | + $contrib_3 = ( empty( $def['contrib_3'] ) ? array() : $def['contrib_3'] ); |
| 630 | + |
603 | 631 | $or_conds = array(); |
604 | 632 | $and_conds = array(); |
605 | | - $sql = ""; |
606 | | - |
607 | | - |
608 | | - if( (boolean)$include_anon_users ){ |
609 | | - $or_conds[] = array("field" => "is_logged_in", "operation" => "=", "value" =>"0"); |
| 633 | + $sql = ''; |
| 634 | + |
| 635 | + if( (boolean)$include_anon_users ) { |
| 636 | + $or_conds[] = array( 'field' => 'is_logged_in', 'operation' => '=', 'value' => '0' ); |
610 | 637 | } |
611 | | - |
612 | | - if(!empty($total_contribs)){ |
613 | | - foreach($total_contribs as $contribs){ |
614 | | - $and_conds[] = array("field" => "user_total_contribs", "operation" => SpecialClickTracking::validate_oper($contribs["operation"]), "value" => intval($contribs["value"])); |
| 638 | + |
| 639 | + if( !empty( $total_contribs ) ) { |
| 640 | + foreach( $total_contribs as $contribs ) { |
| 641 | + $and_conds[] = array( |
| 642 | + 'field' => 'user_total_contribs', |
| 643 | + 'operation' => SpecialClickTracking::validate_oper( $contribs['operation'] ), |
| 644 | + 'value' => intval( $contribs['value'] ) |
| 645 | + ); |
615 | 646 | } |
616 | 647 | } |
617 | | - |
618 | | - if(!empty($contrib_1)){ |
619 | | - foreach($contrib_1 as $contribs){ |
620 | | - $and_conds[] = array("field" => "user_contribs_span1", "operation" => SpecialClickTracking::validate_oper($contribs["operation"]), "value" => intval($contribs["value"])); |
| 648 | + |
| 649 | + if( !empty( $contrib_1 ) ) { |
| 650 | + foreach( $contrib_1 as $contribs ) { |
| 651 | + $and_conds[] = array( |
| 652 | + 'field' => 'user_contribs_span1', |
| 653 | + 'operation' => SpecialClickTracking::validate_oper( $contribs['operation'] ), |
| 654 | + 'value' => intval( $contribs['value'] ) |
| 655 | + ); |
621 | 656 | } |
622 | 657 | } |
623 | | - if(!empty($contrib_2)){ |
624 | | - foreach($contrib_2 as $contribs){ |
625 | | - $and_conds[] = array("field" => "user_contribs_span2", "operation" => SpecialClickTracking::validate_oper($contribs["operation"]), "value" => intval($contribs["value"])); |
| 658 | + |
| 659 | + if( !empty( $contrib_2 ) ) { |
| 660 | + foreach( $contrib_2 as $contribs ) { |
| 661 | + $and_conds[] = array( |
| 662 | + 'field' => 'user_contribs_span2', |
| 663 | + 'operation' => SpecialClickTracking::validate_oper( $contribs['operation'] ), |
| 664 | + 'value' => intval( $contribs['value'] ) |
| 665 | + ); |
626 | 666 | } |
627 | 667 | } |
628 | | - if(!empty($contrib_3)){ |
629 | | - foreach($contrib_3 as $contribs){ |
630 | | - $and_conds[] = array("field" => "user_contribs_span3", "operation" => SpecialClickTracking::validate_oper($contribs["operation"]), "value" => intval($contribs["value"])); |
| 668 | + |
| 669 | + if( !empty( $contrib_3 ) ) { |
| 670 | + foreach( $contrib_3 as $contribs ) { |
| 671 | + $and_conds[] = array( |
| 672 | + 'field' => 'user_contribs_span3', |
| 673 | + 'operation' => SpecialClickTracking::validate_oper( $contribs['operation'] ), |
| 674 | + 'value' => intval( $contribs['value'] ) |
| 675 | + ); |
631 | 676 | } |
632 | 677 | } |
633 | | - |
634 | | - foreach($and_conds as $cond){ |
635 | | - if(!empty($sql)){ |
636 | | - $sql .= " AND "; |
| 678 | + |
| 679 | + foreach( $and_conds as $cond ) { |
| 680 | + if( !empty( $sql ) ) { |
| 681 | + $sql .= ' AND '; |
637 | 682 | } |
638 | | - $sql .= $cond["field"] . " " . $cond["operation"] . " " . $cond["value"]; |
| 683 | + $sql .= $cond['field'] . ' ' . $cond['operation'] . ' ' . $cond['value']; |
639 | 684 | } |
640 | | - foreach($or_conds as $cond){ |
641 | | - if(!empty($sql)){ |
642 | | - $sql .= " OR "; |
| 685 | + |
| 686 | + foreach( $or_conds as $cond ) { |
| 687 | + if( !empty( $sql ) ) { |
| 688 | + $sql .= ' OR '; |
643 | 689 | } |
644 | | - $sql .= $cond["field"] . " " . $cond["operation"] . " " . $cond["value"]; |
| 690 | + $sql .= $cond['field'] . ' ' . $cond['operation'] . ' ' . $cond['value']; |
645 | 691 | } |
646 | | - |
| 692 | + |
647 | 693 | return $sql; |
648 | 694 | } |
649 | | - |
650 | | - public static function validate_oper($operation){ |
651 | | - $o_trim = trim($operation); |
652 | | - switch($o_trim){ //valid operations |
653 | | - case ">": |
654 | | - case "<": |
655 | | - case "<=": |
656 | | - case ">=": |
657 | | - case "=": |
| 695 | + |
| 696 | + public static function validate_oper( $operation ) { |
| 697 | + $o_trim = trim( $operation ); |
| 698 | + switch( $o_trim ) { // valid operations |
| 699 | + case '>': |
| 700 | + case '<': |
| 701 | + case '<=': |
| 702 | + case '>=': |
| 703 | + case '=': |
658 | 704 | return $o_trim; |
659 | 705 | default: |
660 | | - return "="; |
| 706 | + return '='; |
661 | 707 | } |
662 | 708 | } |
663 | | - |
664 | | - |
| 709 | + |
665 | 710 | } |
\ No newline at end of file |
Index: trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.hooks.php |
— | — | @@ -40,22 +40,21 @@ |
41 | 41 | $tables[] = 'click_tracking_events'; |
42 | 42 | return true; |
43 | 43 | } |
44 | | - |
45 | | - /* |
46 | | - * check to see if user is throttled |
| 44 | + |
| 45 | + /** |
| 46 | + * Check to see if user is throttled |
47 | 47 | */ |
48 | 48 | public static function isUserThrottled() { |
49 | 49 | global $wgClickTrackThrottle; |
50 | 50 | return !( $wgClickTrackThrottle >= 0 && rand() % $wgClickTrackThrottle == 0 ); |
51 | 51 | } |
52 | | - |
53 | | - |
| 52 | + |
54 | 53 | /** |
55 | 54 | * Adds JavaScript |
56 | 55 | */ |
57 | 56 | public static function addJS() { |
58 | 57 | global $wgOut; |
59 | | - |
| 58 | + |
60 | 59 | UsabilityInitiativeHooks::initialize(); |
61 | 60 | UsabilityInitiativeHooks::addScript( 'ClickTracking/ClickTracking.js' ); |
62 | 61 | UsabilityInitiativeHooks::addVariables( |
— | — | @@ -64,8 +63,8 @@ |
65 | 64 | 'wgClickTrackingIsThrottled' => ClickTrackingHooks::isUserThrottled() |
66 | 65 | ) |
67 | 66 | ); |
| 67 | + |
68 | 68 | return true; |
69 | | - |
70 | 69 | } |
71 | 70 | |
72 | 71 | /** |
— | — | @@ -108,14 +107,13 @@ |
109 | 108 | return $edits; |
110 | 109 | } |
111 | 110 | |
112 | | - |
113 | 111 | /** |
114 | 112 | * Get event ID from name |
115 | 113 | * @param $event_name String: name of the event to get |
116 | 114 | * @return integer |
117 | 115 | */ |
118 | 116 | public static function getEventIDFromName( $event_name ) { |
119 | | - $dbw = wfGetDB( DB_MASTER ); //replication lag means sometimes a new event will not exist in the table yet |
| 117 | + $dbw = wfGetDB( DB_MASTER ); // replication lag means sometimes a new event will not exist in the table yet |
120 | 118 | |
121 | 119 | $id_num = $dbw->selectField( |
122 | 120 | 'click_tracking_events', |
Index: trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.js |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | (function($) { |
3 | 3 | |
4 | | - if(!wgClickTrackingIsThrottled){ |
| 4 | + if( !wgClickTrackingIsThrottled ) { |
5 | 5 | // creates 'track action' function to call the clicktracking API and send the ID |
6 | 6 | $.trackAction = function ( id ) { |
7 | 7 | $j.post( wgScriptPath + '/api.php', { 'action': 'clicktracking', 'eventid': id, 'token': wgTrackingToken } ); |
Index: trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.js |
— | — | @@ -1,531 +1,509 @@ |
2 | 2 | (function($) { |
3 | 3 | /* Very limited JSON encoder */ |
4 | | - $.json_encode = function (js_obj){ |
| 4 | + $.json_encode = function( js_obj ) { |
5 | 5 | var returnstr = "{ "; |
6 | | - |
7 | | - //trailing commas and json don't mix |
| 6 | + |
| 7 | + // trailing commas and json don't mix |
8 | 8 | var propertynum = 0; |
9 | | - for(property in js_obj){ |
10 | | - if(propertynum > 0){ |
| 9 | + for( property in js_obj ) { |
| 10 | + if( propertynum > 0 ) { |
11 | 11 | returnstr +=", "; |
12 | 12 | } |
13 | 13 | returnstr += "\"" + property + "\"" + " : "; |
14 | | - if(typeof js_obj[property] == 'object'){ |
15 | | - returnstr += $.json_encode(js_obj[property]); |
16 | | - } |
17 | | - else{ |
| 14 | + if( typeof js_obj[property] == 'object' ) { |
| 15 | + returnstr += $.json_encode( js_obj[property] ); |
| 16 | + } else { |
18 | 17 | returnstr += "\"" + js_obj[property] + "\" "; |
19 | 18 | } |
20 | 19 | propertynum++; |
21 | 20 | } |
22 | | - |
23 | | - returnstr+= " }"; |
| 21 | + |
| 22 | + returnstr += " }"; |
24 | 23 | return returnstr; |
25 | 24 | }; |
26 | | - |
27 | | - |
28 | | - |
29 | | - $.getUserDefsFromDialog = function(){ |
| 25 | + |
| 26 | + $.getUserDefsFromDialog = function() { |
30 | 27 | var currUserDefs = new Array(); |
31 | | - if($("#anon_users_checkbox").is(":checked")){ |
32 | | - currUserDefs["anonymous"] = 1; |
| 28 | + if( $("#anon_users_checkbox").is( ":checked" ) ) { |
| 29 | + currUserDefs['anonymous'] = 1; |
| 30 | + } else { |
| 31 | + currUserDefs['anonymous'] = 0; |
33 | 32 | } |
34 | | - else{ |
35 | | - currUserDefs["anonymous"] = 0; |
36 | | - } |
37 | | - |
38 | | - var getCheckBoxData = function(contribName){ |
39 | | - if($("#"+ contribName +"_checkbox").is(":checked")){ |
| 33 | + |
| 34 | + var getCheckBoxData = function( contribName ) { |
| 35 | + if( $("#"+ contribName + "_checkbox").is( ":checked" ) ) { |
40 | 36 | currUserDefs[contribName] = new Array(); |
| 37 | + } else { |
| 38 | + return; |
41 | 39 | } |
42 | | - else{ return;} |
43 | | - var totalConds = $("#" + contribName +"_div").data("totalConditions"); |
| 40 | + var totalConds = $("#" + contribName + "_div").data("totalConditions"); |
44 | 41 | var i; |
45 | | - |
46 | | - for(i = 1; i <= totalConds; i++){ |
47 | | - if($("#"+contribName+"_"+i+"_checkbox").is(":checked")){ |
48 | | - $("#"+contribName+"_"+i+"_ltgt").children().each(function(){ |
49 | | - if($(this).is(":selected")){ |
| 42 | + |
| 43 | + for( i = 1; i <= totalConds; i++ ) { |
| 44 | + if( $("#" + contribName + "_" + i + "_checkbox").is( ":checked" ) ) { |
| 45 | + $("#" + contribName + "_" + i + "_ltgt").children().each(function() { |
| 46 | + if( $(this).is( ":selected" ) ) { |
50 | 47 | var currentCond = new Array(); |
51 | | - switch($(this).attr("value")){ |
52 | | - case 'lt': currentCond["operation"] = "<"; break; |
53 | | - case 'lteq': currentCond["operation"] = "<="; break; |
54 | | - case 'gt': currentCond["operation"] = ">"; break; |
55 | | - case 'gteq' : currentCond["operation"] = ">="; break; |
56 | | - default: currentCond["operation"] = "<"; break; |
| 48 | + switch( $(this).attr("value") ) { |
| 49 | + case 'lt': |
| 50 | + currentCond['operation'] = '<'; |
| 51 | + break; |
| 52 | + case 'lteq': |
| 53 | + currentCond['operation'] = '<='; |
| 54 | + break; |
| 55 | + case 'gt': |
| 56 | + currentCond['operation'] = '>'; |
| 57 | + break; |
| 58 | + case 'gteq': |
| 59 | + currentCond['operation'] = '>='; |
| 60 | + break; |
| 61 | + default: |
| 62 | + currentCond['operation'] = '<'; |
| 63 | + break; |
57 | 64 | } |
58 | | - currentCond["value"] = $("#"+contribName+"_"+i+"_text").val(); |
| 65 | + currentCond['value'] = $("#" + contribName + "_" + i + "_text").val(); |
59 | 66 | currUserDefs[contribName].push(currentCond); |
60 | 67 | } |
61 | 68 | }); |
62 | | - } //ifchecked |
63 | | - }//forloop |
| 69 | + } // ifchecked |
| 70 | + } // forloop |
64 | 71 | }; |
65 | | - |
66 | | - |
| 72 | + |
67 | 73 | getCheckBoxData("total_contribs"); |
68 | 74 | getCheckBoxData("contribs_span_1"); |
69 | 75 | getCheckBoxData("contribs_span_2"); |
70 | 76 | getCheckBoxData("contribs_span_3"); |
71 | 77 | wgClickTrackUserDefs[$("#user_def_alter_legend").data("currentlyEditing")] = currUserDefs; |
72 | 78 | }; |
73 | | - |
74 | | - $.renderUserDefDialogWith = function (userDef, defName){ |
75 | | - //change name |
| 79 | + |
| 80 | + $.renderUserDefDialogWith = function( userDef, defName ) { |
| 81 | + // change name |
76 | 82 | $("#user_def_alter_legend").text($("#user_def_alter_legend").data("defaultChangeText") + " " + defName); |
77 | 83 | $("#user_def_alter_legend").data("currentlyEditing", defName); |
78 | | - |
79 | | - |
80 | | - var setContribs = function(conditionArray, contribName){ |
81 | | - |
82 | | - initialDiv = $("<div></div>").attr("id", contribName +"_div"); |
83 | | - initialDiv.addClass("checkbox_div"); |
84 | | - initialDiv.addClass("control_div"); |
85 | | - |
86 | | - textDiv = $("<div></div>").attr("id", contribName +"_text_div"); |
87 | | - mainCheckbox = $("<input>").attr("id", contribName +"_checkbox"); |
88 | | - mainCheckbox.attr("type", "checkbox"); |
89 | | - mainCheckbox.addClass("user_def_checkbox"); |
90 | | - |
91 | | - if(conditionArray.length > 0){ |
92 | | - mainCheckbox.attr("checked", true); |
| 84 | + |
| 85 | + var setContribs = function( conditionArray, contribName ) { |
| 86 | + initialDiv = $("<div></div>").attr('id', contribName + '_div'); |
| 87 | + initialDiv.addClass('checkbox_div'); |
| 88 | + initialDiv.addClass('control_div'); |
| 89 | + |
| 90 | + textDiv = $("<div></div>").attr('id', contribName + '_text_div'); |
| 91 | + mainCheckbox = $("<input>").attr('id', contribName + '_checkbox'); |
| 92 | + mainCheckbox.attr('type', 'checkbox'); |
| 93 | + mainCheckbox.addClass('user_def_checkbox'); |
| 94 | + |
| 95 | + if( conditionArray.length > 0 ) { |
| 96 | + mainCheckbox.attr( 'checked', true ); |
93 | 97 | } |
94 | | - |
95 | | - textDiv.append(mainCheckbox); |
96 | | - textDiv.text(contribName); //i18n txt here |
97 | | - textDiv.css('display', 'inline'); |
98 | | - initialDiv.append(mainCheckbox); |
99 | | - initialDiv.append(textDiv); |
100 | | - |
101 | | - |
102 | | - |
103 | | - var buildConditionDiv = function (condition, counter, isChecked){ |
104 | | - conditionDiv = $("<div></div>").attr("id", contribName + "_range_" + counter + "_div"); |
105 | | - conditionDiv.addClass("checkbox_div"); |
106 | | - conditionDiv.addClass("sub_option_div"); |
107 | 98 | |
| 99 | + textDiv.append( mainCheckbox ); |
| 100 | + textDiv.text( contribName ); // i18n txt here |
| 101 | + textDiv.css( 'display', 'inline' ); |
| 102 | + initialDiv.append( mainCheckbox ); |
| 103 | + initialDiv.append( textDiv ); |
| 104 | + |
| 105 | + var buildConditionDiv = function( condition, counter, isChecked ) { |
| 106 | + conditionDiv = $("<div></div>").attr('id', contribName + '_range_' + counter + '_div'); |
| 107 | + conditionDiv.addClass( 'checkbox_div' ); |
| 108 | + conditionDiv.addClass( 'sub_option_div' ); |
| 109 | + |
108 | 110 | //initialDiv.append(conditionDiv); |
109 | | - cCheckbox = $("<input></input>").attr("id", contribName+"_"+counter+"_checkbox"); |
110 | | - cCheckbox.attr("type", "checkbox"); |
111 | | - if(isChecked){ |
112 | | - cCheckbox.attr("checked", true); |
| 111 | + cCheckbox = $("<input></input>").attr('id', contribName + '_' + counter + '_checkbox'); |
| 112 | + cCheckbox.attr('type', 'checkbox'); |
| 113 | + if( isChecked ) { |
| 114 | + cCheckbox.attr( 'checked', true ); |
113 | 115 | } |
114 | | - cCheckbox.addClass("number_select_checkbox"); |
115 | | - conditionDiv.append(cCheckbox); |
116 | | - |
117 | | - cSelect = $("<select></select>").attr("id", contribName+"_"+counter+"_ltgt"); |
118 | | - cSelect.addClass("number_select_ltgt"); |
119 | | - |
120 | | - cOpt1 = $("<option></option>").attr("id", contribName+"_"+counter+"_lt"); |
121 | | - cOpt1.addClass("number_select_ltgt_opt"); |
122 | | - cOpt1.attr("value", "lt"); |
123 | | - cOpt1.text("<"); |
124 | | - if(condition["operation"] == "<"){ |
125 | | - cOpt1.attr("selected", true); |
| 116 | + cCheckbox.addClass( 'number_select_checkbox' ); |
| 117 | + conditionDiv.append( cCheckbox ); |
| 118 | + |
| 119 | + cSelect = $("<select></select>").attr('id', contribName + '_' + counter + '_ltgt'); |
| 120 | + cSelect.addClass( 'number_select_ltgt' ); |
| 121 | + |
| 122 | + cOpt1 = $("<option></option>").attr('id', contribName + '_' + counter + '_lt'); |
| 123 | + cOpt1.addClass( 'number_select_ltgt_opt' ); |
| 124 | + cOpt1.attr( 'value', 'lt' ); |
| 125 | + cOpt1.text( '<' ); |
| 126 | + if( condition['operation'] == '<' ) { |
| 127 | + cOpt1.attr( 'selected', true ); |
126 | 128 | } |
127 | | - |
128 | | - |
129 | | - cOpt2 = $("<option></option>").attr("id", contribName+"_"+counter+"_gt"); |
130 | | - cOpt2.addClass("number_select_ltgt_opt"); |
131 | | - cOpt2.attr("value", "gt"); |
132 | | - cOpt2.text(">"); |
133 | | - if(condition["operation"] == ">"){ |
134 | | - cOpt2.attr("selected", true); |
| 129 | + |
| 130 | + cOpt2 = $("<option></option>").attr('id', contribName + '_' + counter + '_gt'); |
| 131 | + cOpt2.addClass( 'number_select_ltgt_opt' ); |
| 132 | + cOpt2.attr( 'value', 'gt' ); |
| 133 | + cOpt2.text( '>' ); |
| 134 | + if( condition['operation'] == '>' ) { |
| 135 | + cOpt2.attr( 'selected', true ); |
135 | 136 | } |
136 | | - |
137 | | - cOpt3 = $("<option></option>").attr("id", contribName+"_"+counter+"_lteq"); |
138 | | - cOpt3.addClass("number_select_ltgt_opt"); |
139 | | - cOpt3.attr("value", "lteq"); |
140 | | - cOpt3.text("<="); |
141 | | - if(condition["operation"] == "<="){ |
142 | | - cOpt3.attr("selected", true); |
| 137 | + |
| 138 | + cOpt3 = $("<option></option>").attr('id', contribName + '_' + counter + '_lteq'); |
| 139 | + cOpt3.addClass( 'number_select_ltgt_opt' ); |
| 140 | + cOpt3.attr( 'value', 'lteq' ); |
| 141 | + cOpt3.text( '<=' ); |
| 142 | + if( condition['operation'] == '<=' ) { |
| 143 | + cOpt3.attr( 'selected', true ); |
143 | 144 | } |
144 | | - |
145 | | - cOpt4 = $("<option></option>").attr("id", contribName+"_"+counter+"_gteq"); |
146 | | - cOpt4.addClass("number_select_ltgt_opt"); |
147 | | - cOpt4.attr("value", "gteq"); |
148 | | - cOpt4.text(">="); |
149 | | - if(condition["operation"] == ">="){ |
150 | | - cOpt4.attr("selected", true); |
| 145 | + |
| 146 | + cOpt4 = $("<option></option>").attr('id', contribName + '_' + counter + '_gteq'); |
| 147 | + cOpt4.addClass( 'number_select_ltgt_opt' ); |
| 148 | + cOpt4.attr( 'value', 'gteq' ); |
| 149 | + cOpt4.text( '>=' ); |
| 150 | + if( condition['operation'] == '>=' ) { |
| 151 | + cOpt4.attr( 'selected', true ); |
151 | 152 | } |
152 | | - |
153 | | - cSelect.append(cOpt1); |
154 | | - cSelect.append(cOpt2); |
155 | | - cSelect.append(cOpt3); |
156 | | - cSelect.append(cOpt4); |
157 | | - conditionDiv.append(cSelect); |
158 | | - |
159 | | - cTextInput = $("<input></input>").attr("id", contribName+"_"+counter+"_text"); |
160 | | - cTextInput.addClass("number_select_text"); |
161 | | - cTextInput.attr('value', condition["value"]); |
162 | | - conditionDiv.append(cTextInput); |
| 153 | + |
| 154 | + cSelect.append( cOpt1 ); |
| 155 | + cSelect.append( cOpt2 ); |
| 156 | + cSelect.append( cOpt3 ); |
| 157 | + cSelect.append( cOpt4 ); |
| 158 | + conditionDiv.append( cSelect ); |
| 159 | + |
| 160 | + cTextInput = $("<input></input>").attr('id', contribName + '_' + counter + '_text'); |
| 161 | + cTextInput.addClass( 'number_select_text' ); |
| 162 | + cTextInput.attr( 'value', condition['value'] ); |
| 163 | + conditionDiv.append( cTextInput ); |
163 | 164 | return conditionDiv; |
164 | 165 | }; |
165 | | - |
166 | | - |
167 | | - var i=0; |
168 | | - for( var condition in conditionArray){ |
| 166 | + |
| 167 | + var i = 0; |
| 168 | + for( var condition in conditionArray ) { |
169 | 169 | i++; |
170 | | - var conditionDiv = buildConditionDiv(conditionArray[condition], i, true); |
171 | | - initialDiv.append(conditionDiv); |
172 | | - } //forloop |
173 | | - initialDiv.data("totalConditions", i); |
174 | | - addConditions = $("<div></div>").attr("id", contribName+"_addbutton"); |
175 | | - addConditions.data("contribName", contribName); |
176 | | - addConditions.addClass("add_condition_button"); |
177 | | - addConditions.text("+"); |
178 | | - initialDiv.append(addConditions); |
179 | | - addConditions.click( function(){ |
180 | | - var initDiv = $("#" + $(this).data('contribName') +"_div"); |
181 | | - var totalConds = initDiv.data('totalConditions'); |
| 170 | + var conditionDiv = buildConditionDiv( conditionArray[condition], i, true ); |
| 171 | + initialDiv.append( conditionDiv ); |
| 172 | + } // forloop |
| 173 | + initialDiv.data( 'totalConditions', i ); |
| 174 | + addConditions = $("<div></div>").attr('id', contribName + '_addbutton'); |
| 175 | + addConditions.data( 'contribName', contribName ); |
| 176 | + addConditions.addClass( 'add_condition_button' ); |
| 177 | + addConditions.text( '+' ); |
| 178 | + initialDiv.append( addConditions ); |
| 179 | + addConditions.click( function() { |
| 180 | + var initDiv = $("#" + $(this).data('contribName') + '_div'); |
| 181 | + var totalConds = initDiv.data( 'totalConditions' ); |
182 | 182 | totalConds++; |
183 | | - initDiv.data('totalConditions', totalConds); |
| 183 | + initDiv.data( 'totalConditions', totalConds ); |
184 | 184 | var tmpCond = new Array(); |
185 | | - tmpCond["operation"] = " "; |
186 | | - tmpCond["value"] = " "; |
| 185 | + tmpCond['operation'] = ' '; |
| 186 | + tmpCond['value'] = ' '; |
187 | 187 | |
188 | 188 | buildConditionDiv(tmpCond, totalConds).insertBefore($(this)); |
189 | | - initDiv.data("totalConditions", totalConds, false); |
190 | | - |
191 | | - |
| 189 | + initDiv.data( 'totalConditions', totalConds, false ); |
192 | 190 | }); |
193 | | - |
| 191 | + |
194 | 192 | return initialDiv; |
195 | | - }; //setcontribs |
196 | | - |
197 | | - |
198 | | - //check anonymous |
| 193 | + }; // setcontribs |
| 194 | + |
| 195 | + // check anonymous |
199 | 196 | var anon = false; |
200 | | - if(parseInt(userDef["anonymous"]) == 1){ |
| 197 | + if( parseInt( userDef['anonymous'] ) == 1 ) { |
201 | 198 | anon = true; |
202 | 199 | } |
203 | 200 | $("#anon_users_checkbox").attr('checked', anon); |
204 | | - |
205 | | - //clear out old contents |
| 201 | + |
| 202 | + // clear out old contents |
206 | 203 | $("#contrib_opts_container").empty(); |
207 | | - |
208 | | - var setup_set_contribs = function(contribName){ |
| 204 | + |
| 205 | + var setup_set_contribs = function( contribName ) { |
209 | 206 | var current_contribs = userDef[contribName]; |
210 | | - if(current_contribs == undefined){ |
| 207 | + if( current_contribs == undefined ) { |
211 | 208 | current_contribs = new Array(); |
212 | 209 | } |
213 | | - $("#contrib_opts_container").append(setContribs(current_contribs, contribName)); |
| 210 | + $("#contrib_opts_container").append( setContribs( current_contribs, contribName ) ); |
214 | 211 | }; |
215 | | - |
216 | | - |
217 | | - //total contribs |
218 | | - setup_set_contribs("total_contribs"); |
219 | | - setup_set_contribs("contribs_span_1"); |
220 | | - setup_set_contribs("contribs_span_2"); |
221 | | - setup_set_contribs("contribs_span_3"); |
222 | | - |
223 | | - //OK button |
224 | | - var okButton = $("<input>").attr("id", "ok_button"); |
225 | | - okButton.attr("type", "button"); |
226 | | - okButton.attr("value", "ok"); |
227 | | - okButton.click(function(){ |
| 212 | + |
| 213 | + // total contribs |
| 214 | + setup_set_contribs( 'total_contribs' ); |
| 215 | + setup_set_contribs( 'contribs_span_1' ); |
| 216 | + setup_set_contribs( 'contribs_span_2' ); |
| 217 | + setup_set_contribs( 'contribs_span_3' ); |
| 218 | + |
| 219 | + // OK button |
| 220 | + var okButton = $("<input>").attr('id', 'ok_button'); |
| 221 | + okButton.attr( 'type', 'button' ); |
| 222 | + okButton.attr( 'value', 'ok' ); |
| 223 | + okButton.click(function() { |
228 | 224 | $.getUserDefsFromDialog(); |
229 | 225 | $("#user_def_dialog").dialog('close'); |
230 | | - |
231 | 226 | }); |
232 | 227 | $("#contrib_opts_container").append(okButton); |
233 | | - |
234 | | - }; //renderUserDefDialogWith |
235 | | - |
236 | | - |
| 228 | + }; // renderUserDefDialogWith |
237 | 229 | |
238 | | - |
239 | | - //functions |
240 | | - $.updateChart = function(){ |
241 | | - |
242 | | - event_name = $("#chart_img").data("event_name"); |
243 | | - |
244 | | - var processChartJSON = function(data, status){ |
245 | | - |
246 | | - var getMax = function(findMax){ |
| 230 | + // functions |
| 231 | + $.updateChart = function() { |
| 232 | + event_name = $("#chart_img").data('event_name'); |
| 233 | + |
| 234 | + var processChartJSON = function( data, status ) { |
| 235 | + |
| 236 | + var getMax = function( findMax ) { |
247 | 237 | var retval = Number.MIN_VALUE; |
248 | | - for(var i in findMax){ |
249 | | - if(findMax[i] > retval) { |
| 238 | + for( var i in findMax ) { |
| 239 | + if( findMax[i] > retval ) { |
250 | 240 | retval = findMax[i]; |
251 | 241 | } |
252 | 242 | } |
253 | 243 | return retval; |
254 | 244 | }; |
255 | | - |
256 | | - max1 = getMax(data['datapoints']['expert']); |
257 | | - max2 = getMax(data['datapoints']['intermediate']); |
258 | | - max3 = getMax(data['datapoints']['basic']); |
259 | | - max = Math.max(max3, Math.max(max1,max2)); |
| 245 | + |
| 246 | + max1 = getMax( data['datapoints']['expert'] ); |
| 247 | + max2 = getMax( data['datapoints']['intermediate'] ); |
| 248 | + max3 = getMax( data['datapoints']['basic'] ); |
| 249 | + max = Math.max( max3, Math.max( max1, max2 ) ); |
260 | 250 | chartURL = 'http://chart.apis.google.com/chart?' + |
261 | 251 | 'chs=400x400&' + |
262 | 252 | 'cht=lc&' + |
263 | 253 | 'chco=FF0000,0000FF,00FF00&' + |
264 | 254 | 'chtt=' + event_name + ' from ' + $("#start_date").val() +' to ' +$("#end_date").val() + "&" + |
265 | | - 'chdl=' + 'Expert|Intermediate|Beginner' + "&"+ |
| 255 | + 'chdl=' + 'Expert|Intermediate|Beginner' + "&" + |
266 | 256 | 'chxt=x,y&' + |
267 | | - 'chd=t:' + data['datapoints']['expert'].join(',') + "|" + |
| 257 | + 'chd=t:' + data['datapoints']['expert'].join(',') + "|" + |
268 | 258 | data['datapoints']['intermediate'].join(',') + "|" + data['datapoints']['basic'].join(',') + "&" + |
269 | 259 | 'chds=0,'+ max +',0,'+ max +',0,'+ max |
270 | 260 | ; |
271 | | - $("#chart_img").attr( "src",chartURL); |
| 261 | + $("#chart_img").attr( 'src', chartURL ); |
272 | 262 | }; |
273 | | - |
274 | | - |
| 263 | + |
275 | 264 | start_date = $("#start_date").val(); |
276 | | - if($("#start_date").hasClass("hidden")){ |
| 265 | + if( $("#start_date").hasClass( 'hidden' ) ) { |
277 | 266 | start_date = '0'; |
278 | 267 | } |
279 | | - |
| 268 | + |
280 | 269 | end_date = $("#end_date").val(); |
281 | | - if($("#end_date").hasClass("hidden")){ |
| 270 | + if( $("#end_date").hasClass( 'hidden' ) ) { |
282 | 271 | end_date = '0'; |
283 | 272 | } |
284 | | - |
285 | | - //post relevant info |
286 | | - $j.post( wgScriptPath + '/api.php', |
287 | | - { 'action': 'specialclicktracking', 'format': 'json', |
288 | | - 'eventid': $("#chart_img").data( "eventid" ), 'increment': $("#chart_increment").val(), |
289 | | - 'startdate': start_date, 'enddate':end_date, 'userdefs': $.json_encode(wgClickTrackUserDefs) } , processChartJSON, "json"); |
| 273 | + |
| 274 | + // post relevant info |
| 275 | + $j.post( wgScriptPath + '/api.php', |
| 276 | + { 'action': 'specialclicktracking', 'format': 'json', |
| 277 | + 'eventid': $("#chart_img").data( 'eventid' ), 'increment': $("#chart_increment").val(), |
| 278 | + 'startdate': start_date, 'enddate': end_date, 'userdefs': $.json_encode( wgClickTrackUserDefs ) }, |
| 279 | + processChartJSON, 'json' |
| 280 | + ); |
290 | 281 | }; |
291 | | - |
292 | | - |
293 | | - //pretty colors for the table |
294 | | - $.colorizeTable = function (){ |
295 | | - //expert |
296 | | - |
297 | | - |
298 | | - //get totals |
| 282 | + |
| 283 | + // pretty colors for the table |
| 284 | + $.colorizeTable = function() { |
| 285 | + // expert |
| 286 | + |
| 287 | + // get totals |
299 | 288 | var expert_total = 0; |
300 | | - |
301 | | - $(".expert_data").each(function(){ |
302 | | - expert_total += parseInt($(this).attr( "value")); |
| 289 | + |
| 290 | + $(".expert_data").each(function() { |
| 291 | + expert_total += parseInt( $(this).attr( 'value' ) ); |
303 | 292 | }); |
304 | | - |
305 | | - //set proper red shade |
306 | | - $(".expert_data").each(function(){ |
| 293 | + |
| 294 | + // set proper red shade |
| 295 | + $(".expert_data").each(function() { |
307 | 296 | var rval = 255; |
308 | | - var gval = (expert_total == 0 ? 255 : 255 - (255 * $(this).attr("value") / expert_total)); |
| 297 | + var gval = ( expert_total == 0 ? 255 : 255 - ( 255 * $(this).attr( 'value' ) / expert_total ) ); |
309 | 298 | var bval = gval; |
310 | | - rgbString = "rgb(" + parseInt(rval) + "," + parseInt(gval) + "," + parseInt(bval) + ")"; |
311 | | - $(this).data("rgb", rgbString); |
312 | | - $(this).css("color", rgbString); |
313 | | - $(this).css("background-color", rgbString); |
| 299 | + rgbString = "rgb(" + parseInt( rval ) + "," + parseInt( gval ) + "," + parseInt( bval ) + ")"; |
| 300 | + $(this).data('rgb', rgbString); |
| 301 | + $(this).css('color', rgbString); |
| 302 | + $(this).css('background-color', rgbString); |
314 | 303 | }); |
315 | | - |
316 | 304 | |
317 | | - //intermediate |
318 | | - |
319 | | - //total |
| 305 | + // intermediate |
| 306 | + |
| 307 | + // total |
320 | 308 | var intermediate_total = 0; |
321 | | - $(".intermediate_data").each(function(){ |
322 | | - intermediate_total += parseInt($(this).attr( "value")); |
| 309 | + $(".intermediate_data").each(function() { |
| 310 | + intermediate_total += parseInt( $(this).attr( 'value' ) ); |
323 | 311 | }); |
324 | | - |
325 | | - |
326 | | - //blue shade |
327 | | - $(".intermediate_data").each(function(){ |
328 | | - var rval = (intermediate_total == 0 ? 255 : 255 - (255 * $(this).attr("value") / intermediate_total)); |
| 312 | + |
| 313 | + // blue shade |
| 314 | + $(".intermediate_data").each(function() { |
| 315 | + var rval = ( intermediate_total == 0 ? 255 : 255 - ( 255 * $(this).attr( 'value' ) / intermediate_total ) ); |
329 | 316 | var gval = rval; |
330 | 317 | var bval = 255; |
331 | | - rgbString = "rgb(" + parseInt(rval) + "," + parseInt(gval) + "," + parseInt(bval) + ")"; |
332 | | - $(this).data("rgb", rgbString); |
333 | | - $(this).css("color", rgbString); |
334 | | - $(this).css("background-color", rgbString); |
| 318 | + rgbString = "rgb(" + parseInt( rval ) + "," + parseInt( gval ) + "," + parseInt( bval ) + ")"; |
| 319 | + $(this).data('rgb', rgbString); |
| 320 | + $(this).css('color', rgbString); |
| 321 | + $(this).css('background-color', rgbString); |
335 | 322 | }); |
336 | | - |
337 | | - //total |
| 323 | + |
| 324 | + // total |
338 | 325 | var basic_total = 0; |
339 | | - $(".basic_data").each(function(){ |
340 | | - basic_total += parseInt($(this).attr( "value")); |
| 326 | + $(".basic_data").each(function() { |
| 327 | + basic_total += parseInt( $(this).attr( 'value' ) ); |
341 | 328 | }); |
342 | | - |
343 | | - //green shade |
344 | | - $(".basic_data").each(function(){ |
345 | | - var rval = (basic_total == 0 ? 255 : 255 - (255 * $(this).attr("value") / basic_total)); |
| 329 | + |
| 330 | + // green shade |
| 331 | + $(".basic_data").each(function() { |
| 332 | + var rval = ( basic_total == 0 ? 255 : 255 - ( 255 * $(this).attr( 'value' ) / basic_total ) ); |
346 | 333 | var gval = 255; |
347 | 334 | var bval = rval; |
348 | | - rgbString = "rgb(" + parseInt(rval) + "," + parseInt(gval) + "," + parseInt(bval) + ")"; |
349 | | - $(this).data("rgb", rgbString); |
350 | | - $(this).css("color", rgbString); |
351 | | - $(this).css("background-color", rgbString); |
| 335 | + rgbString = "rgb(" + parseInt( rval ) + "," + parseInt( gval ) + "," + parseInt( bval ) + ")"; |
| 336 | + $(this).data('rgb', rgbString); |
| 337 | + $(this).css('color', rgbString); |
| 338 | + $(this).css('background-color', rgbString); |
352 | 339 | }); |
353 | | - |
| 340 | + |
354 | 341 | // I wanted to do this with classes, but the element's style rule wins over class rule |
355 | 342 | // and each element has its own alternative color |
356 | | - $(".event_data").mouseover(function(){ |
357 | | - $(this).css("color", "#000000"); |
358 | | - $(this).css("background-color", "#FFFFFF"); |
| 343 | + $(".event_data").mouseover(function() { |
| 344 | + $(this).css('color', '#000000'); |
| 345 | + $(this).css('background-color', '#FFFFFF'); |
359 | 346 | }); |
360 | | - |
361 | | - $(".event_data").mouseout(function(){ |
| 347 | + |
| 348 | + $(".event_data").mouseout(function() { |
362 | 349 | rgbString = $(this).data("rgb"); |
363 | | - $(this).css("color", rgbString); |
364 | | - $(this).css("background-color", rgbString); |
| 350 | + $(this).css('color', rgbString); |
| 351 | + $(this).css('background-color', rgbString); |
365 | 352 | }); |
366 | | - |
367 | | - };//colorize |
368 | | - |
369 | | - $.updateTable = function(){ |
370 | | - |
371 | | - var processTableJSON = function(data, status){ |
372 | | - |
373 | | - //clear |
374 | | - $(".table_data_row").each(function(){ $(this).remove();}); |
375 | | - |
| 353 | + |
| 354 | + }; // colorize |
| 355 | + |
| 356 | + $.updateTable = function() { |
| 357 | + var processTableJSON = function( data, status ) { |
| 358 | + // clear |
| 359 | + $(".table_data_row").each( function() { $(this).remove(); } ); |
| 360 | + |
376 | 361 | var row_count = 0; |
377 | | - for( var row_iter in data['tablevals']['vals']){ |
378 | | - var row = data['tablevals']['vals'][row_iter]; //really, JS? |
| 362 | + for( var row_iter in data['tablevals']['vals'] ) { |
| 363 | + var row = data['tablevals']['vals'][row_iter]; // really, JS? |
379 | 364 | row_count++; |
380 | | - |
| 365 | + |
381 | 366 | var outputRow = $("<tr></tr>"); |
382 | | - outputRow.addClass("table_data_row"); |
383 | | - |
384 | | - var cell =$("<td></td>").attr("id", "event_name_" + row_count); |
385 | | - cell.addClass("event_name"); |
386 | | - cell.attr("value", row['event_id']); |
387 | | - cell.text(row['event_name']); |
388 | | - outputRow.append(cell); |
389 | | - |
390 | | - var createClassCell = function(userclass){ |
391 | | - var newcell = $("<td></td>").attr("id", "event_"+userclass+"_" + row_count); |
392 | | - newcell.addClass("event_data"); |
393 | | - newcell.addClass(userclass+"_data"); |
394 | | - newcell.text(row[userclass]); |
395 | | - newcell.attr("value", row[userclass]); |
396 | | - outputRow.append(newcell); |
397 | | - |
| 367 | + outputRow.addClass( 'table_data_row' ); |
| 368 | + |
| 369 | + var cell =$("<td></td>").attr('id', 'event_name_' + row_count); |
| 370 | + cell.addClass( 'event_name' ); |
| 371 | + cell.attr( 'value', row['event_id'] ); |
| 372 | + cell.text( row['event_name']); |
| 373 | + outputRow.append( cell ); |
| 374 | + |
| 375 | + var createClassCell = function( userclass ) { |
| 376 | + var newcell = $("<td></td>").attr('id', 'event_' + userclass + '_' + row_count); |
| 377 | + newcell.addClass( 'event_data' ); |
| 378 | + newcell.addClass( userclass + '_data' ); |
| 379 | + newcell.text( row[userclass] ); |
| 380 | + newcell.attr( 'value', row[userclass] ); |
| 381 | + outputRow.append( newcell ); |
398 | 382 | }; |
399 | | - |
400 | | - createClassCell("expert"); |
401 | | - createClassCell("intermediate"); |
402 | | - createClassCell("basic"); |
403 | | - createClassCell("total"); |
404 | | - $("#clicktrack_data_table").append(outputRow); |
| 383 | + |
| 384 | + createClassCell( 'expert' ); |
| 385 | + createClassCell( 'intermediate' ); |
| 386 | + createClassCell( 'basic' ); |
| 387 | + createClassCell( 'total' ); |
| 388 | + $("#clicktrack_data_table").append( outputRow ); |
405 | 389 | } |
406 | | - |
| 390 | + |
407 | 391 | $.colorizeTable(); |
408 | 392 | }; |
409 | | - |
410 | | - |
| 393 | + |
411 | 394 | start_date = $("#start_date").val(); |
412 | | - if($("#start_date").hasClass("hidden")){ |
| 395 | + if( $("#start_date").hasClass( 'hidden' ) ) { |
413 | 396 | start_date = '0'; |
414 | 397 | } |
415 | | - |
| 398 | + |
416 | 399 | end_date = $("#end_date").val(); |
417 | | - if($("#end_date").hasClass("hidden")){ |
| 400 | + if( $("#end_date").hasClass( 'hidden' ) ) { |
418 | 401 | end_date = '0'; |
419 | 402 | } |
420 | | - |
421 | | - //post relevant info |
422 | | - $j.post( wgScriptPath + '/api.php', |
423 | | - { 'action': 'specialclicktracking', 'format': 'json', |
424 | | - 'eventid': 1, 'increment': $("#chart_increment").val(), |
425 | | - 'startdate': start_date, 'enddate':end_date, 'userdefs': $.json_encode(wgClickTrackUserDefs), 'tabledata': 1 } , processTableJSON, "json"); |
426 | | - |
427 | | - };//updateTable |
428 | | - |
429 | | - $.setUIControls = function(){ |
430 | | - |
431 | | - //SET UP DATE RANGES |
432 | | - |
433 | | - |
434 | | - //date-pickers for start and end dates |
435 | | - $('.date_range_input').each(function(){ |
| 403 | + |
| 404 | + // post relevant info |
| 405 | + $j.post( wgScriptPath + '/api.php', |
| 406 | + { 'action': 'specialclicktracking', 'format': 'json', |
| 407 | + 'eventid': 1, 'increment': $("#chart_increment").val(), |
| 408 | + 'startdate': start_date, 'enddate': end_date, 'userdefs': $.json_encode( wgClickTrackUserDefs ), 'tabledata': 1 }, |
| 409 | + processTableJSON, 'json' |
| 410 | + ); |
| 411 | + |
| 412 | + }; // updateTable |
| 413 | + |
| 414 | + $.setUIControls = function() { |
| 415 | + // SET UP DATE RANGES |
| 416 | + |
| 417 | + // date-pickers for start and end dates |
| 418 | + $('.date_range_input').each(function() { |
436 | 419 | $(this).datepicker(); |
437 | | - $(this).datepicker('option', 'dateFormat', 'yymmdd'); |
| 420 | + $(this).datepicker( 'option', 'dateFormat', 'yymmdd' ); |
438 | 421 | }); |
439 | 422 | var startDate = new Date(); |
440 | | - $('#start_date').val("20091009"); //click_tracking start date as default |
441 | | - |
442 | | - var toggleDateInput = function(tableRow){ |
443 | | - var checked= false; |
444 | | - tableRow.children().each(function(){ |
445 | | - if(checked == false){ |
446 | | - checked = $(this).children("input:checkbox").eq(0).is(":checked");} |
| 423 | + $('#start_date').val("20091009"); // click_tracking start date as default |
| 424 | + |
| 425 | + var toggleDateInput = function( tableRow ) { |
| 426 | + var checked = false; |
| 427 | + tableRow.children().each( function() { |
| 428 | + if( checked == false ) { |
| 429 | + checked = $(this).children("input:checkbox").eq(0).is(":checked"); |
| 430 | + } |
447 | 431 | }); |
448 | | - |
449 | | - if(checked){ |
450 | | - tableRow.removeClass("disabled_option"); |
451 | | - tableRow.children("td").each(function(){ |
452 | | - $(this).children(".date_range_input").removeClass("hidden"); |
| 432 | + |
| 433 | + if( checked ) { |
| 434 | + tableRow.removeClass( 'disabled_option' ); |
| 435 | + tableRow.children("td").each(function() { |
| 436 | + $(this).children(".date_range_input").removeClass( 'hidden' ); |
453 | 437 | }); |
454 | | - } |
455 | | - else{ |
456 | | - tableRow.children("td").each(function(){ |
457 | | - $(this).children(".date_range_input").addClass("hidden"); |
| 438 | + } else { |
| 439 | + tableRow.children("td").each(function() { |
| 440 | + $(this).children(".date_range_input").addClass( 'hidden' ); |
458 | 441 | }); |
459 | | - tableRow.addClass("disabled_option"); |
| 442 | + tableRow.addClass( 'disabled_option' ); |
460 | 443 | } |
461 | 444 | }; |
462 | | - |
463 | | - $('.date_range_checkbox').click(function(){ |
464 | | - toggleDateInput($(this).closest("tr")); |
| 445 | + |
| 446 | + $('.date_range_checkbox').click(function() { |
| 447 | + toggleDateInput( $(this).closest( 'tr' ) ); |
465 | 448 | }); |
466 | | - |
467 | | - //update table |
| 449 | + |
| 450 | + // update table |
468 | 451 | $('#update_table_button').click($.updateTable); |
469 | | - |
470 | | - //CHART DIALOG |
| 452 | + |
| 453 | + // CHART DIALOG |
471 | 454 | $("#chart_dialog").dialog({ autoOpen: false, width: 400 }); |
472 | | - $("#chart_img").css("cursor","pointer"); |
473 | | - $("#chart_img").click(function(){ |
| 455 | + $("#chart_img").css('cursor', 'pointer'); |
| 456 | + $("#chart_img").click(function() { |
474 | 457 | $("#chart_dialog").dialog('open'); |
475 | 458 | }); |
| 459 | + |
| 460 | + $("#chart_increment").data( 'value', $("#chart_increment").val() ); |
476 | 461 | |
477 | | - $("#chart_increment").data("value", $("#chart_increment").val()); |
478 | | - |
479 | | - $("#change_graph").click(function(){ |
| 462 | + $("#change_graph").click(function() { |
480 | 463 | $("#chart_dialog").dialog('close'); |
481 | 464 | |
482 | | - //check if the value actually changed, if so, update and increment things accordingly |
483 | | - if( $("#chart_increment").data("value") != $("#chart_increment").val() ){ |
484 | | - $("#chart_increment").data("value", $("#chart_increment").val()); |
| 465 | + // check if the value actually changed, if so, update and increment things accordingly |
| 466 | + if( $("#chart_increment").data( 'value' ) != $("#chart_increment").val() ) { |
| 467 | + $("#chart_increment").data( 'value', $("#chart_increment").val() ); |
485 | 468 | $.updateChart(); |
486 | 469 | } |
487 | | - |
| 470 | + |
488 | 471 | }); |
489 | | - |
490 | | - //CHANGE USER INFO DIALOG |
| 472 | + |
| 473 | + // CHANGE USER INFO DIALOG |
491 | 474 | $("#user_def_dialog").dialog({ autoOpen: false, width: 400 }); |
492 | | - $("#user_def_alter_legend").data("defaultChangeText", $("#user_def_alter_legend").text()); |
493 | | - |
494 | | - |
495 | | - //CHANGE USER/INTERMEDIATE/EXPERT DIALOGS |
496 | | - var loadHeaderInfo = function(headerName){ |
497 | | - $("#" + headerName + "_header").css("cursor", "pointer"); |
498 | | - $("#" + headerName + "_header").click(function(){ |
499 | | - $.renderUserDefDialogWith (wgClickTrackUserDefs[headerName], headerName); |
| 475 | + $("#user_def_alter_legend").data( 'defaultChangeText', $("#user_def_alter_legend").text() ); |
| 476 | + |
| 477 | + // CHANGE USER/INTERMEDIATE/EXPERT DIALOGS |
| 478 | + var loadHeaderInfo = function( headerName ) { |
| 479 | + $("#" + headerName + "_header").css('cursor', 'pointer'); |
| 480 | + $("#" + headerName + "_header").click(function() { |
| 481 | + $.renderUserDefDialogWith( wgClickTrackUserDefs[headerName], headerName ); |
500 | 482 | $("#user_def_dialog").dialog('open'); |
501 | 483 | }); |
502 | | - }; //headername |
503 | | - |
504 | | - |
505 | | - loadHeaderInfo("basic"); |
506 | | - loadHeaderInfo("intermediate"); |
507 | | - loadHeaderInfo("expert"); |
508 | | - |
| 484 | + }; // headername |
| 485 | + |
| 486 | + loadHeaderInfo( 'basic' ); |
| 487 | + loadHeaderInfo( 'intermediate' ); |
| 488 | + loadHeaderInfo( 'expert' ); |
| 489 | + |
509 | 490 | }; |
510 | | - |
511 | | - |
512 | | - $.changeDataLinks = function (){ |
513 | | - |
514 | | - $(".event_name").each(function(){ |
515 | | - $(this).css("cursor", "pointer"); |
516 | | - |
517 | | - $(this).click(function(){ |
518 | | - $("#chart_img").data("eventid", $(this).attr( "value" )); |
519 | | - $("#chart_img").data("event_name", $(this).text()); |
| 491 | + |
| 492 | + $.changeDataLinks = function() { |
| 493 | + $(".event_name").each(function() { |
| 494 | + $(this).css('cursor', 'pointer'); |
| 495 | + |
| 496 | + $(this).click(function() { |
| 497 | + $("#chart_img").data( 'eventid', $(this).attr( 'value' ) ); |
| 498 | + $("#chart_img").data( 'event_name', $(this).text() ); |
520 | 499 | $.updateChart(); |
521 | | - });//click |
522 | | - });//each |
523 | | - };//addlink |
524 | | - |
| 500 | + }); // click |
| 501 | + }); // each |
| 502 | + }; // addlink |
| 503 | + |
525 | 504 | return $(this); |
526 | 505 | })(jQuery); |
527 | 506 | |
528 | | -//colorize the table on document.ready |
529 | | -js2AddOnloadHook($j.colorizeTable); |
530 | | -js2AddOnloadHook($j.changeDataLinks); |
531 | | -js2AddOnloadHook($j.setUIControls); |
532 | | - |
| 507 | +// colorize the table on document.ready |
| 508 | +js2AddOnloadHook( $j.colorizeTable ); |
| 509 | +js2AddOnloadHook( $j.changeDataLinks ); |
| 510 | +js2AddOnloadHook( $j.setUIControls ); |
\ No newline at end of file |