3 ///////////////////////////////////////////////////////////////////////////
5 // This file is part of Moodle - http://moodle.org/ //
6 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // Moodle is free software: you can redistribute it and/or modify //
9 // it under the terms of the GNU General Public License as published by //
10 // the Free Software Foundation, either version 3 of the License, or //
11 // (at your option) any later version. //
13 // Moodle is distributed in the hope that it will be useful, //
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
16 // GNU General Public License for more details. //
18 // You should have received a copy of the GNU General Public License //
19 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
21 ///////////////////////////////////////////////////////////////////////////
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
30 * This page display the publication metadata form
33 require_once('../../config.php');
34 require_once($CFG->libdir
. '/filelib.php');
37 //check user access capability to this page
38 $id = required_param('id', PARAM_INT
);
40 $course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST
);
41 require_login($course);
44 $PAGE->set_url('/course/publish/metadata.php', array('id' => $course->id
));
45 $PAGE->set_pagelayout('incourse');
46 $PAGE->set_title(get_string('course') . ': ' . $course->fullname
);
47 $PAGE->set_heading($course->fullname
);
49 require_capability('moodle/course:publish', context_course
::instance($id));
51 // Retrieve hub name and hub url.
54 // Set the publication form.
55 $advertise = optional_param('advertise', false, PARAM_BOOL
);
56 $publicationid = optional_param('publicationid', false, PARAM_INT
);
57 $formparams = array('course' => $course, 'advertise' => $advertise);
59 $publication = \core\hub\publication
::get_publication($publicationid, $course->id
, MUST_EXIST
);
60 $formparams['publication'] = $publication;
61 $advertise = $formparams['advertise'] = $publication->enrollable
;
64 $coursepublicationform = new \core\hub\
course_publication_form('', $formparams);
65 $fromform = $coursepublicationform->get_data();
67 if (!empty($fromform)) {
69 // Retrieve the course information.
70 $courseinfo = new stdClass();
71 $courseinfo->fullname
= $fromform->name
;
72 $courseinfo->shortname
= $fromform->courseshortname
;
73 $courseinfo->description
= $fromform->description
;
74 $courseinfo->language
= $fromform->language
;
75 $courseinfo->publishername
= $fromform->publishername
;
76 $courseinfo->publisheremail
= $fromform->publisheremail
;
77 $courseinfo->contributornames
= $fromform->contributornames
;
78 $courseinfo->coverage
= $fromform->coverage
;
79 $courseinfo->creatorname
= $fromform->creatorname
;
80 $courseinfo->licenceshortname
= $fromform->licence
;
81 $courseinfo->subject
= $fromform->subject
;
82 $courseinfo->audience
= $fromform->audience
;
83 $courseinfo->educationallevel
= $fromform->educationallevel
;
84 $creatornotes = $fromform->creatornotes
;
85 $courseinfo->creatornotes
= $creatornotes['text'];
86 $courseinfo->creatornotesformat
= $creatornotes['format'];
87 $courseinfo->sitecourseid
= $id;
88 if (!empty($fromform->deletescreenshots
)) {
89 $courseinfo->deletescreenshots
= $fromform->deletescreenshots
;
92 $courseinfo->demourl
= $fromform->demourl
;
93 $courseinfo->enrollable
= false;
95 $courseinfo->courseurl
= $fromform->courseurl
;
96 $courseinfo->enrollable
= true;
99 // Retrieve the outcomes of this course.
100 require_once($CFG->libdir
. '/grade/grade_outcome.php');
101 $outcomes = grade_outcome
::fetch_all_available($id);
102 if (!empty($outcomes)) {
103 foreach ($outcomes as $outcome) {
104 $sentoutcome = new stdClass();
105 $sentoutcome->fullname
= $outcome->fullname
;
106 $courseinfo->outcomes
[] = $sentoutcome;
110 // Retrieve the content information from the course.
111 $coursecontext = context_course
::instance($course->id
);
112 $courseblocks = \core\hub\publication
::get_block_instances_by_context($coursecontext->id
);
114 if (!empty($courseblocks)) {
116 foreach ($courseblocks as $courseblock) {
117 if ($courseblock->blockname
!= $blockname) {
118 if (!empty($blockname)) {
119 $courseinfo->contents
[] = $content;
122 $blockname = $courseblock->blockname
;
123 $content = new stdClass();
124 $content->moduletype
= 'block';
125 $content->modulename
= $courseblock->blockname
;
126 $content->contentcount
= 1;
128 $content->contentcount
= $content->contentcount +
1;
131 $courseinfo->contents
[] = $content;
134 $activities = get_fast_modinfo($course, $USER->id
);
135 foreach ($activities->instances
as $activityname => $activitydetails) {
136 $content = new stdClass();
137 $content->moduletype
= 'activity';
138 $content->modulename
= $activityname;
139 $content->contentcount
= count($activities->instances
[$activityname]);
140 $courseinfo->contents
[] = $content;
143 // Save into screenshots field the references to the screenshot content hash
144 // (it will be like a unique id from the hub perspective).
145 if (!empty($fromform->deletescreenshots
) or $share) {
146 $courseinfo->screenshots
= 0;
148 $courseinfo->screenshots
= $fromform->existingscreenshotnumber
;
151 if (!empty($fromform->screenshots
)) {
152 $fs = get_file_storage();
153 $files = $fs->get_area_files(context_user
::instance($USER->id
)->id
, 'user', 'draft', $fromform->screenshots
,
154 'filepath, filename', false);
155 $files = array_filter($files, function(stored_file
$file) {
156 return $file->is_valid_image();
158 $courseinfo->screenshots +
= count($files);
162 $hubcourseid = \core\hub\publication
::publish_course($courseinfo, $files);
164 // Redirect to the backup process page.
166 $params = array('sesskey' => sesskey(), 'id' => $id, 'hubcourseid' => $hubcourseid);
167 $backupprocessurl = new moodle_url("/course/publish/backup.php", $params);
168 redirect($backupprocessurl);
170 // Redirect to the index publis page.
171 redirect(new moodle_url('/course/publish/index.php', ['id' => $id]),
172 get_string('coursepublished', 'hub', 'Moodle.net'), null, \core\output\notification
::NOTIFY_SUCCESS
);
178 echo $OUTPUT->header();
179 echo $OUTPUT->heading(get_string('publishcourseon', 'hub', 'Moodle.net'), 3, 'main');
181 // Display hub information (logo, name, description).
182 $renderer = $PAGE->get_renderer('core', 'course');
183 if ($hubinfo = \core\hub\registration
::get_moodlenet_info()) {
184 echo $renderer->hubinfo($hubinfo);
187 // Display metadata form.
188 $coursepublicationform->display();
189 echo $OUTPUT->footer();