public function execute() { $params = $this->extractRequestParams(); if (!(isset($params['username']) xor isset($params['userid']))) { $this->dieUsage(wfMsg('ep-enlist-invalid-user-args'), 'username-xor-userid'); } if (isset($params['username'])) { $user = User::newFromName($params['username']); $userId = $user->getId(); } else { $userId = $params['userid']; } if ($userId < 1) { $this->dieUsage(wfMsg('ep-enlist-invalid-user'), 'invalid-user'); } if (!$this->userIsAllowed($userId)) { $this->dieUsageMsg(array('badaccess-groups')); } $field = $params['role'] === 'instructor' ? 'instructors' : $params['role'] . '_ambs'; $course = EPCourse::selectRow(array('id', 'name', $field), array('id' => $params['courseid'])); if ($course === false) { $this->dieUsage(wfMsg('ep-enlist-invalid-course'), 'invalid-course'); } $success = false; switch ($params['subaction']) { case 'add': $success = $course->enlistUsers(array($userId), $params['role'], $params['reason']); break; case 'remove': $success = $course->unenlistUsers(array($userId), $params['role'], $params['reason']); break; } $this->getResult()->addValue(null, 'success', $success); }
/** * (non-PHPdoc) * @see EPPager::getFormattedValue() */ public function getFormattedValue($name, $value) { switch ($name) { case 'id': $value = Linker::linkKnown(SpecialPage::getTitleFor('Term', $value), htmlspecialchars($this->getLanguage()->formatNum($value, true))); break; case 'course_id': $value = EPCourse::selectRow('name', array('id' => $value))->getField('name'); $value = Linker::linkKnown(SpecialPage::getTitleFor('Course', $value), htmlspecialchars($value)); break; case 'year': $value = htmlspecialchars($this->getLanguage()->formatNum($value, true)); break; case 'start': case 'end': $value = htmlspecialchars($this->getLanguage()->date($value)); break; case '_status': $value = htmlspecialchars(EPTerm::getStatusMessage($this->currentObject->getStatus())); case 'students': $value = htmlspecialchars($this->getLanguage()->formatNum($value)); break; } return $value; }
/** * 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('Courses')->getLocalURL()); } else { $out->setPageTitle(wfMsgExt('ep-course-title', 'parsemag', $this->subPage)); $course = EPCourse::selectRow(null, array('name' => $this->subPage)); if ($course === false) { $this->displayNavigation(); if ($this->getUser()->isAllowed('ep-course')) { $out->addWikiMsg('ep-course-create', $this->subPage); EPCourse::displayAddNewRegion($this->getContext(), array('name' => $this->subPage)); } else { $out->addWikiMsg('ep-course-none', $this->subPage); } } else { $links = array(); if ($this->getUser()->isAllowed('ep-course')) { $links[wfMsg('ep-course-nav-edit')] = SpecialPage::getTitleFor('EditCourse', $this->subPage); } $this->displayNavigation($links); $this->displaySummary($course); $out->addHTML(Html::element('h2', array(), wfMsg('ep-course-description'))); $out->addHTML($this->getOutput()->parse($course->getField('description'))); $out->addHTML(Html::element('h2', array(), wfMsg('ep-course-terms'))); EPTerm::displayPager($this->getContext(), array('course_id' => $course->getId())); if ($this->getUser()->isAllowed('ep-course')) { $out->addHTML(Html::element('h2', array(), wfMsg('ep-course-add-term'))); EPTerm::displayAddNewControl($this->getContext(), array('course' => $course->getId())); } } } }
/** * Display info for a single course. * * @since 0.1 * * @param EPStudent $student * @param string $courseName */ protected function displayCourse(EPStudent $student, $courseName) { $out = $this->getOutput(); $course = EPCourse::selectRow(null, array('name' => $courseName)); $terms = $student->getTerms(null, array('course_id' => $course->getId())); if ($course !== false && count($terms) > 0) { $out->addWikiMsg('ep-mycourses-show-all'); $out->setPageTitle(wfMsgExt('ep-mycourses-course-title', 'parsemag', $courseName, $course->getOrg('name')->getField('name'))); $this->displayCourseSummary($course, $terms); } else { $this->showError(wfMessage('ep-mycourses-no-such-course', $courseName)); $this->displayCourses($student); } }
/** * Returns the course associated with this term. * * @since 0.1 * * @param string|array|null $fields * * @return EPCourse */ public function getCourse($fields = null) { if ($this->course === false) { $this->course = EPCourse::selectRow($fields, array('id' => $this->loadAndGetField('course_id'))); } return $this->course; }
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'); } }