|
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 * This page display the publication metadata form 00031 */ 00032 00033 require_once('../../config.php'); 00034 require_once($CFG->dirroot . '/course/publish/forms.php'); 00035 require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php'); 00036 require_once($CFG->dirroot . '/course/publish/lib.php'); 00037 require_once($CFG->libdir . '/filelib.php'); 00038 00039 00040 //check user access capability to this page 00041 $id = required_param('id', PARAM_INT); 00042 00043 $course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST); 00044 require_login($course); 00045 00046 //page settings 00047 $PAGE->set_url('/course/publish/metadata.php', array('id' => $course->id)); 00048 $PAGE->set_pagelayout('course'); 00049 $PAGE->set_title(get_string('course') . ': ' . $course->fullname); 00050 $PAGE->set_heading($course->fullname); 00051 00052 //check that the PHP xmlrpc extension is enabled 00053 if (!extension_loaded('xmlrpc')) { 00054 $errornotification = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', ''); 00055 $errornotification .= get_string('xmlrpcdisabledpublish', 'hub'); 00056 $context = get_context_instance(CONTEXT_COURSE, $course->id); 00057 $shortname = format_string($course->shortname, true, array('context' => $context)); 00058 echo $OUTPUT->header(); 00059 echo $OUTPUT->heading(get_string('publishcourse', 'hub', $shortname), 3, 'main'); 00060 echo $OUTPUT->notification($errornotification); 00061 echo $OUTPUT->footer(); 00062 die(); 00063 } 00064 00065 if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE, $id))) { 00066 00067 //retrieve hub name and hub url 00068 $huburl = optional_param('huburl', '', PARAM_URL); 00069 $hubname = optional_param('hubname', '', PARAM_TEXT); 00070 if (empty($huburl) or !confirm_sesskey()) { 00071 throw new moodle_exception('missingparameter'); 00072 } 00073 00074 //set the publication form 00075 $advertise = optional_param('advertise', false, PARAM_BOOL); 00076 $share = optional_param('share', false, PARAM_BOOL); 00077 $coursepublicationform = new course_publication_form('', 00078 array('huburl' => $huburl, 'hubname' => $hubname, 'sesskey' => sesskey(), 00079 'course' => $course, 'advertise' => $advertise, 'share' => $share, 00080 'id' => $id, 'page' => $PAGE)); 00081 $fromform = $coursepublicationform->get_data(); 00082 00083 //retrieve the token to call the hub 00084 $registrationmanager = new registration_manager(); 00085 $registeredhub = $registrationmanager->get_registeredhub($huburl); 00086 00087 //setup web service xml-rpc client 00088 $serverurl = $huburl . "/local/hub/webservice/webservices.php"; 00089 require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php"); 00090 $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $registeredhub->token); 00091 00092 if (!empty($fromform)) { 00093 00094 $publicationmanager = new course_publish_manager(); 00095 00096 //retrieve the course information 00097 $courseinfo = new stdClass(); 00098 $courseinfo->fullname = $fromform->name; 00099 $courseinfo->shortname = $fromform->courseshortname; 00100 $courseinfo->description = $fromform->description; 00101 $courseinfo->language = $fromform->language; 00102 $courseinfo->publishername = $fromform->publishername; 00103 $courseinfo->publisheremail = $fromform->publisheremail; 00104 $courseinfo->contributornames = $fromform->contributornames; 00105 $courseinfo->coverage = $fromform->coverage; 00106 $courseinfo->creatorname = $fromform->creatorname; 00107 $courseinfo->licenceshortname = $fromform->licence; 00108 $courseinfo->subject = $fromform->subject; 00109 $courseinfo->audience = $fromform->audience; 00110 $courseinfo->educationallevel = $fromform->educationallevel; 00111 $creatornotes = $fromform->creatornotes; 00112 $courseinfo->creatornotes = $creatornotes['text']; 00113 $courseinfo->creatornotesformat = $creatornotes['format']; 00114 $courseinfo->sitecourseid = $id; 00115 if (!empty($fromform->deletescreenshots)) { 00116 $courseinfo->deletescreenshots = $fromform->deletescreenshots; 00117 } 00118 if ($share) { 00119 $courseinfo->demourl = $fromform->demourl; 00120 $courseinfo->enrollable = false; 00121 } else { 00122 $courseinfo->courseurl = $fromform->courseurl; 00123 $courseinfo->enrollable = true; 00124 } 00125 00126 //retrieve the outcomes of this course 00127 require_once($CFG->libdir . '/grade/grade_outcome.php'); 00128 $outcomes = grade_outcome::fetch_all_available($id); 00129 if (!empty($outcomes)) { 00130 foreach ($outcomes as $outcome) { 00131 $sentoutcome = new stdClass(); 00132 $sentoutcome->fullname = $outcome->fullname; 00133 $courseinfo->outcomes[] = $sentoutcome; 00134 } 00135 } 00136 00137 //retrieve the content information from the course 00138 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); 00139 $courseblocks = $publicationmanager->get_block_instances_by_context($coursecontext->id, 'blockname'); 00140 00141 if (!empty($courseblocks)) { 00142 $blockname = ''; 00143 foreach ($courseblocks as $courseblock) { 00144 if ($courseblock->blockname != $blockname) { 00145 if (!empty($blockname)) { 00146 $courseinfo->contents[] = $content; 00147 } 00148 00149 $blockname = $courseblock->blockname; 00150 $content = new stdClass(); 00151 $content->moduletype = 'block'; 00152 $content->modulename = $courseblock->blockname; 00153 $content->contentcount = 1; 00154 } else { 00155 $content->contentcount = $content->contentcount + 1; 00156 } 00157 } 00158 $courseinfo->contents[] = $content; 00159 } 00160 00161 $activities = get_fast_modinfo($course, $USER->id); 00162 foreach ($activities->instances as $activityname => $activitydetails) { 00163 $content = new stdClass(); 00164 $content->moduletype = 'activity'; 00165 $content->modulename = $activityname; 00166 $content->contentcount = count($activities->instances[$activityname]); 00167 $courseinfo->contents[] = $content; 00168 } 00169 00170 //save into screenshots field the references to the screenshot content hash 00171 //(it will be like a unique id from the hub perspective) 00172 if (!empty($fromform->deletescreenshots) or $share) { 00173 $courseinfo->screenshots = 0; 00174 } else { 00175 $courseinfo->screenshots = $fromform->existingscreenshotnumber; 00176 } 00177 if (!empty($fromform->screenshots)) { 00178 $screenshots = $fromform->screenshots; 00179 $fs = get_file_storage(); 00180 $files = $fs->get_area_files(get_context_instance(CONTEXT_USER, $USER->id)->id, 'user', 'draft', $screenshots); 00181 if (!empty($files)) { 00182 $courseinfo->screenshots = $courseinfo->screenshots + count($files) - 1; //minus the ./ directory 00183 } 00184 } 00185 00186 // PUBLISH ACTION 00187 00188 //publish the course information 00189 $function = 'hub_register_courses'; 00190 $params = array('courses' => array($courseinfo)); 00191 try { 00192 $courseids = $xmlrpcclient->call($function, $params); 00193 } catch (Exception $e) { 00194 throw new moodle_exception('errorcoursepublish', 'hub', 00195 new moodle_url('/course/view.php', array('id' => $id)), $e->getMessage()); 00196 } 00197 00198 if (count($courseids) != 1) { 00199 throw new moodle_exception('errorcoursewronglypublished', 'hub'); 00200 } 00201 00202 //save the record into the published course table 00203 $publication = $publicationmanager->get_publication($courseids[0], $huburl); 00204 if (empty($publication)) { 00205 //if never been published or if we share, we need to save this new publication record 00206 $publicationmanager->add_course_publication($registeredhub->huburl, $course->id, !$share, $courseids[0]); 00207 } else { 00208 //if we update the enrollable course publication we update the publication record 00209 $publicationmanager->update_enrollable_course_publication($publication->id); 00210 } 00211 00212 // SEND FILES 00213 $curl = new curl(); 00214 00215 // send screenshots 00216 if (!empty($fromform->screenshots)) { 00217 00218 if (!empty($fromform->deletescreenshots) or $share) { 00219 $screenshotnumber = 0; 00220 } else { 00221 $screenshotnumber = $fromform->existingscreenshotnumber; 00222 } 00223 foreach ($files as $file) { 00224 if ($file->is_valid_image()) { 00225 $screenshotnumber = $screenshotnumber + 1; 00226 $params = array(); 00227 $params['filetype'] = HUB_SCREENSHOT_FILE_TYPE; 00228 $params['file'] = $file; 00229 $params['courseid'] = $courseids[0]; 00230 $params['filename'] = $file->get_filename(); 00231 $params['screenshotnumber'] = $screenshotnumber; 00232 $params['token'] = $registeredhub->token; 00233 $curl->post($huburl . "/local/hub/webservice/upload.php", $params); 00234 } 00235 } 00236 } 00237 00238 //redirect to the backup process page 00239 if ($share) { 00240 $params = array('sesskey' => sesskey(), 'id' => $id, 'hubcourseid' => $courseids[0], 00241 'huburl' => $huburl, 'hubname' => $hubname); 00242 $backupprocessurl = new moodle_url("/course/publish/backup.php", $params); 00243 redirect($backupprocessurl); 00244 } else { 00245 //redirect to the index publis page 00246 redirect(new moodle_url('/course/publish/index.php', 00247 array('sesskey' => sesskey(), 'id' => $id, 'published' => true, 00248 'hubname' => $hubname, 'huburl' => $huburl))); 00249 } 00250 } 00251 00253 00254 echo $OUTPUT->header(); 00255 echo $OUTPUT->heading(get_string('publishcourseon', 'hub', !empty($hubname) ? $hubname : $huburl), 3, 'main'); 00256 00257 //display hub information (logo, name, description) 00258 $function = 'hub_get_info'; 00259 $params = array(); 00260 try { 00261 $hubinfo = $xmlrpcclient->call($function, $params); 00262 } catch (Exception $e) { 00263 //only print error log in apache (for backward compatibility) 00264 error_log(print_r($e->getMessage(), true)); 00265 } 00266 $renderer = $PAGE->get_renderer('core', 'publish'); 00267 if (!empty($hubinfo)) { 00268 echo $renderer->hubinfo($hubinfo); 00269 } 00270 00271 //display metadata form 00272 $coursepublicationform->display(); 00273 echo $OUTPUT->footer(); 00274 }