/**
  * Main method.
  *
  * @since 0.1
  *
  * @param string $subPage
  */
 public function execute($subPage)
 {
     parent::execute($subPage);
     if ($this->subPage === '') {
         $this->displayNavigation();
         EPStudent::displayPager($this->getContext());
     } else {
         $this->getOutput()->redirect(SpecialPage::getTitleFor('Student', $this->subPage)->getLocalURL());
     }
 }
Ejemplo n.º 2
0
 protected function displayPage(EPDBObject $course)
 {
     parent::displayPage($course);
     $out = $this->getOutput();
     $out->addElement('h2', array(), wfMsg('ep-course-description'));
     $out->addHTML($this->getOutput()->parse($course->getField('description')));
     $studentIds = array_map(function (EPStudent $student) {
         return $student->getId();
     }, $course->getStudents('id'));
     if (count($studentIds) > 0) {
         $out->addElement('h2', array(), wfMsg('ep-course-articles'));
         EPArticle::displayPager($this->getContext(), array('course_id' => $course->getId()));
         $out->addElement('h2', array(), wfMsg('ep-course-students'));
         EPStudent::displayPager($this->getContext(), array('id' => $studentIds));
     } else {
         // TODO
     }
 }
 /**
  * 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->addHTML(Html::element('h2', array(), wfMsg('ep-student-terms')));
             $termIds = array_map(function (EPTerm $term) {
                 return $term->getId();
             }, $student->getTerms('id'));
             EPTerm::displayPager($this->getContext(), array('id' => $termIds));
         }
     }
 }
Ejemplo n.º 4
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('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
             }
         }
     }
 }
Ejemplo n.º 5
0
 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');
     }
 }
Ejemplo n.º 6
0
 /**
  * Returns the default nav items for @see displayNavigation.
  *
  * @since 0.1
  *
  * @return array
  */
 public static function getDefaultNavigationItems(IContextSource $context)
 {
     $items = array(wfMsg('ep-nav-orgs') => SpecialPage::getTitleFor('Institutions'), wfMsg('ep-nav-courses') => SpecialPage::getTitleFor('Courses'));
     $items[wfMsg('ep-nav-students')] = SpecialPage::getTitleFor('Students');
     $items[wfMsg('ep-nav-oas')] = SpecialPage::getTitleFor('OnlineAmbassadors');
     $items[wfMsg('ep-nav-cas')] = SpecialPage::getTitleFor('CampusAmbassadors');
     $user = $context->getUser();
     if (EPStudent::has(array('user_id' => $user->getId()))) {
         $items[wfMsg('ep-nav-mycourses')] = SpecialPage::getTitleFor('MyCourses');
     }
     if ($user->isAllowed('ep-online') && EPOA::newFromUser($user)->hasCourse()) {
         $items[wfMsg('ep-nav-oaprofile')] = SpecialPage::getTitleFor('OnlineAmbassadorProfile');
     }
     if ($user->isAllowed('ep-campus') && EPCA::newFromUser($user)->hasCourse()) {
         $items[wfMsg('ep-nav-caprofile')] = SpecialPage::getTitleFor('CampusAmbassadorProfile');
     }
     return $items;
 }
 /**
  * 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);
     }
 }
Ejemplo n.º 8
0
 /**
  * Returns the students enrolled in this term.
  *
  * @since 0.1
  *
  * @param string|array|null $fields
  * @param array $conditions
  *
  * @return array of EPStudent
  */
 protected function doGetStudents($fields, array $conditions)
 {
     $conditions[] = array(array('ep_terms', 'id'), $this->getId());
     return EPStudent::select($fields, $conditions, array(), array('ep_students_per_term' => array('INNER JOIN', array(array(array('ep_students_per_term', 'term_id'), array('ep_terms', 'id')))), 'ep_terms' => array('INNER JOIN', array(array(array('ep_students_per_term', 'term_id'), array('ep_terms', 'id'))))));
 }
Ejemplo n.º 9
0
 /**
  * Returns the default nav items for @see displayNavigation.
  *
  * @since 0.1
  *
  * @return array
  */
 protected function getDefaultNavigationItems()
 {
     $items = array(wfMsg('ep-nav-orgs') => SpecialPage::getTitleFor('Institutions'), wfMsg('ep-nav-courses') => SpecialPage::getTitleFor('Courses'), wfMsg('ep-nav-terms') => SpecialPage::getTitleFor('Terms'));
     $items[wfMsg('ep-nav-students')] = SpecialPage::getTitleFor('Students');
     if (EPStudent::has(array('user_id' => $this->getUser()->getId()))) {
         $items[wfMsg('ep-nav-mycourses')] = SpecialPage::getTitleFor('MyCourses');
     }
     return $items;
 }
Ejemplo n.º 10
0
 /**
  * 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;
 }
Ejemplo n.º 11
0
 /**
  * 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());
                     }
                 }
             }
         }
     }
 }