/** * Tests @see EPUtils::getKeyPrefixedValues */ public function testGetKeyPrefixedValues() { $input = array('key' => 'value', ' key ' => ' value ', '- key 2 -' => '- value 2 -'); $output = array('key' => 'key - value', ' key ' => ' key - value ', '- key 2 -' => '- key 2 - - - value 2 -'); // TODO: test this test $this->assertEquals($output, EPUtils::getKeyPrefixedValues($input)); }
/** * (non-PHPdoc) * @see SpecialEPFormPage::getFormFields() * @return array */ protected function getFormFields() { $fields = parent::getFormFields(); $fields['name'] = array('type' => 'text', 'label-message' => 'educationprogram-org-edit-name', 'maxlength' => 255, 'required' => true, 'validation-callback' => function ($value, array $alldata = null) { return strlen($value) < 2 ? wfMsg('educationprogram-org-invalid-name') : true; }); $fields['city'] = array('type' => 'text', 'label-message' => 'educationprogram-org-edit-city', 'required' => true, 'validation-callback' => function ($value, array $alldata = null) { return strlen($value) < 2 ? wfMsg('educationprogram-org-invalid-city') : true; }); $fields['country'] = array('type' => 'select', 'label-message' => 'educationprogram-org-edit-country', 'maxlength' => 255, 'required' => true, 'options' => EPUtils::getCountryOptions($this->getLanguage()->getCode()), 'validation-callback' => array($this, 'countryIsValid')); return $this->processFormFields($fields); }
/** * Returns the default nav items for @see displayNavigation. * * @since 0.1 * * @return array */ protected function getDefaultNavigationItems() { return EPUtils::getDefaultNavigationItems($this->getContext()); }
/** * (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); }
/** * Log an action. * * @since 0.1 * * @param string $subType */ protected function log($subType) { if ($this->log) { $info = $this->getLogInfo($subType); if ($info !== false) { if ($this->revAction !== false) { $info['user'] = $this->revAction->getUser(); $info['comment'] = $this->revAction->getComment(); } $info['subtype'] = $subType; EPUtils::log($info); } } }
/** * Returns the tool links for this ambassador. * * @since 0.1 * * @param IContextSource $context * @param EPCourse|null $course * * @return string */ public function getToolLinks(IContextSource $context, EPCourse $course = null) { return EPUtils::getRoleToolLinks($this, $context, $course); }
/** * Log a change of the instructors of the course. * * @since 0.1 * * @param string $action * @param array $instructors * @param string $message */ protected function logInstructorChange($action, array $instructors, $message) { $names = array(); foreach ($instructors as $userId) { $names[] = EPInstructor::newFromId($userId)->getName(); } $info = array('type' => 'instructor', 'subtype' => $action, 'title' => $this->getTitle(), 'parameters' => array('4::instructorcount' => count($names), '5::instructors' => $GLOBALS['wgLang']->listToText($names))); if ($message !== '') { $info['comment'] = $message; } EPUtils::log($info); }
/** * (non-PHPdoc) * @see EPPager::getFilterOptions() */ protected function getFilterOptions() { return array('country' => array('type' => 'select', 'options' => EPUtils::getCountryOptions($this->getLanguage()->getCode()), 'value' => ''), 'active' => array('type' => 'select', 'options' => array('' => '', wfMsg('eporgpager-yes') => '1', wfMsg('eporgpager-no') => '0'), 'value' => '')); }
/** * Log an action. * * @since 0.1 * * @param string $subType */ protected function log($subType) { if ($this->log) { $info = $this->getLogInfo($subType); if ($info !== false) { $info['subtype'] = $subType; EPUtils::log($info); } } }
/** * Log a change of the instructors of the course. * * @since 0.1 * * @param string $action * @param string $role * @param array $users * @param string $message */ protected function logRoleChange($action, $role, array $users, $message) { $names = array(); $classes = array('instructor' => 'EPInstructor', 'campus' => 'EPCA', 'online' => 'EPOA'); $class = $classes[$role]; foreach ($users as $userId) { $names[] = $class::newFromUserId($userId)->getName(); } $info = array('type' => $role, 'subtype' => $action, 'title' => $this->getTitle(), 'parameters' => array('4::instructorcount' => count($names), '5::instructors' => $GLOBALS['wgLang']->listToText($names))); if ($message !== '') { $info['comment'] = $message; } EPUtils::log($info); }