r106904 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106903‎ | r106904 | r106905 >
Date:00:34, 21 December 2011
Author:jeroendedauw
Status:deferred
Tags:educationprogram 
Comment:
work on year filter - added functions to obtain arrays with fields instead of instances of the db class
Modified paths:
  • /trunk/extensions/EducationProgram/includes/EPDBObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPTermPager.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/includes/EPTermPager.php
@@ -108,6 +108,11 @@
109109 * @see EPPager::getFilterOptions()
110110 */
111111 protected function getFilterOptions() {
 112+ $years = EPTerm::selectFields( 'year', array(), array( 'DISTINCT' ), array(), true );
 113+ asort( $years, SORT_NUMERIC );
 114+ $years = array_merge( array( '' ), $years );
 115+ $years = array_combine( $years, $years );
 116+
112117 return array(
113118 'course_id' => array(
114119 'type' => 'select',
@@ -120,12 +125,8 @@
121126 ),
122127 'year' => array(
123128 'type' => 'select',
124 - 'options' => array_merge(
125 - array( '' => '' ),
126 - array() // TODO
127 - ),
 129+ 'options' => $years,
128130 'value' => '',
129 - 'datatype' => 'int',
130131 ),
131132 );
132133 }
Index: trunk/extensions/EducationProgram/includes/EPDBObject.php
@@ -720,7 +720,7 @@
721721
722722 /**
723723 * Selects the the specified fields of the records matching the provided
724 - * conditions. Field names get prefixed.
 724+ * conditions and returns them as EPDBObject. Field names get prefixed.
725725 *
726726 * @since 0.1
727727 *
@@ -732,6 +732,34 @@
733733 * @return array of self
734734 */
735735 public static function select( $fields = null, array $conditions = array(), array $options = array(), array $joinConds = array() ) {
 736+ $result = static::selectFields( $fields, $conditions, $options, $joinConds );
 737+
 738+ $objects = array();
 739+
 740+ foreach ( $result as $record ) {
 741+ $objects[] = static::newFromArray( $record );
 742+ }
 743+
 744+ return $objects;
 745+ }
 746+
 747+ /**
 748+ * Selects the the specified fields of the records matching the provided
 749+ * conditions and returns them as associative arrays.
 750+ * Provided field names get prefixed.
 751+ * Returned field names will not have a prefix.
 752+ *
 753+ * @since 0.1
 754+ *
 755+ * @param array|string|null $fields
 756+ * @param array $conditions
 757+ * @param array $options
 758+ * @param array $joinConds
 759+ * @param boolean $collapse
 760+ *
 761+ * @return array of array
 762+ */
 763+ public static function selectFields( $fields = null, array $conditions = array(), array $options = array(), array $joinConds = array(), $collapse = false ) {
736764 if ( is_null( $fields ) ) {
737765 $fields = array_keys( static::getFieldTypes() );
738766 }
@@ -753,8 +781,23 @@
754782 $objects = array();
755783
756784 foreach ( $result as $record ) {
757 - $objects[] = static::newFromDBResult( $record );
 785+ $objects[] = static::getFieldsFromDBResult( $record );
758786 }
 787+
 788+ if ( $collapse ) {
 789+ if ( count( $fields ) === 1 ) {
 790+ $objects = array_map( function( $object ) { return array_shift( $object ); }, $objects );
 791+ }
 792+ elseif ( count( $fields ) === 2 ) {
 793+ $o = array();
 794+
 795+ foreach ( $objects as $object ) {
 796+ $o[array_shift( $object )] = array_shift( $object );
 797+ }
 798+
 799+ $objects = $o;
 800+ }
 801+ }
759802
760803 return $objects;
761804 }
@@ -804,13 +847,14 @@
805848 * @param array|string|null $fields
806849 * @param array $conditions
807850 * @param array $options
 851+ * @param array $joinConds
808852 *
809 - * @return self|false
 853+ * @return EPBObject|false
810854 */
811 - public static function selectRow( $fields = null, array $conditions = array(), array $options = array() ) {
 855+ public static function selectRow( $fields = null, array $conditions = array(), array $options = array(), array $joinConds = array() ) {
812856 $options['LIMIT'] = 1;
813857
814 - $objects = static::select( $fields, $conditions, $options );
 858+ $objects = static::select( $fields, $conditions, $options, $joinConds );
815859
816860 return count( $objects ) > 0 ? $objects[0] : false;
817861 }

Status & tagging log