|
Moodle
2.2.1
http://www.collinsharper.com
|
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 course 00025 * @subpackage publish 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 * The forms used for course publication 00031 */ 00032 00033 00034 require_once($CFG->libdir . '/formslib.php'); 00035 require_once($CFG->dirroot . "/" . $CFG->admin . "/registration/lib.php"); 00036 require_once($CFG->dirroot . "/course/publish/lib.php"); 00037 00038 /* 00039 * Hub selector to choose on which hub we want to publish. 00040 */ 00041 00042 class hub_publish_selector_form extends moodleform { 00043 00044 public function definition() { 00045 global $CFG; 00046 $mform = & $this->_form; 00047 $share = $this->_customdata['share']; 00048 00049 $mform->addElement('header', 'site', get_string('selecthub', 'hub')); 00050 00051 $mform->addElement('static', 'info', '', get_string('selecthubinfo', 'hub') . html_writer::empty_tag('br')); 00052 00053 $registrationmanager = new registration_manager(); 00054 $registeredhubs = $registrationmanager->get_registered_on_hubs(); 00055 00056 //Public hub list 00057 $options = array(); 00058 foreach ($registeredhubs as $hub) { 00059 00060 $hubname = $hub->hubname; 00061 $mform->addElement('hidden', clean_param($hub->huburl, PARAM_ALPHANUMEXT), $hubname); 00062 if (empty($hubname)) { 00063 $hubname = $hub->huburl; 00064 } 00065 $mform->addElement('radio', 'huburl', null, ' ' . $hubname, $hub->huburl); 00066 if ($hub->huburl == HUB_MOODLEORGHUBURL) { 00067 $mform->setDefault('huburl', $hub->huburl); 00068 } 00069 } 00070 00071 $mform->addElement('hidden', 'id', $this->_customdata['id']); 00072 00073 if ($share) { 00074 $buttonlabel = get_string('shareonhub', 'hub'); 00075 $mform->addElement('hidden', 'share', true); 00076 } else { 00077 $buttonlabel = get_string('advertiseonhub', 'hub'); 00078 $mform->addElement('hidden', 'advertise', true); 00079 } 00080 00081 $this->add_action_buttons(false, $buttonlabel); 00082 } 00083 00084 } 00085 00086 /* 00087 * Course publication form 00088 */ 00089 00090 class course_publication_form extends moodleform { 00091 00092 public function definition() { 00093 global $CFG, $DB, $USER, $OUTPUT; 00094 00095 $strrequired = get_string('required'); 00096 $mform = & $this->_form; 00097 $huburl = $this->_customdata['huburl']; 00098 $hubname = $this->_customdata['hubname']; 00099 $course = $this->_customdata['course']; 00100 $advertise = $this->_customdata['advertise']; 00101 $share = $this->_customdata['share']; 00102 $page = $this->_customdata['page']; 00103 $site = get_site(); 00104 00105 //hidden parameters 00106 $mform->addElement('hidden', 'huburl', $huburl); 00107 $mform->addElement('hidden', 'hubname', $hubname); 00108 00109 //check on the hub if the course has already been published 00110 $registrationmanager = new registration_manager(); 00111 $registeredhub = $registrationmanager->get_registeredhub($huburl); 00112 $publicationmanager = new course_publish_manager(); 00113 $publications = $publicationmanager->get_publications($registeredhub->huburl, $course->id, $advertise); 00114 00115 if (!empty($publications)) { 00116 //get the last publication of this course 00117 $publication = array_pop($publications); 00118 00119 $function = 'hub_get_courses'; 00120 $options = new stdClass(); 00121 $options->ids = array($publication->hubcourseid); 00122 $options->allsitecourses = 1; 00123 $params = array('search' => '', 'downloadable' => $share, 00124 'enrollable' => !$share, 'options' => $options); 00125 $serverurl = $huburl . "/local/hub/webservice/webservices.php"; 00126 require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php"); 00127 $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $registeredhub->token); 00128 try { 00129 $result = $xmlrpcclient->call($function, $params); 00130 $publishedcourses = $result['courses']; 00131 } catch (Exception $e) { 00132 $error = $OUTPUT->notification(get_string('errorcourseinfo', 'hub', $e->getMessage())); 00133 $mform->addElement('static', 'errorhub', '', $error); 00134 } 00135 } 00136 00137 if (!empty($publishedcourses)) { 00138 $publishedcourse = $publishedcourses[0]; 00139 $hubcourseid = $publishedcourse['id']; 00140 $defaultfullname = $publishedcourse['fullname']; 00141 $defaultshortname = $publishedcourse['shortname']; 00142 $defaultsummary = $publishedcourse['description']; 00143 $defaultlanguage = $publishedcourse['language']; 00144 $defaultpublishername = $publishedcourse['publishername']; 00145 $defaultpublisheremail = $publishedcourse['publisheremail']; 00146 $defaultcontributornames = $publishedcourse['contributornames']; 00147 $defaultcoverage = $publishedcourse['coverage']; 00148 $defaultcreatorname = $publishedcourse['creatorname']; 00149 $defaultlicenceshortname = $publishedcourse['licenceshortname']; 00150 $defaultsubject = $publishedcourse['subject']; 00151 $defaultaudience = $publishedcourse['audience']; 00152 $defaulteducationallevel = $publishedcourse['educationallevel']; 00153 $defaultcreatornotes = $publishedcourse['creatornotes']; 00154 $defaultcreatornotesformat = $publishedcourse['creatornotesformat']; 00155 $screenshotsnumber = $publishedcourse['screenshots']; 00156 $privacy = $publishedcourse['privacy']; 00157 if (($screenshotsnumber > 0) and !empty($privacy)) { 00158 $page->requires->yui_module('moodle-block_community-imagegallery', 00159 'M.blocks_community.init_imagegallery', 00160 array(array('imageids' => array($hubcourseid), 00161 'imagenumbers' => array($screenshotsnumber), 00162 'huburl' => $huburl))); 00163 } 00164 } else { 00165 $defaultfullname = $course->fullname; 00166 $defaultshortname = $course->shortname; 00167 $defaultsummary = clean_param($course->summary, PARAM_TEXT); 00168 if (empty($course->lang)) { 00169 $language = get_site()->lang; 00170 if (empty($language)) { 00171 $defaultlanguage = current_language(); 00172 } else { 00173 $defaultlanguage = $language; 00174 } 00175 } else { 00176 $defaultlanguage = $course->lang; 00177 } 00178 $defaultpublishername = $USER->firstname . ' ' . $USER->lastname; 00179 $defaultpublisheremail = $USER->email; 00180 $defaultcontributornames = ''; 00181 $defaultcoverage = ''; 00182 $defaultcreatorname = $USER->firstname . ' ' . $USER->lastname; 00183 $defaultlicenceshortname = 'cc'; 00184 $defaultsubject = 'none'; 00185 $defaultaudience = HUB_AUDIENCE_STUDENTS; 00186 $defaulteducationallevel = HUB_EDULEVEL_TERTIARY; 00187 $defaultcreatornotes = ''; 00188 $defaultcreatornotesformat = FORMAT_HTML; 00189 $screenshotsnumber = 0; 00190 } 00191 00192 //the input parameters 00193 $mform->addElement('header', 'moodle', get_string('publicationinfo', 'hub')); 00194 00195 $mform->addElement('text', 'name', get_string('coursename', 'hub'), 00196 array('class' => 'metadatatext')); 00197 $mform->addRule('name', $strrequired, 'required', null, 'client'); 00198 $mform->setType('name', PARAM_TEXT); 00199 $mform->setDefault('name', $defaultfullname); 00200 $mform->addHelpButton('name', 'name', 'hub'); 00201 00202 $mform->addElement('hidden', 'id', $this->_customdata['id']); 00203 00204 if ($share) { 00205 $buttonlabel = get_string('shareon', 'hub', !empty($hubname) ? $hubname : $huburl); 00206 00207 $mform->addElement('hidden', 'share', $share); 00208 00209 $mform->addElement('text', 'demourl', get_string('demourl', 'hub'), 00210 array('class' => 'metadatatext')); 00211 $mform->setType('demourl', PARAM_URL); 00212 $mform->setDefault('demourl', new moodle_url("/course/view.php?id=" . $course->id)); 00213 $mform->addHelpButton('demourl', 'demourl', 'hub'); 00214 } 00215 00216 if ($advertise) { 00217 if (empty($publishedcourses)) { 00218 $buttonlabel = get_string('advertiseon', 'hub', !empty($hubname) ? $hubname : $huburl); 00219 } else { 00220 $buttonlabel = get_string('readvertiseon', 'hub', !empty($hubname) ? $hubname : $huburl); 00221 } 00222 $mform->addElement('hidden', 'advertise', $advertise); 00223 $mform->addElement('hidden', 'courseurl', $CFG->wwwroot . "/course/view.php?id=" . $course->id); 00224 $mform->addElement('static', 'courseurlstring', get_string('courseurl', 'hub')); 00225 $mform->setDefault('courseurlstring', new moodle_url("/course/view.php?id=" . $course->id)); 00226 $mform->addHelpButton('courseurlstring', 'courseurl', 'hub'); 00227 } 00228 00229 $mform->addElement('text', 'courseshortname', get_string('courseshortname', 'hub'), 00230 array('class' => 'metadatatext')); 00231 $mform->setDefault('courseshortname', $defaultshortname); 00232 $mform->addHelpButton('courseshortname', 'courseshortname', 'hub'); 00233 00234 $mform->addElement('textarea', 'description', get_string('description'), array('rows' => 10, 00235 'cols' => 57)); 00236 $mform->addRule('description', $strrequired, 'required', null, 'client'); 00237 $mform->setDefault('description', $defaultsummary); 00238 $mform->setType('description', PARAM_TEXT); 00239 $mform->addHelpButton('description', 'description', 'hub'); 00240 00241 $languages = get_string_manager()->get_list_of_languages(); 00242 collatorlib::asort($languages); 00243 $mform->addElement('select', 'language', get_string('language'), $languages); 00244 $mform->setDefault('language', $defaultlanguage); 00245 $mform->addHelpButton('language', 'language', 'hub'); 00246 00247 00248 $mform->addElement('text', 'publishername', get_string('publishername', 'hub'), 00249 array('class' => 'metadatatext')); 00250 $mform->setDefault('publishername', $defaultpublishername); 00251 $mform->addRule('publishername', $strrequired, 'required', null, 'client'); 00252 $mform->addHelpButton('publishername', 'publishername', 'hub'); 00253 00254 $mform->addElement('text', 'publisheremail', get_string('publisheremail', 'hub'), 00255 array('class' => 'metadatatext')); 00256 $mform->setDefault('publisheremail', $defaultpublisheremail); 00257 $mform->addRule('publisheremail', $strrequired, 'required', null, 'client'); 00258 $mform->addHelpButton('publisheremail', 'publisheremail', 'hub'); 00259 00260 $mform->addElement('text', 'creatorname', get_string('creatorname', 'hub'), 00261 array('class' => 'metadatatext')); 00262 $mform->addRule('creatorname', $strrequired, 'required', null, 'client'); 00263 $mform->setType('creatorname', PARAM_TEXT); 00264 $mform->setDefault('creatorname', $defaultcreatorname); 00265 $mform->addHelpButton('creatorname', 'creatorname', 'hub'); 00266 00267 $mform->addElement('text', 'contributornames', get_string('contributornames', 'hub'), 00268 array('class' => 'metadatatext')); 00269 $mform->setDefault('contributornames', $defaultcontributornames); 00270 $mform->addHelpButton('contributornames', 'contributornames', 'hub'); 00271 00272 $mform->addElement('text', 'coverage', get_string('tags', 'hub'), 00273 array('class' => 'metadatatext')); 00274 $mform->setType('coverage', PARAM_TEXT); 00275 $mform->setDefault('coverage', $defaultcoverage); 00276 $mform->addHelpButton('coverage', 'tags', 'hub'); 00277 00278 00279 00280 require_once($CFG->libdir . "/licenselib.php"); 00281 $licensemanager = new license_manager(); 00282 $licences = $licensemanager->get_licenses(); 00283 $options = array(); 00284 foreach ($licences as $license) { 00285 $options[$license->shortname] = get_string($license->shortname, 'license'); 00286 } 00287 $mform->addElement('select', 'licence', get_string('license'), $options); 00288 $mform->setDefault('licence', $defaultlicenceshortname); 00289 unset($options); 00290 $mform->addHelpButton('licence', 'licence', 'hub'); 00291 00292 $options = $publicationmanager->get_sorted_subjects(); 00293 00294 //prepare data for the smartselect 00295 foreach ($options as $key => &$option) { 00296 $keylength = strlen($key); 00297 if ($keylength == 10) { 00298 $option = " " . $option; 00299 } else if ($keylength == 12) { 00300 $option = " " . $option; 00301 } 00302 } 00303 00304 $options = array('none' => get_string('none', 'hub')) + $options; 00305 $mform->addElement('select', 'subject', get_string('subject', 'hub'), $options); 00306 unset($options); 00307 $mform->addHelpButton('subject', 'subject', 'hub'); 00308 $mform->setDefault('subject', $defaultsubject); 00309 $mform->addRule('subject', $strrequired, 'required', null, 'client'); 00310 $this->init_javascript_enhancement('subject', 'smartselect', array('selectablecategories' => false, 'mode' => 'compact')); 00311 00312 $options = array(); 00313 $options[HUB_AUDIENCE_EDUCATORS] = get_string('audienceeducators', 'hub'); 00314 $options[HUB_AUDIENCE_STUDENTS] = get_string('audiencestudents', 'hub'); 00315 $options[HUB_AUDIENCE_ADMINS] = get_string('audienceadmins', 'hub'); 00316 $mform->addElement('select', 'audience', get_string('audience', 'hub'), $options); 00317 $mform->setDefault('audience', $defaultaudience); 00318 unset($options); 00319 $mform->addHelpButton('audience', 'audience', 'hub'); 00320 00321 $options = array(); 00322 $options[HUB_EDULEVEL_PRIMARY] = get_string('edulevelprimary', 'hub'); 00323 $options[HUB_EDULEVEL_SECONDARY] = get_string('edulevelsecondary', 'hub'); 00324 $options[HUB_EDULEVEL_TERTIARY] = get_string('eduleveltertiary', 'hub'); 00325 $options[HUB_EDULEVEL_GOVERNMENT] = get_string('edulevelgovernment', 'hub'); 00326 $options[HUB_EDULEVEL_ASSOCIATION] = get_string('edulevelassociation', 'hub'); 00327 $options[HUB_EDULEVEL_CORPORATE] = get_string('edulevelcorporate', 'hub'); 00328 $options[HUB_EDULEVEL_OTHER] = get_string('edulevelother', 'hub'); 00329 $mform->addElement('select', 'educationallevel', get_string('educationallevel', 'hub'), $options); 00330 $mform->setDefault('educationallevel', $defaulteducationallevel); 00331 unset($options); 00332 $mform->addHelpButton('educationallevel', 'educationallevel', 'hub'); 00333 00334 $editoroptions = array('maxfiles' => 0, 'maxbytes' => 0, 'trusttext' => false, 'forcehttps' => false); 00335 $mform->addElement('editor', 'creatornotes', get_string('creatornotes', 'hub'), '', $editoroptions); 00336 $mform->addRule('creatornotes', $strrequired, 'required', null, 'client'); 00337 $mform->setType('creatornotes', PARAM_CLEANHTML); 00338 $mform->addHelpButton('creatornotes', 'creatornotes', 'hub'); 00339 00340 if ($advertise) { 00341 if (!empty($screenshotsnumber)) { 00342 00343 if (!empty($privacy)) { 00344 $baseurl = new moodle_url($huburl . '/local/hub/webservice/download.php', 00345 array('courseid' => $hubcourseid, 'filetype' => HUB_SCREENSHOT_FILE_TYPE)); 00346 $screenshothtml = html_writer::empty_tag('img', 00347 array('src' => $baseurl, 'alt' => $defaultfullname)); 00348 $screenshothtml = html_writer::tag('div', $screenshothtml, 00349 array('class' => 'coursescreenshot', 00350 'id' => 'image-' . $hubcourseid)); 00351 } else { 00352 $screenshothtml = get_string('existingscreenshotnumber', 'hub', $screenshotsnumber); 00353 } 00354 $mform->addElement('static', 'existingscreenshots', get_string('existingscreenshots', 'hub'), $screenshothtml); 00355 $mform->addHelpButton('existingscreenshots', 'deletescreenshots', 'hub'); 00356 $mform->addElement('checkbox', 'deletescreenshots', '', ' ' . get_string('deletescreenshots', 'hub')); 00357 } 00358 00359 $mform->addElement('hidden', 'existingscreenshotnumber', $screenshotsnumber); 00360 } 00361 00362 $mform->addElement('filemanager', 'screenshots', get_string('addscreenshots', 'hub'), null, 00363 array('subdirs' => 0, 00364 'maxbytes' => 1000000, 00365 'maxfiles' => 3 00366 )); 00367 $mform->addHelpButton('screenshots', 'screenshots', 'hub'); 00368 00369 $this->add_action_buttons(false, $buttonlabel); 00370 00371 //set default value for creatornotes editor 00372 $data = new stdClass(); 00373 $data->creatornotes = array(); 00374 $data->creatornotes['text'] = $defaultcreatornotes; 00375 $data->creatornotes['format'] = $defaultcreatornotesformat; 00376 $this->set_data($data); 00377 } 00378 00379 function validation($data, $files) { 00380 global $CFG; 00381 00382 $errors = array(); 00383 00384 if ($this->_form->_submitValues['subject'] == 'none') { 00385 $errors['subject'] = get_string('mustselectsubject', 'hub'); 00386 } 00387 00388 return $errors; 00389 } 00390 00391 } 00392