Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/blocks/community/forms.php
Go to the documentation of this file.
00001 <?php
00002 
00004 //                                                                       //
00005 // This file is part of Moodle - http://moodle.org/                      //
00006 // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
00007 //                                                                       //
00008 // Moodle is free software: you can redistribute it and/or modify        //
00009 // it under the terms of the GNU General Public License as published by  //
00010 // the Free Software Foundation, either version 3 of the License, or     //
00011 // (at your option) any later version.                                   //
00012 //                                                                       //
00013 // Moodle is distributed in the hope that it will be useful,             //
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
00016 // GNU General Public License for more details.                          //
00017 //                                                                       //
00018 // You should have received a copy of the GNU General Public License     //
00019 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.       //
00020 //                                                                       //
00022 
00023 /*
00024  * @package    blocks
00025  * @subpackage community
00026  * @author     Jerome Mouneyrac <jerome@mouneyrac.com>
00027  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
00028  * @copyright  (C) 1999 onwards Martin Dougiamas  http://dougiamas.com
00029  *
00030  * Form for community search
00031  */
00032 
00033 require_once($CFG->libdir . '/formslib.php');
00034 require_once($CFG->dirroot . '/course/publish/lib.php');
00035 require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
00036 
00037 class community_hub_search_form extends moodleform {
00038 
00039     public function definition() {
00040         global $CFG, $USER, $OUTPUT;
00041         $strrequired = get_string('required');
00042         $mform = & $this->_form;
00043 
00044         //set default value
00045         $search = $this->_customdata['search'];
00046         if (isset($this->_customdata['coverage'])) {
00047             $coverage = $this->_customdata['coverage'];
00048         } else {
00049             $coverage = 'all';
00050         }
00051         if (isset($this->_customdata['licence'])) {
00052             $licence = $this->_customdata['licence'];
00053         } else {
00054             $licence = 'all';
00055         }
00056         if (isset($this->_customdata['subject'])) {
00057             $subject = $this->_customdata['subject'];
00058         } else {
00059             $subject = 'all';
00060         }
00061         if (isset($this->_customdata['audience'])) {
00062             $audience = $this->_customdata['audience'];
00063         } else {
00064             $audience = 'all';
00065         }
00066         if (isset($this->_customdata['language'])) {
00067             $language = $this->_customdata['language'];
00068         } else {
00069             $language = current_language();
00070         }
00071         if (isset($this->_customdata['educationallevel'])) {
00072             $educationallevel = $this->_customdata['educationallevel'];
00073         } else {
00074             $educationallevel = 'all';
00075         }
00076         if (isset($this->_customdata['downloadable'])) {
00077             $downloadable = $this->_customdata['downloadable'];
00078         } else {
00079             $downloadable = 0;
00080         }
00081         if (isset($this->_customdata['orderby'])) {
00082             $orderby = $this->_customdata['orderby'];
00083         } else {
00084             $orderby = 'newest';
00085         }
00086         if (isset($this->_customdata['huburl'])) {
00087             $huburl = $this->_customdata['huburl'];
00088         } else {
00089             $huburl = HUB_MOODLEORGHUBURL;
00090         }
00091 
00092         $mform->addElement('header', 'site', get_string('search', 'block_community'));
00093 
00094         //add the course id (of the context)
00095         $mform->addElement('hidden', 'courseid', $this->_customdata['courseid']);
00096         $mform->addElement('hidden', 'executesearch', 1);
00097 
00098         //retrieve the hub list on the hub directory by web service
00099         $function = 'hubdirectory_get_hubs';
00100         $params = array();
00101         $serverurl = HUB_HUBDIRECTORYURL . "/local/hubdirectory/webservice/webservices.php";
00102         require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
00103         $xmlrpcclient = new webservice_xmlrpc_client($serverurl, 'publichubdirectory');
00104         try {
00105             $hubs = $xmlrpcclient->call($function, $params);
00106         } catch (Exception $e) {
00107             $hubs = array();
00108             $error = $OUTPUT->notification(get_string('errorhublisting', 'block_community', $e->getMessage()));
00109             $mform->addElement('static', 'errorhub', '', $error);
00110         }
00111 
00112         //display list of registered on hub
00113         $registrationmanager = new registration_manager();
00114         $registeredhubs = $registrationmanager->get_registered_on_hubs();
00115         //retrieve some additional hubs that we will add to
00116         //the hub list got from the hub directory
00117         $additionalhubs = array();
00118         foreach ($registeredhubs as $registeredhub) {
00119             $inthepubliclist = false;
00120             foreach ($hubs as $hub) {
00121                 if ($hub['url'] == $registeredhub->huburl) {
00122                     $inthepubliclist = true;
00123                     $hub['registeredon'] = true;
00124                 }
00125             }
00126             if (!$inthepubliclist) {
00127                 $additionalhub = array();
00128                 $additionalhub['name'] = $registeredhub->hubname;
00129                 $additionalhub['url'] = $registeredhub->huburl;
00130                 $additionalhubs[] = $additionalhub;
00131             }
00132         }
00133         if (!empty($additionalhubs)) {
00134             $hubs = array_merge($hubs, $additionalhubs);
00135         }
00136 
00137         if (!empty($hubs)) {
00138             //TODO: sort hubs by trusted/prioritize
00139             //Public hub list
00140             $options = array();
00141             $firsthub = false;
00142             foreach ($hubs as $hub) {
00143                 if (key_exists('id', $hub)) {
00144                     $params = array('hubid' => $hub['id'],
00145                         'filetype' => HUB_HUBSCREENSHOT_FILE_TYPE);
00146                     $imgurl = new moodle_url(HUB_HUBDIRECTORYURL .
00147                                     "/local/hubdirectory/webservice/download.php", $params);
00148                     $ascreenshothtml = html_writer::empty_tag('img',
00149                                     array('src' => $imgurl, 'alt' => $hub['name']));
00150 
00151                     $hubdescription = html_writer::tag('a', $hub['name'],
00152                                     array('class' => 'hublink clearfix', 'href' => $hub['url'],
00153                                         'onclick' => 'this.target="_blank"'));
00154                     $hubdescription .= html_writer::tag('span', $ascreenshothtml,
00155                                     array('class' => 'hubscreenshot'));
00156                     $hubdescriptiontext = html_writer::tag('span', format_text($hub['description'], FORMAT_PLAIN),
00157                                     array('class' => 'hubdescription'));
00158                     if (isset($hub['enrollablecourses'])) { //check needed to avoid warnings for Moodle version < 2011081700
00159                         $additionaldesc = get_string('enrollablecourses', 'block_community') . ': ' . $hub['enrollablecourses'] . ' - ' .
00160                                 get_string('downloadablecourses', 'block_community') . ': ' . $hub['downloadablecourses'];
00161                         $hubdescriptiontext .= html_writer::tag('span', $additionaldesc,
00162                                         array('class' => 'hubadditionaldesc'));
00163                     }
00164                     if ($hub['trusted']) {
00165                     $hubtrusted =  get_string('hubtrusted', 'block_community');
00166                     $hubdescriptiontext .= html_writer::tag('span',
00167                                     $hubtrusted . ' ' . $OUTPUT->doc_link('trusted_hubs'),
00168                                     array('class' => 'trusted'));
00169 
00170                     }
00171                     $hubdescriptiontext = html_writer::tag('span', $hubdescriptiontext,
00172                             array('class' => 'hubdescriptiontext'));
00173 
00174                     $hubdescription = html_writer::tag('span',
00175                                     $hubdescription . $hubdescriptiontext,
00176                                     array('class' => $hub['trusted'] ? 'hubtrusted' : 'hubnottrusted'));
00177                 } else {
00178                     $hubdescription = html_writer::tag('a', $hub['name'],
00179                                     array('class' => 'hublink hubtrusted', 'href' => $hub['url']));
00180                 }
00181 
00182                 if (empty($firsthub)) {
00183                     $mform->addElement('radio', 'huburl', get_string('selecthub', 'block_community'),
00184                             $hubdescription, $hub['url']);
00185                     $mform->setDefault('huburl', $huburl);
00186                     $firsthub = true;
00187                 } else {
00188                     $mform->addElement('radio', 'huburl', '', $hubdescription, $hub['url']);
00189                 }
00190             }
00191 
00192             //display enrol/download select box if the USER has the download capability on the course
00193             if (has_capability('moodle/community:download',
00194                             get_context_instance(CONTEXT_COURSE, $this->_customdata['courseid']))) {
00195                 $options = array(0 => get_string('enrollable', 'block_community'),
00196                     1 => get_string('downloadable', 'block_community'));
00197                 $mform->addElement('select', 'downloadable', get_string('enroldownload', 'block_community'),
00198                         $options);
00199                 $mform->addHelpButton('downloadable', 'enroldownload', 'block_community');
00200             } else {
00201                 $mform->addElement('hidden', 'downloadable', 0);
00202             }
00203 
00204             $options = array();
00205             $options['all'] = get_string('any');
00206             $options[HUB_AUDIENCE_EDUCATORS] = get_string('audienceeducators', 'hub');
00207             $options[HUB_AUDIENCE_STUDENTS] = get_string('audiencestudents', 'hub');
00208             $options[HUB_AUDIENCE_ADMINS] = get_string('audienceadmins', 'hub');
00209             $mform->addElement('select', 'audience', get_string('audience', 'block_community'), $options);
00210             $mform->setDefault('audience', $audience);
00211             unset($options);
00212             $mform->addHelpButton('audience', 'audience', 'block_community');
00213 
00214             $options = array();
00215             $options['all'] = get_string('any');
00216             $options[HUB_EDULEVEL_PRIMARY] = get_string('edulevelprimary', 'hub');
00217             $options[HUB_EDULEVEL_SECONDARY] = get_string('edulevelsecondary', 'hub');
00218             $options[HUB_EDULEVEL_TERTIARY] = get_string('eduleveltertiary', 'hub');
00219             $options[HUB_EDULEVEL_GOVERNMENT] = get_string('edulevelgovernment', 'hub');
00220             $options[HUB_EDULEVEL_ASSOCIATION] = get_string('edulevelassociation', 'hub');
00221             $options[HUB_EDULEVEL_CORPORATE] = get_string('edulevelcorporate', 'hub');
00222             $options[HUB_EDULEVEL_OTHER] = get_string('edulevelother', 'hub');
00223             $mform->addElement('select', 'educationallevel',
00224                     get_string('educationallevel', 'block_community'), $options);
00225             $mform->setDefault('educationallevel', $educationallevel);
00226             unset($options);
00227             $mform->addHelpButton('educationallevel', 'educationallevel', 'block_community');
00228 
00229             $publicationmanager = new course_publish_manager();
00230             $options = $publicationmanager->get_sorted_subjects();
00231             foreach ($options as $key => &$option) {
00232                 $keylength = strlen($key);
00233                 if ($keylength == 10) {
00234                     $option = "&nbsp;&nbsp;" . $option;
00235                 } else if ($keylength == 12) {
00236                     $option = "&nbsp;&nbsp;&nbsp;&nbsp;" . $option;
00237                 }
00238             }
00239             $options = array_merge(array('all' => get_string('any')), $options);
00240             $mform->addElement('select', 'subject', get_string('subject', 'block_community'),
00241                     $options, array('id' => 'communitysubject'));
00242             $mform->setDefault('subject', $subject);
00243             unset($options);
00244             $mform->addHelpButton('subject', 'subject', 'block_community');
00245             $this->init_javascript_enhancement('subject', 'smartselect',
00246                     array('selectablecategories' => true, 'mode' => 'compact'));
00247 
00248             require_once($CFG->libdir . "/licenselib.php");
00249             $licensemanager = new license_manager();
00250             $licences = $licensemanager->get_licenses();
00251             $options = array();
00252             $options['all'] = get_string('any');
00253             foreach ($licences as $license) {
00254                 $options[$license->shortname] = get_string($license->shortname, 'license');
00255             }
00256             $mform->addElement('select', 'licence', get_string('licence', 'block_community'), $options);
00257             unset($options);
00258             $mform->addHelpButton('licence', 'licence', 'block_community');
00259             $mform->setDefault('licence', $licence);
00260 
00261             $languages = get_string_manager()->get_list_of_languages();
00262             collatorlib::asort($languages);
00263             $languages = array_merge(array('all' => get_string('any')), $languages);
00264             $mform->addElement('select', 'language', get_string('language'), $languages);
00265             $mform->setDefault('language', $language);
00266             $mform->addHelpButton('language', 'language', 'block_community');
00267 
00268             $mform->addElement('radio', 'orderby', get_string('orderby', 'block_community'),
00269                     get_string('orderbynewest', 'block_community'), 'newest');
00270             $mform->addElement('radio', 'orderby', null,
00271                     get_string('orderbyeldest', 'block_community'), 'eldest');
00272             $mform->addElement('radio', 'orderby', null,
00273                     get_string('orderbyname', 'block_community'), 'fullname');
00274             $mform->addElement('radio', 'orderby', null,
00275                     get_string('orderbypublisher', 'block_community'), 'publisher');
00276             $mform->addElement('radio', 'orderby', null,
00277                     get_string('orderbyratingaverage', 'block_community'), 'ratingaverage');
00278             $mform->setDefault('orderby', $orderby);
00279             $mform->setType('orderby', PARAM_ALPHA);
00280 
00281             $mform->addElement('text', 'search', get_string('keywords', 'block_community'));
00282             $mform->addHelpButton('search', 'keywords', 'block_community');
00283 
00284 
00285             $mform->addElement('submit', 'submitbutton', get_string('search', 'block_community'));
00286         }
00287     }
00288 
00289     function validation($data, $files) {
00290         global $CFG;
00291 
00292         $errors = array();
00293 
00294         if (empty($this->_form->_submitValues['huburl'])) {
00295             $errors['huburl'] = get_string('nohubselected', 'hub');
00296         }
00297 
00298         return $errors;
00299     }
00300 
00301 }
 All Data Structures Namespaces Files Functions Variables Enumerations