/** * Main method. * * @since 0.1 * * @param string $subPage */ public function execute($subPage) { parent::execute($subPage); if ($this->getRequest()->getCheck('enrolled')) { EPStudent::setReadDb(DB_MASTER); } $student = EPStudent::newFromUser($this->getUser()); if ($student === false) { $this->getOutput()->addWikiMsg('ep-mycourses-not-a-student'); } else { if ($this->getUser()->isAllowed('ep-org')) { $this->displayNavigation(); } if ($this->subPage === '') { $this->displayCourses($student); } else { $this->displayCourse($student, $this->subPage); } } }
protected function displayEnrollment() { if ($this->getRequest()->getCheck('enrolled')) { EPStudent::setReadDb(DB_MASTER); } $student = EPStudent::newFromUser($this->getUser()); $courses = $student->getCourses('id'); $courseIds = array_map(function (EPCourse $course) { return $course->getId(); }, $courses); if ($this->getRequest()->getCheck('enrolled') && in_array($this->getRequest()->getInt('enrolled'), $courseIds)) { $course = EPCourse::selectRow(array('name', 'org_id'), array('id' => $this->getRequest()->getInt('enrolled'))); $this->showSuccess(wfMessage('ep-mycourses-enrolled', $course->getField('name'), $course->getOrg()->getField('name'))); } if (count($courseIds) === 1) { $course = $courses[0]; $course->loadFields(); $this->displayCourse($course); } elseif (count($courseIds) > 1) { $this->getOutput()->addElement('h2', array(), wfMsg('ep-mycourses-enrollment')); EPCourse::displayPager($this->getContext(), array('id' => $courseIds), true, 'enrollment'); } }
/** * Just enroll the user in the term. * * @since 0.1 * * @param EPTerm $term * * @return boolean Success indicator */ protected function doEnroll(EPTerm $term) { $student = EPStudent::newFromUser($this->getUser(), array('id')); $hadStudent = $student !== false; $fields = array('active_enroll' => 1); if (!$hadStudent) { $student = new EPStudent(array('user_id' => $this->getUser()->getId()), true); $fields['first_enroll'] = wfTimestamp(TS_MW); } $student->setFields($fields); $success = $student->writeToDB(); if ($success) { $success = $student->associateWithTerms(array($term)) && $success; if (!$hadStudent) { $this->getUser()->setOption('ep_showtoplink', true); $this->getUser()->saveSettings(); } } return $success; }
/** * Display the tabs for a course or institution. * * @since 0.1 * * @param SkinTemplate $sktemplate * @param array $links * @param Title $title */ protected static function displayTabs(SkinTemplate &$sktemplate, array &$links, Title $title) { $classes = array(EP_NS_INSTITUTION => 'EPOrg', EP_NS_COURSE => 'EPCourse'); $exists = null; if (array_key_exists($title->getNamespace(), $classes)) { $links['views'] = array(); $links['actions'] = array(); $user = $sktemplate->getUser(); $class = $classes[$title->getNamespace()]; $exists = $class::hasIdentifier($title->getText()); $type = $sktemplate->getRequest()->getText('action'); $isSpecial = $sktemplate->getTitle()->isSpecialPage(); if ($exists) { $links['views']['view'] = array('class' => !$isSpecial && $type === '' ? 'selected' : false, 'text' => wfMsg('ep-tab-view'), 'href' => $title->getLocalUrl()); } if ($user->isAllowed($class::getEditRight())) { $links['views']['edit'] = array('class' => $type === 'edit' ? 'selected' : false, 'text' => wfMsg($exists ? 'ep-tab-edit' : 'ep-tab-create'), 'href' => $title->getLocalUrl(array('action' => 'edit'))); } if ($exists) { $links['views']['history'] = array('class' => $type === 'history' ? 'selected' : false, 'text' => wfMsg('ep-tab-history'), 'href' => $title->getLocalUrl(array('action' => 'history'))); if ($title->getNamespace() === EP_NS_COURSE) { if ($user->isAllowed('ep-enroll')) { $student = EPStudent::newFromUser($user); if ($student === false || !$student->hasCourse(array('name' => $title->getText()))) { $links['views']['enroll'] = array('class' => $isSpecial ? 'selected' : false, 'text' => wfMsg('ep-tab-enroll'), 'href' => SpecialPage::getTitleFor('Enroll', $title->getText())->getLocalURL()); } } } } } }