/**
  * 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()));
             }
         }
     }
 }
 /**
  * Main method.
  *
  * @since 0.1
  *
  * @param string|null $subPage
  */
 public function execute($subPage)
 {
     parent::execute($subPage);
     if ($this->subPage === '') {
         $this->displayNavigation();
         EPOrg::displayAddNewControl($this->getContext());
         EPOrg::displayPager($this->getContext());
     } else {
         $this->getOutput()->redirect(Title::newFromText($this->subPage, EP_NS_INSTITUTION)->getLocalURL());
     }
 }
 /**
  * Main method.
  *
  * @since 0.1
  *
  * @param string|null $subPage
  */
 public function execute($subPage)
 {
     parent::execute($subPage);
     if ($this->subPage === '') {
         $this->displayNavigation();
         EPOrg::displayAddNewControl($this->getContext());
         EPOrg::displayPager($this->getContext());
     } else {
         $this->getOutput()->redirect(SpecialPage::getTitleFor('Institution', $this->subPage)->getLocalURL());
     }
 }
 /**
  * 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();
     $fields['name'] = array('type' => 'text', 'label-message' => 'ep-course-edit-name', 'maxlength' => 255, 'required' => true, 'validation-callback' => function ($value, array $alldata = null) {
         return strlen($value) < 5 ? wfMsgExt('ep-course-invalid-name', 'parsemag', 5) : true;
     });
     $orgOptions = EPOrg::getOrgOptions();
     $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['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);
     return $this->processFormFields($fields);
 }
 /**
  * Associate the student with the provided terms.
  *
  * @since 0.1
  *
  * @param array $terms
  *
  * @return bool
  */
 public function associateWithTerms(array $terms)
 {
     $dbw = wfGetDB(DB_MASTER);
     $success = true;
     $dbw->begin();
     foreach ($terms as $term) {
         $success = $dbw->insert('ep_students_per_term', array('spt_student_id' => $this->getId(), 'spt_term_id' => $term->getId())) && $success;
     }
     $dbw->commit();
     foreach ($terms as $term) {
         EPCourse::updateSummaryFields('students', array('id' => $term->getField('course_id')));
         EPOrg::updateSummaryFields('students', array('id' => $term->getField('org_id')));
         EPTerm::updateSummaryFields('students', array('id' => $this->getId()));
     }
     return $success;
 }
 /**
  * Gets the summary data.
  *
  * @since 0.1
  *
  * @param EPCourse $course
  *
  * @return array
  */
 protected function getSummaryData(EPDBObject $course)
 {
     $stats = array();
     $stats['name'] = htmlspecialchars($course->getField('name'));
     $org = EPOrg::selectFieldsRow('name', array('id' => $course->getField('org_id')));
     $stats['org'] = Linker::linkKnown(SpecialPage::getTitleFor('Institution', $org), htmlspecialchars($org));
     $stats['status'] = wfMsgHtml($course->getField('active') ? 'ep-course-active' : 'ep-course-inactive');
     $lang = $this->getLanguage();
     $stats['students'] = htmlspecialchars($lang->formatNum($course->getField('students')));
     $termCount = EPTerm::count(array('course_id' => $course->getId()));
     $stats['terms'] = htmlspecialchars($lang->formatNum($termCount));
     if ($termCount > 0) {
         $stats['terms'] = Linker::linkKnown(SpecialPage::getTitleFor('Terms'), $stats['terms'], array(), array('course_id' => $course->getId()));
     }
     $stats['instructors'] = $this->getInstructorsList($course) . $this->getInstructorControls($course);
     return $stats;
 }
Example #8
0
 /**
  * Gets the summary data.
  *
  * @since 0.1
  *
  * @param EPCourse $course
  *
  * @return array
  */
 protected function getSummaryData(EPDBObject $course)
 {
     $stats = array();
     $orgName = EPOrg::selectFieldsRow('name', array('id' => $course->getField('org_id')));
     $stats['org'] = EPOrg::getLinkFor($orgName);
     $lang = $this->getLanguage();
     $stats['term'] = htmlspecialchars($course->getField('term'));
     $stats['start'] = htmlspecialchars($lang->timeanddate($course->getField('start'), true));
     $stats['end'] = htmlspecialchars($lang->timeanddate($course->getField('end'), true));
     $stats['students'] = htmlspecialchars($lang->formatNum($course->getField('students')));
     $stats['status'] = htmlspecialchars(EPCourse::getStatusMessage($course->getStatus()));
     if ($this->getUser()->isAllowed('ep-token')) {
         $stats['token'] = Linker::linkKnown(SpecialPage::getTitleFor('Enroll', $course->getId() . '/' . $course->getField('token')), htmlspecialchars($course->getField('token')));
     }
     $stats['instructors'] = $this->getRoleList($course, 'instructor') . $this->getRoleControls($course, 'instructor');
     $stats['online'] = $this->getRoleList($course, 'online') . $this->getRoleControls($course, 'online');
     $stats['campus'] = $this->getRoleList($course, 'campus') . $this->getRoleControls($course, 'campus');
     return $stats;
 }
Example #9
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);
 }
Example #10
0
 /**
  * (non-PHPdoc)
  * @see EPPager::getFormattedValue()
  */
 public function getFormattedValue($name, $value)
 {
     switch ($name) {
         case 'name':
             $value = EPOrg::getLinkFor($value);
             break;
         case 'country':
             $countries = array_flip(EPUtils::getCountryOptions($this->getLanguage()->getCode()));
             $value = htmlspecialchars($countries[$value]);
             break;
         case 'courses':
         case 'students':
             $rawValue = $value;
             $value = htmlspecialchars($this->getLanguage()->formatNum($value));
             if ($rawValue > 0 && $name === 'courses') {
                 $value = Linker::linkKnown(SpecialPage::getTitleFor($this->getLanguage()->ucfirst($name)), $value, array(), array('org_id' => $this->currentObject->getId()));
             }
             break;
         case 'active':
             $value = wfMsgHtml('eporgpager-' . ($value == '1' ? 'yes' : 'no'));
             break;
     }
     return $value;
 }
Example #11
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;
 }
Example #12
0
 /**
  * Returns a list of orgs in an array that can be fed to select inputs.
  *
  * @since 0.1
  *
  * @param array|null $orgs
  *
  * @return array
  */
 public static function getOrgOptions(array $orgs = null)
 {
     $options = array();
     if (is_null($orgs)) {
         $orgs = EPOrg::select(array('name', 'id'));
     }
     foreach ($orgs as $org) {
         $options[$org->getField('name')] = $org->getId();
     }
     return $options;
 }
 /**
  * (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;
 }
 /**
  * (non-PHPdoc)
  * @see EPPager::getFilterOptions()
  */
 protected function getFilterOptions()
 {
     return array('org_id' => array('type' => 'select', 'options' => array_merge(array('' => ''), EPOrg::getOrgOptions(EPOrg::select(array('name', 'id')))), 'value' => '', 'datatype' => 'int'), 'active' => array('type' => 'select', 'options' => array('' => '', wfMsg('epcoursepager-yes') => '1', wfMsg('epcoursepager-no') => '0'), 'value' => ''));
 }
 /**
  * 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);
 }
Example #16
0
 /**
  * Adds a control to add a new course 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 (EPOrg::has()) {
         EPCourse::displayAddNewControl($context, $args);
     } elseif ($context->getUser()->isAllowed('ep-org')) {
         $context->getOutput()->addWikiMsg('ep-courses-addorgfirst');
     }
 }
Example #17
0
 /**
  * Returns the org associated with this term.
  *
  * @since 0.1
  *
  * @param string|array|null $fields
  *
  * @return EPOrg
  */
 public function getOrg($fields = null)
 {
     if ($this->org === false) {
         $this->org = EPOrg::selectRow($fields, array('id' => $this->loadAndGetField('org_id')));
     }
     return $this->org;
 }