Index: trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.php |
— | — | @@ -7,579 +7,532 @@ |
8 | 8 | */ |
9 | 9 | |
10 | 10 | class SpecialClickTracking extends SpecialPage { |
11 | | - |
12 | | - // set to zero for 'all' |
13 | | - private $top_results = 10; |
14 | | - private $normalize_top_results = false; |
15 | | - private $normalize_results = false; |
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 ); |
| 11 | + |
| 12 | + private static $minimum_date = '20091009'; //YYYYMMDD (+1 for today) |
| 13 | + |
| 14 | + private static $userTypes = array("basic" => 0, "intermediate" => 1, "expert" => 2); |
20 | 15 | private $user_defs = array(); |
21 | | - |
22 | | - // array of event_id => event_name |
23 | | - public static $expert_user_conds = "user_total_contribs > 10 "; |
24 | | - public static $intermediate_user_conds = "user_total_contribs < 10 AND user_total_contribs > 1 "; |
25 | | - public static $basic_user_conds = "user_total_contribs <= 1"; |
26 | | - |
27 | | - /** |
28 | | - * " DISTINCT session_id " |
29 | | - * |
30 | | - * " select count(*), event_id from click_tracking group by event_id order by count(*) desc limit 10;" |
31 | | - * |
32 | | - */ |
33 | | - private $event_id_to_name = array(); |
34 | | - private $name_to_event_id = array(); |
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' ); |
| 16 | + |
| 17 | + |
| 18 | + function __construct() { |
| 19 | + parent::__construct( 'ClickTracking' , 'clicktrack'); |
42 | 20 | wfLoadExtensionMessages( 'ClickTracking' ); |
43 | 21 | UsabilityInitiativeHooks::initialize(); |
44 | 22 | UsabilityInitiativeHooks::addStyle( 'ClickTracking/SpecialClickTracking.css' ); |
45 | 23 | UsabilityInitiativeHooks::addScript( 'ClickTracking/SpecialClickTracking.js' ); |
46 | 24 | } |
47 | | - |
48 | | - function setDefaults() { |
49 | | - $this->user_defs['basic'] = array( |
50 | | - 'anonymous' => '1', |
51 | | - 'total_contribs' => array( |
52 | | - array( 'operation' => '<=', 'value' => '1' ), |
| 25 | + |
| 26 | + |
| 27 | + function setDefaults(){ |
| 28 | + $this->user_defs["basic"] = array( |
| 29 | + "anonymous" => "1", |
| 30 | + "total_contribs" => array( |
| 31 | + array("operation" => "<=", "value" => "10"), |
53 | 32 | ), |
54 | 33 | ); |
55 | | - |
56 | | - $this->user_defs['intermediate'] = array( |
57 | | - 'anonymous' => '0', |
58 | | - 'total_contribs' => array( |
59 | | - array( 'operation' => '<', 'value' => '10' ), |
60 | | - array( 'operation' => '>', 'value' => '1' ), |
| 34 | + |
| 35 | + $this->user_defs["intermediate"] = array( |
| 36 | + "anonymous" => "0", |
| 37 | + "total_contribs" => array( |
| 38 | + array("operation" => "<", "value" => "400"), |
| 39 | + array("operation" => ">", "value" => "10"), |
61 | 40 | ), |
62 | 41 | ); |
63 | | - |
64 | | - $this->user_defs['expert'] = array( |
65 | | - 'anonymous' => '0', |
66 | | - 'total_contribs' => array( |
67 | | - array( 'operation' => '>=', 'value' => '10' ), |
| 42 | + |
| 43 | + $this->user_defs["expert"] = array( |
| 44 | + "anonymous" => "0", |
| 45 | + "total_contribs" => array( |
| 46 | + array("operation" => ">=", "value" => "400"), |
68 | 47 | ), |
69 | 48 | ); |
70 | | - |
| 49 | + |
| 50 | + |
71 | 51 | } |
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 ) { |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + function execute( $par ) { |
79 | 56 | global $wgOut, $wgUser; |
80 | | - |
| 57 | + |
81 | 58 | // Check permissions |
82 | 59 | if ( !$this->userCanExecute( $wgUser ) ) { |
83 | 60 | $this->displayRestrictionError(); |
84 | 61 | return; |
85 | 62 | } |
86 | | - |
| 63 | + |
| 64 | + |
87 | 65 | $this->setHeaders(); |
88 | 66 | $this->setDefaults(); |
89 | | - |
90 | | - $wgOut->addScript( '<script type="text/javascript">' . "var wgClickTrackUserDefs = " . json_encode( $this->user_defs ) . '</script>' ); |
91 | | - |
| 67 | + |
| 68 | + $wgOut->addScript('<script type="text/javascript">'. "var wgClickTrackUserDefs = ".json_encode($this->user_defs). '</script>'); |
| 69 | + |
92 | 70 | $wgOut->setPageTitle( wfMsg( 'ct-title' ) ); |
93 | | - |
94 | | - $outputTable = ''; |
95 | | - |
96 | | - // grab top N |
| 71 | + |
| 72 | + $outputTable =""; |
| 73 | + |
| 74 | + |
| 75 | + //grab top N |
97 | 76 | $events = $this->getTopEvents(); |
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 |
| 77 | + |
| 78 | + //open table |
| 79 | + $outputTable .= Xml::openElement( "table", array( "class" =>"sortable click-data", "id" => "clicktrack_data_table" ) ); |
| 80 | + |
| 81 | + //create a row for every event |
103 | 82 | $i = 0; |
104 | 83 | $db_result; |
105 | | - |
106 | | - // build row headers |
| 84 | + |
| 85 | + //build row headers |
107 | 86 | $header_row = array(); |
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 ) { |
| 87 | + |
| 88 | + $header_row["event_header"] = wfMsg( 'ct-event-name' ); |
| 89 | + $header_row["expert_header"] = wfMsg( 'ct-expert-header' ); |
| 90 | + $header_row["intermediate_header"] = wfMsg( 'ct-intermediate-header' ); |
| 91 | + $header_row["basic_header"] = wfMsg( 'ct-beginner-header' ); |
| 92 | + $header_row["total_header"] = wfMsg( 'ct-total-header' ); |
| 93 | + $outputTable .= Xml::buildTableRow( array( "class"=>"table_headers" ), $header_row ); |
| 94 | + |
| 95 | + //foreach event, build a row |
| 96 | + while(($db_result = $events->fetchRow()) != null){ |
118 | 97 | ++$i; |
119 | | - $outputTable .= $this->buildRow( $db_result, $i, $this->user_defs ); |
| 98 | + $outputTable .= $this->buildRow( $db_result, $i, $this->user_defs); |
120 | 99 | } |
121 | | - |
122 | | - // close table |
123 | | - $outputTable .= Xml::closeElement( 'table' ); |
124 | | - |
| 100 | + |
| 101 | + |
| 102 | + //close table |
| 103 | + $outputTable .= Xml::closeElement("table"); |
| 104 | + |
125 | 105 | $wgOut->addHTML( $outputTable ); |
126 | 106 | |
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() ); |
| 107 | + $wgOut->addHTML($this->buildDateRange()); |
| 108 | + |
| 109 | + //build chart |
| 110 | + $wgOut->addHTML($this->buildChart("advanced.hide",10, "20090815", "20090902", 1)); |
| 111 | + |
| 112 | + //$wgOut->addHTML($this->buildControlBox()); |
| 113 | + |
| 114 | + $wgOut->addHTML($this->buildChartDialog()); |
| 115 | + $wgOut->addHTML($this->buildUserDefBlankDialog()); |
| 116 | + |
136 | 117 | } |
| 118 | + |
137 | 119 | |
138 | 120 | /** |
139 | 121 | * Gets the data to build a chart for PHP or JS purposes |
140 | | - * @param $event_id event id this chart is for |
| 122 | + * @param $event_id event id this chart is for |
141 | 123 | * @param $minTime minimum day |
142 | 124 | * @param $maxTime maximum day |
143 | 125 | * @param $increment number of day(s) to increment in units |
144 | | - * @param $userDefs user defintions |
145 | | - * @param $isUserDefsJSON Boolean: true if userDefs is JSON |
| 126 | + * @param $userDefs user defintions |
| 127 | + * @param $isUserDefsJSON true if userDefs is JSON |
146 | 128 | * @return array with chart info |
147 | 129 | */ |
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 |
| 130 | + static function getChartData($event_id, $minTime, $maxTime, $increment, $userDefs, $isUserDefsJSON=true){ |
| 131 | + //get data |
| 132 | + date_default_timezone_set('UTC'); |
| 133 | + |
| 134 | + if($maxTime == 0){ |
| 135 | + $maxTime = gmdate("Ymd",time()); //today |
154 | 136 | } |
155 | | - if( $minTime == 0 ) { |
| 137 | + if($minTime == 0){ |
156 | 138 | $minTime = self::$minimum_date; |
157 | 139 | } |
158 | | - |
159 | | - // FIXME: On PHP 5.3+, this will be MUCH cleaner |
| 140 | + |
| 141 | + |
| 142 | + //FIXME: On PHP 5.3+, this will be MUCH cleaner |
160 | 143 | $currBeginDate = new DateTime( $minTime ); |
161 | 144 | $currEndDate = new DateTime( $minTime ); |
162 | 145 | $endDate = new DateTime( $maxTime ); |
163 | | - |
164 | | - // get user definitions |
165 | | - if( $isUserDefsJSON ) { |
166 | | - $userDefs = json_decode( $userDefs, true ); |
| 146 | + |
| 147 | + |
| 148 | + //get user definitions |
| 149 | + if($isUserDefsJSON){ |
| 150 | + $userDefs = json_decode($userDefs, true); |
167 | 151 | } |
168 | | - |
| 152 | + |
169 | 153 | $basicUserData = array(); |
170 | 154 | $intermediateUserData = array(); |
171 | 155 | $expertUserData = array(); |
172 | | - |
| 156 | + |
173 | 157 | // PHP 5.3...hurry! |
174 | | - $plural = ( $increment == 1 ? '' : 's' ); |
175 | | - |
176 | | - while( $currEndDate->format( 'U' ) < $endDate->format( 'U' ) ) { |
| 158 | + $plural = ( $increment == 1 ? "" : "s" ); |
| 159 | + |
| 160 | + while( $currEndDate->format( "U" ) < $endDate->format( "U" ) ){ |
177 | 161 | $currEndDate->modify( "+$increment day$plural" ); |
178 | | - |
179 | | - $minDate = $currBeginDate->format( 'Ymd' ); |
180 | | - $maxDate = $currEndDate->format( 'Ymd' ); |
181 | | - |
| 162 | + |
| 163 | + $minDate = $currBeginDate->format("Ymd"); |
| 164 | + $maxDate = $currEndDate->format("Ymd"); |
| 165 | + |
182 | 166 | $basicUserData[] = self::getTableValue( $event_id, $userDefs['basic'], $minDate, $maxDate ); |
183 | 167 | $intermediateUserData[] = self::getTableValue( $event_id, $userDefs['intermediate'], $minDate, $maxDate ); |
184 | 168 | $expertUserData[] = self::getTableValue( $event_id, $userDefs['expert'], $minDate, $maxDate ); |
185 | 169 | $currBeginDate->modify( "+$increment day$plural" ); |
186 | 170 | } |
187 | | - return array( 'expert' => $expertUserData, 'basic' => $basicUserData, 'intermediate' => $intermediateUserData ); |
188 | | - } |
| 171 | + return array("expert" => $expertUserData, "basic" => $basicUserData, "intermediate" => $intermediateUserData); |
| 172 | + } |
189 | 173 | |
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 | | - ); |
| 174 | + function buildChart($event_name, $event_id, $minTime, $maxTime, $increment){ |
| 175 | + $chartData = self::getChartData($event_id, $minTime, $maxTime, $increment, $this->user_defs, false); |
| 176 | + $chartSrc = $this->getGoogleChartParams( $event_id, $event_name, $minTime, $maxTime, $chartData["basic"], $chartData["intermediate"], $chartData["expert"]); |
196 | 177 | return Xml::element( 'img', array( 'src' => $chartSrc , 'id' => 'chart_img' ) ); |
197 | 178 | } |
198 | | - |
| 179 | + |
| 180 | + |
199 | 181 | function getGoogleChartParams( $event_id, $event_name, $minDate, $maxDate, $basicUserData, $intermediateUserData, $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 ) . "|" . |
| 182 | + $max = max( max($basicUserData), max($intermediateUserData), max($expertUserData)); |
| 183 | + return "http://chart.apis.google.com/chart?" . wfArrayToCGI( |
| 184 | + array( |
| 185 | + 'chs' => '400x400', |
| 186 | + 'cht' => 'lc', |
| 187 | + 'chco' => 'FF0000,0000FF,00FF00', |
| 188 | + 'chtt' => "$event_name from $minDate to $maxDate", |
| 189 | + 'chdl' => 'Expert|Intermediate|Beginner', |
| 190 | + 'chxt' => 'x,y', |
| 191 | + 'chd' => 't:' . implode( "," , $expertUserData ) . "|" . |
210 | 192 | implode( "," , $intermediateUserData ) . "|" . implode( "," , $basicUserData ), |
211 | | - 'chds' => "0,$max,0,$max,0,$max" |
212 | | - ) |
213 | | - ); |
| 193 | + 'chds' => "0,$max,0,$max,0,$max" |
| 194 | + )); |
214 | 195 | } |
215 | | - |
| 196 | + |
| 197 | + |
216 | 198 | function buildUserDefBlankDialog(){ |
217 | | - $control = ''; |
218 | | - $control .= Xml::openElement( 'div', array( 'id' => 'user_def_dialog', 'class' => 'dialog' ) ); |
219 | | - |
| 199 | + $control = ""; |
| 200 | + $control .= Xml::openElement("div", array("id" => "user_def_dialog", "class" => "dialog")); |
| 201 | + |
220 | 202 | //currently editing...----| |
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 | | - |
| 203 | + $control .= Xml::openElement("form", array("id" => "user_definition_form", "class" => "user_def_form")); |
| 204 | + $control .= Xml::openElement("fieldset", array("id" => "user_def_alter_fieldset")); |
| 205 | + $control .= Xml::openElement("legend", array("id" => "user_def_alter_legend")); |
| 206 | + $control .= wfMsg( "editing" ); |
| 207 | + $control .= Xml::closeElement("legend"); |
| 208 | + |
227 | 209 | //[] anonymous users? |
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 | | - |
| 210 | + $control .= Xml::openElement("div", array("id" => "anon_users_div", "class" => "checkbox_div control_div")); |
| 211 | + $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "anon_users_checkbox", "class" => "user_def_checkbox")); |
| 212 | + $control .= Xml::closeElement("input"); |
| 213 | + $control .= wfMsg("anon-users"); |
| 214 | + $control .= Xml::closeElement("div"); |
| 215 | + |
234 | 216 | // ---------------- |
235 | | - $control .= Xml::openElement( 'hr' ); |
236 | | - $control .= Xml::closeElement( 'hr' ); |
237 | | - $control .= Xml::openElement( 'div', array( 'id' => 'contrib_opts_container' ) ); |
238 | | - |
| 217 | + $control .= Xml::openElement("hr"); |
| 218 | + $control .= Xml::closeElement("hr"); |
| 219 | + $control .= Xml::openElement("div", array("id" => "contrib_opts_container")); |
| 220 | + |
239 | 221 | // [] users with contributions [>=V] [n ] |
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 | | - |
| 222 | + $control .= Xml::openElement("div", array("id" => "total_users_contrib_div", "class" => "checkbox_div control_div")); |
| 223 | + $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "contrib_checkbox", "class" => "user_def_checkbox")); |
| 224 | + $control .= Xml::closeElement("input"); |
| 225 | + $control .= wfMsg("user-contribs"); |
| 226 | + |
| 227 | + |
| 228 | + $control .= Xml::closeElement("div"); |
| 229 | + |
247 | 230 | // [] contributions in timespan 1 |
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 | | - |
| 231 | + $control .= Xml::openElement("div", array("id" => "contrib_span_1_div", "class" => "checkbox_div control_div")); |
| 232 | + |
| 233 | + $control .= Xml::openElement("div", array("id" => "contrib_span_1_text_div", "class" => "checkbox_div")); |
| 234 | + $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "contrib_span_1_checkbox", "class" => "user_def_checkbox")); |
| 235 | + $control .= Xml::closeElement("input"); |
| 236 | + $control .= wfMsg("user-span") . " 1"; |
| 237 | + $control .= Xml::closeElement("div"); |
| 238 | + $control .= Xml::closeElement("div"); |
| 239 | + |
263 | 240 | // [] contributions in timespan 2 |
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 | | - |
| 241 | + $control .= Xml::openElement("div", array("id" => "contrib_span_2_div", "class" => "checkbox_div control_div")); |
| 242 | + |
| 243 | + $control .= Xml::openElement("div", array("id" => "contrib_span_2_text_div", "class" => "checkbox_div")); |
| 244 | + $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "contrib_span_2_checkbox", "class" => "user_def_checkbox")); |
| 245 | + $control .= Xml::closeElement("input"); |
| 246 | + $control .= wfMsg("user-span") . " 2"; |
| 247 | + $control .= Xml::closeElement("div"); |
| 248 | + $control .= Xml::closeElement("div"); |
| 249 | + |
273 | 250 | // [] contributions in timespan 3 |
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' ); |
| 251 | + $control .= Xml::openElement("div", array("id" => "contrib_span_3_div", "class" => "checkbox_div control_div")); |
| 252 | + |
| 253 | + $control .= Xml::openElement("div", array("id" => "contrib_span_3_text_div", "class" => "checkbox_div")); |
| 254 | + $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "contrib_span_3_checkbox", "class" => "user_def_checkbox")); |
| 255 | + $control .= Xml::closeElement("input"); |
| 256 | + $control .= wfMsg("user-span") . " 3"; |
| 257 | + $control .= Xml::closeElement("div"); |
| 258 | + $control .= Xml::closeElement("div"); |
| 259 | + |
| 260 | + |
| 261 | + |
| 262 | + |
| 263 | + $control .= Xml::closeElement("div");//close contrib opts |
| 264 | + |
| 265 | + $control .= Xml::closeElement("fieldset"); |
| 266 | + $control .= Xml::closeElement("form"); |
| 267 | + $control .= Xml::closeElement("div"); |
288 | 268 | return $control; |
289 | 269 | } |
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' ); |
| 270 | + |
| 271 | + |
| 272 | + |
| 273 | + function buildUserDefNumberSelect($include_checkbox, $include_and, $ids){ |
| 274 | + $control = ""; |
| 275 | + if($include_checkbox){ |
| 276 | + $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "{$ids}_checkbox", "class" => "number_select_checkbox")); |
| 277 | + $control .= Xml::closeElement("input"); |
296 | 278 | } |
297 | | - |
298 | | - if( $include_and ) { |
299 | | - $control .= wfMsg( 'ct-and' ); |
| 279 | + |
| 280 | + if($include_and){ |
| 281 | + $control .= wfMsg("ct-and"); |
300 | 282 | } |
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' ) ); |
| 283 | + |
| 284 | + $control .= Xml::openElement("select", array("id" => "{$ids}_ltgt", "class" => "number_select_ltgt")); |
| 285 | + $control .= Xml::openElement("option", array("id" => "{$ids}_lt", "class" => "number_select_ltgt_opt", "value" => "lt")); |
304 | 286 | $control .= "<="; |
305 | | - $control .= Xml::closeElement( 'option' ); |
306 | | - $control .= Xml::openElement( 'option', array( 'id' => "{$ids}_gt", 'class' => 'number_select_ltgt_opt', 'value' => 'gt' ) ); |
| 287 | + $control .= Xml::closeElement("option"); |
| 288 | + $control .= Xml::openElement("option", array("id" => "{$ids}_gt", "class" => "number_select_ltgt_opt", "value" => "gt")); |
307 | 289 | $control .= ">="; |
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' ); |
| 290 | + $control .= Xml::closeElement("option"); |
| 291 | + $control .= Xml::closeElement("select"); |
| 292 | + $control .= Xml::openElement("input", array("type" => "text", "id" => "{$ids}_text", "class" => "number_select_text")); |
| 293 | + $control .= Xml::closeElement("input"); |
312 | 294 | return $control; |
313 | 295 | } |
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' ); |
| 296 | + |
| 297 | + |
| 298 | + function buildChartDialog(){ |
| 299 | + $control = ""; |
| 300 | + $control .= Xml::openElement("div", array("id" => "chart_dialog", "class" => "dialog")); |
| 301 | + |
| 302 | + $control .= Xml::openElement("form", array("id" => "chart_dialog_form", "class" => "chart_form")); |
| 303 | + $control .= Xml::openElement("fieldset", array("id" => "chart_dialog_alter_fieldset")); |
| 304 | + $control .= Xml::openElement("legend", array("id" => "chart_dialog_alter_legend")); |
| 305 | + $control .= wfMsg( "ct-increment-by" ); |
| 306 | + $control .= Xml::closeElement("legend"); |
| 307 | + |
| 308 | + $control .= Xml::openElement("table", array("id" => "chart_dialog_increment_table")); |
| 309 | + $control .= Xml::openElement("tbody", array("id" => "chart_dialog_increment_tbody")); |
| 310 | + |
| 311 | + $control .= Xml::openElement("tr", array("id" => "chart_dialog_increment_row")); |
| 312 | + |
| 313 | + $control .= Xml::openElement("td", array("id" => "chart_dialog_increment_cell")); |
| 314 | + $control .= Xml::openElement("input", array("type" => "text", "id" => "chart_increment", "class" => "chart_dialog_area", "value" => '1')); |
| 315 | + $control .= Xml::closeElement("input"); |
| 316 | + $control .= Xml::closeElement("td"); |
| 317 | + |
| 318 | + $control .= Xml::openElement("td", array("id" => "chart_dialog_button_cell")); |
| 319 | + $control .= Xml::openElement("input", array("type" => "button", "id" => "change_graph", "value" => wfMsg( "ct-change-graph" ) ) ); |
| 320 | + $control .= Xml::closeElement("input"); |
| 321 | + $control .= Xml::closeElement("td"); |
| 322 | + |
| 323 | + $control .= Xml::closeElement("tr"); |
| 324 | + |
| 325 | + $control .= Xml::closeElement("tbody"); |
| 326 | + $control .= Xml::closeElement("table"); |
| 327 | + $control .= Xml::closeElement("fieldset"); |
| 328 | + $control .= Xml::closeElement("form"); |
| 329 | + $control .= Xml::closeElement("div"); |
360 | 330 | return $control; |
361 | 331 | } |
| 332 | + |
| 333 | + |
| 334 | + function buildDateRange(){ |
| 335 | + $control = Xml::openElement("form", array("id" => "date_range")); |
| 336 | + |
| 337 | + $control .= Xml::openElement("fieldset", array("id" => "date_range_fieldset")); |
| 338 | + $control .= Xml::openElement("legend", array("id" => "date_range_legend")); |
| 339 | + $control .= wfMsg('ct-date-range'); |
| 340 | + $control .= Xml::closeElement("legend"); |
| 341 | + |
362 | 342 | |
363 | | - function buildDateRange() { |
364 | | - $control = Xml::openElement( 'form', array( 'id' => 'date_range' ) ); |
| 343 | + |
| 344 | + $control .= Xml::openElement("table", array("id" => "date_range_table")); |
| 345 | + $control .= Xml::openElement("tbody", array("id" => "date_range_tbody")); |
| 346 | + |
| 347 | + |
| 348 | + $control .= Xml::openElement("tr", array("id" => "start_date_row")); |
| 349 | + |
| 350 | + $control .= Xml::openElement("td", array("id" => "start_date_label", "class" => "date_range_label")); |
| 351 | + $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "start_date_checkbox", "class" => "date_range_checkbox", "checked" => "")); |
| 352 | + $control .= Xml::closeElement("input"); |
| 353 | + $control .= wfMsg( "ct-start-date" ); |
| 354 | + $control .= Xml::closeElement("td"); |
| 355 | + |
| 356 | + $control .= Xml::openElement("td", array("id" => "start_date_textarea")); |
| 357 | + $control .= Xml::openElement("input", array("type" => "text", "id" => "start_date", "class" => "date_range_input")); |
| 358 | + $control .= Xml::closeElement("input"); |
| 359 | + $control .= Xml::closeElement("td"); |
| 360 | + |
| 361 | + $control .= Xml::closeElement("tr"); |
| 362 | + |
| 363 | + $control .= Xml::openElement("tr", array("id" => "end_date_row")); |
| 364 | + |
| 365 | + $control .= Xml::openElement("td", array("id" => "end_date_label", "class" => "date_range_label")); |
| 366 | + $control .= Xml::openElement("input", array("type" => "checkbox", "id" => "end_date_checkbox", "class" => "date_range_checkbox", "checked" => "")); |
| 367 | + $control .= Xml::closeElement("input"); |
| 368 | + $control .= wfMsg( "ct-end-date" ); |
| 369 | + $control .= Xml::closeElement("td"); |
| 370 | + |
| 371 | + $control .= Xml::openElement("td", array("id" => "end_date_textarea")); |
| 372 | + $control .= Xml::openElement("input", array("type" => "text", "id" => "end_date", "class" => "date_range_input")); |
| 373 | + $control .= Xml::closeElement("input"); |
| 374 | + $control .= Xml::closeElement("td"); |
| 375 | + |
| 376 | + $control .= Xml::closeElement("tr"); |
| 377 | + |
365 | 378 | |
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 | | - |
| 379 | + $control .= Xml::openElement("tr", array("id" => "update_row")); |
| 380 | + |
| 381 | + $control .= Xml::openElement("td"); |
| 382 | + $control .= Xml::closeElement("td"); |
| 383 | + |
| 384 | + $control .= Xml::openElement("td", array("id" => "update_table_button_td")); |
| 385 | + $control .= Xml::openElement("input", array("type" => "button", "id" => "update_table_button", "class" => "update_button", "value" =>wfMsg("ct-update-table"))); |
| 386 | + $control .= Xml::closeElement("input"); |
| 387 | + $control .= Xml::closeElement("td"); |
| 388 | + |
| 389 | + $control .= Xml::closeElement("tr"); |
| 390 | + |
| 391 | + $control .= Xml::closeElement("tbody"); |
| 392 | + $control .= Xml::closeElement("table"); |
| 393 | + $control .= Xml::closeElement("fieldset"); |
| 394 | + |
| 395 | + $control .= Xml::closeElement("form"); |
| 396 | + |
443 | 397 | return $control; |
444 | 398 | } |
445 | | - |
446 | | - public static function buildRowArray( $minTime, $maxTime, $userDefs, $is_JSON = true) { |
447 | | - if( $minTime == 0 ) { |
| 399 | + |
| 400 | + |
| 401 | + /** |
| 402 | + * |
| 403 | + * @param $minTime |
| 404 | + * @param $maxTime |
| 405 | + * @param $userDefs |
| 406 | + * @param $is_JSON |
| 407 | + * @return unknown_type |
| 408 | + */ |
| 409 | + public static function buildRowArray($minTime, $maxTime, $userDefs, $is_JSON= true){ |
| 410 | + |
| 411 | + |
| 412 | + if($minTime == 0){ |
448 | 413 | $minTime = self::$minimum_date; |
449 | 414 | } |
450 | | - |
451 | | - if( $maxTime == 0 ) { |
452 | | - $maxTime = gmdate( 'Ymd', time() ); // today |
| 415 | + if($maxTime == 0){ |
| 416 | + $maxTime = gmdate("Ymd",time()); //today |
453 | 417 | } |
454 | | - |
455 | | - if( $is_JSON ) { |
456 | | - $userDefs = json_decode( $userDefs, true ); |
| 418 | + |
| 419 | + if($is_JSON){ |
| 420 | + $userDefs = json_decode($userDefs, true); |
457 | 421 | } |
458 | | - |
459 | | - $events = self::getTopEvents( $minTime, $maxTime ); |
460 | | - |
| 422 | + |
| 423 | + |
| 424 | + $events = self::getTopEvents($minTime, $maxTime); |
| 425 | + |
461 | 426 | $returnArray = array(); |
462 | | - |
463 | | - while( ( $data_result = $events->fetchRow() ) != null ) { |
| 427 | + |
| 428 | + while(($data_result = $events->fetchRow()) != null){ |
464 | 429 | $outputArray = array(); |
465 | 430 | $outputArray['event_name'] = $data_result['event_name']; |
466 | 431 | $outputArray['event_id'] = $data_result['event_id']; |
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']; |
| 432 | + $outputArray['expert'] = self::getTableValue($data_result['event_id'], $userDefs["expert"]); |
| 433 | + $outputArray['intermediate'] = self::getTableValue($data_result['event_id'], $userDefs["intermediate"]); |
| 434 | + $outputArray['basic'] = self::getTableValue($data_result['event_id'], $userDefs["basic"]); |
| 435 | + $outputArray['total'] = $data_result["totalevtid"]; |
471 | 436 | $returnArray[] = $outputArray; |
472 | 437 | } |
473 | | - |
| 438 | + |
474 | 439 | return $returnArray; |
| 440 | + |
475 | 441 | } |
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; |
| 442 | + |
| 443 | + function buildRow($data_result, $row_count, $userDefs){ |
| 444 | + |
| 445 | + $outputRow = Xml::openElement("tr", array("class" => "table_data_row")); |
| 446 | + |
| 447 | + //event name |
| 448 | + $outputRow .=Xml::openElement("td", |
| 449 | + array("class" => "event_name", "id" => "event_name_$row_count", "value" =>$data_result['event_id'])); |
| 450 | + $outputRow .= $data_result['event_name']; |
| 451 | + $outputRow .=Xml::closeElement("td"); |
| 452 | + |
| 453 | + //advanced users |
| 454 | + $cellValue = self::getTableValue($data_result['event_id'], $userDefs["expert"]); |
| 455 | + $outputRow .=Xml::openElement("td", |
| 456 | + array("class" => "event_data expert_data", "id" => "event_expert_$row_count", |
| 457 | + "value" => $cellValue)); |
| 458 | + $outputRow .= $cellValue; |
| 459 | + $outputRow .=Xml::closeElement("td"); |
| 460 | + |
| 461 | + //intermediate users |
| 462 | + $cellValue = self::getTableValue($data_result['event_id'], $userDefs["intermediate"]); |
| 463 | + $outputRow .=Xml::openElement("td", |
| 464 | + array("class" => "event_data intermediate_data", "id" => "event_intermediate_$row_count", |
| 465 | + "value" => $cellValue)); |
| 466 | + $outputRow .= $cellValue; |
| 467 | + $outputRow .=Xml::closeElement("td"); |
| 468 | + |
| 469 | + //basic users |
| 470 | + $cellValue = self::getTableValue($data_result['event_id'], $userDefs["basic"]); |
| 471 | + $outputRow .=Xml::openElement("td", |
| 472 | + array("class" => "event_data basic_data", "id" => "event_basic_$row_count", |
| 473 | + "value" => $cellValue)); |
| 474 | + $outputRow .= $cellValue; |
| 475 | + $outputRow .=Xml::closeElement("td"); |
| 476 | + |
| 477 | + //totals |
| 478 | + $cellValue = $data_result["totalevtid"]; |
| 479 | + $outputRow .=Xml::openElement("td", |
| 480 | + array("class" => "event_data total_data", "id" => "total_$row_count", |
| 481 | + "value" => $cellValue)); |
| 482 | + $outputRow .= $cellValue; |
| 483 | + $outputRow .=Xml::closeElement("td"); |
| 484 | + |
| 485 | + |
| 486 | + $outputRow .= Xml::closeElement("tr"); |
| 487 | + |
| 488 | + return $outputRow; |
| 489 | + |
541 | 490 | } |
542 | 491 | |
543 | | - /** |
544 | | - * Get time constraints |
| 492 | + /* |
| 493 | + * get time constraints |
545 | 494 | * @param minTime minimum day (YYYYMMDD) |
546 | 495 | * @param maxTime max day (YYYYMMDD) |
547 | 496 | * NOTE: once some of the constraints have been finalized, this will use more of the Database functions and not raw SQL |
548 | 497 | */ |
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'"; |
| 498 | + static function getTimeConstraintsStatement( $minTime, $maxTime ){ |
| 499 | + if($minTime == 0 || $maxTime == 0){ |
| 500 | + return ''; |
554 | 501 | } |
| 502 | + else { |
| 503 | + |
| 504 | + return "WHERE `action_time` >= '$minTime' AND `action_time` <= '$maxTime'"; |
| 505 | + } |
| 506 | + |
555 | 507 | } |
556 | | - |
| 508 | + |
| 509 | + |
557 | 510 | /** |
558 | 511 | * Gets the top N events as set in the page pref |
559 | 512 | * @param $time_constraint_statement |
560 | 513 | * @return unknown_type |
561 | 514 | * NOTE: once some of the constraints have been finalized, this will use more of the Database functions and not raw SQL |
562 | 515 | */ |
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 ); |
| 516 | + public static function getTopEvents($minTime = "", $maxTime = "", $normalize_top_results = false){ |
| 517 | + |
| 518 | + $normalize = "click_tracking"; |
| 519 | + //escaped |
| 520 | + |
| 521 | + $time_constraint_statement = self::getTimeConstraintsStatement($minTime,$maxTime); |
568 | 522 | $time_constraint = $time_constraint_statement; |
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 = ''; |
| 523 | + |
| 524 | + if($normalize_top_results){ |
| 525 | + $normalize = "(select distinct session_id, event_id from click_tracking $time_constraint_statement) as t1"; |
| 526 | + $time_constraint = ""; |
573 | 527 | } |
574 | | - |
575 | | - $join = ' '; |
576 | | - $sql = "SELECT COUNT(event_id) AS totalevtid, event_id,event_name FROM $normalize" . |
| 528 | + $join = " "; |
| 529 | + $sql = "select count(event_id) as totalevtid, event_id,event_name from $normalize" . |
577 | 530 | " LEFT JOIN click_tracking_events ON event_id=click_tracking_events.id". |
578 | | - " $time_constraint GROUP BY event_id ORDER BY totalevtid DESC"; |
579 | | - |
580 | | - // returns count(event_id),event_id, event_name, top one first |
| 531 | + " $time_constraint group by event_id order by totalevtid desc"; |
| 532 | + |
| 533 | + //returns count(event_id),event_id, event_name, top one first |
581 | 534 | $dbr = wfGetDB( DB_SLAVE ); |
582 | | - $dbresult = $dbr->query( $sql, __METHOD__ ); |
583 | | - |
| 535 | + $dbresult = $dbr->query($sql); |
| 536 | + |
584 | 537 | return $dbresult; |
585 | 538 | } |
586 | 539 | |
— | — | @@ -587,30 +540,31 @@ |
588 | 541 | * Gets a table value for a given User ID |
589 | 542 | * NOTE: once some of the constraints have been finalized, this will use more of the Database functions and not raw SQL |
590 | 543 | */ |
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 ); |
| 544 | + static function getTableValue($event_id, $userDef, $minTime = '', $maxTime = '', $normalize_results = false){ |
| 545 | + |
| 546 | + $normalize = "click_tracking"; |
| 547 | + //escaped |
| 548 | + $time_constraint_statement = self::getTimeConstraintsStatement($minTime,$maxTime); |
595 | 549 | $time_constraint = $time_constraint_statement; |
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 = ''; |
| 550 | + if($normalize_results){ |
| 551 | + $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"; |
| 552 | + $time_constraint = ""; |
599 | 553 | } |
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 | | - |
| 554 | + |
| 555 | + $user_conditions = SpecialClickTracking::buildUserDefQuery($userDef); |
| 556 | + |
| 557 | + $where = ($time_constraint == "" ? "where" : ""); |
| 558 | + |
| 559 | + $and = ($time_constraint == "" ? "": "and"); |
| 560 | + |
| 561 | + $sql ="select count(*) as totalcount from $normalize $where $time_constraint $and ($user_conditions) and event_id=$event_id"; |
| 562 | + |
609 | 563 | $dbr = wfGetDB( DB_SLAVE ); |
610 | | - $result = $dbr->query( $sql, __METHOD__ ); |
| 564 | + $result = $dbr->query($sql); |
611 | 565 | $resRow = $result->fetchRow(); |
612 | | - return $resRow['totalcount']; |
| 566 | + return $resRow["totalcount"]; |
613 | 567 | } |
614 | | - |
| 568 | + |
615 | 569 | /** |
616 | 570 | * Generates a query for a user type definition |
617 | 571 | * @param $include_anon_users boolean, include anon users or not |
— | — | @@ -620,90 +574,74 @@ |
621 | 575 | * @param $contrib_3 array, nonempty AND conditions for user_contribs_1 |
622 | 576 | * @return unknown_type query |
623 | 577 | */ |
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 | | - |
| 578 | + public static function buildUserDefQuery($def){ |
| 579 | + |
| 580 | + $include_anon_users = (empty($def['anonymous'])?array():$def['anonymous']); |
| 581 | + $total_contribs = (empty($def['total_contribs'])?array():$def['total_contribs']); |
| 582 | + $contrib_1 = (empty($def['contrib_1'])?array():$def['contrib_1']); |
| 583 | + $contrib_2 = (empty($def['contrib_2'])?array():$def['contrib_2']); |
| 584 | + $contrib_3 = (empty($def['contrib_3'])?array():$def['contrib_3']); |
| 585 | + |
631 | 586 | $or_conds = array(); |
632 | 587 | $and_conds = array(); |
633 | | - $sql = ''; |
634 | | - |
635 | | - if( (boolean)$include_anon_users ) { |
636 | | - $or_conds[] = array( 'field' => 'is_logged_in', 'operation' => '=', 'value' => '0' ); |
| 588 | + $sql = ""; |
| 589 | + |
| 590 | + |
| 591 | + if( (boolean)$include_anon_users ){ |
| 592 | + $or_conds[] = array("field" => "is_logged_in", "operation" => "=", "value" =>"0"); |
637 | 593 | } |
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 | | - ); |
| 594 | + |
| 595 | + if(!empty($total_contribs)){ |
| 596 | + foreach($total_contribs as $contribs){ |
| 597 | + $and_conds[] = array("field" => "user_total_contribs", "operation" => SpecialClickTracking::validate_oper($contribs["operation"]), "value" => intval($contribs["value"])); |
646 | 598 | } |
647 | 599 | } |
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 | | - ); |
| 600 | + |
| 601 | + if(!empty($contrib_1)){ |
| 602 | + foreach($contrib_1 as $contribs){ |
| 603 | + $and_conds[] = array("field" => "user_contribs_span1", "operation" => SpecialClickTracking::validate_oper($contribs["operation"]), "value" => intval($contribs["value"])); |
656 | 604 | } |
657 | 605 | } |
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 | | - ); |
| 606 | + if(!empty($contrib_2)){ |
| 607 | + foreach($contrib_2 as $contribs){ |
| 608 | + $and_conds[] = array("field" => "user_contribs_span2", "operation" => SpecialClickTracking::validate_oper($contribs["operation"]), "value" => intval($contribs["value"])); |
666 | 609 | } |
667 | 610 | } |
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 | | - ); |
| 611 | + if(!empty($contrib_3)){ |
| 612 | + foreach($contrib_3 as $contribs){ |
| 613 | + $and_conds[] = array("field" => "user_contribs_span3", "operation" => SpecialClickTracking::validate_oper($contribs["operation"]), "value" => intval($contribs["value"])); |
676 | 614 | } |
677 | 615 | } |
678 | | - |
679 | | - foreach( $and_conds as $cond ) { |
680 | | - if( !empty( $sql ) ) { |
681 | | - $sql .= ' AND '; |
| 616 | + |
| 617 | + foreach($and_conds as $cond){ |
| 618 | + if(!empty($sql)){ |
| 619 | + $sql .= " AND "; |
682 | 620 | } |
683 | | - $sql .= $cond['field'] . ' ' . $cond['operation'] . ' ' . $cond['value']; |
| 621 | + $sql .= $cond["field"] . " " . $cond["operation"] . " " . $cond["value"]; |
684 | 622 | } |
685 | | - |
686 | | - foreach( $or_conds as $cond ) { |
687 | | - if( !empty( $sql ) ) { |
688 | | - $sql .= ' OR '; |
| 623 | + foreach($or_conds as $cond){ |
| 624 | + if(!empty($sql)){ |
| 625 | + $sql .= " OR "; |
689 | 626 | } |
690 | | - $sql .= $cond['field'] . ' ' . $cond['operation'] . ' ' . $cond['value']; |
| 627 | + $sql .= $cond["field"] . " " . $cond["operation"] . " " . $cond["value"]; |
691 | 628 | } |
692 | | - |
| 629 | + |
693 | 630 | return $sql; |
694 | 631 | } |
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 '=': |
| 632 | + |
| 633 | + public static function validate_oper($operation){ |
| 634 | + $o_trim = trim($operation); |
| 635 | + switch($o_trim){ //valid operations |
| 636 | + case ">": |
| 637 | + case "<": |
| 638 | + case "<=": |
| 639 | + case ">=": |
| 640 | + case "=": |
704 | 641 | return $o_trim; |
705 | 642 | default: |
706 | | - return '='; |
| 643 | + return "="; |
707 | 644 | } |
708 | 645 | } |
709 | | - |
| 646 | + |
| 647 | + |
710 | 648 | } |
\ No newline at end of file |