. /** * Global search search form definition * * @package core_search * @copyright Prateek Sachan {@link http://prateeksachan.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_search\output\form; defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class search extends \moodleform { /** * Form definition. * * @return void */ function definition() { global $CFG; $mform =& $this->_form; $mform->disable_form_change_checker(); $mform->addElement('header', 'search', get_string('search', 'search')); // Help info depends on the selected search engine. $mform->addElement('text', 'q', get_string('enteryoursearchquery', 'search')); $mform->addHelpButton('q', 'searchinfo', $this->_customdata['searchengine']); $mform->setType('q', PARAM_TEXT); $mform->addRule('q', get_string('required'), 'required', null, 'client'); // Show the 'search within' option if the user came from a particular context. if (!empty($this->_customdata['searchwithin'])) { $mform->addElement('select', 'searchwithin', get_string('searchwithin', 'search'), $this->_customdata['searchwithin']); $mform->setDefault('searchwithin', ''); } // If the search engine provides multiple ways to order results, show options. if (!empty($this->_customdata['orderoptions']) && count($this->_customdata['orderoptions']) > 1) { $mform->addElement('select', 'order', get_string('order', 'search'), $this->_customdata['orderoptions']); $mform->setDefault('order', 'relevance'); } $mform->addElement('header', 'filtersection', get_string('filterheader', 'search')); $mform->setExpanded('filtersection', false); $mform->addElement('text', 'title', get_string('title', 'search')); $mform->setType('title', PARAM_TEXT); $search = \core_search\manager::instance(); $searchareas = \core_search\manager::get_search_areas_list(true); $areanames = array(); foreach ($searchareas as $areaid => $searcharea) { $areanames[$areaid] = $searcharea->get_visible_name(); } // Sort the array by the text. \core_collator::asort($areanames); $options = array( 'multiple' => true, 'noselectionstring' => get_string('allareas', 'search'), ); $mform->addElement('autocomplete', 'areaids', get_string('searcharea', 'search'), $areanames, $options); $options = array( 'multiple' => true, 'limittoenrolled' => !is_siteadmin(), 'noselectionstring' => get_string('allcourses', 'search'), ); $mform->addElement('course', 'courseids', get_string('courses', 'core'), $options); $mform->setType('courseids', PARAM_INT); // Course options should be hidden if we choose to search within a specific location. if (!empty($this->_customdata['searchwithin'])) { $mform->hideIf('courseids', 'searchwithin', 'ne', ''); } $mform->addElement('date_time_selector', 'timestart', get_string('fromtime', 'search'), array('optional' => true)); $mform->setDefault('timestart', 0); $mform->addElement('date_time_selector', 'timeend', get_string('totime', 'search'), array('optional' => true)); $mform->setDefault('timeend', 0); // Source context i.e. the page they came from when they clicked search. $mform->addElement('hidden', 'context'); $mform->setType('context', PARAM_INT); $this->add_action_buttons(false, get_string('search', 'search')); } }