https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113975

Revision: 113975
Author:   jeroendedauw
Date:     2012-03-15 23:21:29 +0000 (Thu, 15 Mar 2012)
Log Message:
-----------
Follow up to r113967; 

Modified Paths:
--------------
    trunk/extensions/EducationProgram/includes/EPCourse.php
    trunk/extensions/EducationProgram/includes/EPStudent.php
    trunk/extensions/EducationProgram/includes/EPStudentPager.php
    trunk/extensions/EducationProgram/includes/EPStudents.php
    trunk/extensions/EducationProgram/specials/SpecialEnroll.php
    trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php

Modified: trunk/extensions/EducationProgram/includes/EPCourse.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPCourse.php     2012-03-15 
23:17:03 UTC (rev 113974)
+++ trunk/extensions/EducationProgram/includes/EPCourse.php     2012-03-15 
23:21:29 UTC (rev 113975)
@@ -590,6 +590,14 @@
                                $this->enableLogging();
                        }
 
+                       if ( $success && $role === 'student' ) {
+                               foreach ( $addedUsers as $userId ) {
+                                       $student = EPStudent::newFromUserId( 
$userId, true, 'id' );
+                                       $student->onEnrolled( $this->getId() );
+                                       $student->save();
+                               }
+                       }
+
                        if ( $success && !is_null( $revAction ) ) {
                                $action = count( $addedUsers ) == 1 && 
$revAction->getUser()->getId() === $addedUsers[0] ? 'selfadd' : 'add';
                                $this->logRoleChange( $action, $role, 
$addedUsers, $revAction->getComment() );

Modified: trunk/extensions/EducationProgram/includes/EPStudent.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPStudent.php    2012-03-15 
23:17:03 UTC (rev 113974)
+++ trunk/extensions/EducationProgram/includes/EPStudent.php    2012-03-15 
23:21:29 UTC (rev 113975)
@@ -72,4 +72,24 @@
                $this->setFields( $fields );
        }
 
+       /**
+        * Should be called whenever a user is enrolled as student.
+        *
+        * @since 0.1
+        *
+        * @param integer $courseId
+        */
+       public function onEnrolled( $courseId ) {
+               if ( !$this->hasField( 'first_course' ) ) {
+                       $this->setField( 'first_course', $courseId );
+                       $this->setField( 'first_enroll', wfTimestampNow() );
+               }
+
+               $this->setField( 'last_course', $courseId );
+               $this->setField( 'last_enroll', wfTimestampNow() );
+
+               $this->getUser()->setOption( 'ep_showtoplink', true );
+               $this->getUser()->saveSettings();
+       }
+
 }

Modified: trunk/extensions/EducationProgram/includes/EPStudentPager.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPStudentPager.php       
2012-03-15 23:17:03 UTC (rev 113974)
+++ trunk/extensions/EducationProgram/includes/EPStudentPager.php       
2012-03-15 23:21:29 UTC (rev 113975)
@@ -55,7 +55,7 @@
                        'user_id',
                        'first_enroll',
                        'last_active',
-                       'active_enroll',
+                       //'active_enroll',
                );
        }
 

Modified: trunk/extensions/EducationProgram/includes/EPStudents.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPStudents.php   2012-03-15 
23:17:03 UTC (rev 113974)
+++ trunk/extensions/EducationProgram/includes/EPStudents.php   2012-03-15 
23:21:29 UTC (rev 113975)
@@ -55,7 +55,9 @@
 
                        'user_id' => 'int',
                        'first_enroll' => 'str', // TS_MW
-
+                       'first_course' => 'int',
+                       'last_enroll' => 'str', // TS_MW
+                       'last_course' => 'int',
                        'last_active' => 'str', // TS_MW
                        'active_enroll' => 'bool',
                );

Modified: trunk/extensions/EducationProgram/specials/SpecialEnroll.php
===================================================================
--- trunk/extensions/EducationProgram/specials/SpecialEnroll.php        
2012-03-15 23:17:03 UTC (rev 113974)
+++ trunk/extensions/EducationProgram/specials/SpecialEnroll.php        
2012-03-15 23:21:29 UTC (rev 113975)
@@ -241,22 +241,14 @@
 
                if ( !$hadStudent ) {
                        $student = EPStudents::singleton()->newFromArray( 
array( 'user_id' => $this->getUser()->getId() ), true );
-                       $fields['first_enroll'] = wfTimestamp( TS_MW );
                }
 
                $student->setFields( $fields );
 
                $success = $student->save();
 
-               if ( $success ) {
-                       $success = $student->associateWithCourses( array( 
$course ) ) && $success;
+               $success = $success && $student->associateWithCourses( array( 
$course ) );
 
-                       if ( !$hadStudent ) {
-                               $this->getUser()->setOption( 'ep_showtoplink', 
true );
-                               $this->getUser()->saveSettings();
-                       }
-               }
-
                return $success;
        }
 

Modified: trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php
===================================================================
--- trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php       
2012-03-15 23:17:03 UTC (rev 113974)
+++ trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php       
2012-03-15 23:21:29 UTC (rev 113975)
@@ -97,9 +97,9 @@
        public function __construct( IContextSource $context, array $conds = 
array() ) {
                $this->mDefaultDirection = true;
 
-//             $conds[] = 'last_active > ' . wfGetDB( DB_SLAVE )->addQuotes(
-//                     wfTimestamp( TS_MW, time() - ( EPSettings::get( 
'recentActivityLimit' ) ) )
-//             );
+               $conds[] = 'last_active > ' . wfGetDB( DB_SLAVE )->addQuotes(
+                       wfTimestamp( TS_MW, time() - ( EPSettings::get( 
'recentActivityLimit' ) ) )
+               );
 
                parent::__construct( $context, $conds, EPStudents::singleton() 
);
        }


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to