https://www.mediawiki.org/wiki/Special:Code/MediaWiki/111907
Revision: 111907
Author: jeroendedauw
Date: 2012-02-20 02:14:42 +0000 (Mon, 20 Feb 2012)
Log Message:
-----------
fixed some small issues and added docs
Modified Paths:
--------------
trunk/extensions/EducationProgram/actions/EditCourseAction.php
trunk/extensions/EducationProgram/includes/EPRoleObject.php
trunk/extensions/EducationProgram/maintenance/importWEPData.php
Modified: trunk/extensions/EducationProgram/actions/EditCourseAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EditCourseAction.php
2012-02-20 02:12:48 UTC (rev 111906)
+++ trunk/extensions/EducationProgram/actions/EditCourseAction.php
2012-02-20 02:14:42 UTC (rev 111907)
@@ -100,8 +100,6 @@
* @return array
*/
protected function titleToNameAndTerm( $titleText ) {
- $term = '';
-
$matches = array();
preg_match( '/(.*)\((.*)\)/', $titleText, $matches );
@@ -109,6 +107,10 @@
$name = trim( $matches[1] );
$term = trim( $matches[2] );
}
+ else {
+ $name = $titleText;
+ $term = '';
+ }
return array( $name, $term );
}
Modified: trunk/extensions/EducationProgram/includes/EPRoleObject.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPRoleObject.php 2012-02-20
02:12:48 UTC (rev 111906)
+++ trunk/extensions/EducationProgram/includes/EPRoleObject.php 2012-02-20
02:14:42 UTC (rev 111907)
@@ -52,7 +52,7 @@
$class = $map[get_called_class()];
$table = $class::singleton();
- $userRole = $table->selectRow( null, $data );
+ $userRole = $table->selectRow( $fields, $data );
return $userRole === false ? new static( $table, $data, true )
: $userRole;
}
Modified: trunk/extensions/EducationProgram/maintenance/importWEPData.php
===================================================================
--- trunk/extensions/EducationProgram/maintenance/importWEPData.php
2012-02-20 02:12:48 UTC (rev 111906)
+++ trunk/extensions/EducationProgram/maintenance/importWEPData.php
2012-02-20 02:14:42 UTC (rev 111907)
@@ -79,7 +79,14 @@
echo "Import completed!\n\n";
}
- protected function insertOrgs( array $orgs ) {
+ /**
+ * Insert the orgs.
+ *
+ * @since 0.1
+ *
+ * @param array $orgs Org names as keys. Values get set to the id after
insertion.
+ */
+ protected function insertOrgs( array &$orgs ) {
wfGetDB( DB_MASTER )->begin();
foreach ( $orgs as $org => &$id ) {
@@ -98,6 +105,14 @@
wfGetDB( DB_MASTER )->commit();
}
+ /**
+ * Insert the courses.
+ *
+ * @param array $courses
+ * @param array $orgs
+ *
+ * @return array Inserted courses. keys are names, values are ids
+ */
protected function insertCourses( array $courses, array $orgs ) {
$courseIds = array();
@@ -125,6 +140,17 @@
return $courseIds;
}
+ /**
+ * Insert the students.
+ * Create user account if none matches the name yet.
+ * Create student profile if none matches the user yet.
+ * Associate with courses.
+ *
+ * @since 0.1
+ *
+ * @param array $students Keys are names, values are arrays with course
names
+ * @param array $courseIds Maps course names to ids
+ */
protected function insertStudents( array $students, array $courseIds ) {
foreach ( $students as $student => $courseNames ) {
$name = $student;
@@ -145,15 +171,7 @@
else {
$student = EPStudent::newFromUser(
$user );
- if ( $student === false ) {
- $student = new EPStudent(
- array(
- 'user_id' =>
$user->getId(),
- 'first_enroll'
=> wfTimestamp( TS_MW )
- ),
- true
- );
-
+ if ( is_null( $student->getId() ) ) {
if ( !$student->save() ) {
echo "Failed to insert
student '$name'. (failed create student profile)\n";
continue;
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs