/** * Main method. * * @since 0.1 * * @param string $subPage */ public function execute($subPage) { parent::execute($subPage); $args = explode('/', $this->subPage, 2); if (!ctype_digit($args[0])) { $this->showWarning(wfMessage($args[0] === '' ? 'ep-enroll-no-id' : 'ep-enroll-invalid-id')); } else { $term = EPTerm::selectRow(null, array('id' => $args[0])); if ($term === false) { $this->showWarning(wfMessage('ep-enroll-invalid-id')); } elseif ($term->getStatus() === 'current') { $token = ''; $tokenIsValid = $term->getField('token') === ''; if (!$tokenIsValid) { $tokenIsValid = $term->getField('token') === $token; if (count($args) === 2) { $token = $args[1]; } elseif ($this->getRequest()->wasPosted() && $this->getRequest()->getCheck('wptoken')) { $token = $this->getRequest()->getText('wptoken'); } } if ($tokenIsValid) { $this->showEnrollmentView($term); } else { if ($token !== '') { $this->showWarning(wfMessage('ep-enroll-invalid-token')); } $this->showTokenInput(); } } else { $this->showWarning(wfMessage('ep-enroll-term-' . $term->getStatus())); } } }
/** * Main method. * * @since 0.1 * * @param string $subPage */ public function execute($subPage) { parent::execute($subPage); $out = $this->getOutput(); if (trim($subPage) === '') { $this->getOutput()->redirect(SpecialPage::getTitleFor('Terms')->getLocalURL()); } else { $out->setPageTitle(wfMsgExt('ep-term-title', 'parsemag', $this->subPage)); $term = EPTerm::selectRow(null, array('id' => $this->subPage)); if ($term === false) { $this->displayNavigation(); if ($this->getUser()->isAllowed('ep-term')) { $out->addWikiMsg('ep-term-create', $this->subPage); EPTerm::displayAddNewRegion($this->getContext(), array('id' => $this->subPage)); } else { $out->addWikiMsg('ep-term-none', $this->subPage); } } else { $links = array(); if ($this->getUser()->isAllowed('ep-term')) { $links[wfMsg('ep-term-nav-edit')] = SpecialPage::getTitleFor('EditTerm', $this->subPage); } $this->displayNavigation($links); $this->displaySummary($term); $out->addHTML(Html::element('h2', array(), wfMsg('ep-term-description'))); $out->addHTML($this->getOutput()->parse($term->getField('description'))); $studentIds = array_map(function (EPStudent $student) { return $student->getId(); }, $term->getStudents('id')); if (count($studentIds) > 0) { $out->addHTML(Html::element('h2', array(), wfMsg('ep-term-students'))); EPStudent::displayPager($this->getContext(), array('id' => $studentIds)); } else { // TODO } } } }
/** * Display the courses this student is linked to. * * @since 0.1 * * @param EPStudent $student */ protected function displayCourses(EPStudent $student) { $out = $this->getOutput(); if ($student->hasTerm()) { if ($this->getRequest()->getCheck('enrolled')) { $term = EPTerm::selectRow(null, array('id' => $this->getRequest()->getInt('enrolled'))); if ($term !== false) { $this->showSuccess(wfMessage('ep-mycourses-enrolled', $term->getCourse()->getField('name'), $term->getOrg()->getField('name'))); } } $currentCourses = $student->getCurrentCourses(); $passedCourses = $student->getPassedCourses(); if (count($currentCourses) > 0) { $out->addHTML(Html::element('h2', array(), wfMsg('ep-mycourses-current'))); $this->displayCoursesList($currentCourses); } if (count($passedCourses) > 0) { $out->addHTML(Html::element('h2', array(), wfMsg('ep-mycourses-passed'))); $this->displayCoursesList($passedCourses); } } else { $out->addWikiMsg('ep-mycourses-not-enrolled'); } }