/**
  * 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('Institutions')->getLocalURL());
     } else {
         $out->setPageTitle(wfMsgExt('ep-institution-title', 'parsemag', $this->subPage));
         $org = EPOrg::selectRow(null, array('name' => $this->subPage));
         if ($org === false) {
             $this->displayNavigation();
             if ($this->getUser()->isAllowed('ep-org')) {
                 $out->addWikiMsg('ep-institution-create', $this->subPage);
                 EPOrg::displayAddNewControl($this->getContext(), array('name' => $this->subPage));
             } else {
                 $out->addWikiMsg('ep-institution-none', $this->subPage);
             }
         } else {
             $links = array();
             if ($this->getUser()->isAllowed('ep-org')) {
                 $links[wfMsg('ep-institution-nav-edit')] = SpecialPage::getTitleFor('EditInstitution', $this->subPage);
             }
             $this->displayNavigation($links);
             $this->displaySummary($org);
             $out->addHTML(Html::element('h2', array(), wfMsg('ep-institution-courses')));
             EPCourse::displayPager($this->getContext(), array('org_id' => $org->getId()));
             if ($this->getUser()->isAllowed('ep-course')) {
                 $out->addHTML(Html::element('h2', array(), wfMsg('ep-institution-add-course')));
                 EPCourse::displayAddNewControl($this->getContext(), array('org' => $org->getId()));
             }
         }
     }
 }
Пример #2
0
 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);
 }
Пример #3
0
 /**
  * Main method.
  *
  * @since 0.1
  *
  * @param string|null $subPage
  */
 public function execute($subPage)
 {
     parent::execute($subPage);
     if ($this->subPage === '') {
         $this->displayNavigation();
         EPCourse::displayAddNewRegion($this->getContext());
         EPCourse::displayPager($this->getContext());
     } else {
         $this->getOutput()->redirect(Title::newFromText($this->subPage, EP_NS_COURSE)->getLocalURL());
     }
 }
Пример #4
0
 protected function displayPage(EPDBObject $org)
 {
     parent::displayPage($org);
     $out = $this->getOutput();
     $out->addElement('h2', array(), wfMsg('ep-institution-courses'));
     EPCourse::displayPager($this->getContext(), array('org_id' => $org->getId()));
     if ($this->getUser()->isAllowed('ep-course')) {
         $out->addElement('h2', array(), wfMsg('ep-institution-add-course'));
         EPCourse::displayAddNewControl($this->getContext(), array('org' => $org->getId()));
     }
 }
 /**
  * Main method.
  *
  * @since 0.1
  *
  * @param string|null $arg
  */
 public function execute($subPage)
 {
     parent::execute($subPage);
     if ($this->subPage === '') {
         $this->displayNavigation();
         EPCourse::displayAddNewRegion($this->getContext());
         EPCourse::displayPager($this->getContext());
     } else {
         $this->getOutput()->redirect(SpecialPage::getTitleFor('Course', $this->subPage)->getLocalURL());
     }
 }
Пример #6
0
 /**
  * Gets the summary data.
  *
  * @since 0.1
  *
  * @param EPTerm $term
  *
  * @return array
  */
 protected function getSummaryData(EPDBObject $term)
 {
     $stats = array();
     $org = EPOrg::selectFieldsRow('name', array('id' => $term->getField('org_id')));
     $stats['org'] = Linker::linkKnown(SpecialPage::getTitleFor('Institution', $org), htmlspecialchars($org));
     $course = EPCourse::selectFieldsRow('name', array('id' => $term->getField('course_id')));
     $stats['course'] = Linker::linkKnown(SpecialPage::getTitleFor('Course', $course), htmlspecialchars($course));
     $stats['year'] = htmlspecialchars($this->getLanguage()->formatNum($term->getField('year'), true));
     $stats['start'] = htmlspecialchars($this->getLanguage()->timeanddate($term->getField('start'), true));
     $stats['end'] = htmlspecialchars($this->getLanguage()->timeanddate($term->getField('end'), true));
     if ($this->getUser()->isAllowed('ep-token')) {
         $stats['token'] = Linker::linkKnown(SpecialPage::getTitleFor('Enroll', $term->getId() . '/' . $term->getField('token')), htmlspecialchars($term->getField('token')));
     }
     return $stats;
 }
 /**
  * (non-PHPdoc)
  * @see SpecialEPFormPage::getFormFields()
  * @return array
  */
 protected function getFormFields()
 {
     $fields = parent::getFormFields();
     $courseOptions = EPCourse::getCourseOptions();
     $fields['course_id'] = array('type' => 'select', 'label-message' => 'ep-term-edit-course', 'required' => true, 'options' => $courseOptions, 'validation-callback' => function ($value, array $alldata = null) use($courseOptions) {
         return in_array((int) $value, array_values($courseOptions)) ? true : wfMsg('ep-term-invalid-course');
     });
     $fields['token'] = array('type' => 'text', 'label-message' => 'ep-term-edit-token', 'maxlength' => 255, 'required' => true, 'size' => 20, 'validation-callback' => function ($value, array $alldata = null) {
         $strLen = strlen($value);
         return $strLen !== 0 && $strLen < 2 ? wfMsgExt('ep-term-invalid-token', 'parsemag', 2) : true;
     });
     $fields['year'] = array('type' => 'int', 'label-message' => 'ep-term-edit-year', 'required' => true, 'min' => 2000, 'max' => 9001, 'size' => 15);
     $fields['start'] = array('class' => 'EPHTMLDateField', 'label-message' => 'ep-term-edit-start', 'required' => true);
     $fields['end'] = array('class' => 'EPHTMLDateField', 'label-message' => 'ep-term-edit-end', 'required' => true);
     $fields['description'] = array('type' => 'textarea', 'label-message' => 'ep-term-edit-description', 'required' => true, 'validation-callback' => function ($value, array $alldata = null) {
         return strlen($value) < 10 ? wfMsgExt('ep-term-invalid-description', 'parsemag', 10) : true;
     }, 'rows' => 10);
     return $this->processFormFields($fields);
 }
Пример #8
0
 /**
  * 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('Students')->getLocalURL());
     } else {
         $this->displayNavigation();
         $student = EPStudent::selectRow(null, array('id' => $this->subPage));
         if ($student === false) {
             $out->addWikiMsg('ep-student-none', $this->subPage);
         } else {
             $out->setPageTitle(wfMsgExt('ep-student-title', 'parsemag', $student->getName()));
             $this->displaySummary($student);
             $out->addElement('h2', array(), wfMsg('ep-student-courses'));
             $courseIds = array_map(function (EPCourse $course) {
                 return $course->getId();
             }, $student->getCourses('id'));
             EPCourse::displayPager($this->getContext(), array('id' => $courseIds));
         }
     }
 }
Пример #9
0
 /**
  * Associate the student with the provided courses.
  *
  * @since 0.1
  *
  * @param array $courses
  *
  * @return bool
  */
 public function associateWithCourses(array $courses)
 {
     $dbw = wfGetDB(DB_MASTER);
     $success = true;
     $dbw->begin();
     foreach ($courses as $course) {
         $success = $dbw->insert('ep_students_per_course', array('spc_student_id' => $this->getId(), 'spc_course_id' => $course->getId())) && $success;
     }
     $dbw->commit();
     foreach ($courses as $course) {
         EPOrg::updateSummaryFields('students', array('id' => $course->getField('org_id')));
         EPCourse::updateSummaryFields('students', array('id' => $course->getId()));
     }
     return $success;
 }
 /**
  * Display the summary for a course.
  *
  * @since 0.1
  *
  * @param EPCourse $course
  * @param array $terms
  */
 protected function displayCourseSummary(EPCourse $course, array $terms)
 {
     $info = array();
     $info['name'] = $course->getField('name');
     $info['org'] = EPOrg::selectFieldsRow('name', array('id' => $course->getField('org_id')));
     foreach ($info as &$inf) {
         $inf = htmlspecialchars($inf);
     }
     $this->displaySummary($course, false, $info);
 }
Пример #11
0
 /**
  * Returns the courses this student is linked to (via terms).
  *
  * @since 0.1
  *
  * @param string|null|array $fields
  * @param array $conditions
  * @param array $termConditions
  *
  * @return array of EPCourse
  */
 public function getCourses($fields = null, array $conditions = array(), array $termConditions = array())
 {
     $courseIds = array_reduce($this->getTerms('course_id', $termConditions), function (array $ids, EPTerm $term) {
         $ids[] = $term->getField('course_id');
         return $ids;
     }, array());
     if (count($courseIds) < 1) {
         return array();
     }
     $conditions['id'] = array_unique($courseIds);
     return EPCourse::select($fields, $conditions);
 }
Пример #12
0
 /**
  * Adds a control to add a new term to the provided context
  * or show a message if this is not possible for some reason.
  *
  * @since 0.1
  *
  * @param IContextSource $context
  * @param array $args
  */
 public static function displayAddNewRegion(IContextSource $context, array $args = array())
 {
     if (EPCourse::has()) {
         EPTerm::displayAddNewControl($context, $args);
     } elseif ($context->getUser()->isAllowed('ep-course')) {
         $context->getOutput()->addWikiMsg('ep-terms-addcoursefirst');
     }
 }
Пример #13
0
 /**
  * Retruns the courses linked to this org.
  *
  * @since 0.1
  *
  * @param array|null $fields
  *
  * @return array of EPCourse
  */
 public function getCourses(array $fields = null)
 {
     if ($this->courses === false) {
         $this->courses = EPCourse::select($fields, array('org_id' => $this->getId()));
     }
     return $this->courses;
 }
Пример #14
0
 protected function getInstructorControls(EPCourse $course)
 {
     $user = $this->getUser();
     $links = array();
     if (($user->isAllowed('ep-instructor') || $user->isAllowed('ep-beinstructor')) && !in_array($user->getId(), $course->getField('instructors'))) {
         $links[] = Html::element('a', array('href' => '#', 'class' => 'ep-add-instructor', 'data-courseid' => $course->getId(), 'data-coursename' => $course->getField('name'), 'data-mode' => 'self'), wfMsg('ep-course-become-instructor'));
     }
     if ($user->isAllowed('ep-instructor')) {
         $links[] = Html::element('a', array('href' => '#', 'class' => 'ep-add-instructor', 'data-courseid' => $course->getId(), 'data-coursename' => $course->getField('name')), wfMsg('ep-course-add-instructor'));
     }
     if (count($links) > 0) {
         $this->getOutput()->addModules('ep.instructor');
         return '<br />' . $this->getLanguage()->pipeList($links);
     } else {
         return '';
     }
 }
Пример #15
0
 /**
  * Returns the courses this online ambassdor is associated with.
  *
  * @since 0.1
  *
  * @param string|array|null $fields
  * @param array $conditions
  *
  * @return array of EPCourse
  */
 protected function doGetCourses($fields, array $conditions)
 {
     $conditions[] = array(array('ep_oas_per_course', 'user_id'), $this->getField('user_id'));
     return EPCourse::select($fields, $conditions, array(), array('ep_oas_per_course' => array('INNER JOIN', array(array(array('ep_oas_per_course', 'course_id'), array('ep_courses', 'id'))))));
 }
Пример #16
0
 protected function displayCourse(EPCourse $course)
 {
     $out = $this->getOutput();
     $out->addElement('h2', array(), wfMsg('ep-mycourses-course-enrollment'));
     $out->addHTML('You are currently enrolled in ' . $course->getField('name'));
     // TODO
 }
Пример #17
0
 /**
  * (non-PHPdoc)
  * @see EPPager::getFilterOptions()
  */
 protected function getFilterOptions()
 {
     $options = array();
     if (!array_key_exists('course_id', $this->conds)) {
         $options['course_id'] = array('type' => 'select', 'options' => array_merge(array('' => ''), EPCourse::getCourseOptions(EPCourse::select(array('name', 'id')))), 'value' => '', 'datatype' => 'int');
         $options['org_id'] = array('type' => 'select', 'options' => array_merge(array('' => ''), EPOrg::getOrgOptions(EPOrg::select(array('name', 'id')))), 'value' => '', 'datatype' => 'int');
     }
     $years = EPTerm::selectFields('year', array(), array('DISTINCT'), array(), true);
     asort($years, SORT_NUMERIC);
     $years = array_merge(array(''), $years);
     $years = array_combine($years, $years);
     $options['year'] = array('type' => 'select', 'options' => $years, 'value' => '');
     $options['status'] = array('type' => 'select', 'options' => array_merge(array('' => ''), EPTerm::getStatuses()), 'value' => 'current');
     return $options;
 }
Пример #18
0
 /**
  * Returns the courses this student is enrolled in.
  *
  * @since 0.1
  *
  * @param string|array|null $fields
  * @param array $conditions
  *
  * @return array of EPCourse
  */
 protected function doGetCourses($fields, array $conditions)
 {
     $conditions[] = array(array('ep_students', 'id'), $this->getId());
     return EPCourse::select($fields, $conditions, array(), array('ep_students_per_course' => array('INNER JOIN', array(array(array('ep_students_per_course', 'course_id'), array('ep_courses', 'id')))), 'ep_students' => array('INNER JOIN', array(array(array('ep_students_per_course', 'student_id'), array('ep_students', 'id'))))));
 }
Пример #19
0
 /**
  * (non-PHPdoc)
  * @see EPPager::getFilterOptions()
  */
 protected function getFilterOptions()
 {
     $options = array();
     $options['org_id'] = array('type' => 'select', 'options' => array_merge(array('' => ''), EPOrg::getOrgOptions(EPOrg::select(array('name', 'id')))), 'value' => '', 'datatype' => 'int');
     $terms = EPCourse::selectFields('term', array(), array('DISTINCT'), array(), true);
     natcasesort($terms);
     $terms = array_merge(array(''), $terms);
     $terms = array_combine($terms, $terms);
     $options['term'] = array('type' => 'select', 'options' => $terms, 'value' => '');
     //		$options['lang'] = array(
     //			'type' => 'select',
     //			'options' => EPUtils::getLanguageOptions( $this->getLanguage()->getCode() ),
     //			'value' => '',
     //		);
     $options['status'] = array('type' => 'select', 'options' => array_merge(array('' => ''), EPCourse::getStatuses()), 'value' => 'current');
     return $options;
 }
Пример #20
0
 /**
  * Returns role a controls for the course if the
  * current user has the right permissions.
  *
  * @since 0.1
  *
  * @param EPCourse $course
  * @param string $roleName
  *
  * @return string
  */
 protected function getRoleControls(EPCourse $course, $roleName)
 {
     $user = $this->getUser();
     $links = array();
     $field = $roleName === 'instructor' ? 'instructors' : $roleName . '_ambs';
     if (($user->isAllowed('ep-' . $roleName) || $user->isAllowed('ep-be' . $roleName)) && !in_array($user->getId(), $course->getField($field))) {
         $links[] = Html::element('a', array('href' => '#', 'class' => 'ep-add-role', 'data-role' => $roleName, 'data-courseid' => $course->getId(), 'data-coursename' => $course->getField('name'), 'data-mode' => 'self'), wfMsg('ep-course-become-' . $roleName));
     }
     if ($user->isAllowed('ep-' . $roleName)) {
         $links[] = Html::element('a', array('href' => '#', 'class' => 'ep-add-role', 'data-role' => $roleName, 'data-courseid' => $course->getId(), 'data-coursename' => $course->getField('name')), wfMsg('ep-course-add-' . $roleName));
     }
     if (count($links) > 0) {
         $this->getOutput()->addModules('ep.enlist');
         return '<br />' . $this->getLanguage()->pipeList($links);
     } else {
         return '';
     }
 }
Пример #21
0
 /**
  * Gets called after the form is saved.
  *
  * @since 0.1
  */
 public function onSuccess()
 {
     $this->getOutput()->redirect(SpecialPage::getTitleFor('MyCourses')->getLocalURL(array('enrolled' => $this->course->getId())));
 }
Пример #22
0
 /**
  * (non-PHPdoc)
  * @see EPEditAction::getFormFields()
  * @return array
  */
 protected function getFormFields()
 {
     $fields = parent::getFormFields();
     $orgOptions = EPOrg::getOrgOptions();
     $fields['name'] = array('type' => 'text', 'label-message' => 'ep-course-edit-name', 'required' => true);
     $mcs = EPCourse::selectFields('mc', array(), array('DISTINCT'));
     if ($this->getRequest()->getCheck('newname')) {
         $newName = $this->getRequest()->getText('newname');
         $mcs = array_merge(array($newName => $newName), $mcs);
     } else {
         $mcs = array_merge(array('' => ''), $mcs);
     }
     $fields['mc'] = array('class' => 'EPHTMLCombobox', 'label-message' => 'ep-course-edit-mc', 'required' => true, 'options' => array_combine($mcs, $mcs));
     $fields['org_id'] = array('type' => 'select', 'label-message' => 'ep-course-edit-org', 'required' => true, 'options' => $orgOptions, 'validation-callback' => function ($value, array $alldata = null) use($orgOptions) {
         return in_array((int) $value, array_values($orgOptions)) ? true : wfMsg('ep-course-invalid-org');
     });
     $fields['token'] = array('type' => 'text', 'label-message' => 'ep-course-edit-token', 'maxlength' => 255, 'size' => 20, 'validation-callback' => function ($value, array $alldata = null) {
         $strLen = strlen($value);
         return $strLen !== 0 && $strLen < 2 ? wfMsgExt('ep-course-invalid-token', 'parsemag', 2) : true;
     });
     $fields['term'] = array('type' => 'text', 'label-message' => 'ep-course-edit-term', 'required' => true);
     $fields['start'] = array('class' => 'EPHTMLDateField', 'label-message' => 'ep-course-edit-start', 'required' => true);
     $fields['end'] = array('class' => 'EPHTMLDateField', 'label-message' => 'ep-course-edit-end', 'required' => true);
     $fieldFields = EPCourse::selectFields('field', array(), array('DISTINCT'));
     $fieldFields = array_merge(array('' => ''), $fieldFields);
     $fields['field'] = array('class' => 'EPHTMLCombobox', 'label-message' => 'ep-course-edit-field', 'required' => true, 'options' => array_combine($fieldFields, $fieldFields));
     $levels = EPCourse::selectFields('level', array(), array('DISTINCT'));
     $levels = array_merge(array('' => ''), $levels);
     $fields['level'] = array('class' => 'EPHTMLCombobox', 'label-message' => 'ep-course-edit-level', 'required' => true, 'options' => array_combine($levels, $levels));
     $langOptions = EPUtils::getLanguageOptions($this->getLanguage()->getCode());
     $fields['lang'] = array('type' => 'select', 'label-message' => 'ep-course-edit-lang', 'maxlength' => 255, 'required' => true, 'options' => $langOptions, 'validation-callback' => function ($value, array $alldata = null) use($langOptions) {
         return in_array($value, $langOptions) ? true : wfMsg('ep-course-invalid-lang');
     });
     $fields['description'] = array('type' => 'textarea', 'label-message' => 'ep-course-edit-description', 'required' => true, 'validation-callback' => function ($value, array $alldata = null) {
         return strlen($value) < 10 ? wfMsgExt('ep-course-invalid-description', 'parsemag', 10) : true;
     }, 'rows' => 10, 'id' => 'wpTextbox1');
     return $this->processFormFields($fields);
 }
Пример #23
0
 /**
  * Called on special pages after the special tab is added but before variants have been added.
  * @see https://www.mediawiki.org/wiki/Manual:Hooks/SkinTemplateNavigation::SpecialPage
  *
  * @since 0.1
  *
  * @param SkinTemplate $sktemplate
  * @param array $links
  *
  * @return false
  */
 public static function onSpecialPageTabs(SkinTemplate &$sktemplate, array &$links)
 {
     $textParts = SpecialPageFactory::resolveAlias($sktemplate->getTitle()->getText());
     if ($textParts[0] === 'Enroll' && !is_null($textParts[1]) && trim($textParts[1]) !== '') {
         // Remove the token from the title if needed.
         if (!$sktemplate->getRequest()->getCheck('wptoken')) {
             $textParts[1] = explode('/', $textParts[1]);
             if (count($textParts[1]) > 1) {
                 array_pop($textParts[1]);
             }
             $textParts[1] = implode('/', $textParts[1]);
         }
         $title = EPCourse::getTitleFor($textParts[1]);
         if (!is_null($title)) {
             self::displayTabs($sktemplate, $links, $title);
         }
     }
     return false;
 }