function activities_inuse($id) { static $modnames = null; global $DB, $CFG; if ($modnames === null) { $modnames = array(0 => array(), 1 => array()); if ($allmods = $DB->get_records("modules")) { foreach ($allmods as $mod) { if (file_exists("$CFG->dirroot/mod/$mod->name/lib.php") && $mod->visible) { $modnames[0][$mod->name] = get_string("modulename", "$mod->name"); $modnames[1][$mod->name] = get_string("modulenameplural", "$mod->name"); } } collatorlib::asort($modnames[0]); collatorlib::asort($modnames[1]); } } $modnames = $modnames[(int) $plural]; $modulesinuse = array(); $modulesinuse[null] = '---------Select----------'; $dbmanager = $DB->get_manager(); foreach ($modnames as $module => $details) { if ($dbmanager->table_exists($module) && $DB->record_exists($module, array('course' => $id))) { $modulesinuse[$module] = $details; } } return $modulesinuse; }
function get_content() { global $CFG, $DB, $OUTPUT; if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass(); $this->content->items = array(); $this->content->icons = array(); $this->content->footer = ''; $course = $this->page->course; require_once $CFG->dirroot . '/course/lib.php'; $modinfo = get_fast_modinfo($course); $modfullnames = array(); $archetypes = array(); foreach ($modinfo->cms as $cm) { // Exclude activities which are not visible or have no link (=label) if (!$cm->uservisible or !$cm->has_view()) { continue; } if (array_key_exists($cm->modname, $modfullnames)) { continue; } if (!array_key_exists($cm->modname, $archetypes)) { $archetypes[$cm->modname] = plugin_supports('mod', $cm->modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER); } if ($archetypes[$cm->modname] == MOD_ARCHETYPE_RESOURCE) { if (!array_key_exists('resources', $modfullnames)) { $modfullnames['resources'] = get_string('resources'); } } else { $modfullnames[$cm->modname] = $cm->modplural; } } collatorlib::asort($modfullnames); foreach ($modfullnames as $modname => $modfullname) { if ($modname === 'resources') { $icon = '<img src="' . $OUTPUT->pix_url('f/html') . '" class="icon" alt="" /> '; $this->content->items[] = '<a href="' . $CFG->wwwroot . '/course/resources.php?id=' . $course->id . '">' . $icon . $modfullname . '</a>'; } else { $icon = '<img src="' . $OUTPUT->pix_url('icon', $modname) . '" class="icon" alt="" /> '; $this->content->items[] = '<a href="' . $CFG->wwwroot . '/mod/' . $modname . '/index.php?id=' . $course->id . '">' . $icon . $modfullname . '</a>'; } } return $this->content; }
/** * Locale-aware version of PHP's asort function. * @param array $array The array to sort. Sorted in place. */ public static function sort_array(&$array) { if (class_exists('core_collator')) { core_collator::asort($array); } else { collatorlib::asort($array); } }
/** * Get the names of all the filters installed in this Moodle. * * @global object * @return array path => filter name from the appropriate lang file. e.g. * array('mod/glossary' => 'Glossary Auto-linking', 'filter/tex' => 'TeX Notation'); * sorted in alphabetical order of name. */ function filter_get_all_installed() { global $CFG; $filternames = array(); // TODO: deprecated since 2.2, will be out in 2.3, see MDL-29996 $filterlocations = array('mod', 'filter'); foreach ($filterlocations as $filterlocation) { // TODO: move get_list_of_plugins() to get_plugin_list() $filters = get_list_of_plugins($filterlocation); foreach ($filters as $filter) { // MDL-29994 - Ignore mod/data and mod/glossary filters forever, this will be out in 2.3 if ($filterlocation == 'mod' && ($filter == 'data' || $filter == 'glossary')) { continue; } $path = $filterlocation . '/' . $filter; if (is_readable($CFG->dirroot . '/' . $path . '/filter.php')) { $strfiltername = filter_get_name($path); $filternames[$path] = $strfiltername; } } } collatorlib::asort($filternames); return $filternames; }
/** * Returns a number of useful structures for course displays */ function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) { global $CFG, $DB, $COURSE; $mods = array(); // course modules indexed by id $modnames = array(); // all course module names (except resource!) $modnamesplural = array(); // all course module names (plural form) $modnamesused = array(); // course module names used if ($allmods = $DB->get_records("modules")) { foreach ($allmods as $mod) { if (!file_exists("{$CFG->dirroot}/mod/{$mod->name}/lib.php")) { continue; } if ($mod->visible) { $modnames[$mod->name] = get_string("modulename", "{$mod->name}"); $modnamesplural[$mod->name] = get_string("modulenameplural", "{$mod->name}"); } } collatorlib::asort($modnames); } else { print_error("nomodules", 'debug'); } $course = $courseid == $COURSE->id ? $COURSE : $DB->get_record('course', array('id' => $courseid)); $modinfo = get_fast_modinfo($course); if ($rawmods = $modinfo->cms) { foreach ($rawmods as $mod) { // Index the mods if (empty($modnames[$mod->modname])) { continue; } $mods[$mod->id] = $mod; $mods[$mod->id]->modfullname = $modnames[$mod->modname]; if (!$mod->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE, $courseid))) { continue; } // Check groupings if (!groups_course_module_visible($mod)) { continue; } $modnamesused[$mod->modname] = $modnames[$mod->modname]; } if ($modnamesused) { collatorlib::asort($modnamesused); } } }
/** * Returns grade options for gradebook grade category menu * * @param int $courseid The course ID * @param bool $includenew Include option for new category at array index -1 * @return array of grade categories in course */ function grade_get_categories_menu($courseid, $includenew = false) { $result = array(); if (!($categories = grade_category::fetch_all(array('courseid' => $courseid)))) { //make sure course category exists if (!grade_category::fetch_course_category($courseid)) { debugging('Can not create course grade category!'); return $result; } $categories = grade_category::fetch_all(array('courseid' => $courseid)); } foreach ($categories as $key => $category) { if ($category->is_course_category()) { $result[$category->id] = get_string('uncategorised', 'grades'); unset($categories[$key]); } } if ($includenew) { $result[-1] = get_string('newcategory', 'grades'); } $cats = array(); foreach ($categories as $category) { $cats[$category->id] = $category->get_name(); } collatorlib::asort($cats); return $result + $cats; }
/** * Returns localised list of installed translations * * @param bool $returnall return all or just enabled * @return array moodle translation code => localised translation name */ public function get_list_of_translations($returnall = false) { global $CFG; $languages = array(); if (!empty($CFG->langcache) and is_readable($this->menucache)) { // try to re-use the cached list of all available languages $cachedlist = json_decode(file_get_contents($this->menucache), true); if (is_array($cachedlist) and !empty($cachedlist)) { // the cache file is restored correctly if (!$returnall and !empty($this->translist)) { // return just enabled translations foreach ($cachedlist as $langcode => $langname) { if (in_array($langcode, $this->translist)) { $languages[$langcode] = $langname; } } return $languages; } else { // return all translations return $cachedlist; } } } // the cached list of languages is not available, let us populate the list if (!$returnall and !empty($this->translist)) { // return only some translations foreach ($this->translist as $lang) { $lang = trim($lang); //Just trim spaces to be a bit more permissive if (strstr($lang, '_local') !== false) { continue; } if (strstr($lang, '_utf8') !== false) { continue; } if ($lang !== 'en' and !file_exists("{$this->otherroot}/{$lang}/langconfig.php")) { // some broken or missing lang - can not switch to it anyway continue; } $string = $this->load_component_strings('langconfig', $lang); if (!empty($string['thislanguage'])) { $languages[$lang] = $string['thislanguage'] . ' (' . $lang . ')'; } unset($string); } } else { // return all languages available in system $langdirs = get_list_of_plugins('', '', $this->otherroot); $langdirs = array_merge($langdirs, array("{$CFG->dirroot}/lang/en" => 'en')); // Sort all // Loop through all langs and get info foreach ($langdirs as $lang) { if (strstr($lang, '_local') !== false) { continue; } if (strstr($lang, '_utf8') !== false) { continue; } $string = $this->load_component_strings('langconfig', $lang); if (!empty($string['thislanguage'])) { $languages[$lang] = $string['thislanguage'] . ' (' . $lang . ')'; } unset($string); } if (!empty($CFG->langcache) and !empty($this->menucache)) { // cache the list so that it can be used next time collatorlib::asort($languages); check_dir_exists(dirname($this->menucache), true, true); file_put_contents($this->menucache, json_encode($languages)); } } collatorlib::asort($languages); return $languages; }
public function definition_after_data() { global $CFG, $DB; $mform = $this->_form; $course = $this->_customdata['course']; $context = context_course::instance($course->id); if (!empty($CFG->enableavailability)) { $mform->addElement('header', 'availabilityconditions', get_string('availabilityconditions', 'condition')); $mform->setExpanded('availabilityconditions', false); // String used by conditions more than once $strcondnone = get_string('none', 'condition'); // Grouping conditions - only if grouping is enabled at site level if (!empty($CFG->enablegroupmembersonly)) { $options = array(); if ($groupings = $DB->get_records('groupings', array('courseid' => $course->id))) { foreach ($groupings as $grouping) { $options[$grouping->id] = format_string($grouping->name, true, array('context' => $context)); } } collatorlib::asort($options); $options = array(0 => get_string('none')) + $options; $mform->addElement('select', 'groupingid', get_string('groupingsection', 'group'), $options); $mform->addHelpButton('groupingid', 'groupingsection', 'group'); } // Available from/to defaults to midnight because then the display // will be nicer where it tells users when they can access it (it // shows only the date and not time). $date = usergetdate(time()); $midnight = make_timestamp($date['year'], $date['mon'], $date['mday']); // Date and time conditions. $mform->addElement('date_time_selector', 'availablefrom', get_string('availablefrom', 'condition'), array('optional' => true, 'defaulttime' => $midnight)); $mform->addElement('date_time_selector', 'availableuntil', get_string('availableuntil', 'condition'), array('optional' => true, 'defaulttime' => $midnight)); // Conditions based on grades $gradeoptions = array(); $items = grade_item::fetch_all(array('courseid' => $course->id)); $items = $items ? $items : array(); foreach ($items as $id => $item) { $gradeoptions[$id] = $item->get_name(); } asort($gradeoptions); $gradeoptions = array(0 => $strcondnone) + $gradeoptions; $grouparray = array(); $grouparray[] = $mform->createElement('select', 'conditiongradeitemid', '', $gradeoptions); $grouparray[] = $mform->createElement('static', '', '', ' ' . get_string('grade_atleast', 'condition') . ' '); $grouparray[] = $mform->createElement('text', 'conditiongrademin', '', array('size' => 3)); $grouparray[] = $mform->createElement('static', '', '', '% ' . get_string('grade_upto', 'condition') . ' '); $grouparray[] = $mform->createElement('text', 'conditiongrademax', '', array('size' => 3)); $grouparray[] = $mform->createElement('static', '', '', '%'); $group = $mform->createElement('group', 'conditiongradegroup', get_string('gradecondition', 'condition'), $grouparray); // Get full version (including condition info) of section object $ci = new condition_info_section($this->_customdata['cs']); $fullcs = $ci->get_full_section(); $count = count($fullcs->conditionsgrade) + 1; // Grade conditions $this->repeat_elements(array($group), $count, array('conditiongradegroup[conditiongrademin]' => array('type' => PARAM_RAW), 'conditiongradegroup[conditiongrademax]' => array('type' => PARAM_RAW)), 'conditiongraderepeats', 'conditiongradeadds', 2, get_string('addgrades', 'condition'), true); $mform->addHelpButton('conditiongradegroup[0]', 'gradecondition', 'condition'); // Conditions based on user fields $operators = condition_info::get_condition_user_field_operators(); $useroptions = condition_info::get_condition_user_fields(array('context' => $context)); asort($useroptions); $useroptions = array(0 => $strcondnone) + $useroptions; $grouparray = array(); $grouparray[] =& $mform->createElement('select', 'conditionfield', '', $useroptions); $grouparray[] =& $mform->createElement('select', 'conditionfieldoperator', '', $operators); $grouparray[] =& $mform->createElement('text', 'conditionfieldvalue'); $group = $mform->createElement('group', 'conditionfieldgroup', get_string('userfield', 'condition'), $grouparray); $fieldcount = count($fullcs->conditionsfield) + 1; $this->repeat_elements(array($group), $fieldcount, array('conditionfieldgroup[conditionfieldvalue]' => array('type' => PARAM_RAW)), 'conditionfieldrepeats', 'conditionfieldadds', 2, get_string('adduserfields', 'condition'), true); $mform->addHelpButton('conditionfieldgroup[0]', 'userfield', 'condition'); // Conditions based on completion $completion = new completion_info($course); if ($completion->is_enabled()) { $completionoptions = array(); $modinfo = get_fast_modinfo($course); foreach ($modinfo->cms as $id => $cm) { // Add each course-module if it: // (a) has completion turned on // (b) does not belong to current course-section if ($cm->completion && $fullcs->id != $cm->section) { $completionoptions[$id] = $cm->name; } } asort($completionoptions); $completionoptions = array(0 => $strcondnone) + $completionoptions; $completionvalues = array(COMPLETION_COMPLETE => get_string('completion_complete', 'condition'), COMPLETION_INCOMPLETE => get_string('completion_incomplete', 'condition'), COMPLETION_COMPLETE_PASS => get_string('completion_pass', 'condition'), COMPLETION_COMPLETE_FAIL => get_string('completion_fail', 'condition')); $grouparray = array(); $grouparray[] = $mform->createElement('select', 'conditionsourcecmid', '', $completionoptions); $grouparray[] = $mform->createElement('select', 'conditionrequiredcompletion', '', $completionvalues); $group = $mform->createElement('group', 'conditioncompletiongroup', get_string('completioncondition', 'condition'), $grouparray); $count = count($fullcs->conditionscompletion) + 1; $this->repeat_elements(array($group), $count, array(), 'conditioncompletionrepeats', 'conditioncompletionadds', 2, get_string('addcompletions', 'condition'), true); $mform->addHelpButton('conditioncompletiongroup[0]', 'completionconditionsection', 'condition'); } // Availability conditions - set up form values if (!empty($CFG->enableavailability)) { $num = 0; foreach ($fullcs->conditionsgrade as $gradeitemid => $minmax) { $groupelements = $mform->getElement('conditiongradegroup[' . $num . ']')->getElements(); $groupelements[0]->setValue($gradeitemid); $groupelements[2]->setValue(is_null($minmax->min) ? '' : format_float($minmax->min, 5, true, true)); $groupelements[4]->setValue(is_null($minmax->max) ? '' : format_float($minmax->max, 5, true, true)); $num++; } $num = 0; foreach ($fullcs->conditionsfield as $fieldid => $data) { $groupelements = $mform->getElement('conditionfieldgroup[' . $num . ']')->getElements(); $groupelements[0]->setValue($fieldid); $groupelements[1]->setValue(is_null($data->operator) ? '' : $data->operator); $groupelements[2]->setValue(is_null($data->value) ? '' : $data->value); $num++; } if ($completion->is_enabled()) { $num = 0; foreach ($fullcs->conditionscompletion as $othercmid => $state) { $groupelements = $mform->getElement('conditioncompletiongroup[' . $num . ']')->getElements(); $groupelements[0]->setValue($othercmid); $groupelements[1]->setValue($state); $num++; } } } // Do we display availability info to students? $showhide = array(CONDITION_STUDENTVIEW_SHOW => get_string('showavailabilitysection_show', 'condition'), CONDITION_STUDENTVIEW_HIDE => get_string('showavailabilitysection_hide', 'condition')); $mform->addElement('select', 'showavailability', get_string('showavailabilitysection', 'condition'), $showhide); } $this->add_action_buttons(); }
function definition_after_data() { global $DB; $mform = $this->_form; // add available groupings if ($courseid = $mform->getElementValue('id') and $mform->elementExists('defaultgroupingid')) { $options = array(); if ($groupings = $DB->get_records('groupings', array('courseid' => $courseid))) { foreach ($groupings as $grouping) { $options[$grouping->id] = format_string($grouping->name); } } collatorlib::asort($options); $gr_el =& $mform->getElement('defaultgroupingid'); $gr_el->load($options); } // add course format options $formatvalue = $mform->getElementValue('format'); if (is_array($formatvalue) && !empty($formatvalue)) { $courseformat = course_get_format((object) array('format' => $formatvalue[0])); $elements = $courseformat->create_edit_form_elements($mform); for ($i = 0; $i < count($elements); $i++) { $mform->insertElementBefore($mform->removeElement($elements[$i]->getName(), false), 'addcourseformatoptionshere'); } } }
/** * Returns array of localised human-readable module names used in this course * * @param bool $plural if true returns the plural form of modules names * @return array */ public function get_used_module_names($plural = false) { $modnames = get_module_types_names($plural); $modnamesused = array(); foreach ($this->get_cms() as $cmid => $mod) { if (isset($modnames[$mod->modname]) && $mod->uservisible) { $modnamesused[$mod->modname] = $modnames[$mod->modname]; } } collatorlib::asort($modnamesused); return $modnamesused; }
public function definition() { global $CFG, $DB; $strrequired = get_string('required'); $mform =& $this->_form; $huburl = $this->_customdata['huburl']; $hubname = $this->_customdata['hubname']; $password = $this->_customdata['password']; $admin = get_admin(); $site = get_site(); //retrieve config for this hub and set default if they don't exist $cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT); $sitename = get_config('hub', 'site_name_' . $cleanhuburl); if ($sitename === false) { $sitename = format_string($site->fullname, true, array('context' => context_course::instance(SITEID))); } $sitedescription = get_config('hub', 'site_description_' . $cleanhuburl); if ($sitedescription === false) { $sitedescription = $site->summary; } $contactname = get_config('hub', 'site_contactname_' . $cleanhuburl); if ($contactname === false) { $contactname = fullname($admin, true); } $contactemail = get_config('hub', 'site_contactemail_' . $cleanhuburl); if ($contactemail === false) { $contactemail = $admin->email; } $contactphone = get_config('hub', 'site_contactphone_' . $cleanhuburl); if ($contactphone === false) { $contactphone = $admin->phone1; } $imageurl = get_config('hub', 'site_imageurl_' . $cleanhuburl); $privacy = get_config('hub', 'site_privacy_' . $cleanhuburl); $address = get_config('hub', 'site_address_' . $cleanhuburl); $region = get_config('hub', 'site_region_' . $cleanhuburl); $country = get_config('hub', 'site_country_' . $cleanhuburl); if ($country === false) { $country = $admin->country; } $language = get_config('hub', 'site_language_' . $cleanhuburl); if ($language === false) { $language = current_language(); } $geolocation = get_config('hub', 'site_geolocation_' . $cleanhuburl); $contactable = get_config('hub', 'site_contactable_' . $cleanhuburl); $emailalert = get_config('hub', 'site_emailalert_' . $cleanhuburl); $emailalert = $emailalert === 0 ? 0 : 1; $coursesnumber = get_config('hub', 'site_coursesnumber_' . $cleanhuburl); $usersnumber = get_config('hub', 'site_usersnumber_' . $cleanhuburl); $roleassignmentsnumber = get_config('hub', 'site_roleassignmentsnumber_' . $cleanhuburl); $postsnumber = get_config('hub', 'site_postsnumber_' . $cleanhuburl); $questionsnumber = get_config('hub', 'site_questionsnumber_' . $cleanhuburl); $resourcesnumber = get_config('hub', 'site_resourcesnumber_' . $cleanhuburl); $badgesnumber = get_config('hub', 'site_badges_' . $cleanhuburl); $issuedbadgesnumber = get_config('hub', 'site_issuedbadges_' . $cleanhuburl); $mediancoursesize = get_config('hub', 'site_mediancoursesize_' . $cleanhuburl); $participantnumberaveragecfg = get_config('hub', 'site_participantnumberaverage_' . $cleanhuburl); $modulenumberaveragecfg = get_config('hub', 'site_modulenumberaverage_' . $cleanhuburl); //hidden parameters $mform->addElement('hidden', 'huburl', $huburl); $mform->setType('huburl', PARAM_URL); $mform->addElement('hidden', 'hubname', $hubname); $mform->setType('hubname', PARAM_TEXT); $mform->addElement('hidden', 'password', $password); $mform->setType('password', PARAM_RAW); //the input parameters $mform->addElement('header', 'moodle', get_string('registrationinfo', 'hub')); $mform->addElement('text', 'name', get_string('sitename', 'hub'), array('class' => 'registration_textfield')); $mform->addRule('name', $strrequired, 'required', null, 'client'); $mform->setType('name', PARAM_TEXT); $mform->setDefault('name', $sitename); $mform->addHelpButton('name', 'sitename', 'hub'); $options = array(); $registrationmanager = new registration_manager(); $options[HUB_SITENOTPUBLISHED] = $registrationmanager->get_site_privacy_string(HUB_SITENOTPUBLISHED); $options[HUB_SITENAMEPUBLISHED] = $registrationmanager->get_site_privacy_string(HUB_SITENAMEPUBLISHED); $options[HUB_SITELINKPUBLISHED] = $registrationmanager->get_site_privacy_string(HUB_SITELINKPUBLISHED); $mform->addElement('select', 'privacy', get_string('siteprivacy', 'hub'), $options); $mform->setDefault('privacy', $privacy); $mform->setType('privacy', PARAM_ALPHA); $mform->addHelpButton('privacy', 'privacy', 'hub'); unset($options); $mform->addElement('textarea', 'description', get_string('sitedesc', 'hub'), array('rows' => 8, 'cols' => 41)); $mform->addRule('description', $strrequired, 'required', null, 'client'); $mform->setDefault('description', $sitedescription); $mform->setType('description', PARAM_TEXT); $mform->addHelpButton('description', 'sitedesc', 'hub'); $languages = get_string_manager()->get_list_of_languages(); collatorlib::asort($languages); $mform->addElement('select', 'language', get_string('sitelang', 'hub'), $languages); $mform->setType('language', PARAM_ALPHANUMEXT); $mform->addHelpButton('language', 'sitelang', 'hub'); $mform->setDefault('language', $language); $mform->addElement('textarea', 'address', get_string('postaladdress', 'hub'), array('rows' => 4, 'cols' => 41)); $mform->setType('address', PARAM_TEXT); $mform->setDefault('address', $address); $mform->addHelpButton('address', 'postaladdress', 'hub'); //TODO: use the region array I generated // $mform->addElement('select', 'region', get_string('selectaregion'), array('-' => '-')); // $mform->setDefault('region', $region); $mform->addElement('hidden', 'regioncode', '-'); $mform->setType('regioncode', PARAM_ALPHANUMEXT); $countries = get_string_manager()->get_list_of_countries(); $mform->addElement('select', 'countrycode', get_string('sitecountry', 'hub'), $countries); $mform->setDefault('countrycode', $country); $mform->setType('countrycode', PARAM_ALPHANUMEXT); $mform->addHelpButton('countrycode', 'sitecountry', 'hub'); $mform->addElement('text', 'geolocation', get_string('sitegeolocation', 'hub'), array('class' => 'registration_textfield')); $mform->setDefault('geolocation', $geolocation); $mform->setType('geolocation', PARAM_RAW); $mform->addHelpButton('geolocation', 'sitegeolocation', 'hub'); $mform->addElement('text', 'contactname', get_string('siteadmin', 'hub'), array('class' => 'registration_textfield')); $mform->addRule('contactname', $strrequired, 'required', null, 'client'); $mform->setType('contactname', PARAM_TEXT); $mform->setDefault('contactname', $contactname); $mform->addHelpButton('contactname', 'siteadmin', 'hub'); $mform->addElement('text', 'contactphone', get_string('sitephone', 'hub'), array('class' => 'registration_textfield')); $mform->setType('contactphone', PARAM_TEXT); $mform->addHelpButton('contactphone', 'sitephone', 'hub'); $mform->addElement('text', 'contactemail', get_string('siteemail', 'hub'), array('class' => 'registration_textfield')); $mform->addRule('contactemail', $strrequired, 'required', null, 'client'); $mform->setType('contactemail', PARAM_EMAIL); $mform->setDefault('contactemail', $contactemail); $mform->addHelpButton('contactemail', 'siteemail', 'hub'); $options = array(); $options[0] = get_string("registrationcontactno"); $options[1] = get_string("registrationcontactyes"); $mform->addElement('select', 'contactable', get_string('siteregistrationcontact', 'hub'), $options); $mform->setDefault('contactable', $contactable); $mform->setType('contactable', PARAM_INT); $mform->addHelpButton('contactable', 'siteregistrationcontact', 'hub'); unset($options); $options = array(); $options[0] = get_string("registrationno"); $options[1] = get_string("registrationyes"); $mform->addElement('select', 'emailalert', get_string('siteregistrationemail', 'hub'), $options); $mform->setDefault('emailalert', $emailalert); $mform->setType('emailalert', PARAM_INT); $mform->addHelpButton('emailalert', 'siteregistrationemail', 'hub'); unset($options); //TODO site logo $mform->addElement('hidden', 'imageurl', ''); //TODO: temporary $mform->setType('imageurl', PARAM_URL); $mform->addElement('static', 'urlstring', get_string('siteurl', 'hub'), $CFG->wwwroot); $mform->addHelpButton('urlstring', 'siteurl', 'hub'); $mform->addElement('static', 'versionstring', get_string('siteversion', 'hub'), $CFG->version); $mform->addElement('hidden', 'moodleversion', $CFG->version); $mform->setType('moodleversion', PARAM_INT); $mform->addHelpButton('versionstring', 'siteversion', 'hub'); $mform->addElement('static', 'releasestring', get_string('siterelease', 'hub'), $CFG->release); $mform->addElement('hidden', 'moodlerelease', $CFG->release); $mform->setType('moodlerelease', PARAM_TEXT); $mform->addHelpButton('releasestring', 'siterelease', 'hub'); /// Display statistic that are going to be retrieve by the hub $coursecount = $DB->count_records('course') - 1; $usercount = $DB->count_records('user', array('deleted' => 0)); $roleassigncount = $DB->count_records('role_assignments'); $postcount = $DB->count_records('forum_posts'); $questioncount = $DB->count_records('question'); $resourcecount = $DB->count_records('resource'); require_once $CFG->dirroot . "/course/lib.php"; $participantnumberaverage = number_format(average_number_of_participants(), 2); $modulenumberaverage = number_format(average_number_of_courses_modules(), 2); require_once $CFG->libdir . '/badgeslib.php'; $badges = $DB->count_records_select('badge', 'status <> ' . BADGE_STATUS_ARCHIVED); $issuedbadges = $DB->count_records('badge_issued'); if (HUB_MOODLEORGHUBURL != $huburl) { $mform->addElement('checkbox', 'courses', get_string('sendfollowinginfo', 'hub'), " " . get_string('coursesnumber', 'hub', $coursecount)); $mform->setDefault('courses', $coursesnumber != -1); $mform->setType('courses', PARAM_INT); $mform->addHelpButton('courses', 'sendfollowinginfo', 'hub'); $mform->addElement('checkbox', 'users', '', " " . get_string('usersnumber', 'hub', $usercount)); $mform->setDefault('users', $usersnumber != -1); $mform->setType('users', PARAM_INT); $mform->addElement('checkbox', 'roleassignments', '', " " . get_string('roleassignmentsnumber', 'hub', $roleassigncount)); $mform->setDefault('roleassignments', $roleassignmentsnumber != -1); $mform->setType('roleassignments', PARAM_INT); $mform->addElement('checkbox', 'posts', '', " " . get_string('postsnumber', 'hub', $postcount)); $mform->setDefault('posts', $postsnumber != -1); $mform->setType('posts', PARAM_INT); $mform->addElement('checkbox', 'questions', '', " " . get_string('questionsnumber', 'hub', $questioncount)); $mform->setDefault('questions', $questionsnumber != -1); $mform->setType('questions', PARAM_INT); $mform->addElement('checkbox', 'resources', '', " " . get_string('resourcesnumber', 'hub', $resourcecount)); $mform->setDefault('resources', $resourcesnumber != -1); $mform->setType('resources', PARAM_INT); $mform->addElement('checkbox', 'badges', '', " " . get_string('badgesnumber', 'hub', $badges)); $mform->setDefault('badges', $badgesnumber != -1); $mform->setType('resources', PARAM_INT); $mform->addElement('checkbox', 'issuedbadges', '', " " . get_string('issuedbadgesnumber', 'hub', $issuedbadges)); $mform->setDefault('issuedbadges', $issuedbadgesnumber != -1); $mform->setType('resources', PARAM_INT); $mform->addElement('checkbox', 'participantnumberaverage', '', " " . get_string('participantnumberaverage', 'hub', $participantnumberaverage)); $mform->setDefault('participantnumberaverage', $participantnumberaveragecfg != -1); $mform->setType('participantnumberaverage', PARAM_FLOAT); $mform->addElement('checkbox', 'modulenumberaverage', '', " " . get_string('modulenumberaverage', 'hub', $modulenumberaverage)); $mform->setDefault('modulenumberaverage', $modulenumberaveragecfg != -1); $mform->setType('modulenumberaverage', PARAM_FLOAT); } else { $mform->addElement('static', 'courseslabel', get_string('sendfollowinginfo', 'hub'), " " . get_string('coursesnumber', 'hub', $coursecount)); $mform->addElement('hidden', 'courses', 1); $mform->setType('courses', PARAM_INT); $mform->addHelpButton('courseslabel', 'sendfollowinginfo', 'hub'); $mform->addElement('static', 'userslabel', '', " " . get_string('usersnumber', 'hub', $usercount)); $mform->addElement('hidden', 'users', 1); $mform->setType('users', PARAM_INT); $mform->addElement('static', 'roleassignmentslabel', '', " " . get_string('roleassignmentsnumber', 'hub', $roleassigncount)); $mform->addElement('hidden', 'roleassignments', 1); $mform->setType('roleassignments', PARAM_INT); $mform->addElement('static', 'postslabel', '', " " . get_string('postsnumber', 'hub', $postcount)); $mform->addElement('hidden', 'posts', 1); $mform->setType('posts', PARAM_INT); $mform->addElement('static', 'questionslabel', '', " " . get_string('questionsnumber', 'hub', $questioncount)); $mform->addElement('hidden', 'questions', 1); $mform->setType('questions', PARAM_INT); $mform->addElement('static', 'resourceslabel', '', " " . get_string('resourcesnumber', 'hub', $resourcecount)); $mform->addElement('hidden', 'resources', 1); $mform->setType('resources', PARAM_INT); $mform->addElement('static', 'badgeslabel', '', " " . get_string('badgesnumber', 'hub', $badges)); $mform->addElement('hidden', 'badges', 1); $mform->setType('badges', PARAM_INT); $mform->addElement('static', 'issuedbadgeslabel', '', " " . get_string('issuedbadgesnumber', 'hub', $issuedbadges)); $mform->addElement('hidden', 'issuedbadges', true); $mform->setType('issuedbadges', PARAM_INT); $mform->addElement('static', 'participantnumberaveragelabel', '', " " . get_string('participantnumberaverage', 'hub', $participantnumberaverage)); $mform->addElement('hidden', 'participantnumberaverage', 1); $mform->setType('participantnumberaverage', PARAM_FLOAT); $mform->addElement('static', 'modulenumberaveragelabel', '', " " . get_string('modulenumberaverage', 'hub', $modulenumberaverage)); $mform->addElement('hidden', 'modulenumberaverage', 1); $mform->setType('modulenumberaverage', PARAM_FLOAT); } //check if it's a first registration or update $hubregistered = $registrationmanager->get_registeredhub($huburl); if (!empty($hubregistered)) { $buttonlabel = get_string('updatesite', 'hub', !empty($hubname) ? $hubname : $huburl); $mform->addElement('hidden', 'update', true); $mform->setType('update', PARAM_BOOL); } else { $buttonlabel = get_string('registersite', 'hub', !empty($hubname) ? $hubname : $huburl); } $this->add_action_buttons(false, $buttonlabel); }
/** * Cleans the list of options and returns it as a string separating options with |||. * * @param string $value The string containing the escaped options. * @return string The options */ protected function get_unescaped_options($value) { // Can be multiple comma separated, with valuable commas escaped with backslash. $optionsarray = array_map('trim', preg_replace('/\\\\,/', ',', preg_split('/(?<!\\\\),/', $value))); // Sort by value (keeping the keys is irrelevant). collatorlib::asort($optionsarray, SORT_STRING); // Returning it as a string which is easier to match against other values. return implode('|||', $optionsarray); }
/** * Obtains the last unique sufix (numeric) using the test course prefix. * * @return int The last generated numeric value. */ protected static function get_last_testcourse_id() { global $DB; $params = array(); $params['shortnameprefix'] = $DB->sql_like_escape(self::SHORTNAMEPREFIX) . '%'; $like = $DB->sql_like('shortname', ':shortnameprefix'); if (!($testcourses = $DB->get_records_select('course', $like, $params, '', 'shortname'))) { return 0; } // SQL order by is not appropiate here as is ordering strings. $shortnames = array_keys($testcourses); collatorlib::asort($shortnames, collatorlib::SORT_NATURAL); $shortnames = array_reverse($shortnames); // They come ordered by shortname DESC, so non-numeric values will be the first ones. $prefixnchars = strlen(self::SHORTNAMEPREFIX); foreach ($shortnames as $shortname) { $sufix = substr($shortname, $prefixnchars); if (preg_match('/^[\\d]+$/', $sufix)) { return $sufix; } } // If all sufixes are not numeric this is the first make test site run. return 0; }
public function definition() { global $CFG, $DB, $USER, $OUTPUT; $strrequired = get_string('required'); $mform =& $this->_form; $huburl = $this->_customdata['huburl']; $hubname = $this->_customdata['hubname']; $course = $this->_customdata['course']; $advertise = $this->_customdata['advertise']; $share = $this->_customdata['share']; $page = $this->_customdata['page']; $site = get_site(); //hidden parameters $mform->addElement('hidden', 'huburl', $huburl); $mform->setType('huburl', PARAM_URL); $mform->addElement('hidden', 'hubname', $hubname); $mform->setType('hubname', PARAM_TEXT); //check on the hub if the course has already been published $registrationmanager = new registration_manager(); $registeredhub = $registrationmanager->get_registeredhub($huburl); $publicationmanager = new course_publish_manager(); $publications = $publicationmanager->get_publications($registeredhub->huburl, $course->id, $advertise); if (!empty($publications)) { //get the last publication of this course $publication = array_pop($publications); $function = 'hub_get_courses'; $options = new stdClass(); $options->ids = array($publication->hubcourseid); $options->allsitecourses = 1; $params = array('search' => '', 'downloadable' => $share, 'enrollable' => !$share, 'options' => $options); $serverurl = $huburl . "/local/hub/webservice/webservices.php"; require_once $CFG->dirroot . "/webservice/xmlrpc/lib.php"; $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $registeredhub->token); try { $result = $xmlrpcclient->call($function, $params); $publishedcourses = $result['courses']; } catch (Exception $e) { $error = $OUTPUT->notification(get_string('errorcourseinfo', 'hub', $e->getMessage())); $mform->addElement('static', 'errorhub', '', $error); } } if (!empty($publishedcourses)) { $publishedcourse = $publishedcourses[0]; $hubcourseid = $publishedcourse['id']; $defaultfullname = $publishedcourse['fullname']; $defaultshortname = $publishedcourse['shortname']; $defaultsummary = $publishedcourse['description']; $defaultlanguage = $publishedcourse['language']; $defaultpublishername = $publishedcourse['publishername']; $defaultpublisheremail = $publishedcourse['publisheremail']; $defaultcontributornames = $publishedcourse['contributornames']; $defaultcoverage = $publishedcourse['coverage']; $defaultcreatorname = $publishedcourse['creatorname']; $defaultlicenceshortname = $publishedcourse['licenceshortname']; $defaultsubject = $publishedcourse['subject']; $defaultaudience = $publishedcourse['audience']; $defaulteducationallevel = $publishedcourse['educationallevel']; $defaultcreatornotes = $publishedcourse['creatornotes']; $defaultcreatornotesformat = $publishedcourse['creatornotesformat']; $screenshotsnumber = $publishedcourse['screenshots']; $privacy = $publishedcourse['privacy']; if ($screenshotsnumber > 0 and !empty($privacy)) { $page->requires->yui_module('moodle-block_community-imagegallery', 'M.blocks_community.init_imagegallery', array(array('imageids' => array($hubcourseid), 'imagenumbers' => array($screenshotsnumber), 'huburl' => $huburl))); } } else { $defaultfullname = $course->fullname; $defaultshortname = $course->shortname; $defaultsummary = clean_param($course->summary, PARAM_TEXT); if (empty($course->lang)) { $language = get_site()->lang; if (empty($language)) { $defaultlanguage = current_language(); } else { $defaultlanguage = $language; } } else { $defaultlanguage = $course->lang; } $defaultpublishername = $USER->firstname . ' ' . $USER->lastname; $defaultpublisheremail = $USER->email; $defaultcontributornames = ''; $defaultcoverage = ''; $defaultcreatorname = $USER->firstname . ' ' . $USER->lastname; $defaultlicenceshortname = 'cc'; $defaultsubject = 'none'; $defaultaudience = HUB_AUDIENCE_STUDENTS; $defaulteducationallevel = HUB_EDULEVEL_TERTIARY; $defaultcreatornotes = ''; $defaultcreatornotesformat = FORMAT_HTML; $screenshotsnumber = 0; } //the input parameters $mform->addElement('header', 'moodle', get_string('publicationinfo', 'hub')); $mform->addElement('text', 'name', get_string('coursename', 'hub'), array('class' => 'metadatatext')); $mform->addRule('name', $strrequired, 'required', null, 'client'); $mform->setType('name', PARAM_TEXT); $mform->setDefault('name', $defaultfullname); $mform->addHelpButton('name', 'name', 'hub'); $mform->addElement('hidden', 'id', $this->_customdata['id']); $mform->setType('id', PARAM_INT); if ($share) { $buttonlabel = get_string('shareon', 'hub', !empty($hubname) ? $hubname : $huburl); $mform->addElement('hidden', 'share', $share); $mform->setType('share', PARAM_BOOL); $mform->addElement('text', 'demourl', get_string('demourl', 'hub'), array('class' => 'metadatatext')); $mform->setType('demourl', PARAM_URL); $mform->setDefault('demourl', new moodle_url("/course/view.php?id=" . $course->id)); $mform->addHelpButton('demourl', 'demourl', 'hub'); } if ($advertise) { if (empty($publishedcourses)) { $buttonlabel = get_string('advertiseon', 'hub', !empty($hubname) ? $hubname : $huburl); } else { $buttonlabel = get_string('readvertiseon', 'hub', !empty($hubname) ? $hubname : $huburl); } $mform->addElement('hidden', 'advertise', $advertise); $mform->setType('advertise', PARAM_BOOL); $mform->addElement('hidden', 'courseurl', $CFG->wwwroot . "/course/view.php?id=" . $course->id); $mform->setType('courseurl', PARAM_URL); $mform->addElement('static', 'courseurlstring', get_string('courseurl', 'hub')); $mform->setDefault('courseurlstring', new moodle_url("/course/view.php?id=" . $course->id)); $mform->addHelpButton('courseurlstring', 'courseurl', 'hub'); } $mform->addElement('text', 'courseshortname', get_string('courseshortname', 'hub'), array('class' => 'metadatatext')); $mform->setDefault('courseshortname', $defaultshortname); $mform->addHelpButton('courseshortname', 'courseshortname', 'hub'); $mform->setType('courseshortname', PARAM_TEXT); $mform->addElement('textarea', 'description', get_string('description'), array('rows' => 10, 'cols' => 57)); $mform->addRule('description', $strrequired, 'required', null, 'client'); $mform->setDefault('description', $defaultsummary); $mform->setType('description', PARAM_TEXT); $mform->addHelpButton('description', 'description', 'hub'); $languages = get_string_manager()->get_list_of_languages(); collatorlib::asort($languages); $mform->addElement('select', 'language', get_string('language'), $languages); $mform->setDefault('language', $defaultlanguage); $mform->addHelpButton('language', 'language', 'hub'); $mform->addElement('text', 'publishername', get_string('publishername', 'hub'), array('class' => 'metadatatext')); $mform->setDefault('publishername', $defaultpublishername); $mform->addRule('publishername', $strrequired, 'required', null, 'client'); $mform->addHelpButton('publishername', 'publishername', 'hub'); $mform->setType('publishername', PARAM_NOTAGS); $mform->addElement('text', 'publisheremail', get_string('publisheremail', 'hub'), array('class' => 'metadatatext')); $mform->setDefault('publisheremail', $defaultpublisheremail); $mform->addRule('publisheremail', $strrequired, 'required', null, 'client'); $mform->addHelpButton('publisheremail', 'publisheremail', 'hub'); $mform->setType('publisheremail', PARAM_EMAIL); $mform->addElement('text', 'creatorname', get_string('creatorname', 'hub'), array('class' => 'metadatatext')); $mform->addRule('creatorname', $strrequired, 'required', null, 'client'); $mform->setType('creatorname', PARAM_NOTAGS); $mform->setDefault('creatorname', $defaultcreatorname); $mform->addHelpButton('creatorname', 'creatorname', 'hub'); $mform->addElement('text', 'contributornames', get_string('contributornames', 'hub'), array('class' => 'metadatatext')); $mform->setDefault('contributornames', $defaultcontributornames); $mform->addHelpButton('contributornames', 'contributornames', 'hub'); $mform->setType('contributornames', PARAM_NOTAGS); $mform->addElement('text', 'coverage', get_string('tags', 'hub'), array('class' => 'metadatatext')); $mform->setType('coverage', PARAM_TEXT); $mform->setDefault('coverage', $defaultcoverage); $mform->addHelpButton('coverage', 'tags', 'hub'); require_once $CFG->libdir . "/licenselib.php"; $licensemanager = new license_manager(); $licences = $licensemanager->get_licenses(); $options = array(); foreach ($licences as $license) { $options[$license->shortname] = get_string($license->shortname, 'license'); } $mform->addElement('select', 'licence', get_string('license'), $options); $mform->setDefault('licence', $defaultlicenceshortname); unset($options); $mform->addHelpButton('licence', 'licence', 'hub'); $options = $publicationmanager->get_sorted_subjects(); //prepare data for the smartselect foreach ($options as $key => &$option) { $keylength = strlen($key); if ($keylength == 10) { $option = " " . $option; } else { if ($keylength == 12) { $option = " " . $option; } } } $options = array('none' => get_string('none', 'hub')) + $options; $mform->addElement('select', 'subject', get_string('subject', 'hub'), $options); unset($options); $mform->addHelpButton('subject', 'subject', 'hub'); $mform->setDefault('subject', $defaultsubject); $mform->addRule('subject', $strrequired, 'required', null, 'client'); $this->init_javascript_enhancement('subject', 'smartselect', array('selectablecategories' => false, 'mode' => 'compact')); $options = array(); $options[HUB_AUDIENCE_EDUCATORS] = get_string('audienceeducators', 'hub'); $options[HUB_AUDIENCE_STUDENTS] = get_string('audiencestudents', 'hub'); $options[HUB_AUDIENCE_ADMINS] = get_string('audienceadmins', 'hub'); $mform->addElement('select', 'audience', get_string('audience', 'hub'), $options); $mform->setDefault('audience', $defaultaudience); unset($options); $mform->addHelpButton('audience', 'audience', 'hub'); $options = array(); $options[HUB_EDULEVEL_PRIMARY] = get_string('edulevelprimary', 'hub'); $options[HUB_EDULEVEL_SECONDARY] = get_string('edulevelsecondary', 'hub'); $options[HUB_EDULEVEL_TERTIARY] = get_string('eduleveltertiary', 'hub'); $options[HUB_EDULEVEL_GOVERNMENT] = get_string('edulevelgovernment', 'hub'); $options[HUB_EDULEVEL_ASSOCIATION] = get_string('edulevelassociation', 'hub'); $options[HUB_EDULEVEL_CORPORATE] = get_string('edulevelcorporate', 'hub'); $options[HUB_EDULEVEL_OTHER] = get_string('edulevelother', 'hub'); $mform->addElement('select', 'educationallevel', get_string('educationallevel', 'hub'), $options); $mform->setDefault('educationallevel', $defaulteducationallevel); unset($options); $mform->addHelpButton('educationallevel', 'educationallevel', 'hub'); $editoroptions = array('maxfiles' => 0, 'maxbytes' => 0, 'trusttext' => false, 'forcehttps' => false); $mform->addElement('editor', 'creatornotes', get_string('creatornotes', 'hub'), '', $editoroptions); $mform->addRule('creatornotes', $strrequired, 'required', null, 'client'); $mform->setType('creatornotes', PARAM_CLEANHTML); $mform->addHelpButton('creatornotes', 'creatornotes', 'hub'); if ($advertise) { if (!empty($screenshotsnumber)) { if (!empty($privacy)) { $baseurl = new moodle_url($huburl . '/local/hub/webservice/download.php', array('courseid' => $hubcourseid, 'filetype' => HUB_SCREENSHOT_FILE_TYPE)); $screenshothtml = html_writer::empty_tag('img', array('src' => $baseurl, 'alt' => $defaultfullname)); $screenshothtml = html_writer::tag('div', $screenshothtml, array('class' => 'coursescreenshot', 'id' => 'image-' . $hubcourseid)); } else { $screenshothtml = get_string('existingscreenshotnumber', 'hub', $screenshotsnumber); } $mform->addElement('static', 'existingscreenshots', get_string('existingscreenshots', 'hub'), $screenshothtml); $mform->addHelpButton('existingscreenshots', 'deletescreenshots', 'hub'); $mform->addElement('checkbox', 'deletescreenshots', '', ' ' . get_string('deletescreenshots', 'hub')); } $mform->addElement('hidden', 'existingscreenshotnumber', $screenshotsnumber); $mform->setType('existingscreenshotnumber', PARAM_INT); } $mform->addElement('filemanager', 'screenshots', get_string('addscreenshots', 'hub'), null, array('subdirs' => 0, 'maxbytes' => 1000000, 'maxfiles' => 3)); $mform->addHelpButton('screenshots', 'screenshots', 'hub'); $this->add_action_buttons(false, $buttonlabel); //set default value for creatornotes editor $data = new stdClass(); $data->creatornotes = array(); $data->creatornotes['text'] = $defaultcreatornotes; $data->creatornotes['format'] = $defaultcreatornotesformat; $this->set_data($data); }
function definition() { global $CFG, $COURSE, $DB; $mform =& $this->_form; //------------------------------------------------------------------------------- $mform->addElement('header', 'general', get_string('general', 'form')); $mform->addElement('text', 'name', get_string('forumname', 'forum'), array('size'=>'64')); if (!empty($CFG->formatstringstriptags)) { $mform->setType('name', PARAM_TEXT); } else { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor(true, get_string('forumintro', 'forum')); $forumtypes = forum_get_forum_types(); collatorlib::asort($forumtypes, collatorlib::SORT_STRING); $mform->addElement('select', 'type', get_string('forumtype', 'forum'), $forumtypes); $mform->addHelpButton('type', 'forumtype', 'forum'); $mform->setDefault('type', 'general'); // Attachments and word count. $mform->addElement('header', 'attachmentswordcounthdr', get_string('attachmentswordcount', 'forum')); $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes, 0, $CFG->forum_maxbytes); $choices[1] = get_string('uploadnotallowed'); $mform->addElement('select', 'maxbytes', get_string('maxattachmentsize', 'forum'), $choices); $mform->addHelpButton('maxbytes', 'maxattachmentsize', 'forum'); $mform->setDefault('maxbytes', $CFG->forum_maxbytes); $choices = array( 0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 20 => 20, 50 => 50, 100 => 100 ); $mform->addElement('select', 'maxattachments', get_string('maxattachments', 'forum'), $choices); $mform->addHelpButton('maxattachments', 'maxattachments', 'forum'); $mform->setDefault('maxattachments', $CFG->forum_maxattachments); $mform->addElement('selectyesno', 'displaywordcount', get_string('displaywordcount', 'forum')); $mform->addHelpButton('displaywordcount', 'displaywordcount', 'forum'); $mform->setDefault('displaywordcount', 0); // Subscription and tracking. $mform->addElement('header', 'subscriptionandtrackinghdr', get_string('subscriptionandtracking', 'forum')); $options = array(); $options[FORUM_CHOOSESUBSCRIBE] = get_string('subscriptionoptional', 'forum'); $options[FORUM_FORCESUBSCRIBE] = get_string('subscriptionforced', 'forum'); $options[FORUM_INITIALSUBSCRIBE] = get_string('subscriptionauto', 'forum'); $options[FORUM_DISALLOWSUBSCRIBE] = get_string('subscriptiondisabled','forum'); $mform->addElement('select', 'forcesubscribe', get_string('subscriptionmode', 'forum'), $options); $mform->addHelpButton('forcesubscribe', 'subscriptionmode', 'forum'); $options = array(); $options[FORUM_TRACKING_OPTIONAL] = get_string('trackingoptional', 'forum'); $options[FORUM_TRACKING_OFF] = get_string('trackingoff', 'forum'); $options[FORUM_TRACKING_ON] = get_string('trackingon', 'forum'); $mform->addElement('select', 'trackingtype', get_string('trackingtype', 'forum'), $options); $mform->addHelpButton('trackingtype', 'trackingtype', 'forum'); if ($CFG->enablerssfeeds && isset($CFG->forum_enablerssfeeds) && $CFG->forum_enablerssfeeds) { //------------------------------------------------------------------------------- $mform->addElement('header', 'rssheader', get_string('rss')); $choices = array(); $choices[0] = get_string('none'); $choices[1] = get_string('discussions', 'forum'); $choices[2] = get_string('posts', 'forum'); $mform->addElement('select', 'rsstype', get_string('rsstype'), $choices); $mform->addHelpButton('rsstype', 'rsstype', 'forum'); $choices = array(); $choices[0] = '0'; $choices[1] = '1'; $choices[2] = '2'; $choices[3] = '3'; $choices[4] = '4'; $choices[5] = '5'; $choices[10] = '10'; $choices[15] = '15'; $choices[20] = '20'; $choices[25] = '25'; $choices[30] = '30'; $choices[40] = '40'; $choices[50] = '50'; $mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices); $mform->addHelpButton('rssarticles', 'rssarticles', 'forum'); $mform->disabledIf('rssarticles', 'rsstype', 'eq', '0'); } //------------------------------------------------------------------------------- $mform->addElement('header', 'blockafterheader', get_string('blockafter', 'forum')); $options = array(); $options[0] = get_string('blockperioddisabled','forum'); $options[60*60*24] = '1 '.get_string('day'); $options[60*60*24*2] = '2 '.get_string('days'); $options[60*60*24*3] = '3 '.get_string('days'); $options[60*60*24*4] = '4 '.get_string('days'); $options[60*60*24*5] = '5 '.get_string('days'); $options[60*60*24*6] = '6 '.get_string('days'); $options[60*60*24*7] = '1 '.get_string('week'); $mform->addElement('select', 'blockperiod', get_string('blockperiod', 'forum'), $options); $mform->addHelpButton('blockperiod', 'blockperiod', 'forum'); $mform->addElement('text', 'blockafter', get_string('blockafter', 'forum')); $mform->setType('blockafter', PARAM_INT); $mform->setDefault('blockafter', '0'); $mform->addRule('blockafter', null, 'numeric', null, 'client'); $mform->addHelpButton('blockafter', 'blockafter', 'forum'); $mform->disabledIf('blockafter', 'blockperiod', 'eq', 0); $mform->addElement('text', 'warnafter', get_string('warnafter', 'forum')); $mform->setType('warnafter', PARAM_INT); $mform->setDefault('warnafter', '0'); $mform->addRule('warnafter', null, 'numeric', null, 'client'); $mform->addHelpButton('warnafter', 'warnafter', 'forum'); $mform->disabledIf('warnafter', 'blockperiod', 'eq', 0); $coursecontext = context_course::instance($COURSE->id); plagiarism_get_form_elements_module($mform, $coursecontext, 'mod_forum'); //------------------------------------------------------------------------------- $this->standard_grading_coursemodule_elements(); $this->standard_coursemodule_elements(); //------------------------------------------------------------------------------- // buttons $this->add_action_buttons(); }
/** * Locale aware sorting, the key associations are kept, values are sorted alphabetically. * * @param array $arr array to be sorted (reference) * @param int $sortflag One of Collator::SORT_REGULAR, Collator::SORT_NUMERIC, Collator::SORT_STRING * @return void modifies parameter */ public static function asort(array &$arr, $sortflag = null) { debugging('textlib::asort has been superseeded by collatorlib::asort please upgrade your code to use that', DEBUG_DEVELOPER); collatorlib::asort($arr, $sortflag); }
/** * Sort an array of question types according to the order the admin set up, * and then alphabetically for the rest. * @param array qtype->name() => qtype->local_name(). * @return array sorted array. */ public static function sort_qtype_array($qtypes, $config = null) { if (is_null($config)) { $config = self::get_config(); } $sortorder = array(); $otherqtypes = array(); foreach ($qtypes as $name => $localname) { $sortvar = $name . '_sortorder'; if (isset($config->$sortvar)) { $sortorder[$config->$sortvar] = $name; } else { $otherqtypes[$name] = $localname; } } ksort($sortorder); collatorlib::asort($otherqtypes); $sortedqtypes = array(); foreach ($sortorder as $name) { $sortedqtypes[$name] = $qtypes[$name]; } foreach ($otherqtypes as $name => $notused) { $sortedqtypes[$name] = $qtypes[$name]; } return $sortedqtypes; }
/// Print the table of all installed local plugins $table = new flexible_table('localplugins_administration_table'); $table->define_columns(array('name', 'version', 'delete')); $table->define_headers(array(get_string('plugin'), get_string('version'), get_string('delete'))); $table->define_baseurl($PAGE->url); $table->set_attribute('id', 'localplugins'); $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide'); $table->setup(); $plugins = array(); foreach (get_plugin_list('local') as $plugin => $plugindir) { if (get_string_manager()->string_exists('pluginname', 'local_' . $plugin)) { $strpluginname = get_string('pluginname', 'local_' . $plugin); } else { $strpluginname = $plugin; } $plugins[$plugin] = $strpluginname; } collatorlib::asort($plugins); foreach ($plugins as $plugin => $name) { $delete = new moodle_url($PAGE->url, array('delete' => $plugin, 'sesskey' => sesskey())); $delete = html_writer::link($delete, get_string('delete')); $version = get_config('local_' . $plugin); if (!empty($version->version)) { $version = $version->version; } else { $version = '?'; } $table->add_data(array($name, $version, $delete)); } $table->print_html(); echo $OUTPUT->footer();
/** * Returns the localised human-readable names of all used modules * * @param bool $plural if true returns the plural forms of the names * @return array where key is the module name (component name without 'mod_') and * the value is the human-readable string. Array sorted alphabetically by value */ function get_module_types_names($plural = false) { static $modnames = null; global $DB, $CFG; if ($modnames === null) { $modnames = array(0 => array(), 1 => array()); if ($allmods = $DB->get_records("modules")) { foreach ($allmods as $mod) { if (file_exists("{$CFG->dirroot}/mod/{$mod->name}/lib.php") && $mod->visible) { $modnames[0][$mod->name] = get_string("modulename", "{$mod->name}"); $modnames[1][$mod->name] = get_string("modulenameplural", "{$mod->name}"); } } collatorlib::asort($modnames[0]); collatorlib::asort($modnames[1]); } } return $modnames[(int) $plural]; }
public function test_legacy_collatorlib() { $arr = array('b' => 'ab', 1 => 'aa', 0 => 'cc'); $result = collatorlib::asort($arr); $this->assertSame(array('aa', 'ab', 'cc'), array_values($arr)); $this->assertSame(array(1, 'b', 0), array_keys($arr)); $this->assertTrue($result); }
/** * Tests the static asort method * @return void */ public function test_asort() { $arr = array('b' => 'ab', 1 => 'aa', 0 => 'cc'); $result = collatorlib::asort($arr); $this->assertSame(array_values($arr), array('aa', 'ab', 'cc')); $this->assertSame(array_keys($arr), array(1, 'b', 0)); $this->assertTrue($result); $arr = array('b' => 'ab', 1 => 'aa', 0 => 'cc'); $result = collatorlib::asort($arr, collatorlib::SORT_STRING); $this->assertSame(array_values($arr), array('aa', 'ab', 'cc')); $this->assertSame(array_keys($arr), array(1, 'b', 0)); $this->assertTrue($result); $arr = array('b' => 'aac', 1 => 'Aac', 0 => 'cc'); $result = collatorlib::asort($arr, collatorlib::SORT_STRING | collatorlib::CASE_SENSITIVE); $this->assertSame(array_values($arr), array('Aac', 'aac', 'cc')); $this->assertSame(array_keys($arr), array(1, 'b', 0)); $this->assertTrue($result); $arr = array('b' => 'a1', 1 => 'a10', 0 => 'a3b'); $result = collatorlib::asort($arr); $this->assertSame(array_values($arr), array('a1', 'a10', 'a3b')); $this->assertSame(array_keys($arr), array('b', 1, 0)); $this->assertTrue($result); $arr = array('b' => 'a1', 1 => 'a10', 0 => 'a3b'); $result = collatorlib::asort($arr, collatorlib::SORT_NATURAL); $this->assertSame(array_values($arr), array('a1', 'a3b', 'a10')); $this->assertSame(array_keys($arr), array('b', 0, 1)); $this->assertTrue($result); $arr = array('b' => '1.1.1', 1 => '1.2', 0 => '1.20.2'); $result = collatorlib::asort($arr, collatorlib::SORT_NATURAL); $this->assertSame(array_values($arr), array('1.1.1', '1.2', '1.20.2')); $this->assertSame(array_keys($arr), array('b', 1, 0)); $this->assertTrue($result); $arr = array('b' => '-1', 1 => 1000, 0 => -1.2, 3 => 1, 4 => false); $result = collatorlib::asort($arr, collatorlib::SORT_NUMERIC); $this->assertSame(array_values($arr), array(-1.2, '-1', false, 1, 1000)); $this->assertSame(array_keys($arr), array(0, 'b', 4, 3, 1)); $this->assertTrue($result); $arr = array('b' => array(1), 1 => array(2, 3), 0 => 1); $result = collatorlib::asort($arr, collatorlib::SORT_REGULAR); $this->assertSame(array_values($arr), array(1, array(1), array(2, 3))); $this->assertSame(array_keys($arr), array(0, 'b', 1)); $this->assertTrue($result); // test sorting of array of arrays - first element should be used for actual comparison $arr = array(0 => array('bb', 'z'), 1 => array('ab', 'a'), 2 => array('zz', 'x')); $result = collatorlib::asort($arr, collatorlib::SORT_REGULAR); $this->assertSame(array_keys($arr), array(1, 0, 2)); $this->assertTrue($result); $arr = array('a' => 'áb', 'b' => 'ab', 1 => 'aa', 0 => 'cc', 'x' => 'Áb'); $result = collatorlib::asort($arr); $this->assertSame(array_values($arr), array('aa', 'ab', 'áb', 'Áb', 'cc'), $this->error); $this->assertSame(array_keys($arr), array(1, 'b', 'a', 'x', 0), $this->error); $this->assertTrue($result); $a = array(2 => 'b', 1 => 'c'); $c =& $a; $b =& $a; collatorlib::asort($b); $this->assertSame($a, $b); $this->assertSame($c, $b); }
/** * Get the names of all the filters installed in this Moodle. * * @return array path => filter name from the appropriate lang file. e.g. * array('tex' => 'TeX Notation'); * sorted in alphabetical order of name. */ function filter_get_all_installed() { global $CFG; $filternames = array(); foreach (get_plugin_list('filter') as $filter => $fulldir) { if (is_readable("{$fulldir}/filter.php")) { $filternames[$filter] = filter_get_name($filter); } } collatorlib::asort($filternames); return $filternames; }
} if (!$blockobject) { // ignore $undeletable = ''; } else { if (in_array($blockname, $undeletableblocktypes)) { $undeletable = '<a href="blocks.php?unprotect=' . $blockid . '&sesskey=' . sesskey() . '" title="' . $strunprotect . '">' . '<img src="' . $OUTPUT->pix_url('t/unlock') . '" class="icon" alt="' . $strunprotect . '" /></a>'; } else { $undeletable = '<a href="blocks.php?protect=' . $blockid . '&sesskey=' . sesskey() . '" title="' . $strprotect . '">' . '<img src="' . $OUTPUT->pix_url('t/unlock_gray') . '" class="icon" alt="' . $strprotect . '" /></a>'; } } $row = array('<span' . $class . '>' . $strblockname . '</span>', $blocklist, '<span' . $class . '>' . $version . '</span>', $visible, $undeletable, $delete, $settings); $tablerows[] = array(strip_tags($strblockname), $row); // first element will be used for sorting } collatorlib::asort($tablerows); foreach ($tablerows as $row) { $table->add_data($row[1]); } $table->print_html(); if (!empty($incompatible)) { echo $OUTPUT->heading(get_string('incompatibleblocks', 'blockstable', 'admin')); $table = new flexible_table('admin-blocks-incompatible'); $table->define_columns(array('block', 'delete')); $table->define_headers(array($strname, $strdelete)); $table->define_baseurl($CFG->wwwroot . '/' . $CFG->admin . '/blocks.php'); $table->set_attribute('class', 'incompatibleblockstable generaltable'); $table->setup(); foreach ($incompatible as $block) { $table->add_data(array($block->name, '<a href="blocks.php?delete=' . $block->id . '&sesskey=' . sesskey() . '">' . $strdelete . '</a>')); }
public function get_listing($path = '', $page = '') { global $CFG, $OUTPUT; $list = array(); $list['list'] = array(); // process breacrumb trail $list['path'] = array( array('name'=>get_string('root', 'repository_filesystem'), 'path'=>'') ); $trail = ''; if (!empty($path)) { $parts = explode('/', $path); if (count($parts) > 1) { foreach ($parts as $part) { if (!empty($part)) { $trail .= ('/'.$part); $list['path'][] = array('name'=>$part, 'path'=>$trail); } } } else { $list['path'][] = array('name'=>$path, 'path'=>$path); } $this->root_path .= ($path.'/'); } $list['manage'] = false; $list['dynload'] = true; $list['nologin'] = true; $list['nosearch'] = true; // retrieve list of files and directories and sort them $fileslist = array(); $dirslist = array(); if ($dh = opendir($this->root_path)) { while (($file = readdir($dh)) != false) { if ( $file != '.' and $file !='..') { if (is_file($this->root_path.$file)) { $fileslist[] = $file; } else { $dirslist[] = $file; } } } } collatorlib::asort($fileslist, collatorlib::SORT_STRING); collatorlib::asort($dirslist, collatorlib::SORT_STRING); // fill the $list['list'] foreach ($dirslist as $file) { if (!empty($path)) { $current_path = $path . '/'. $file; } else { $current_path = $file; } $list['list'][] = array( 'title' => $file, 'children' => array(), 'datecreated' => filectime($this->root_path.$file), 'datemodified' => filemtime($this->root_path.$file), 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false), 'path' => $current_path ); } foreach ($fileslist as $file) { $list['list'][] = array( 'title' => $file, 'source' => $path.'/'.$file, 'size' => filesize($this->root_path.$file), 'datecreated' => filectime($this->root_path.$file), 'datemodified' => filemtime($this->root_path.$file), 'thumbnail' => $OUTPUT->pix_url(file_extension_icon($file, 90))->out(false), 'icon' => $OUTPUT->pix_url(file_extension_icon($file, 24))->out(false) ); } $list['list'] = array_filter($list['list'], array($this, 'filter')); return $list; }
/** * Return a {@link block_contents} representing the add a new block UI, if * this user is allowed to see it. * * @return block_contents an appropriate block_contents, or null if the user * cannot add any blocks here. */ function block_add_block_ui($page, $output) { global $CFG, $OUTPUT; if (!$page->user_is_editing() || !$page->user_can_edit_blocks()) { return null; } $bc = new block_contents(); $bc->title = get_string('addblock'); $bc->add_class('block_adminblock'); $missingblocks = $page->blocks->get_addable_blocks(); if (empty($missingblocks)) { $bc->content = get_string('noblockstoaddhere'); return $bc; } $menu = array(); foreach ($missingblocks as $block) { $blockobject = block_instance($block->name); if ($blockobject !== false && $blockobject->user_can_addto($page)) { $menu[$block->name] = $blockobject->get_title(); } } collatorlib::asort($menu); $actionurl = new moodle_url($page->url, array('sesskey' => sesskey())); $select = new single_select($actionurl, 'bui_addblock', $menu, null, array('' => get_string('adddots')), 'add_block'); $select->set_label(get_string('addblock'), array('class' => 'accesshide')); $bc->content = $OUTPUT->render($select); return $bc; }
function test_asort() { $arr = array('b' => 'ab', 1 => 'aa', 0 => 'cc'); collatorlib::asort($arr); $this->assertIdentical(array_keys($arr), array(1, 'b', 0)); $this->assertIdentical(array_values($arr), array('aa', 'ab', 'cc')); $arr = array('a' => 'áb', 'b' => 'ab', 1 => 'aa', 0 => 'cc'); collatorlib::asort($arr); $this->assertIdentical(array_keys($arr), array(1, 'b', 'a', 0), $this->error); $this->assertIdentical(array_values($arr), array('aa', 'ab', 'áb', 'cc'), $this->error); }
$table->define_headers(array($strname, $strcourses, $strversion, $strhide . '/' . $strshow, $strprotecthdr, $strdelete, $strsettings)); $table->define_baseurl($CFG->wwwroot . '/' . $CFG->admin . '/blocks.php'); $table->set_attribute('class', 'compatibleblockstable blockstable generaltable'); $table->setup(); $tablerows = array(); // Sort blocks using current locale. $blocknames = array(); foreach ($blocks as $blockid => $block) { $blockname = $block->name; if (file_exists("{$CFG->dirroot}/blocks/{$blockname}/block_{$blockname}.php")) { $blocknames[$blockid] = get_string('pluginname', 'block_' . $blockname); } else { $blocknames[$blockid] = $blockname; } } collatorlib::asort($blocknames); foreach ($blocknames as $blockid => $strblockname) { $block = $blocks[$blockid]; $blockname = $block->name; if (!file_exists("{$CFG->dirroot}/blocks/{$blockname}/block_{$blockname}.php")) { $blockobject = false; $strblockname = '<span class="notifyproblem">' . $strblockname . ' (' . get_string('missingfromdisk') . ')</span>'; $plugin = new stdClass(); $plugin->version = $block->version; } else { $plugin = new stdClass(); $plugin->version = '???'; if (file_exists("{$CFG->dirroot}/blocks/{$blockname}/version.php")) { include "{$CFG->dirroot}/blocks/{$blockname}/version.php"; } if (!($blockobject = block_instance($block->name))) {
/** * Get list of available import or export formats * @param string $type 'import' if import list, otherwise export list assumed * @return array sorted list of import/export formats available */ function get_import_export_formats($type) { global $CFG; require_once $CFG->dirroot . '/question/format.php'; $formatclasses = get_plugin_list_with_class('qformat', '', 'format.php'); $fileformatname = array(); foreach ($formatclasses as $component => $formatclass) { $format = new $formatclass(); if ($type == 'import') { $provided = $format->provide_import(); } else { $provided = $format->provide_export(); } if ($provided) { list($notused, $fileformat) = explode('_', $component, 2); $fileformatnames[$fileformat] = get_string('pluginname', $component); } } collatorlib::asort($fileformatnames); return $fileformatnames; }
public function definition() { global $CFG, $USER, $OUTPUT; $strrequired = get_string('required'); $mform =& $this->_form; //set default value $search = $this->_customdata['search']; if (isset($this->_customdata['coverage'])) { $coverage = $this->_customdata['coverage']; } else { $coverage = 'all'; } if (isset($this->_customdata['licence'])) { $licence = $this->_customdata['licence']; } else { $licence = 'all'; } if (isset($this->_customdata['subject'])) { $subject = $this->_customdata['subject']; } else { $subject = 'all'; } if (isset($this->_customdata['audience'])) { $audience = $this->_customdata['audience']; } else { $audience = 'all'; } if (isset($this->_customdata['language'])) { $language = $this->_customdata['language']; } else { $language = current_language(); } if (isset($this->_customdata['educationallevel'])) { $educationallevel = $this->_customdata['educationallevel']; } else { $educationallevel = 'all'; } if (isset($this->_customdata['downloadable'])) { $downloadable = $this->_customdata['downloadable']; } else { $downloadable = 0; } if (isset($this->_customdata['orderby'])) { $orderby = $this->_customdata['orderby']; } else { $orderby = 'newest'; } if (isset($this->_customdata['huburl'])) { $huburl = $this->_customdata['huburl']; } else { $huburl = HUB_MOODLEORGHUBURL; } $mform->addElement('header', 'site', get_string('search', 'block_community')); //add the course id (of the context) $mform->addElement('hidden', 'courseid', $this->_customdata['courseid']); $mform->addElement('hidden', 'executesearch', 1); //retrieve the hub list on the hub directory by web service $function = 'hubdirectory_get_hubs'; $params = array(); $serverurl = HUB_HUBDIRECTORYURL . "/local/hubdirectory/webservice/webservices.php"; require_once $CFG->dirroot . "/webservice/xmlrpc/lib.php"; $xmlrpcclient = new webservice_xmlrpc_client($serverurl, 'publichubdirectory'); try { $hubs = $xmlrpcclient->call($function, $params); } catch (Exception $e) { $hubs = array(); $error = $OUTPUT->notification(get_string('errorhublisting', 'block_community', $e->getMessage())); $mform->addElement('static', 'errorhub', '', $error); } //display list of registered on hub $registrationmanager = new registration_manager(); $registeredhubs = $registrationmanager->get_registered_on_hubs(); //retrieve some additional hubs that we will add to //the hub list got from the hub directory $additionalhubs = array(); foreach ($registeredhubs as $registeredhub) { $inthepubliclist = false; foreach ($hubs as $hub) { if ($hub['url'] == $registeredhub->huburl) { $inthepubliclist = true; $hub['registeredon'] = true; } } if (!$inthepubliclist) { $additionalhub = array(); $additionalhub['name'] = $registeredhub->hubname; $additionalhub['url'] = $registeredhub->huburl; $additionalhubs[] = $additionalhub; } } if (!empty($additionalhubs)) { $hubs = array_merge($hubs, $additionalhubs); } if (!empty($hubs)) { //TODO: sort hubs by trusted/prioritize //Public hub list $options = array(); $firsthub = false; foreach ($hubs as $hub) { if (array_key_exists('id', $hub)) { $params = array('hubid' => $hub['id'], 'filetype' => HUB_HUBSCREENSHOT_FILE_TYPE); $imgurl = new moodle_url(HUB_HUBDIRECTORYURL . "/local/hubdirectory/webservice/download.php", $params); $ascreenshothtml = html_writer::empty_tag('img', array('src' => $imgurl, 'alt' => $hub['name'])); $hubdescription = html_writer::tag('a', $hub['name'], array('class' => 'hublink clearfix', 'href' => $hub['url'], 'onclick' => 'this.target="_blank"')); $hubdescription .= html_writer::tag('span', $ascreenshothtml, array('class' => 'hubscreenshot')); $hubdescriptiontext = html_writer::tag('span', format_text($hub['description'], FORMAT_PLAIN), array('class' => 'hubdescription')); if (isset($hub['enrollablecourses'])) { //check needed to avoid warnings for Moodle version < 2011081700 $additionaldesc = get_string('enrollablecourses', 'block_community') . ': ' . $hub['enrollablecourses'] . ' - ' . get_string('downloadablecourses', 'block_community') . ': ' . $hub['downloadablecourses']; $hubdescriptiontext .= html_writer::tag('span', $additionaldesc, array('class' => 'hubadditionaldesc')); } if ($hub['trusted']) { $hubtrusted = get_string('hubtrusted', 'block_community'); $hubdescriptiontext .= html_writer::tag('span', $hubtrusted . ' ' . $OUTPUT->doc_link('trusted_hubs'), array('class' => 'trusted')); } $hubdescriptiontext = html_writer::tag('span', $hubdescriptiontext, array('class' => 'hubdescriptiontext')); $hubdescription = html_writer::tag('span', $hubdescription . $hubdescriptiontext, array('class' => $hub['trusted'] ? 'hubtrusted' : 'hubnottrusted')); } else { $hubdescription = html_writer::tag('a', $hub['name'], array('class' => 'hublink hubtrusted', 'href' => $hub['url'])); } if (empty($firsthub)) { $mform->addElement('radio', 'huburl', get_string('selecthub', 'block_community'), $hubdescription, $hub['url']); $mform->setDefault('huburl', $huburl); $firsthub = true; } else { $mform->addElement('radio', 'huburl', '', $hubdescription, $hub['url']); } } //display enrol/download select box if the USER has the download capability on the course if (has_capability('moodle/community:download', context_course::instance($this->_customdata['courseid']))) { $options = array(0 => get_string('enrollable', 'block_community'), 1 => get_string('downloadable', 'block_community')); $mform->addElement('select', 'downloadable', get_string('enroldownload', 'block_community'), $options); $mform->addHelpButton('downloadable', 'enroldownload', 'block_community'); } else { $mform->addElement('hidden', 'downloadable', 0); } $options = array(); $options['all'] = get_string('any'); $options[HUB_AUDIENCE_EDUCATORS] = get_string('audienceeducators', 'hub'); $options[HUB_AUDIENCE_STUDENTS] = get_string('audiencestudents', 'hub'); $options[HUB_AUDIENCE_ADMINS] = get_string('audienceadmins', 'hub'); $mform->addElement('select', 'audience', get_string('audience', 'block_community'), $options); $mform->setDefault('audience', $audience); unset($options); $mform->addHelpButton('audience', 'audience', 'block_community'); $options = array(); $options['all'] = get_string('any'); $options[HUB_EDULEVEL_PRIMARY] = get_string('edulevelprimary', 'hub'); $options[HUB_EDULEVEL_SECONDARY] = get_string('edulevelsecondary', 'hub'); $options[HUB_EDULEVEL_TERTIARY] = get_string('eduleveltertiary', 'hub'); $options[HUB_EDULEVEL_GOVERNMENT] = get_string('edulevelgovernment', 'hub'); $options[HUB_EDULEVEL_ASSOCIATION] = get_string('edulevelassociation', 'hub'); $options[HUB_EDULEVEL_CORPORATE] = get_string('edulevelcorporate', 'hub'); $options[HUB_EDULEVEL_OTHER] = get_string('edulevelother', 'hub'); $mform->addElement('select', 'educationallevel', get_string('educationallevel', 'block_community'), $options); $mform->setDefault('educationallevel', $educationallevel); unset($options); $mform->addHelpButton('educationallevel', 'educationallevel', 'block_community'); $publicationmanager = new course_publish_manager(); $options = $publicationmanager->get_sorted_subjects(); foreach ($options as $key => &$option) { $keylength = strlen($key); if ($keylength == 10) { $option = " " . $option; } else { if ($keylength == 12) { $option = " " . $option; } } } $options = array_merge(array('all' => get_string('any')), $options); $mform->addElement('select', 'subject', get_string('subject', 'block_community'), $options, array('id' => 'communitysubject')); $mform->setDefault('subject', $subject); unset($options); $mform->addHelpButton('subject', 'subject', 'block_community'); $this->init_javascript_enhancement('subject', 'smartselect', array('selectablecategories' => true, 'mode' => 'compact')); require_once $CFG->libdir . "/licenselib.php"; $licensemanager = new license_manager(); $licences = $licensemanager->get_licenses(); $options = array(); $options['all'] = get_string('any'); foreach ($licences as $license) { $options[$license->shortname] = get_string($license->shortname, 'license'); } $mform->addElement('select', 'licence', get_string('licence', 'block_community'), $options); unset($options); $mform->addHelpButton('licence', 'licence', 'block_community'); $mform->setDefault('licence', $licence); $languages = get_string_manager()->get_list_of_languages(); collatorlib::asort($languages); $languages = array_merge(array('all' => get_string('any')), $languages); $mform->addElement('select', 'language', get_string('language'), $languages); $mform->setDefault('language', $language); $mform->addHelpButton('language', 'language', 'block_community'); $mform->addElement('radio', 'orderby', get_string('orderby', 'block_community'), get_string('orderbynewest', 'block_community'), 'newest'); $mform->addElement('radio', 'orderby', null, get_string('orderbyeldest', 'block_community'), 'eldest'); $mform->addElement('radio', 'orderby', null, get_string('orderbyname', 'block_community'), 'fullname'); $mform->addElement('radio', 'orderby', null, get_string('orderbypublisher', 'block_community'), 'publisher'); $mform->addElement('radio', 'orderby', null, get_string('orderbyratingaverage', 'block_community'), 'ratingaverage'); $mform->setDefault('orderby', $orderby); $mform->setType('orderby', PARAM_ALPHA); $mform->addElement('text', 'search', get_string('keywords', 'block_community')); $mform->addHelpButton('search', 'keywords', 'block_community'); $mform->addElement('submit', 'submitbutton', get_string('search', 'block_community')); } }
public function test_legacy_collatorlib() { $arr = array('b' => 'ab', 1 => 'aa', 0 => 'cc'); $result = collatorlib::asort($arr); $this->assertDebuggingCalled(null, null, 'This fails if any other test uses the deprecated collatorlib class.'); $this->assertSame(array('aa', 'ab', 'cc'), array_values($arr)); $this->assertSame(array(1, 'b', 0), array_keys($arr)); $this->assertTrue($result); }