Index: trunk/extensions/EducationProgram/EducationProgram.i18n.alias.php |
— | — | @@ -28,5 +28,6 @@ |
29 | 29 | 'EducationProgram' => array( 'EducationProgram' ), |
30 | 30 | 'EditCourse' => array( 'EditCourse' ), |
31 | 31 | 'EditInstitution' => array( 'EditInstitution' ), |
| 32 | + 'EditTerm' => array( 'EditTerm' ), |
32 | 33 | 'Enroll' => array( 'Enroll' ), |
33 | 34 | ); |
Index: trunk/extensions/EducationProgram/sql/EducationProgram.sql |
— | — | @@ -38,6 +38,7 @@ |
39 | 39 | CREATE INDEX /*i*/ep_term_year ON /*_*/ep_terms (term_year); |
40 | 40 | CREATE INDEX /*i*/ep_term_start ON /*_*/ep_terms (term_start); |
41 | 41 | CREATE INDEX /*i*/ep_term_end ON /*_*/ep_terms (term_end); |
| 42 | +CREATE UNIQUE INDEX /*i*/ep_trem_period ON /*_*/ep_terms (term_org_id, term_start, term_start); |
42 | 43 | |
43 | 44 | -- Students. In essence this is an extension to the user table. |
44 | 45 | CREATE TABLE IF NOT EXISTS /*_*/ep_students ( |
— | — | @@ -94,4 +95,4 @@ |
95 | 96 | CREATE INDEX /*i*/ep_revision_deleted ON /*_*/ep_revisions (rev_deleted); |
96 | 97 | |
97 | 98 | -- TODO: figure out how to best do logging. |
\ No newline at end of file |
| 99 | +-- Can the core stuff be used in a sane way for this? |
Index: trunk/extensions/EducationProgram/specials/SpecialEnroll.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | * @since 0.1 |
21 | 21 | */ |
22 | 22 | public function __construct() { |
23 | | - parent::__construct( 'Enroll', 'epstudent', false ); |
| 23 | + parent::__construct( 'Enroll', '', false ); |
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
— | — | @@ -32,9 +32,82 @@ |
33 | 33 | public function execute( $subPage ) { |
34 | 34 | parent::execute( $subPage ); |
35 | 35 | |
| 36 | + $args = explode( '/', $this->subPage, 2 ); |
| 37 | + |
| 38 | + if ( !ctype_digit( $args[0] ) ) { |
| 39 | + $this->showWarning( wfMessage( $args[0] === '' ? 'ep-enroll-no-id' : 'ep-enroll-invalid-id' ) ); |
| 40 | + } |
| 41 | + elseif ( count( $args ) === 1 ) { |
| 42 | + // TODO: might want to have an input here |
| 43 | + $this->showWarning( wfMessage( 'ep-enroll-no-token' ) ); |
| 44 | + } |
| 45 | + elseif ( count( $args ) === 2 ) { |
| 46 | + $term = EPTerm::selectRow( null, array( |
| 47 | + 'id' => $args[0], |
| 48 | + 'token' => strtolower( $args[1] ) |
| 49 | + ) ); |
| 50 | + |
| 51 | + if ( $term === false ) { |
| 52 | + $this->showWarning( wfMessage( 'ep-enroll-invalid-token' ) ); |
| 53 | + } |
| 54 | + else { |
| 55 | + if ( $this->getUser()->isLoggedIn() ) { |
| 56 | + if ( $this->getUser()->isAllowed( 'epstudent' ) ) { |
| 57 | + $this->showEntrollmentForm( $term ); |
| 58 | + } |
| 59 | + else { |
| 60 | + $this->showWarning( wfMessage( 'ep-enroll-not-allowed' ) ); |
| 61 | + } |
| 62 | + } |
| 63 | + else { |
| 64 | + $this->showSignupLink( $term ); |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * |
| 73 | + * |
| 74 | + * @param EPTerm $term |
| 75 | + * |
| 76 | + * @since 0.1 |
| 77 | + */ |
| 78 | + protected function showSignupLink( EPTerm $term ) { |
36 | 79 | $out = $this->getOutput(); |
37 | | - |
38 | | - // TODO: AUTH |
| 80 | + |
| 81 | + $out->addWikiMsg( 'ep-enroll-login-first' ); |
| 82 | + |
| 83 | + $out->addHTML( Linker::linkKnown( |
| 84 | + SpecialPage::getTitleFor( 'UserLogin' ), |
| 85 | + wfMsgHtml( 'ep-enroll-login-and-entroll' ), |
| 86 | + array(), |
| 87 | + array( |
| 88 | + 'returnto' => $this->getTitle( $this->subPage )->getFullText() |
| 89 | + ) |
| 90 | + ) ); |
| 91 | + |
| 92 | + $out->addHTML( Linker::linkKnown( |
| 93 | + SpecialPage::getTitleFor( 'UserLogin' ), |
| 94 | + wfMsgHtml( 'ep-enroll-signup-and-entroll' ), |
| 95 | + array(), |
| 96 | + array( |
| 97 | + 'returnto' => $this->getTitle( $this->subPage )->getFullText(), |
| 98 | + 'type' => 'signup' |
| 99 | + ) |
| 100 | + ) ); |
39 | 101 | } |
| 102 | + |
| 103 | + /** |
| 104 | + * |
| 105 | + * |
| 106 | + * @since 0.1 |
| 107 | + * |
| 108 | + * @param EPTerm $term |
| 109 | + */ |
| 110 | + protected function showEntrollmentForm( EPTerm $term ) { |
| 111 | + |
| 112 | + } |
40 | 113 | |
41 | 114 | } |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -190,6 +190,16 @@ |
191 | 191 | 'specialterm-summary-token' => 'Enrollment token', |
192 | 192 | 'ep-term-nav-edit' => 'Edit this term', |
193 | 193 | |
| 194 | + // Special:Enroll |
| 195 | + 'ep-enroll-login-first' => 'Before you can enroll in this course, you need to login.', |
| 196 | + 'ep-enroll-login-and-entroll' => 'Login with an existing account & enroll', |
| 197 | + 'ep-enroll-signup-and-entroll' => 'Create a new account & enroll', |
| 198 | + 'ep-enroll-not-allowed' => 'Your account is not allowed to enroll', |
| 199 | + 'ep-enroll-invalid-id' => 'The term you tried to enroll for does not exist. A list of existing terms can be found [[Special:Terms|here]].', |
| 200 | + 'ep-enroll-no-id' => 'You need to specify a term to enroll for. A list of existing terms can be found [[Special:Terms|here]].', |
| 201 | + 'ep-enroll-no-token' => 'You need to provide the token needed to enroll for this term.', |
| 202 | + 'ep-enroll-invalid-token' => 'The token you provided is invalid.', |
| 203 | + |
194 | 204 | // Navigation links |
195 | 205 | 'ep-nav-orgs' => 'Institution list', |
196 | 206 | 'ep-nav-courses' => 'Courses list', |