Merge branch 'MDL-62962-master' of git://github.com/junpataleta/moodle
[moodle.git] / blocks / community / forms.php
blob8142b5c80afd8518b7992a33383e9a68596a3f1f
1 <?php
2 ///////////////////////////////////////////////////////////////////////////
3 // //
4 // This file is part of Moodle - http://moodle.org/ //
5 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
6 // //
7 // Moodle is free software: you can redistribute it and/or modify //
8 // it under the terms of the GNU General Public License as published by //
9 // the Free Software Foundation, either version 3 of the License, or //
10 // (at your option) any later version. //
11 // //
12 // Moodle is distributed in the hope that it will be useful, //
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
15 // GNU General Public License for more details. //
16 // //
17 // You should have received a copy of the GNU General Public License //
18 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
19 // //
20 ///////////////////////////////////////////////////////////////////////////
22 /**
23 * Form for community search
25 * @package block_community
26 * @author Jerome Mouneyrac <jerome@mouneyrac.com>
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL
28 * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
31 require_once($CFG->libdir . '/formslib.php');
33 class community_hub_search_form extends moodleform {
35 public function definition() {
36 global $CFG;
37 $mform = & $this->_form;
39 //set default value
40 $search = $this->_customdata['search'];
41 if (isset($this->_customdata['coverage'])) {
42 $coverage = $this->_customdata['coverage'];
43 } else {
44 $coverage = 'all';
46 if (isset($this->_customdata['licence'])) {
47 $licence = $this->_customdata['licence'];
48 } else {
49 $licence = 'all';
51 if (isset($this->_customdata['subject'])) {
52 $subject = $this->_customdata['subject'];
53 } else {
54 $subject = 'all';
56 if (isset($this->_customdata['audience'])) {
57 $audience = $this->_customdata['audience'];
58 } else {
59 $audience = 'all';
61 if (isset($this->_customdata['language'])) {
62 $language = $this->_customdata['language'];
63 } else {
64 $language = current_language();
66 if (isset($this->_customdata['educationallevel'])) {
67 $educationallevel = $this->_customdata['educationallevel'];
68 } else {
69 $educationallevel = 'all';
71 if (isset($this->_customdata['downloadable'])) {
72 $downloadable = $this->_customdata['downloadable'];
73 } else {
74 $downloadable = 1;
76 if (isset($this->_customdata['orderby'])) {
77 $orderby = $this->_customdata['orderby'];
78 } else {
79 $orderby = 'newest';
82 $mform->addElement('header', 'site', get_string('search', 'block_community'));
84 //add the course id (of the context)
85 $mform->addElement('hidden', 'courseid', $this->_customdata['courseid']);
86 $mform->setType('courseid', PARAM_INT);
87 $mform->addElement('hidden', 'executesearch', 1);
88 $mform->setType('executesearch', PARAM_INT);
90 // Display enrol/download select box if the USER has the download capability on the course.
91 if (has_capability('moodle/community:download',
92 context_course::instance($this->_customdata['courseid']))) {
93 $options = array(0 => get_string('enrollable', 'block_community'),
94 1 => get_string('downloadable', 'block_community'));
95 $mform->addElement('select', 'downloadable', get_string('enroldownload', 'block_community'),
96 $options);
97 $mform->addHelpButton('downloadable', 'enroldownload', 'block_community');
99 $mform->setDefault('downloadable', $downloadable);
100 } else {
101 $mform->addElement('hidden', 'downloadable', 0);
103 $mform->setType('downloadable', PARAM_INT);
105 $options = \core\hub\publication::audience_options(true);
106 $mform->addElement('select', 'audience', get_string('audience', 'block_community'), $options);
107 $mform->setDefault('audience', $audience);
108 unset($options);
109 $mform->addHelpButton('audience', 'audience', 'block_community');
111 $options = \core\hub\publication::educational_level_options(true);
112 $mform->addElement('select', 'educationallevel',
113 get_string('educationallevel', 'block_community'), $options);
114 $mform->setDefault('educationallevel', $educationallevel);
115 unset($options);
116 $mform->addHelpButton('educationallevel', 'educationallevel', 'block_community');
118 $options = \core\hub\publication::get_sorted_subjects();
119 $mform->addElement('searchableselector', 'subject', get_string('subject', 'block_community'),
120 $options, array('id' => 'communitysubject'));
121 $mform->setDefault('subject', $subject);
122 unset($options);
123 $mform->addHelpButton('subject', 'subject', 'block_community');
125 require_once($CFG->libdir . "/licenselib.php");
126 $licensemanager = new license_manager();
127 $licences = $licensemanager->get_licenses();
128 $options = array();
129 $options['all'] = get_string('any');
130 foreach ($licences as $license) {
131 $options[$license->shortname] = get_string($license->shortname, 'license');
133 $mform->addElement('select', 'licence', get_string('licence', 'block_community'), $options);
134 unset($options);
135 $mform->addHelpButton('licence', 'licence', 'block_community');
136 $mform->setDefault('licence', $licence);
138 $languages = get_string_manager()->get_list_of_languages();
139 core_collator::asort($languages);
140 $languages = array_merge(array('all' => get_string('any')), $languages);
141 $mform->addElement('select', 'language', get_string('language'), $languages);
143 $mform->setDefault('language', $language);
144 $mform->addHelpButton('language', 'language', 'block_community');
146 $mform->addElement('select', 'orderby', get_string('orderby', 'block_community'),
147 array('newest' => get_string('orderbynewest', 'block_community'),
148 'eldest' => get_string('orderbyeldest', 'block_community'),
149 'fullname' => get_string('orderbyname', 'block_community'),
150 'publisher' => get_string('orderbypublisher', 'block_community'),
151 'ratingaverage' => get_string('orderbyratingaverage', 'block_community')));
153 $mform->setDefault('orderby', $orderby);
154 $mform->addHelpButton('orderby', 'orderby', 'block_community');
155 $mform->setType('orderby', PARAM_ALPHA);
157 $mform->setAdvanced('audience');
158 $mform->setAdvanced('educationallevel');
159 $mform->setAdvanced('subject');
160 $mform->setAdvanced('licence');
161 $mform->setAdvanced('language');
162 $mform->setAdvanced('orderby');
164 $mform->addElement('text', 'search', get_string('keywords', 'block_community'),
165 array('size' => 30));
166 $mform->addHelpButton('search', 'keywords', 'block_community');
167 $mform->setType('search', PARAM_NOTAGS);
169 $mform->addElement('submit', 'submitbutton', get_string('search', 'block_community'));