r108015 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108014‎ | r108015 | r108016 >
Date:11:26, 4 January 2012
Author:jeroendedauw
Status:deferred
Tags:educationprogram 
Comment:
work on student pager
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPStudentPager.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/includes/EPStudentPager.php
@@ -67,8 +67,13 @@
6868 $name = $user->getRealName() === '' ? $user->getName() : $user->getRealName();
6969
7070 $value = Linker::userLink( $value, $name ) . Linker::userToolLinks( $value, $name );
71 -
7271 break;
 72+ case '_courses_current':
 73+ $value = 'foo'; // TODO
 74+ break;
 75+ case '_courses_passed':
 76+ $value = 'bar'; // TODO
 77+ break;
7378 }
7479
7580 return $value;
@@ -92,4 +97,25 @@
9398 return array();
9499 }
95100
 101+ /**
 102+ * (non-PHPdoc)
 103+ * @see EPPager::hasActionsColumn()
 104+ */
 105+ protected function hasActionsColumn() {
 106+ return false;
 107+ }
 108+
 109+ /**
 110+ * (non-PHPdoc)
 111+ * @see EPPager::getFieldNames()
 112+ */
 113+ public function getFieldNames() {
 114+ $fields = parent::getFieldNames();
 115+
 116+ $fields['_courses_current'] = 'current-courses';
 117+ $fields['_courses_passed'] = 'passed-courses';
 118+
 119+ return $fields;
 120+ }
 121+
96122 }
Index: trunk/extensions/EducationProgram/includes/EPPager.php
@@ -154,7 +154,8 @@
155155 $value = $this->getLanguage()->pipeList( $this->getControlLinks( $this->currentObject ) );
156156 }
157157 else {
158 - $value = isset( $row->$field ) ? $row->$field : null;
 158+ $prefixedField = $c::getPrefixedField( $field );
 159+ $value = isset( $row->$prefixedField ) ? $row->$prefixedField : null;
159160 }
160161
161162 $formatted = strval( $this->formatValue( $field, $value ) );
@@ -177,20 +178,22 @@
178179 * @return array
179180 */
180181 public function getFieldNames() {
181 - $conds = $this->conds; // Yeah, this is needed in PHP 5.3 >_>
182 - $fields = array_filter( $this->getFields(), function( $name ) use ( $conds ) {
183 - return !array_key_exists( $name, $conds );
184 - } );
185 -
186 - $fields = $this->getFieldNameList( $fields );
187 -
 182+ $fields = array();
 183+
188184 if ( $this->hasMultipleItemControl() ) {
189 - // This is a hack to get an extra column for select all control.
190 - $fields = array_merge( array( '_select' => '' ), $fields );
 185+ $fields['_select'] = '';
191186 }
192 -
193 - $fields['_controls'] = ''; // This is a hack to get an extra column for the control links.
194 -
 187+
 188+ foreach ( $this->getFields() as $field ) {
 189+ if ( !array_key_exists( $field, $this->conds ) ) {
 190+ $fields[$field] = $field;
 191+ }
 192+ }
 193+
 194+ if ( $this->hasActionsColumn() ) {
 195+ $fields['_controls'] = '';
 196+ }
 197+
195198 return $fields;
196199 }
197200
@@ -255,6 +258,7 @@
256259 }
257260
258261 /**
 262+ * Returns whether the pager has multiple item actions and therefore should show the multiple items control.
259263 *
260264 * @since 0.1
261265 *
@@ -263,6 +267,17 @@
264268 protected function hasMultipleItemControl() {
265269 return count( $this->getMultipleItemActions() ) > 0;
266270 }
 271+
 272+ /**
 273+ * Returns whether the pager should show an extra column for item actions.
 274+ *
 275+ * @since 0.1
 276+ *
 277+ * @return boolean
 278+ */
 279+ protected function hasActionsColumn() {
 280+ return true;
 281+ }
267282
268283 /**
269284 * Returns the fields to display.
@@ -297,7 +312,6 @@
298313 * @return array
299314 */
300315 protected function getConditions() {
301 - $req = $this->getRequest();
302316 $conds = array();
303317
304318 $filterOptions = $this->getFilterOptions();
@@ -330,28 +344,6 @@
331345 }
332346
333347 /**
334 - * Takes a list of (unprefixed) field names and return them in an associative array where
335 - * the keys are the prefixed field names and the values are header messages.
336 - *
337 - * @since 0.1
338 - *
339 - * @param array $fields
340 - *
341 - * @return array
342 - */
343 - protected function getFieldNameList( array $fields ) {
344 - $headers = array();
345 - $c = $this->className;
346 -
347 - foreach ( $fields as $fieldName => $fieldLabel ) {
348 - $message = $fieldLabel === '' ? '' : $this->getMsg( 'header-' . $fieldLabel );
349 - $headers[$c::getPrefixedField( $fieldLabel )] = $message;
350 - }
351 -
352 - return $headers;
353 - }
354 -
355 - /**
356348 * Should return an array with the names of the fields that are sortable.
357349 *
358350 * @since 0.1
@@ -495,8 +487,7 @@
496488 * @see TablePager::formatValue()
497489 */
498490 public final function formatValue( $name, $value ) {
499 - $c = $this->className; // Yeah, this is needed in PHP 5.3 >_>
500 - return $this->getFormattedValue( $c::unprefixFieldName( $name ), $value );
 491+ return $this->getFormattedValue( $name, $value );
501492 }
502493
503494 /**
@@ -565,6 +556,10 @@
566557
567558 # Make table header
568559 foreach ( $fields as $field => $name ) {
 560+ $c = $this->className; // Yeah, this is needed in PHP 5.3 >_>
 561+ $prefixedField = $c::getPrefixedField( $field );
 562+ $name = $name === '' ? '' : $this->getMsg( 'header-' . $name );
 563+
569564 if ( $field === '_select' ) {
570565 $s .= '<th width="30px">' . Html::element( 'input', array(
571566 'type' => 'checkbox',
@@ -575,30 +570,32 @@
576571 }
577572 elseif ( strval( $name ) == '' ) {
578573 $s .= "<th>&#160;</th>\n";
579 - } elseif ( $this->isFieldSortable( $field ) ) {
580 - $query = array( 'sort' => $field, 'limit' => $this->mLimit );
581 - if ( $field == $this->mSort ) {
 574+ } elseif ( $this->isFieldSortable( $prefixedField ) ) {
 575+ $query = array( 'sort' => $prefixedField, 'limit' => $this->mLimit );
 576+
 577+ if ( $prefixedField == $this->mSort ) {
582578 # This is the sorted column
583579 # Prepare a link that goes in the other sort order
584580 if ( $this->mDefaultDirection ) {
585 - # Descending
586 - $image = 'Arr_d.png';
587 - $query['asc'] = '1';
588 - $query['desc'] = '';
589 - $alt = htmlspecialchars( wfMsg( 'descending_abbrev' ) );
 581+ # Descending
 582+ $image = 'Arr_d.png';
 583+ $query['asc'] = '1';
 584+ $query['desc'] = '';
 585+ $alt = htmlspecialchars( wfMsg( 'descending_abbrev' ) );
 586+ } else {
 587+ # Ascending
 588+ $image = 'Arr_u.png';
 589+ $query['asc'] = '';
 590+ $query['desc'] = '1';
 591+ $alt = htmlspecialchars( wfMsg( 'ascending_abbrev' ) );
 592+ }
 593+
 594+ $image = htmlspecialchars( "$wgStylePath/common/images/$image" );
 595+ $link = $this->makeLink(
 596+ "<img width=\"12\" height=\"12\" alt=\"$alt\" src=\"$image\" />" .
 597+ htmlspecialchars( $name ), $query );
 598+ $s .= "<th class=\"$sortClass\">$link</th>\n";
590599 } else {
591 - # Ascending
592 - $image = 'Arr_u.png';
593 - $query['asc'] = '';
594 - $query['desc'] = '1';
595 - $alt = htmlspecialchars( wfMsg( 'ascending_abbrev' ) );
596 - }
597 - $image = htmlspecialchars( "$wgStylePath/common/images/$image" );
598 - $link = $this->makeLink(
599 - "<img width=\"12\" height=\"12\" alt=\"$alt\" src=\"$image\" />" .
600 - htmlspecialchars( $name ), $query );
601 - $s .= "<th class=\"$sortClass\">$link</th>\n";
602 - } else {
603600 $s .= '<th>' . $this->makeLink( htmlspecialchars( $name ), $query ) . "</th>\n";
604601 }
605602 }
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -142,6 +142,8 @@
143143 // Student pager
144144 'epstudentpager-header-user-id' => 'User',
145145 'epstudentpager-header-id' => 'Id',
 146+ 'epstudentpager-header-current-courses' => 'Current courses',
 147+ 'epstudentpager-header-passed-courses' => 'Passed courses',
146148
147149 // Special:EditInstitution
148150 'editinstitution-text' => 'Enter the institution details below and click submit to save your changes.',

Status & tagging log