Index: trunk/extensions/EducationProgram/maintenance/importWEPData.php |
— | — | @@ -79,7 +79,14 @@ |
80 | 80 | echo "Import completed!\n\n"; |
81 | 81 | } |
82 | 82 | |
83 | | - protected function insertOrgs( array $orgs ) { |
| 83 | + /** |
| 84 | + * Insert the orgs. |
| 85 | + * |
| 86 | + * @since 0.1 |
| 87 | + * |
| 88 | + * @param array $orgs Org names as keys. Values get set to the id after insertion. |
| 89 | + */ |
| 90 | + protected function insertOrgs( array &$orgs ) { |
84 | 91 | wfGetDB( DB_MASTER )->begin(); |
85 | 92 | |
86 | 93 | foreach ( $orgs as $org => &$id ) { |
— | — | @@ -98,6 +105,14 @@ |
99 | 106 | wfGetDB( DB_MASTER )->commit(); |
100 | 107 | } |
101 | 108 | |
| 109 | + /** |
| 110 | + * Insert the courses. |
| 111 | + * |
| 112 | + * @param array $courses |
| 113 | + * @param array $orgs |
| 114 | + * |
| 115 | + * @return array Inserted courses. keys are names, values are ids |
| 116 | + */ |
102 | 117 | protected function insertCourses( array $courses, array $orgs ) { |
103 | 118 | $courseIds = array(); |
104 | 119 | |
— | — | @@ -125,6 +140,17 @@ |
126 | 141 | return $courseIds; |
127 | 142 | } |
128 | 143 | |
| 144 | + /** |
| 145 | + * Insert the students. |
| 146 | + * Create user account if none matches the name yet. |
| 147 | + * Create student profile if none matches the user yet. |
| 148 | + * Associate with courses. |
| 149 | + * |
| 150 | + * @since 0.1 |
| 151 | + * |
| 152 | + * @param array $students Keys are names, values are arrays with course names |
| 153 | + * @param array $courseIds Maps course names to ids |
| 154 | + */ |
129 | 155 | protected function insertStudents( array $students, array $courseIds ) { |
130 | 156 | foreach ( $students as $student => $courseNames ) { |
131 | 157 | $name = $student; |
— | — | @@ -145,15 +171,7 @@ |
146 | 172 | else { |
147 | 173 | $student = EPStudent::newFromUser( $user ); |
148 | 174 | |
149 | | - if ( $student === false ) { |
150 | | - $student = new EPStudent( |
151 | | - array( |
152 | | - 'user_id' => $user->getId(), |
153 | | - 'first_enroll' => wfTimestamp( TS_MW ) |
154 | | - ), |
155 | | - true |
156 | | - ); |
157 | | - |
| 175 | + if ( is_null( $student->getId() ) ) { |
158 | 176 | if ( !$student->save() ) { |
159 | 177 | echo "Failed to insert student '$name'. (failed create student profile)\n"; |
160 | 178 | continue; |
Index: trunk/extensions/EducationProgram/actions/EditCourseAction.php |
— | — | @@ -100,8 +100,6 @@ |
101 | 101 | * @return array |
102 | 102 | */ |
103 | 103 | protected function titleToNameAndTerm( $titleText ) { |
104 | | - $term = ''; |
105 | | - |
106 | 104 | $matches = array(); |
107 | 105 | preg_match( '/(.*)\((.*)\)/', $titleText, $matches ); |
108 | 106 | |
— | — | @@ -109,6 +107,10 @@ |
110 | 108 | $name = trim( $matches[1] ); |
111 | 109 | $term = trim( $matches[2] ); |
112 | 110 | } |
| 111 | + else { |
| 112 | + $name = $titleText; |
| 113 | + $term = ''; |
| 114 | + } |
113 | 115 | |
114 | 116 | return array( $name, $term ); |
115 | 117 | } |
Index: trunk/extensions/EducationProgram/includes/EPRoleObject.php |
— | — | @@ -52,7 +52,7 @@ |
53 | 53 | $class = $map[get_called_class()]; |
54 | 54 | $table = $class::singleton(); |
55 | 55 | |
56 | | - $userRole = $table->selectRow( null, $data ); |
| 56 | + $userRole = $table->selectRow( $fields, $data ); |
57 | 57 | return $userRole === false ? new static( $table, $data, true ) : $userRole; |
58 | 58 | } |
59 | 59 | |