mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
hub MDL-19309 new site registration form + course publication + community block
This commit is contained in:
parent
7b4c6d34b8
commit
07ab0c80ec
36 changed files with 3208 additions and 21 deletions
|
@ -3412,6 +3412,26 @@ function get_course_by_idnumber ($idnumber) {
|
|||
return $DB->get_record('course', array('idnumber' => $idnumber));
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Average number of participants (in non-empty courses)
|
||||
* @return integer
|
||||
*/
|
||||
function average_number_of_participants() {
|
||||
global $DB;
|
||||
return 0;
|
||||
return $avg;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Average number of course modules (in non-empty courses)
|
||||
* @return integer
|
||||
*/
|
||||
function average_number_of_courses_modules() {
|
||||
global $DB;
|
||||
return 0;
|
||||
return $avg;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class pertains to course requests and contains methods associated with
|
||||
* create, approving, and removing course requests.
|
||||
|
|
220
course/publish/forms.php
Normal file
220
course/publish/forms.php
Normal file
|
@ -0,0 +1,220 @@
|
|||
<?php
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// This file is part of Moodle - http://moodle.org/ //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// //
|
||||
// Moodle is free software: you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation, either version 3 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// Moodle is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
* @package course
|
||||
* @subpackage publish
|
||||
* @author Jerome Mouneyrac <jerome@mouneyrac.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
|
||||
* @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
|
||||
*
|
||||
* The forms used for course publication
|
||||
*/
|
||||
|
||||
|
||||
require_once($CFG->dirroot.'/lib/formslib.php');
|
||||
require_once($CFG->dirroot."/lib/hublib.php");
|
||||
|
||||
/*
|
||||
* Hub selector to choose on which hub we want to publish.
|
||||
*/
|
||||
class hub_publish_selector_form extends moodleform {
|
||||
|
||||
public function definition() {
|
||||
global $CFG;
|
||||
$mform =& $this->_form;
|
||||
$share = $this->_customdata['share'];
|
||||
|
||||
$mform->addElement('header', 'site', get_string('selecthub', 'hub'));
|
||||
|
||||
$hubmanager = new hub();
|
||||
$registeredhubs = $hubmanager->get_registered_on_hubs();
|
||||
|
||||
//Public hub list
|
||||
$options = array();
|
||||
foreach ($registeredhubs as $hub) {
|
||||
$options[$hub->huburl] = $hub->huburl;
|
||||
$hubname = $hub->hubname;
|
||||
$mform->addElement('hidden', clean_param($hub->huburl, PARAM_ALPHANUMEXT), $hubname);
|
||||
}
|
||||
$mform->addElement('select', 'huburl', get_string('publichub','hub'),
|
||||
$options, array("size" => 15));
|
||||
|
||||
$mform->addElement('hidden', 'id', $this->_customdata['id']);
|
||||
|
||||
if ($share) {
|
||||
$buttonlabel = get_string('shareonhub', 'hub');
|
||||
$mform->addElement('hidden', 'share', true);
|
||||
} else {
|
||||
$buttonlabel = get_string('advertiseonhub', 'hub');
|
||||
$mform->addElement('hidden', 'advertise', true);
|
||||
}
|
||||
|
||||
$this->add_action_buttons(false, $buttonlabel);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Course publication form
|
||||
*/
|
||||
class course_publication_form extends moodleform {
|
||||
|
||||
public function definition() {
|
||||
global $CFG, $DB, $USER;
|
||||
|
||||
$strrequired = get_string('required');
|
||||
$mform =& $this->_form;
|
||||
$huburl = $this->_customdata['huburl'];
|
||||
$hubname = $this->_customdata['hubname'];
|
||||
$course = $this->_customdata['course'];
|
||||
$advertise = $this->_customdata['advertise'];
|
||||
$share = $this->_customdata['share'];
|
||||
$site = get_site();
|
||||
|
||||
//hidden parameters
|
||||
$mform->addElement('hidden', 'huburl', $huburl);
|
||||
$mform->addElement('hidden', 'hubname', $hubname);
|
||||
|
||||
//the input parameters
|
||||
$mform->addElement('header', 'moodle', get_string('publicationinfo', 'hub'));
|
||||
|
||||
$mform->addElement('text','name' , get_string('coursename', 'hub'));
|
||||
$mform->addRule('name', $strrequired, 'required', null, 'client');
|
||||
$mform->setType('name', PARAM_TEXT);
|
||||
$mform->setDefault('name', $course->fullname);
|
||||
|
||||
$mform->addElement('hidden', 'id', $this->_customdata['id']);
|
||||
|
||||
if ($share) {
|
||||
$buttonlabel = get_string('shareon', 'hub', !empty($hubname)?$hubname:$huburl);
|
||||
$mform->addElement('hidden', 'share', $share);
|
||||
|
||||
$mform->addElement('text', 'demourl', get_string('demourl', 'hub'));
|
||||
$mform->setType('demourl', PARAM_URL);
|
||||
$mform->setDefault('demourl', new moodle_url("/course/view.php?id=".$course->id));
|
||||
}
|
||||
|
||||
if ($advertise) {
|
||||
$buttonlabel = get_string('advertiseon', 'hub', !empty($hubname)?$hubname:$huburl);
|
||||
$mform->addElement('hidden', 'advertise', $advertise);
|
||||
|
||||
$mform->addElement('text', 'courseurl', get_string('courseurl', 'hub'));
|
||||
$mform->setType('courseurl', PARAM_URL);
|
||||
$mform->setDefault('courseurl', new moodle_url("/course/view.php?id=".$course->id));
|
||||
}
|
||||
|
||||
$mform->addElement('text', 'courseshortname',get_string('courseshortname', 'hub'));
|
||||
$mform->setDefault('courseshortname', $course->shortname);
|
||||
|
||||
$mform->addElement('textarea', 'description', get_string('description'), array('rows'=>10));
|
||||
$mform->addRule('description', $strrequired, 'required', null, 'client');
|
||||
$mform->setDefault('description', $course->summary);
|
||||
$mform->setType('description', PARAM_TEXT);
|
||||
|
||||
$languages = get_string_manager()->get_list_of_languages();
|
||||
|
||||
$mform->addElement('select', 'language',get_string('language'), $languages);
|
||||
if (empty($course->lang)) {
|
||||
$language = get_site()->lang;
|
||||
if (empty($language)) {
|
||||
$mform->setDefault('language', current_language());
|
||||
} else {
|
||||
$mform->setDefault('language', $language);
|
||||
}
|
||||
} else {
|
||||
$mform->setDefault('language', $course->lang);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$mform->addElement('text', 'publishername',get_string('publishername', 'hub'));
|
||||
$mform->setDefault('publishername', $USER->firstname.' '.$USER->lastname);
|
||||
$mform->addRule('publishername', $strrequired, 'required', null, 'client');
|
||||
|
||||
$mform->addElement('text', 'contributornames', get_string('contributornames', 'hub'));
|
||||
$mform->setDefault('contributornames', '');
|
||||
|
||||
$mform->addElement('text','coverage' , get_string('tags', 'hub'));
|
||||
$mform->setType('coverage', PARAM_TEXT);
|
||||
|
||||
$mform->addElement('text', 'creatorname', get_string('creatorname', 'hub'));
|
||||
$mform->addRule('creatorname', $strrequired, 'required', null, 'client');
|
||||
$mform->setType('creatorname', PARAM_TEXT);
|
||||
$mform->setDefault('creatorname', $USER->firstname.' '.$USER->lastname);
|
||||
|
||||
require_once($CFG->dirroot."/lib/licenselib.php");
|
||||
$licensemanager = new license_manager();
|
||||
$licences = $licensemanager->get_licenses();
|
||||
$options = array();
|
||||
foreach ($licences as $license) {
|
||||
$options[$license->shortname] = get_string($license->shortname, 'license');
|
||||
}
|
||||
$mform->addElement('select', 'licence', get_string('license'), $options);
|
||||
$mform->setDefault('licence', 'cc');
|
||||
unset($options);
|
||||
|
||||
$options = get_string_manager()->load_component_strings('edufields', current_language());
|
||||
$mform->addElement('select', 'subject', get_string('subject', 'hub'), $options);
|
||||
unset($options);
|
||||
|
||||
$options = array();
|
||||
$options[AUDIENCE_EDUCATORS] = get_string('audienceeducators', 'hub');
|
||||
$options[AUDIENCE_STUDENTS] = get_string('audiencestudents', 'hub');
|
||||
$options[AUDIENCE_ADMINS] = get_string('audienceadmins', 'hub');
|
||||
$mform->addElement('select', 'audience', get_string('audience', 'hub'), $options);
|
||||
$mform->setDefault('audience', AUDIENCE_EDUCATORS);
|
||||
unset($options);
|
||||
|
||||
$options = array();
|
||||
$options[EDULEVEL_PRIMARY] = get_string('edulevelprimary', 'hub');
|
||||
$options[EDULEVEL_SECONDARY] = get_string('edulevelsecondary', 'hub');
|
||||
$options[EDULEVEL_TERTIARY] = get_string('eduleveltertiary', 'hub');
|
||||
$options[EDULEVEL_GOVERNMENT] = get_string('edulevelgovernment', 'hub');
|
||||
$options[EDULEVEL_ASSOCIATION] = get_string('edulevelassociation', 'hub');
|
||||
$options[EDULEVEL_CORPORATE] = get_string('edulevelcorporate', 'hub');
|
||||
$options[EDULEVEL_OTHER] = get_string('edulevelother', 'hub');
|
||||
$mform->addElement('select', 'educationallevel', get_string('educationallevel', 'hub'), $options);
|
||||
$mform->setDefault('educationallevel', EDULEVEL_TERTIARY);
|
||||
unset($options);
|
||||
|
||||
$editoroptions = array('maxfiles'=>0, 'maxbytes'=>0, 'trusttext'=>false, 'forcehttps'=>false);
|
||||
$mform->addElement('editor', 'creatornotes', get_string('creatornotes', 'hub'), '', $editoroptions);
|
||||
$mform->addRule('creatornotes', $strrequired, 'required', null, 'client');
|
||||
$mform->setDefault('creatornotes', '');
|
||||
$mform->setType('creatornotes', PARAM_CLEANHTML);
|
||||
|
||||
|
||||
|
||||
$mform->addElement('filemanager', 'screenshots', get_string('screenshots','hub'), null,
|
||||
array('subdirs'=>0,
|
||||
'maxbytes'=>1000000,
|
||||
'maxfiles'=>3,
|
||||
'filetypes'=>array('image')
|
||||
));
|
||||
$mform->setHelpButton('screenshots', array('screenshots', get_string('screenshots', 'hub'), 'hub'));
|
||||
|
||||
$this->add_action_buttons(false, $buttonlabel);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
67
course/publish/hubselector.php
Normal file
67
course/publish/hubselector.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/*
|
||||
* @package course
|
||||
* @subpackage publish
|
||||
* @author Jerome Mouneyrac <jerome@mouneyrac.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
|
||||
* @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
|
||||
*
|
||||
* On this page the user selects where he wants to publish the course
|
||||
*/
|
||||
|
||||
require('../../config.php');
|
||||
|
||||
require_once($CFG->dirroot.'/lib/hublib.php');
|
||||
require_once($CFG->dirroot.'/course/publish/forms.php');
|
||||
|
||||
$id = optional_param('id', 0, PARAM_INT);
|
||||
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
|
||||
require_login($course);
|
||||
|
||||
$PAGE->set_url('/course/publish/hubselector.php', array('id' => $course->id));
|
||||
$PAGE->set_pagelayout('course');
|
||||
$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
|
||||
$PAGE->set_heading($course->fullname);
|
||||
|
||||
|
||||
$share = optional_param('share', false, PARAM_BOOL);
|
||||
$advertise = optional_param('advertise', false, PARAM_BOOL);
|
||||
$hubselectorform = new hub_publish_selector_form('',
|
||||
array('id' => $id, 'share' => $share, 'advertise' => $advertise));
|
||||
$fromform = $hubselectorform->get_data();
|
||||
|
||||
//// Redirect to the registration form if an URL has been choosen ////
|
||||
$huburl = optional_param('huburl', false, PARAM_URL);
|
||||
|
||||
//redirect
|
||||
if (!empty($huburl) and confirm_sesskey()) {
|
||||
$hubname = optional_param(clean_param($huburl, PARAM_ALPHANUMEXT), '', PARAM_TEXT);
|
||||
$params = array('sesskey' => sesskey(), 'id' => $id,
|
||||
'huburl' => $huburl, 'hubname' => $hubname, 'share' => $share, 'advertise' => $advertise);
|
||||
redirect(new moodle_url($CFG->wwwroot."/course/publish/metadata.php",
|
||||
$params));
|
||||
}
|
||||
|
||||
|
||||
//// OUTPUT ////
|
||||
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('publishon', 'hub'), 3, 'main');
|
||||
$hubselectorform->display();
|
||||
echo $OUTPUT->footer();
|
69
course/publish/index.php
Normal file
69
course/publish/index.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/*
|
||||
* @package course
|
||||
* @subpackage publish
|
||||
* @author Jerome Mouneyrac <jerome@mouneyrac.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
|
||||
* @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
|
||||
*
|
||||
* The user selects if he wants to publish the course on Moodle.org hub or
|
||||
* on a specific hub. The site must be registered on a hub to be able to
|
||||
* publish a course on it.
|
||||
*/
|
||||
|
||||
require('../../config.php');
|
||||
require_once($CFG->dirroot.'/lib/hublib.php');
|
||||
|
||||
$id = optional_param('id', 0, PARAM_INT);
|
||||
|
||||
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
|
||||
|
||||
require_login($course);
|
||||
|
||||
if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE, $id))) {
|
||||
|
||||
$PAGE->set_url('/course/publish/index.php', array('id' => $course->id));
|
||||
$PAGE->set_pagelayout('course');
|
||||
$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
|
||||
$PAGE->set_heading($course->fullname);
|
||||
|
||||
|
||||
$renderer = $PAGE->get_renderer('core', 'publish');
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('publishon', 'hub'), 3, 'main');
|
||||
|
||||
//check if the site is registered on Moodle.org hub
|
||||
//check if the site is registered on any other specific hub
|
||||
$hub = new hub();
|
||||
$registeredonmoodleorg = false;
|
||||
$registeredonhub = false;
|
||||
|
||||
$hubs = $hub->get_registered_on_hubs();
|
||||
foreach ($hubs as $hub) {
|
||||
if ($hub->huburl == MOODLEORGHUBURL) {
|
||||
$registeredonmoodleorg = true;
|
||||
} else {
|
||||
$registeredonhub = true;
|
||||
}
|
||||
}
|
||||
|
||||
echo $renderer->publicationselector($course->id, $registeredonmoodleorg, $registeredonhub);
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
}
|
74
course/publish/metadata.php
Normal file
74
course/publish/metadata.php
Normal file
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// This file is part of Moodle - http://moodle.org/ //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// //
|
||||
// Moodle is free software: you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation, either version 3 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// Moodle is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
* @package course
|
||||
* @subpackage publish
|
||||
* @author Jerome Mouneyrac <jerome@mouneyrac.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
|
||||
* @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
|
||||
*
|
||||
* This page display the publication metadata form
|
||||
*/
|
||||
|
||||
require_once('../../config.php');
|
||||
require_once($CFG->dirroot.'/course/publish/forms.php');
|
||||
require_once($CFG->dirroot.'/lib/hublib.php');
|
||||
|
||||
//check user access capability to this page
|
||||
$id = optional_param('id', 0, PARAM_INT);
|
||||
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
|
||||
require_login($course);
|
||||
|
||||
if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE, $id))) {
|
||||
|
||||
//page settings
|
||||
$PAGE->set_url('/course/publish/metadata.php', array('id' => $course->id));
|
||||
$PAGE->set_pagelayout('course');
|
||||
$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
|
||||
$PAGE->set_heading($course->fullname);
|
||||
|
||||
//retrieve hub name and hub url
|
||||
$huburl = optional_param('huburl', '', PARAM_URL);
|
||||
$hubname = optional_param('hubname', '', PARAM_TEXT);
|
||||
if (empty($huburl) or !confirm_sesskey()) {
|
||||
throw new moodle_exception('cannotaccessthispage');
|
||||
}
|
||||
|
||||
//set the publication form
|
||||
$advertise = optional_param('advertise', false, PARAM_BOOL);
|
||||
$share = optional_param('share', false, PARAM_BOOL);
|
||||
$coursepublicationform = new course_publication_form( new moodle_url('/course/publish/publish.php'),
|
||||
array('huburl' => $huburl, 'hubname' => $hubname, 'sesskey' => sesskey(),
|
||||
'course' => $course, 'advertise' => $advertise, 'share' => $share,
|
||||
'id' => $id));
|
||||
$fromform = $coursepublicationform->get_data();
|
||||
|
||||
|
||||
/////// OUTPUT SECTION /////////////
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
$coursepublicationform->display();
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
}
|
170
course/publish/publish.php
Normal file
170
course/publish/publish.php
Normal file
|
@ -0,0 +1,170 @@
|
|||
<?php
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// This file is part of Moodle - http://moodle.org/ //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// //
|
||||
// Moodle is free software: you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation, either version 3 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// Moodle is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
* @package course
|
||||
* @subpackage publish
|
||||
* @author Jerome Mouneyrac <jerome@mouneyrac.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
|
||||
* @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
|
||||
*
|
||||
* This page handles the publication process.
|
||||
* It sends metadata by web services
|
||||
* It also sends screenshots and backup files.
|
||||
*/
|
||||
|
||||
require_once('../../config.php');
|
||||
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
|
||||
require_once($CFG->dirroot . '/course/publish/forms.php');
|
||||
require_once($CFG->dirroot . '/webservice/lib.php');
|
||||
require_once($CFG->dirroot . '/lib/hublib.php');
|
||||
|
||||
//check user access capability to this page
|
||||
$id = optional_param('id', 0, PARAM_INT);
|
||||
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
|
||||
require_login($course);
|
||||
|
||||
if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE, $id))) {
|
||||
|
||||
//page settings
|
||||
$PAGE->set_url('/course/publish/publish.php', array('id' => $course->id));
|
||||
$PAGE->set_pagelayout('course');
|
||||
$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
|
||||
$PAGE->set_heading($course->fullname);
|
||||
|
||||
//retrieve hub name and hub url, also check the session
|
||||
$huburl = optional_param('huburl', '', PARAM_URL);
|
||||
$hubname = optional_param('hubname', '', PARAM_TEXT);
|
||||
if (empty($huburl) or !confirm_sesskey()) {
|
||||
throw new moodle_exception('cannotaccessthispage');
|
||||
}
|
||||
|
||||
$advertise = optional_param('advertise', false, PARAM_BOOL);
|
||||
$share = optional_param('share', false, PARAM_BOOL);
|
||||
|
||||
$huburl = optional_param('huburl', false, PARAM_URL);
|
||||
$hubname = optional_param('hubname', false, PARAM_TEXT);
|
||||
|
||||
//retrieve the course information
|
||||
$courseinfo = new stdClass();
|
||||
$courseinfo->fullname = optional_param('name', false, PARAM_TEXT);
|
||||
$courseinfo->shortname = optional_param('courseshortname', false, PARAM_ALPHANUMEXT);
|
||||
$courseinfo->description = optional_param('description', false, PARAM_TEXT);
|
||||
$courseinfo->language = optional_param('language', false, PARAM_ALPHANUMEXT);
|
||||
$courseinfo->publishername = optional_param('publishername', false, PARAM_TEXT);
|
||||
$courseinfo->contributornames = optional_param('contributornames', false, PARAM_TEXT);
|
||||
$courseinfo->coverage = optional_param('coverage', false, PARAM_TEXT);
|
||||
$courseinfo->creatorname = optional_param('creatorname', false, PARAM_TEXT);
|
||||
$courseinfo->licenceshortname = optional_param('licence', false, PARAM_ALPHANUMEXT);
|
||||
$courseinfo->subject = optional_param('subject', false, PARAM_INTEGER);
|
||||
$courseinfo->audience = optional_param('audience', false, PARAM_ALPHA);
|
||||
$courseinfo->educationallevel = optional_param('educationallevel', false, PARAM_ALPHA);
|
||||
$creatornotes = optional_param('creatornotes', false, PARAM_RAW);
|
||||
$courseinfo->creatornotes = $creatornotes['text'];
|
||||
$courseinfo->creatornotesformat = $creatornotes['format'];
|
||||
if ($share) {
|
||||
$courseinfo->demourl = optional_param('demourl', false, PARAM_URL);
|
||||
$courseinfo->enrollable = false;
|
||||
} else {
|
||||
$courseinfo->courseurl = optional_param('courseurl', false, PARAM_URL);
|
||||
$courseinfo->enrollable = true;
|
||||
}
|
||||
|
||||
//save into screenshots field the references to the screenshot content hash
|
||||
//(it will be like a unique id from the hub perspective)
|
||||
$screenshots = optional_param('screenshots', false, PARAM_INTEGER);
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files(get_context_instance(CONTEXT_USER, $USER->id)->id, 'user_draft', $screenshots);
|
||||
if (!empty($files)) {
|
||||
$courseinfo->screenshotsids = '';
|
||||
foreach ($files as $file) {
|
||||
if ($file->is_valid_image()) {
|
||||
$courseinfo->screenshotsids = $courseinfo->screenshotsids . "notsend:" . $file->get_contenthash() . ";";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// HEADER - needed here because the backup write some stuff
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
// BACKUP ACTION
|
||||
if ($share) {
|
||||
$bc = new backup_controller(backup::TYPE_1COURSE, $course->id, backup::FORMAT_MOODLE,
|
||||
backup::INTERACTIVE_YES, backup::MODE_HUB, $USER->id);
|
||||
$bc->finish_ui();
|
||||
$bc->execute_plan();
|
||||
$backup = $bc->get_results();
|
||||
$backupfile = $backup['backup_destination'];
|
||||
}
|
||||
|
||||
// PUBLISH ACTION
|
||||
|
||||
//retrieve the token to call the hub
|
||||
$hub = new hub();
|
||||
$registeredhub = $hub->get_registeredhub($huburl);
|
||||
|
||||
//publish the course information
|
||||
$function = 'hub_register_courses';
|
||||
$params = array(array($courseinfo));
|
||||
$serverurl = $huburl."/local/hub/webservice/webservices.php";
|
||||
require_once($CFG->dirroot."/webservice/xmlrpc/lib.php");
|
||||
$xmlrpcclient = new webservice_xmlrpc_client();
|
||||
$result = $xmlrpcclient->call($serverurl, $registeredhub->token, $function, $params);
|
||||
|
||||
$courseregisteredmsg = $OUTPUT->notification(get_string('coursepublished', 'hub'), 'notifysuccess');
|
||||
|
||||
|
||||
// SEND FILES
|
||||
|
||||
// send screenshots
|
||||
require_once($CFG->dirroot. "/lib/filelib.php");
|
||||
$params = array('token' => $registeredhub->token, 'filetype' => SCREENSHOT_FILE_TYPE,
|
||||
'courseshortname' => $courseinfo->shortname);
|
||||
$curl = new curl();
|
||||
foreach ($files as $file) {
|
||||
if ($file->is_valid_image()) {
|
||||
$params['file'] = $file;
|
||||
$params['filename'] = $file->get_filename();
|
||||
$curl->post($huburl."/local/hub/webservice/upload.php", $params);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// send backup
|
||||
if ($share) {
|
||||
$params['filetype'] = BACKUP_FILE_TYPE;
|
||||
$params['file'] = $backupfile;
|
||||
$params['filename'] = $backupfile->get_filename();
|
||||
$curl->post($huburl."/local/hub/webservice/upload.php", $params);
|
||||
}
|
||||
|
||||
//TODO: Delete the backup from user_tohub
|
||||
|
||||
// OUTPUT SECTION
|
||||
|
||||
//Display update notification result
|
||||
if (!empty($courseregisteredmsg)) {
|
||||
echo $courseregisteredmsg;
|
||||
}
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
}
|
107
course/publish/renderer.php
Normal file
107
course/publish/renderer.php
Normal file
|
@ -0,0 +1,107 @@
|
|||
<?php
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// This file is part of Moodle - http://moodle.org/ //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// //
|
||||
// Moodle is free software: you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation, either version 3 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// Moodle is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Course publish renderer.
|
||||
* @package course
|
||||
* @subpackage publish
|
||||
* @copyright 2010 Moodle Pty Ltd (http://moodle.com)
|
||||
* @author Jerome Mouneyrac
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_publish_renderer extends plugin_renderer_base {
|
||||
|
||||
/**
|
||||
* Display the page to publish a course on Moodle.org or on a specific hub
|
||||
*/
|
||||
public function publicationselector($courseid, $registeredonmoodleorg, $registeredonhub) {
|
||||
global $OUTPUT;
|
||||
|
||||
$table = new html_table();
|
||||
$table->head = array(get_string('moodleorg', 'hub'), get_string('specifichub', 'hub'));
|
||||
$table->size = array('50%', '50%');
|
||||
|
||||
//Moodle.org information cell
|
||||
$moodleorgcell = get_string('moodleorgpublicationdetail', 'hub');
|
||||
$moodleorgcell .= html_writer::empty_tag('br').html_writer::empty_tag('br');
|
||||
$moodleorgcell = html_writer::tag('div', $moodleorgcell, array('class' => 'justifytext'));
|
||||
|
||||
//Specific hub information cell
|
||||
$specifichubcell = get_string('specifichubpublicationdetail', 'hub');
|
||||
$specifichubcell .= html_writer::empty_tag('br').html_writer::empty_tag('br');
|
||||
$specifichubcell = html_writer::tag('div', $specifichubcell, array('class' => 'justifytext'));
|
||||
|
||||
//add information cells
|
||||
$cells = array($moodleorgcell, $specifichubcell);
|
||||
$row = new html_table_row($cells);
|
||||
$table->data[] = $row;
|
||||
|
||||
//Moodle.org button cell
|
||||
if ($registeredonmoodleorg) {
|
||||
$advertiseonmoodleorgurl = new moodle_url("/course/publish/metadata.php",
|
||||
array('sesskey' => sesskey(), 'huburl' => MOODLEORGHUBURL, 'id' => $courseid
|
||||
, 'hubname' => 'Moodle.org', 'advertise' => true));
|
||||
$advertiseonmoodleorgbutton = new single_button($advertiseonmoodleorgurl, get_string('advertiseonmoodleorg', 'hub'));
|
||||
$advertiseonmoodleorgbutton->class = 'centeredbutton';
|
||||
$advertiseonmoodleorgbuttonhtml = $OUTPUT->render($advertiseonmoodleorgbutton);
|
||||
|
||||
$shareonmoodleorgurl = new moodle_url("/course/publish/metadata.php",
|
||||
array('sesskey' => sesskey(), 'huburl' => MOODLEORGHUBURL, 'id' => $courseid
|
||||
, 'hubname' => 'Moodle.org', 'share' => true));
|
||||
$shareonmoodleorgbutton = new single_button($shareonmoodleorgurl, get_string('shareonmoodleorg', 'hub'));
|
||||
$shareonmoodleorgbutton->class = 'centeredbutton';
|
||||
$shareonmoodleorgbuttonhtml = $OUTPUT->render($shareonmoodleorgbutton);
|
||||
|
||||
$moodleorgcell = $advertiseonmoodleorgbuttonhtml." ".$shareonmoodleorgbuttonhtml;
|
||||
} else {
|
||||
$moodleorgcell = html_writer::tag('span',
|
||||
get_string('notregisteredonmoodleorg', 'hub') , array('class' => 'publicationwarning'));
|
||||
}
|
||||
|
||||
//Specific hub button cell
|
||||
if ($registeredonhub) {
|
||||
$advertisespecifichuburl = new moodle_url("/course/publish/hubselector.php",
|
||||
array('sesskey' => sesskey(), 'id' => $courseid, 'advertise' => true));
|
||||
$advertiseonspecifichubbutton = new single_button($advertisespecifichuburl, get_string('advertiseonspecifichub', 'hub'));
|
||||
$advertiseonspecifichubbutton->class = 'centeredbutton';
|
||||
$advertiseonspecifichubbuttonhtml = $OUTPUT->render($advertiseonspecifichubbutton);
|
||||
|
||||
$sharespecifichuburl = new moodle_url("/course/publish/hubselector.php",
|
||||
array('sesskey' => sesskey(), 'id' => $courseid, 'share' => true));
|
||||
$shareonspecifichubbutton = new single_button($sharespecifichuburl, get_string('shareonspecifichub', 'hub'));
|
||||
$shareonspecifichubbutton->class = 'centeredbutton';
|
||||
$shareonspecifichubbuttonhtml = $OUTPUT->render($shareonspecifichubbutton);
|
||||
$specifichubcell = $advertiseonspecifichubbuttonhtml. " " . $shareonspecifichubbuttonhtml;
|
||||
} else {
|
||||
$specifichubcell = html_writer::tag('span',
|
||||
get_string('notregisteredonhub', 'hub') , array('class' => 'publicationwarning'));
|
||||
}
|
||||
|
||||
//add button cells
|
||||
$cells = array($moodleorgcell, $specifichubcell);
|
||||
$row = new html_table_row($cells);
|
||||
$table->data[] = $row;
|
||||
|
||||
return html_writer::table($table);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue