r106702 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106701‎ | r106702 | r106703 >
Date:21:35, 19 December 2011
Author:jeroendedauw
Status:deferred
Tags:educationprogram 
Comment:
work on course pager and filter
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCoursePager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPDBObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrgPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPPager.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/includes/EPOrgPager.php
@@ -56,17 +56,17 @@
5757
5858 /**
5959 * (non-PHPdoc)
60 - * @see TablePager::formatValue()
 60+ * @see EPPager::getFormattedValue()
6161 */
62 - public function formatValue( $name, $value ) {
 62+ public function getFormattedValue( $name, $value ) {
6363 switch ( $name ) {
64 - case 'org_name':
 64+ case 'name':
6565 $value = Linker::linkKnown(
6666 SpecialPage::getTitleFor( 'Institution', $value ),
6767 $value
6868 );
6969 break;
70 - case 'org_country':
 70+ case 'country':
7171 $countries = array_flip( efEpGetCountryOptions() );
7272 $value = $countries[$value];
7373 break;
Index: trunk/extensions/EducationProgram/includes/EPDBObject.php
@@ -735,6 +735,9 @@
736736 if ( is_null( $fields ) ) {
737737 $fields = array_keys( static::getFieldTypes() );
738738 }
 739+ else {
 740+ $fields = (array)$fields;
 741+ }
739742
740743 $tables = array( static::getDBTable() );
741744 $joinConds = static::getProcessedJoinConds( $joinConds, $tables );
Index: trunk/extensions/EducationProgram/includes/EPPager.php
@@ -271,11 +271,22 @@
272272 foreach ( $filterOptions as $optionName => &$optionData ) {
273273 if ( $req->getCheck( $optionName ) ) {
274274 $optionData['value'] = $req->getVal( $optionName );
275 - $req->setSessionData( __CLASS__ . $optionName, $optionData['value'] );
 275+ $req->setSessionData( get_called_class() . $optionName, $optionData['value'] );
276276 $changed = true;
 277+
 278+ if ( array_key_exists( 'datatype', $optionData ) ) {
 279+ switch ( $optionData['datatype'] ) {
 280+ case 'int':
 281+ $optionData['value'] = (int)$optionData['value'];
 282+ break;
 283+ case 'float':
 284+ $optionData['value'] = (float)$optionData['value'];
 285+ break;
 286+ }
 287+ }
277288 }
278 - elseif ( !is_null( $req->getSessionData( __CLASS__ . $optionName ) ) ) {
279 - $optionData['value'] = $req->getSessionData( __CLASS__ . $optionName );
 289+ elseif ( !is_null( $req->getSessionData( get_called_class() . $optionName ) ) ) {
 290+ $optionData['value'] = $req->getSessionData( get_called_class() . $optionName );
280291 $changed = true;
281292 }
282293 }
@@ -296,5 +307,24 @@
297308 protected function getMsg( $messageKey ) {
298309 return wfMsg( strtolower( $this->className ) . 'pager-' . str_replace( '_', '-', $messageKey ) );
299310 }
 311+
 312+ /**
 313+ * (non-PHPdoc)
 314+ * @see TablePager::formatValue()
 315+ */
 316+ public final function formatValue( $name, $value ) {
 317+ $c = $this->className; // Yeah, this is needed in PHP 5.3 >_>
 318+ return $this->getFormattedValue( $c::unprefixFieldName( $name ), $value );
 319+ }
 320+
 321+ /**
 322+ * Similar to TablePager::formatValue, but passes along the name of the field without prefix.
 323+ *
 324+ * @param string $name
 325+ * @param string $value
 326+ *
 327+ * @return string
 328+ */
 329+ protected abstract function getFormattedValue( $name, $value );
300330
301331 }
Index: trunk/extensions/EducationProgram/includes/EPCoursePager.php
@@ -32,7 +32,8 @@
3333 */
3434 public function getFieldNames() {
3535 return parent::getFieldNameList( array(
36 - // TODO
 36+ 'org_id',
 37+ 'name',
3738 ) );
3839 }
3940
@@ -54,20 +55,31 @@
5556
5657 /**
5758 * (non-PHPdoc)
58 - * @see TablePager::formatValue()
 59+ * @see EPPager::getFormattedValue()
5960 */
60 - public function formatValue( $name, $value ) {
 61+ protected function getFormattedValue( $name, $value ) {
6162 switch ( $name ) {
62 - case '': // TODO
63 - $value = $value;
 63+ case 'name':
 64+ $value = Linker::linkKnown(
 65+ SpecialPage::getTitleFor( 'Course', $value ),
 66+ $value
 67+ );
6468 break;
 69+ case 'org_id':
 70+ $value = EPOrg::selectRow( 'name', array( 'id' => $value ) )->getField( 'name' );
 71+
 72+ $value = Linker::linkKnown(
 73+ SpecialPage::getTitleFor( 'Institution', $value ),
 74+ $value
 75+ );
 76+ break;
6577 }
6678
6779 return $value;
6880 }
6981
7082 function getDefaultSort() {
71 - return ''; // TODO
 83+ return 'asc';
7284 }
7385
7486 /**
@@ -75,7 +87,27 @@
7688 * @see EPPager::getSortableFields()
7789 */
7890 protected function getSortableFields() {
79 - return array();
 91+ return array(
 92+ 'name',
 93+ );
8094 }
 95+
 96+ /**
 97+ * (non-PHPdoc)
 98+ * @see EPPager::getFilterOptions()
 99+ */
 100+ protected function getFilterOptions() {
 101+ return array(
 102+ 'org_id' => array(
 103+ 'type' => 'select',
 104+ 'options' => array_merge(
 105+ array( '' => '' ),
 106+ EPOrg::getOrgOptions( EPOrg::select( array( 'name', 'id' ) ) )
 107+ ),
 108+ 'value' => '',
 109+ 'datatype' => 'int',
 110+ ),
 111+ );
 112+ }
81113
82114 }
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -98,6 +98,11 @@
9999 'eporgpager-header-country' => 'Country',
100100 'eporgpager-filter-country' => 'Country',
101101
 102+ // Institution pager
 103+ 'epcoursepager-header-name' => 'Name',
 104+ 'epcoursepager-header-org-id' => 'Institution',
 105+ 'epcoursepager-filter-org-id' => 'Institution',
 106+
102107 // Special:EditInstitution
103108 'editinstitution-text' => 'Enter the institution details below and click submit to save your changes.',
104109 'educationprogram-org-edit-name' => 'Institution name',

Follow-up revisions

RevisionCommit summaryAuthorDate
r106703Follow up to r106702; fix casting issuejeroendedauw21:39, 19 December 2011

Status & tagging log