Index: trunk/extensions/EducationProgram/specials/SpecialEnroll.php |
— | — | @@ -241,22 +241,14 @@ |
242 | 242 | |
243 | 243 | if ( !$hadStudent ) { |
244 | 244 | $student = EPStudents::singleton()->newFromArray( array( 'user_id' => $this->getUser()->getId() ), true ); |
245 | | - $fields['first_enroll'] = wfTimestamp( TS_MW ); |
246 | 245 | } |
247 | 246 | |
248 | 247 | $student->setFields( $fields ); |
249 | 248 | |
250 | 249 | $success = $student->save(); |
251 | 250 | |
252 | | - if ( $success ) { |
253 | | - $success = $student->associateWithCourses( array( $course ) ) && $success; |
| 251 | + $success = $success && $student->associateWithCourses( array( $course ) ); |
254 | 252 | |
255 | | - if ( !$hadStudent ) { |
256 | | - $this->getUser()->setOption( 'ep_showtoplink', true ); |
257 | | - $this->getUser()->saveSettings(); |
258 | | - } |
259 | | - } |
260 | | - |
261 | 253 | return $success; |
262 | 254 | } |
263 | 255 | |
Index: trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php |
— | — | @@ -97,9 +97,9 @@ |
98 | 98 | public function __construct( IContextSource $context, array $conds = array() ) { |
99 | 99 | $this->mDefaultDirection = true; |
100 | 100 | |
101 | | -// $conds[] = 'last_active > ' . wfGetDB( DB_SLAVE )->addQuotes( |
102 | | -// wfTimestamp( TS_MW, time() - ( EPSettings::get( 'recentActivityLimit' ) ) ) |
103 | | -// ); |
| 101 | + $conds[] = 'last_active > ' . wfGetDB( DB_SLAVE )->addQuotes( |
| 102 | + wfTimestamp( TS_MW, time() - ( EPSettings::get( 'recentActivityLimit' ) ) ) |
| 103 | + ); |
104 | 104 | |
105 | 105 | parent::__construct( $context, $conds, EPStudents::singleton() ); |
106 | 106 | } |
Index: trunk/extensions/EducationProgram/includes/EPStudentPager.php |
— | — | @@ -55,7 +55,7 @@ |
56 | 56 | 'user_id', |
57 | 57 | 'first_enroll', |
58 | 58 | 'last_active', |
59 | | - 'active_enroll', |
| 59 | + //'active_enroll', |
60 | 60 | ); |
61 | 61 | } |
62 | 62 | |
Index: trunk/extensions/EducationProgram/includes/EPStudents.php |
— | — | @@ -55,7 +55,9 @@ |
56 | 56 | |
57 | 57 | 'user_id' => 'int', |
58 | 58 | 'first_enroll' => 'str', // TS_MW |
59 | | - |
| 59 | + 'first_course' => 'int', |
| 60 | + 'last_enroll' => 'str', // TS_MW |
| 61 | + 'last_course' => 'int', |
60 | 62 | 'last_active' => 'str', // TS_MW |
61 | 63 | 'active_enroll' => 'bool', |
62 | 64 | ); |
Index: trunk/extensions/EducationProgram/includes/EPStudent.php |
— | — | @@ -72,4 +72,24 @@ |
73 | 73 | $this->setFields( $fields ); |
74 | 74 | } |
75 | 75 | |
| 76 | + /** |
| 77 | + * Should be called whenever a user is enrolled as student. |
| 78 | + * |
| 79 | + * @since 0.1 |
| 80 | + * |
| 81 | + * @param integer $courseId |
| 82 | + */ |
| 83 | + public function onEnrolled( $courseId ) { |
| 84 | + if ( !$this->hasField( 'first_course' ) ) { |
| 85 | + $this->setField( 'first_course', $courseId ); |
| 86 | + $this->setField( 'first_enroll', wfTimestampNow() ); |
| 87 | + } |
| 88 | + |
| 89 | + $this->setField( 'last_course', $courseId ); |
| 90 | + $this->setField( 'last_enroll', wfTimestampNow() ); |
| 91 | + |
| 92 | + $this->getUser()->setOption( 'ep_showtoplink', true ); |
| 93 | + $this->getUser()->saveSettings(); |
| 94 | + } |
| 95 | + |
76 | 96 | } |
Index: trunk/extensions/EducationProgram/includes/EPCourse.php |
— | — | @@ -590,6 +590,14 @@ |
591 | 591 | $this->enableLogging(); |
592 | 592 | } |
593 | 593 | |
| 594 | + if ( $success && $role === 'student' ) { |
| 595 | + foreach ( $addedUsers as $userId ) { |
| 596 | + $student = EPStudent::newFromUserId( $userId, true, 'id' ); |
| 597 | + $student->onEnrolled( $this->getId() ); |
| 598 | + $student->save(); |
| 599 | + } |
| 600 | + } |
| 601 | + |
594 | 602 | if ( $success && !is_null( $revAction ) ) { |
595 | 603 | $action = count( $addedUsers ) == 1 && $revAction->getUser()->getId() === $addedUsers[0] ? 'selfadd' : 'add'; |
596 | 604 | $this->logRoleChange( $action, $role, $addedUsers, $revAction->getComment() ); |