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

Revision: 113967
Author:   jeroendedauw
Date:     2012-03-15 22:51:58 +0000 (Thu, 15 Mar 2012)
Log Message:
-----------
work on adding special:StudentActivity

Modified Paths:
--------------
    trunk/extensions/EducationProgram/EducationProgram.hooks.php
    trunk/extensions/EducationProgram/EducationProgram.i18n.alias.php
    trunk/extensions/EducationProgram/EducationProgram.i18n.php
    trunk/extensions/EducationProgram/EducationProgram.php
    trunk/extensions/EducationProgram/EducationProgram.settings.php
    trunk/extensions/EducationProgram/sql/EducationProgram.sql

Added Paths:
-----------
    trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php
    trunk/extensions/EducationProgram/sql/AddActivityStuff.sql

Modified: trunk/extensions/EducationProgram/EducationProgram.hooks.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.hooks.php        
2012-03-15 22:40:27 UTC (rev 113966)
+++ trunk/extensions/EducationProgram/EducationProgram.hooks.php        
2012-03-15 22:51:58 UTC (rev 113967)
@@ -53,6 +53,14 @@
                        true
                ) );
 
+               $updater->addExtensionUpdate( array(
+                       'addField',
+                       'ep_users_per_course',
+                       'upc_time',
+                       dirname( __FILE__ ) . '/sql/AddActivityStuff.sql',
+                       true
+               ) );
+
                return true;
        }
 

Modified: trunk/extensions/EducationProgram/EducationProgram.i18n.alias.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.i18n.alias.php   
2012-03-15 22:40:27 UTC (rev 113966)
+++ trunk/extensions/EducationProgram/EducationProgram.i18n.alias.php   
2012-03-15 22:51:58 UTC (rev 113967)
@@ -26,10 +26,9 @@
        'Disenroll' => array( 'Disenroll' ),
        'CampusAmbassadors' => array( 'CampusAmbassadors' ),
        'OnlineAmbassadors' => array( 'OnlineAmbassadors' ),
-//     'CampusAmbassador' => array( 'CampusAmbassador' ),
-//     'OnlineAmbassador' => array( 'OnlineAmbassador' ),
        'OnlineAmbassadorProfile' => array( 'OnlineAmbassadorProfile' ),
        'CampusAmbassadorProfile' => array( 'CampusAmbassadorProfile' ),
+       'StudentActivity' => array( 'StudentActivity' ),
 );
 
 /** Dutch (Nederlands) */

Modified: trunk/extensions/EducationProgram/EducationProgram.i18n.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-03-15 
22:40:27 UTC (rev 113966)
+++ trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-03-15 
22:51:58 UTC (rev 113967)
@@ -200,6 +200,7 @@
        'special-onlineambassador' => 'Online ambassador',
        'special-campusambassador' => 'Campus ambassador',
        'special-disenroll' => 'Disenroll',
+       'special-studentactivity' => 'Student activity',
 
        // Course statuses
        'ep-course-status-passed' => 'Passed',
@@ -362,6 +363,12 @@
        'epoapager-header-courses' => 'Current courses',
        'ep-oa-noresults' => 'There are no Online Ambassadors to list.',
 
+       // Student activity pager
+       'epstudentactivitypager-header-user-id' => 'Student',
+       'epstudentactivitypager-header-org-id' => 'Institution',
+       'epstudentactivitypager-header-last-course' => 'Course',
+       'epstudentactivitypager-header-last-active' => 'Last activity',
+
        // Institution editing
        'editinstitution-text' => 'Enter the institution details below and 
click submit to save your changes.',
        'educationprogram-org-edit-name' => 'Institution name',
@@ -825,7 +832,6 @@
        'special-onlineambassador' => '{{doc-special|onlineambassador}}',
        'special-campusambassador' => '{{doc-special|campusambassador}}',
        'special-disenroll' => '{{doc-special|disenroll}}',
+       'special-studentactivity' => '{{doc-special|studentactivity}}',
 
-
-
 );

Modified: trunk/extensions/EducationProgram/EducationProgram.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.php      2012-03-15 
22:40:27 UTC (rev 113966)
+++ trunk/extensions/EducationProgram/EducationProgram.php      2012-03-15 
22:51:58 UTC (rev 113967)
@@ -142,6 +142,7 @@
 $wgAutoloadClasses['SpecialOAProfile']                                 = 
dirname( __FILE__ ) . '/specials/SpecialOAProfile.php';
 $wgAutoloadClasses['SpecialCAProfile']                                 = 
dirname( __FILE__ ) . '/specials/SpecialCAProfile.php';
 $wgAutoloadClasses['SpecialAmbassadorProfile']                 = dirname( 
__FILE__ ) . '/specials/SpecialAmbassadorProfile.php';
+$wgAutoloadClasses['SpecialStudentActivity']           = dirname( __FILE__ ) . 
'/specials/SpecialStudentActivity.php';
 
 // Special pages
 $wgSpecialPages['MyCourses']                                           = 
'SpecialMyCourses';
@@ -156,6 +157,7 @@
 $wgSpecialPages['OnlineAmbassadors']                           = 'SpecialOAs';
 $wgSpecialPages['CampusAmbassadorProfile']                     = 
'SpecialCAProfile';
 $wgSpecialPages['OnlineAmbassadorProfile']                     = 
'SpecialOAProfile';
+$wgSpecialPages['StudentActivity']                                     = 
'SpecialStudentActivity';
 
 $wgSpecialPageGroups['MyCourses']                                      = 
'education';
 $wgSpecialPageGroups['Institutions']                           = 'education';
@@ -169,6 +171,7 @@
 $wgSpecialPageGroups['OnlineAmbassadorProfile']        = 'education';
 $wgSpecialPageGroups['Enroll']                                                 
= 'education';
 $wgSpecialPageGroups['Disenroll']                                      = 
'education';
+$wgSpecialPageGroups['StudentActivity']                        = 'education';
 
 define( 'EP_STUDENT', 0 );
 define( 'EP_INSTRUCTOR', 1 );

Modified: trunk/extensions/EducationProgram/EducationProgram.settings.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.settings.php     
2012-03-15 22:40:27 UTC (rev 113966)
+++ trunk/extensions/EducationProgram/EducationProgram.settings.php     
2012-03-15 22:51:58 UTC (rev 113967)
@@ -34,7 +34,8 @@
                        ),
                        'ambassadorCommonsUrl' => 
'https://commons.wikimedia.org/wiki/Special:UploadWizard',
                        'citylessCountries' => array( 'BT', 'BV', 'IO', 'VG', 
'TD', 'CX', 'CC', 'KM', 'DJ', 'GQ', 'FK', 'FX', 'TF', 'GW', 'HM', 'KI', 'YT', 
'MS', 'NR', 'NU', 'NF', 'PN', 'SH', 'PM', 'WS', 'SC', 'GS', 'SJ', 'TK', 'TP', 
'TV', 'UM', 'VU', 'EH' ),
-                       'ambassadorImgWidth' => 140
+                       'ambassadorImgWidth' => 140,
+                       'recentActivityLimit' => 24 * 60 * 60,
                );
        }
 

Added: trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php
===================================================================
--- trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php       
                        (rev 0)
+++ trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php       
2012-03-15 22:51:58 UTC (rev 113967)
@@ -0,0 +1,237 @@
+<?php
+
+/**
+ * Page listing recent student activity.
+ *
+ * @since 0.1
+ *
+ * @file SpecialStudentActivity.php
+ * @ingroup EducationProgram
+ *
+ * @licence GNU GPL v3 or later
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class SpecialStudentActivity extends SpecialEPPage {
+
+       /**
+        * Constructor.
+        *
+        * @since 0.1
+        */
+       public function __construct() {
+               parent::__construct( 'StudentActivity' );
+       }
+
+       /**
+        * Main method.
+        *
+        * @since 0.1
+        *
+        * @param string $subPage
+        */
+       public function execute( $subPage ) {
+               parent::execute( $subPage );
+
+               $this->displayNavigation();
+
+               $out = $this->getOutput();
+
+               $pager = new EPStudentActivityPager( $this->getContext(), 
array() );
+
+               if ( $pager->getNumRows() ) {
+                       $out->addHTML(
+                               $pager->getFilterControl() .
+                               $pager->getNavigationBar() .
+                               $pager->getBody() .
+                               $pager->getNavigationBar() .
+                               $pager->getMultipleItemControl()
+                       );
+               }
+               else {
+                       $out->addHTML( $pager->getFilterControl( true ) );
+                       $out->addWikiMsg( 'ep-studentactivity-noresults' );
+               }
+       }
+
+}
+
+
+/**
+ * Student pager, primarily for Special:Students.
+ *
+ * @since 0.1
+ *
+ * @file EPStudentPager.php
+ * @ingroup EductaionProgram
+ *
+ * @licence GNU GPL v3 or later
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class EPStudentActivityPager extends EPPager {
+
+       /**
+        * List of user ids mapped to user names and real names, set in 
doBatchLookups.
+        * The real names will just hold the user name when no real name is set.
+        * user id => array( user name, real name )
+        *
+        * @since 0.1
+        * @var array
+        */
+       protected $userNames = array();
+
+       /**
+        * List of user ids with the names of their associated courses.
+        * user id => array( course name 0, ... )
+        *
+        * @since 0.1
+        * @var array
+        */
+       protected $courseNames = array();
+
+       /**
+        * Constructor.
+        *
+        * @param IContextSource $context
+        * @param array $conds
+        */
+       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' ) ) )
+//             );
+
+               parent::__construct( $context, $conds, EPStudents::singleton() 
);
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see EPPager::getFields()
+        */
+       public function getFields() {
+               return array(
+                       'id',
+                       'user_id',
+                       'last_course',
+                       'last_active',
+               );
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see TablePager::getRowClass()
+        */
+       function getRowClass( $row ) {
+               return 'ep-studentactivity-row';
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see TablePager::getTableClass()
+        */
+       public function getTableClass() {
+               return 'TablePager ep-studentactivity';
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see EPPager::getFormattedValue()
+        */
+       protected function getFormattedValue( $name, $value ) {
+               switch ( $name ) {
+                       case 'user_id':
+                               if ( array_key_exists( $value, $this->userNames 
) ) {
+                                       list( $userName, $realName ) = 
$this->userNames[$value];
+                                       $value = Linker::userLink( $value, 
$userName, $realName ) . Linker::userToolLinks( $value, $userName );
+                               }
+                               else {
+                                       wfWarn( 'User id not in 
$this->userNames in ' . __METHOD__ );
+                               }
+                               break;
+                       case 'first_enroll': case 'last_active':
+                       $value = htmlspecialchars( $this->getLanguage()->date( 
$value ) );
+                       break;
+               }
+
+               return $value;
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see EPPager::getSortableFields()
+        */
+       protected function getSortableFields() {
+               return array(
+               );
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see EPPager::hasActionsColumn()
+        */
+       protected function hasActionsColumn() {
+               return false;
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see IndexPager::getDefaultSort()
+        */
+       function getDefaultSort() {
+               return 'last_active';
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see EPPager::getFieldNames()
+        */
+       public function getFieldNames() {
+               $fields = parent::getFieldNames();
+
+               unset( $fields['id'] );
+
+               $fields = wfArrayInsertAfter( $fields, array( 'org_id' => 
'org-id' ), 'user_id' );
+
+               return $fields;
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see IndexPager::doBatchLookups()
+        */
+       protected function doBatchLookups() {
+               $userIds = array();
+               $field = $this->table->getPrefixedField( 'user_id' );
+
+               while( $student = $this->mResult->fetchObject() ) {
+                       $userIds[] = (int)$student->$field;
+               }
+
+               if ( !empty( $userIds ) ) {
+                       $result = wfGetDB( DB_SLAVE )->select(
+                               'user',
+                               array( 'user_id', 'user_name', 'user_real_name' 
),
+                               array( 'user_id' => $userIds ),
+                               __METHOD__
+                       );
+
+                       while( $user = $result->fetchObject() ) {
+                               $real = $user->user_real_name === '' ? 
$user->user_name : $user->user_real_name;
+                               $this->userNames[$user->user_id] = array( 
$user->user_name, $real );
+                       }
+
+                       $courseNameField = 
EPCourses::singleton()->getPrefixedField( 'name' );
+
+                       // TODO: $this->courseNames[] =
+               }
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see EPPager::getMsg()
+        */
+       protected function getMsg( $messageKey ) {
+               return wfMsg( strtolower( get_called_class() ) . '-' . 
str_replace( '_', '-', $messageKey ) );
+       }
+
+}
\ No newline at end of file

Added: trunk/extensions/EducationProgram/sql/AddActivityStuff.sql
===================================================================
--- trunk/extensions/EducationProgram/sql/AddActivityStuff.sql                  
        (rev 0)
+++ trunk/extensions/EducationProgram/sql/AddActivityStuff.sql  2012-03-15 
22:51:58 UTC (rev 113967)
@@ -0,0 +1,20 @@
+-- MySQL patch for the Education Program extension.
+-- Licence: GNU GPL v3+
+-- Author: Jeroen De Dauw < [email protected] >
+
+ALTER TABLE /*_*/ep_users_per_course ADD COLUMN upc_time varbinary(14) NOT 
NULL;
+
+CREATE INDEX /*i*/ep_upc_time ON /*_*/ep_users_per_course (upc_time);
+
+ALTER TABLE /*_*/ep_students ADD COLUMN student_last_enroll varbinary(14) NOT 
NULL;
+ALTER TABLE /*_*/ep_students ADD COLUMN student_last_course INT unsigned NOT 
NULL;
+ALTER TABLE /*_*/ep_students ADD COLUMN student_first_course INT unsigned NOT 
NULL;
+
+CREATE INDEX /*i*/ep_students_first_course ON /*_*/ep_students 
(student_first_course);
+CREATE INDEX /*i*/ep_students_last_enroll ON /*_*/ep_students 
(student_last_enroll);
+CREATE INDEX /*i*/ep_students_last_course ON /*_*/ep_students 
(student_last_course);
+
+UPDATE /*_*/ep_users_per_course SET upc_time = '20120315224638';
+UPDATE /*_*/ep_students SET student_last_enroll = '20120315224638';
+UPDATE /*_*/ep_students SET student_last_active = '20120315224638';
+

Modified: trunk/extensions/EducationProgram/sql/EducationProgram.sql
===================================================================
--- trunk/extensions/EducationProgram/sql/EducationProgram.sql  2012-03-15 
22:40:27 UTC (rev 113966)
+++ trunk/extensions/EducationProgram/sql/EducationProgram.sql  2012-03-15 
22:51:58 UTC (rev 113967)
@@ -100,28 +100,36 @@
 CREATE TABLE IF NOT EXISTS /*_*/ep_users_per_course (
   upc_user_id                INT unsigned        NOT NULL, -- Foreign key on 
ep_user.user_id
   upc_course_id              INT unsigned        NOT NULL, -- Foreign key on 
ep_courses.course_id
-  upc_role                   TINYINT unsigned    NOT NULL -- The role the user 
has for the course
+  upc_role                   TINYINT unsigned    NOT NULL, -- The role the 
user has for the course
+  upc_time                   varbinary(14)       NOT NULL -- Time at which the 
link was made
 ) /*$wgDBTableOptions*/;
 
 CREATE UNIQUE INDEX /*i*/ep_users_per_course ON /*_*/ep_users_per_course 
(upc_user_id, upc_course_id, upc_role);
 CREATE INDEX /*i*/ep_upc_course_id ON /*_*/ep_users_per_course (upc_course_id);
 CREATE INDEX /*i*/ep_upc_role ON /*_*/ep_users_per_course (upc_role);
+CREATE INDEX /*i*/ep_upc_time ON /*_*/ep_users_per_course (upc_time);
 
 
 
 -- Students. In essence this is an extension to the user table.
 CREATE TABLE IF NOT EXISTS /*_*/ep_students (
   student_id                 INT unsigned        NOT NULL auto_increment 
PRIMARY KEY,
+  student_user_id            INT unsigned        NOT NULL, -- Foreign key on 
user.user_id
 
-  student_user_id            INT unsigned        NOT NULL, -- Foreign key on 
user.user_id
+  -- Summary fields - cahing data or computations on data stored elswhere
   student_first_enroll       varbinary(14)       NOT NULL, -- Time of first 
enrollment
-
-  student_last_active        varbinary(14)       NOT NULL, -- Time of last 
activity
+  student_first_course       INT unsigned        NOT NULL, -- First course the 
user enrolled in
+  student_last_enroll        varbinary(14)       NOT NULL, -- Time of last 
enrollment
+  student_last_course        INT unsigned        NOT NULL, -- Last course the 
user enrolled in
+  student_last_active        varbinary(14)       NOT NULL, -- Time of last 
activity in article NS
   student_active_enroll      TINYINT unsigned    NOT NULL -- If the student is 
enrolled in any active courses
 ) /*$wgDBTableOptions*/;
 
 CREATE UNIQUE INDEX /*i*/ep_students_user_id ON /*_*/ep_students 
(student_user_id);
 CREATE INDEX /*i*/ep_students_first_enroll ON /*_*/ep_students 
(student_first_enroll);
+CREATE INDEX /*i*/ep_students_first_course ON /*_*/ep_students 
(student_first_course);
+CREATE INDEX /*i*/ep_students_last_enroll ON /*_*/ep_students 
(student_last_enroll);
+CREATE INDEX /*i*/ep_students_last_course ON /*_*/ep_students 
(student_last_course);
 CREATE INDEX /*i*/ep_students_last_active ON /*_*/ep_students 
(student_last_active);
 CREATE INDEX /*i*/ep_students_active_enroll ON /*_*/ep_students 
(student_active_enroll);
 


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

Reply via email to