Example #1
0
 public function definition()
 {
     global $CFG;
     $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['visibility'])) {
         $visibility = $this->_customdata['visibility'];
     } else {
         $visibility = COURSEVISIBILITY_NOTVISIBLE;
     }
     if (isset($this->_customdata['downloadable'])) {
         $downloadable = $this->_customdata['downloadable'];
     } else {
         $downloadable = 1;
     }
     if (isset($this->_customdata['siteid'])) {
         $siteid = $this->_customdata['siteid'];
     } else {
         $siteid = 'all';
     }
     if (isset($this->_customdata['lastmodified'])) {
         $lastmodified = $this->_customdata['lastmodified'];
     } else {
         $lastmodified = HUB_LASTMODIFIED_WEEK;
     }
     if (isset($this->_customdata['orderby'])) {
         $orderby = $this->_customdata['orderby'];
     } else {
         $orderby = 'newest';
     }
     $mform->addElement('header', 'site', get_string('search', 'local_hub'));
     $options = array(0 => get_string('enrollable', 'local_hub'), 1 => get_string('downloadable', 'local_hub'));
     if (key_exists('adminform', $this->_customdata)) {
         $options = array('all' => get_string('any')) + $options;
     }
     $mform->addElement('select', 'downloadable', get_string('enroldownload', 'local_hub'), $options);
     $mform->addHelpButton('downloadable', 'enroldownload', 'local_hub');
     $mform->setDefault('downloadable', $downloadable);
     //visible field
     //Note: doesn't matter if form html is hacked, index script does not return any invisible courses
     if (key_exists('adminform', $this->_customdata)) {
         $options = array();
         $options[COURSEVISIBILITY_ALL] = get_string('visibilityall', 'local_hub');
         $options[COURSEVISIBILITY_VISIBLE] = get_string('visibilityyes', 'local_hub');
         $options[COURSEVISIBILITY_NOTVISIBLE] = get_string('visibilityno', 'local_hub');
         $mform->addElement('select', 'visibility', get_string('visibility', 'local_hub'), $options);
         $mform->setDefault('visibility', $visibility);
         unset($options);
         $mform->addHelpButton('visibility', 'visibility', 'local_hub');
     }
     $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', 'local_hub'), $options);
     $mform->setDefault('audience', $audience);
     unset($options);
     $mform->addHelpButton('audience', 'audience', 'local_hub');
     if (key_exists('adminform', $this->_customdata)) {
         $options = array();
         $options['all'] = '-';
         $options[HUB_LASTMODIFIED_WEEK] = get_string('periodweek', 'local_hub');
         $options[HUB_LASTMODIFIED_FORTEENNIGHT] = get_string('periodforteennight', 'local_hub');
         $options[HUB_LASTMODIFIED_MONTH] = get_string('periodmonth', 'local_hub');
         $mform->addElement('select', 'lastmodified', get_string('lastmodified', 'local_hub'), $options);
         $mform->setDefault('lastmodified', $lastmodified);
         unset($options);
         $mform->addHelpButton('lastmodified', 'lastmodified', 'local_hub');
     }
     $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', 'local_hub'), $options);
     $mform->setDefault('educationallevel', $educationallevel);
     unset($options);
     $mform->addHelpButton('educationallevel', 'educationallevel', 'local_hub');
     require_once $CFG->dirroot . "/course/publish/lib.php";
     $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', 'hub'), $options);
     $mform->setDefault('subject', $subject);
     unset($options);
     $mform->addHelpButton('subject', 'subject', 'local_hub');
     $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('license'), $options);
     unset($options);
     $mform->addHelpButton('licence', 'licence', 'local_hub');
     $mform->setDefault('licence', $licence);
     //search for only language that exist in the course DB
     require_once $CFG->dirroot . "/local/hub/lib.php";
     $hub = new local_hub();
     $courseslanguages = $hub->get_courses_languages();
     $alllanguages = get_string_manager()->get_list_of_languages();
     $languages = array();
     foreach ($courseslanguages as $languagecode => $lang) {
         if (isset($alllanguages[$languagecode])) {
             $languages[$languagecode] = $alllanguages[$languagecode];
         }
     }
     asort($languages, SORT_LOCALE_STRING);
     $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', 'local_hub');
     $mform->addElement('select', 'orderby', get_string('orderby', 'local_hub'), array('newest' => get_string('orderbynewest', 'local_hub'), 'eldest' => get_string('orderbyeldest', 'local_hub'), 'fullname' => get_string('orderbyname', 'local_hub'), 'publisher' => get_string('orderbypublisher', 'local_hub'), 'ratingaverage' => get_string('orderbyratingaverage', 'local_hub')));
     $mform->setDefault('orderby', $orderby);
     $mform->setType('orderby', PARAM_ALPHA);
     $mform->addHelpButton('orderby', 'orderby', 'local_hub');
     $mform->setAdvanced('audience');
     $mform->setAdvanced('educationallevel');
     $mform->setAdvanced('subject');
     $mform->setAdvanced('licence');
     $mform->setAdvanced('language');
     $mform->setAdvanced('orderby');
     if (key_exists('adminform', $this->_customdata)) {
         if ($hub->get_sites(array(), 0, 0, true) < 100) {
             // field not humanly usable over 100 sites.
             $sites = $hub->get_sites();
             $siteids = array();
             foreach ($sites as $site) {
                 $siteids[$site->id] = $site->name;
             }
             asort($siteids, SORT_LOCALE_STRING);
             $siteids = array('all' => get_string('any')) + $siteids;
             $mform->addElement('select', 'siteid', get_string('site', 'local_hub'), $siteids);
             $mform->setDefault('siteid', $siteid);
             $mform->addHelpButton('siteid', 'site', 'local_hub');
         }
     }
     $mform->addElement('text', 'search', get_string('keywords', 'local_hub'));
     $mform->setType('search', PARAM_ALPHANUMEXT);
     $mform->addHelpButton('search', 'keywords', 'local_hub');
     $mform->setDefault('search', $search);
     $mform->addElement('submit', 'submitbutton', get_string('search', 'local_hub'));
 }