r107667 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107666‎ | r107667 | r107668 >
Date:22:48, 30 December 2011
Author:jeroendedauw
Status:deferred
Tags:educationprogram 
Comment:
fixes to queries
Modified paths:
  • /trunk/extensions/EducationProgram/includes/EPDBObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPMentor.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPStudent.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/includes/EPMentor.php
@@ -77,7 +77,7 @@
7878 */
7979 protected function doGetOrgs( $fields, array $conditions ) {
8080 $conditions = array_merge(
81 - array( array( 'ep_mentors_per_org', 'mentor_id' ), $this->getId() ),
 81+ array( array( 'ep_mentors', 'id' ), $this->getId() ),
8282 $conditions
8383 );
8484
@@ -85,7 +85,10 @@
8686 $fields,
8787 $conditions,
8888 array(),
89 - array( 'orgs' => array( 'INNER JOIN', array( array( array( 'ep_mentors_per_org', 'org_id' ), array( 'orgs', 'id' ) ) ) ) )
 89+ array(
 90+ 'ep_mentors_per_org' => array( 'INNER JOIN', array( array( array( 'ep_mentors_per_org', 'org_id' ), array( 'orgs', 'id' ) ) ) ),
 91+ 'ep_mentors' => array( 'INNER JOIN', array( array( array( 'ep_mentors_per_org', 'mentor_id' ), array( 'ep_mentors', 'id' ) ) ) )
 92+ )
9093 );
9194 }
9295
Index: trunk/extensions/EducationProgram/includes/EPStudent.php
@@ -86,12 +86,12 @@
8787 *
8888 * @since 0.1
8989 *
90 - * @param array|null $fields
 90+ * @param string|array|null $fields
9191 * @param array $conditions
9292 *
9393 * @return array of EPTerm
9494 */
95 - public function getTerms( array $fields = null, array $conditions = array() ) {
 95+ public function getTerms( $fields = null, array $conditions = array() ) {
9696 if ( count( $conditions ) !== 0 ) {
9797 return $this->doGetTerms( $fields, $conditions );
9898 }
@@ -115,22 +115,22 @@
116116 *
117117 * @since 0.1
118118 *
119 - * @param array|null $fields
 119+ * @param string|array|null $fields
120120 * @param array $conditions
121121 *
122122 * @return array of EPTerm
123123 */
124124 protected function doGetTerms( $fields, array $conditions ) {
125 - $conditions = array_merge(
126 - array( array( 'ep_students_per_term', 'student_id' ), $this->getId() ),
127 - $conditions
128 - );
 125+ $conditions[] = array( array( 'ep_students', 'id' ), $this->getId() );
129126
130127 return EPTerm::select(
131128 $fields,
132129 $conditions,
133130 array(),
134 - array( 'terms' => array( 'INNER JOIN', array( array( array( 'ep_students_per_term', 'term_id' ), array( 'terms', 'id' ) ) ) ) )
 131+ array(
 132+ 'ep_students_per_term' => array( 'INNER JOIN', array( array( array( 'ep_students_per_term', 'term_id' ), array( 'ep_terms', 'id' ) ) ) ),
 133+ 'ep_students' => array( 'INNER JOIN', array( array( array( 'ep_students_per_term', 'student_id' ), array( 'ep_students', 'id' ) ) ) )
 134+ )
135135 );
136136 }
137137
Index: trunk/extensions/EducationProgram/includes/EPDBObject.php
@@ -552,8 +552,8 @@
553553 static $prefixes = false;
554554
555555 if ( $prefixes === false ) {
556 - foreach ( $GLOBALS['egEPDBObjects'] as $classOrIndex => $object ) {
557 - $prefixes[$object['table']] = $object['prefix'];
 556+ foreach ( $GLOBALS['egEPDBObjects'] as $classInfo ) {
 557+ $prefixes[$classInfo['table']] = $classInfo['prefix'];
558558 }
559559 }
560560
@@ -578,7 +578,7 @@
579579 * their values as value. The field names are prefixed with the
580580 * db field prefix.
581581 *
582 - * Field names can also be provdied as an array with as first element a table name, such as
 582+ * Field names can also be provided as an array with as first element a table name, such as
583583 * $conditions = array(
584584 * array( array( 'tablename', 'fieldname' ), $value ),
585585 * );
@@ -775,7 +775,7 @@
776776
777777 $tables = array( static::getDBTable() );
778778 $joinConds = static::getProcessedJoinConds( $joinConds, $tables );
779 -
 779+
780780 $result = static::rawSelect(
781781 static::getPrefixedFields( $fields ),
782782 static::getPrefixedValues( $conditions ),
@@ -834,13 +834,21 @@
835835 static::getPrefixedField( $joinCondPart[0] ),
836836 static::getPrefixedField( $joinCondPart[1] ),
837837 );
838 -
 838+
 839+ if ( !in_array( $joinCondPart[0][0], $tables ) ) {
 840+ $tables[] = $joinCondPart[0][0];
 841+ }
 842+
 843+ if ( !in_array( $joinCondPart[1][0], $tables ) ) {
 844+ $tables[] = $joinCondPart[1][0];
 845+ }
 846+
839847 $cond[1][] = implode( '=', $parts );
840848 }
841849
842 - $conds = $cond;
 850+ $conds[] = $cond;
843851 }
844 -
 852+ //if (count($conds)) {q($conds);}
845853 return $conds;
846854 }
847855
@@ -864,7 +872,7 @@
865873
866874 return count( $objects ) > 0 ? $objects[0] : false;
867875 }
868 -
 876+
869877 /**
870878 * Selects the the specified fields of the first record matching the provided
871879 * conditions and returns it as an associative array, or false when nothing matches.
@@ -957,7 +965,7 @@
958966
959967 /**
960968 * Update the records matching the provided conditions by
961 - * setting the fields that are keys in the $values patam to
 969+ * setting the fields that are keys in the $values param to
962970 * their corresponding values.
963971 *
964972 * @since 0.1

Status & tagging log