Index: trunk/extensions/EducationProgram/includes/EPTermPager.php |
— | — | @@ -108,6 +108,11 @@ |
109 | 109 | * @see EPPager::getFilterOptions() |
110 | 110 | */ |
111 | 111 | 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 | + |
112 | 117 | return array( |
113 | 118 | 'course_id' => array( |
114 | 119 | 'type' => 'select', |
— | — | @@ -120,12 +125,8 @@ |
121 | 126 | ), |
122 | 127 | 'year' => array( |
123 | 128 | 'type' => 'select', |
124 | | - 'options' => array_merge( |
125 | | - array( '' => '' ), |
126 | | - array() // TODO |
127 | | - ), |
| 129 | + 'options' => $years, |
128 | 130 | 'value' => '', |
129 | | - 'datatype' => 'int', |
130 | 131 | ), |
131 | 132 | ); |
132 | 133 | } |
Index: trunk/extensions/EducationProgram/includes/EPDBObject.php |
— | — | @@ -720,7 +720,7 @@ |
721 | 721 | |
722 | 722 | /** |
723 | 723 | * 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. |
725 | 725 | * |
726 | 726 | * @since 0.1 |
727 | 727 | * |
— | — | @@ -732,6 +732,34 @@ |
733 | 733 | * @return array of self |
734 | 734 | */ |
735 | 735 | 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 ) { |
736 | 764 | if ( is_null( $fields ) ) { |
737 | 765 | $fields = array_keys( static::getFieldTypes() ); |
738 | 766 | } |
— | — | @@ -753,8 +781,23 @@ |
754 | 782 | $objects = array(); |
755 | 783 | |
756 | 784 | foreach ( $result as $record ) { |
757 | | - $objects[] = static::newFromDBResult( $record ); |
| 785 | + $objects[] = static::getFieldsFromDBResult( $record ); |
758 | 786 | } |
| 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 | + } |
759 | 802 | |
760 | 803 | return $objects; |
761 | 804 | } |
— | — | @@ -804,13 +847,14 @@ |
805 | 848 | * @param array|string|null $fields |
806 | 849 | * @param array $conditions |
807 | 850 | * @param array $options |
| 851 | + * @param array $joinConds |
808 | 852 | * |
809 | | - * @return self|false |
| 853 | + * @return EPBObject|false |
810 | 854 | */ |
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() ) { |
812 | 856 | $options['LIMIT'] = 1; |
813 | 857 | |
814 | | - $objects = static::select( $fields, $conditions, $options ); |
| 858 | + $objects = static::select( $fields, $conditions, $options, $joinConds ); |
815 | 859 | |
816 | 860 | return count( $objects ) > 0 ? $objects[0] : false; |
817 | 861 | } |