Skip to content

Commit

Permalink
publish course MDL-19315 refactor the publish index page + add unpubl…
Browse files Browse the repository at this point in the history
…ish operation
  • Loading branch information
mouneyrac committed May 19, 2010
1 parent 1345cc5 commit 4676eaf
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 82 deletions.
10 changes: 6 additions & 4 deletions course/publish/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ public function definition() {
//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);
if (empty($hubname)) {
$hubname = $hub->huburl;
}
$mform->addElement('radio','huburl',null,' '.$hubname, $hub->huburl);
}
$mform->addElement('select', 'huburl', get_string('publichub','hub'),
$options, array("size" => 15));

$mform->addElement('hidden', 'id', $this->_customdata['id']);

Expand Down Expand Up @@ -179,7 +181,7 @@ public function definition() {
}

if ($advertise) {
if (empty($publications)) {
if (empty($publishedcourses)) {
$buttonlabel = get_string('advertiseon', 'hub', !empty($hubname)?$hubname:$huburl);
} else {
$buttonlabel = get_string('readvertiseon', 'hub', !empty($hubname)?$hubname:$huburl);
Expand Down
76 changes: 62 additions & 14 deletions course/publish/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,76 @@
$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;
/// UNPUBLISH
$confirmmessage = '';
$cancel = optional_param('cancel', 0, PARAM_BOOL);
if (!empty($cancel) and confirm_sesskey()) {
$confirm = optional_param('confirm', 0, PARAM_BOOL);
$hubname = optional_param('hubname', 0, PARAM_TEXT);
$huburl = optional_param('huburl', 0, PARAM_URL);
$hubcourseid = optional_param('hubcourseid', 0, PARAM_INT);
$publicationid = optional_param('publicationid', 0, PARAM_INT);
$timepublished = optional_param('timepublished', 0, PARAM_INT);
$publication->courseshortname = $course->shortname;
$publication->courseid = $course->id;
$publication->hubname = $hubname;
$publication->huburl = $huburl;
$publication->hubcourseid = $hubcourseid;
$publication->timepublished = $timepublished;
if (empty($publication->hubname)) {
$publication->hubname = $huburl;
}
$publication->id = $publicationid;
if($confirm) {
//unpublish the publication by web service
$registeredhub = $hub->get_registeredhub($huburl);
$function = 'hub_unregister_courses';
$params = array(array( $publication->hubcourseid));
$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);

//delete the publication from the database
$hub->delete_publication($publicationid);

//display confirmation message
$confirmmessage = $OUTPUT->notification(get_string('courseunpublished', 'hub', $publication), 'notifysuccess');

} else {
$registeredonhub = true;
//display confirmation page for unpublishing

echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('unpublishcourse', 'hub', $course->shortname), 3, 'main');
echo $renderer->confirmunpublishing($publication);
echo $OUTPUT->footer();
die();
}
}

echo $renderer->publicationselector($course->id, $registeredonmoodleorg, $registeredonhub);
//check if a course was published
if (optional_param('published', 0, PARAM_TEXT)) {
$confirmmessage = $OUTPUT->notification(get_string('coursepublished', 'hub'), 'notifysuccess');
}


/// OUTPUT
echo $OUTPUT->header();
echo $confirmmessage;

echo $OUTPUT->heading(get_string('publishcourse', 'hub', $course->shortname), 3, 'main');
echo $renderer->publicationselector($course->id);

$publications = $hub->get_course_publications($course->id);
if (!empty($publications)) {
echo $OUTPUT->heading(get_string('publishedon', 'hub'), 3, 'main');
echo $renderer->registeredonhublisting($course->id, $publications);
}

echo $OUTPUT->footer();

}
16 changes: 10 additions & 6 deletions course/publish/metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@
require_once('../../config.php');
require_once($CFG->dirroot.'/course/publish/forms.php');
require_once($CFG->dirroot.'/lib/hublib.php');
require_once($CFG->dirroot.'/lib/filelib.php');
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.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');
Expand Down Expand Up @@ -134,9 +136,6 @@
throw new moodle_exception('coursewronglypublished');
}

$courseregisteredmsg = $OUTPUT->notification(get_string('coursepublished', 'hub'), 'notifysuccess');


//save the record into the published course table
$publication = $hub->get_publication($courseids[0]);
if (empty($publication)) {
Expand All @@ -149,13 +148,14 @@


// SEND FILES
$curl = new curl();

// send screenshots
if (!empty($fromform->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;
Expand All @@ -178,7 +178,11 @@


//TODO: Delete the backup from user_tohub



//redirect to the index publis page
redirect(new moodle_url('/course/publish/index.php',
array('sesskey' => sesskey(), 'id' => $id, 'published' => true)));
}


Expand Down
151 changes: 99 additions & 52 deletions course/publish/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,78 +30,125 @@
class core_publish_renderer extends plugin_renderer_base {

/**
* Display the page to publish a course on Moodle.org or on a specific hub
* Display the selector to advertise or publish a course
*/
public function publicationselector($courseid, $registeredonmoodleorg, $registeredonhub) {
public function publicationselector($courseid) {
global $OUTPUT;

$table = new html_table();
$table->head = array(get_string('moodleorg', 'hub'), get_string('specifichub', 'hub'));
$table->head = array(get_string('advertise', 'hub'), get_string('share', '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'));
//Advertise information cell
$advertisecell = get_string('advertisepublicationdetail', 'hub');
$advertisecell .= html_writer::empty_tag('br').html_writer::empty_tag('br');
$advertisecell = html_writer::tag('div', $advertisecell, 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'));
//Share information cell
$sharecell = get_string('sharepublicationdetail', 'hub');
$sharecell .= html_writer::empty_tag('br').html_writer::empty_tag('br');
$sharecell = html_writer::tag('div', $sharecell, array('class' => 'justifytext'));

//add information cells
$cells = array($moodleorgcell, $specifichubcell);
$cells = array($advertisecell, $sharecell);
$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'));
}
$advertiseurl = new moodle_url("/course/publish/hubselector.php",
array('sesskey' => sesskey(), 'id' => $courseid, 'advertise' => true));
$advertisebutton = new single_button($advertiseurl, get_string('selecthubforadvertise', 'hub'));
$advertisebutton->class = 'centeredbutton';
$advertisecell = $OUTPUT->render($advertisebutton);

//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'));
}
$shareurl = new moodle_url("/course/publish/hubselector.php",
array('sesskey' => sesskey(), 'id' => $courseid, 'share' => true));
$sharebutton = new single_button($shareurl, get_string('selecthubforsharing', 'hub'));
$sharebutton->class = 'centeredbutton';
$sharecell = $OUTPUT->render($sharebutton);

//add button cells
$cells = array($moodleorgcell, $specifichubcell);
$cells = array($advertisecell, $sharecell);
$row = new html_table_row($cells);
$table->data[] = $row;

return html_writer::table($table);

}

/**
* Display the listing of hub where a course is registered on
*/
public function registeredonhublisting($courseid, $publications) {
global $OUTPUT;

$table = new html_table();
$table->head = array(get_string('type', 'hub'), get_string('hub', 'hub'), get_string('date'), get_string('operation', 'hub'));
$table->size = array('10%', '50%', '30%', '%10');

foreach ($publications as $publication) {

$updatebuttonhtml = '';

if ($publication->enrollable) {
$params = array('sesskey' => sesskey(), 'id' => $publication->courseid,
'huburl' => $publication->huburl, 'hubname' => $publication->hubname,
'share' => !$publication->enrollable, 'advertise' => $publication->enrollable);
$updateurl = new moodle_url("/course/publish/metadata.php", $params);
$updatebutton = new single_button($updateurl, get_string('update', 'hub'));
$updatebutton->class = 'centeredbutton';
$updatebuttonhtml = $OUTPUT->render($updatebutton);
}

$params = array('sesskey' => sesskey(), 'id' => $publication->courseid, 'hubcourseid' => $publication->hubcourseid,
'huburl' => $publication->huburl, 'hubname' => $publication->hubname,
'cancel' => true, 'publicationid' => $publication->id, 'timepublished' => $publication->timepublished);
$cancelurl = new moodle_url("/course/publish/index.php", $params);
$cancelbutton = new single_button($cancelurl, get_string('cancel', 'hub'));
$cancelbutton->class = 'centeredbutton';
$cancelbuttonhtml = $OUTPUT->render($cancelbutton);

if (!empty($updatebuttonhtml)) {
$brtag = html_writer::empty_tag('br');
$operations = $updatebuttonhtml . $brtag . $cancelbuttonhtml;
} else {
$operations = $cancelbuttonhtml;
}

$hubname = html_writer::tag('a', $publication->hubname?$publication->hubname:$publication->huburl,
array('href' => $publication->huburl));

//add button cells
$cells = array($publication->enrollable?get_string('advertised', 'hub'):get_string('uploaded', 'hub'),
$hubname, userdate($publication->timepublished),$operations);
$row = new html_table_row($cells);
$table->data[] = $row;

}

return html_writer::table($table);

}

/**
* Display unpublishing confirmation page
* @param object $publication
* $publication->courseshortname
$publication->courseid
$publication->hubname
$publication->huburl
$publication->id
*/
public function confirmunpublishing($publication) {
global $OUTPUT;
$optionsyes = array('sesskey' => sesskey(), 'id' => $publication->courseid, 'hubcourseid' => $publication->hubcourseid,
'huburl' => $publication->huburl, 'hubname' => $publication->hubname,
'cancel' => true, 'publicationid' => $publication->id, 'confirm' => true);
$optionsno = array('sesskey'=>sesskey(), 'id' => $publication->courseid);
$publication->hubname = html_writer::tag('a', $publication->hubname,
array('href' => $publication->huburl));
$formcontinue = new single_button(new moodle_url("/course/publish/index.php", $optionsyes), get_string('unpublish', 'hub'), 'post');
$formcancel = new single_button(new moodle_url("/course/publish/index.php", $optionsno), get_string('cancel'), 'get');
return $OUTPUT->confirm(get_string('unpublishconfirmation', 'hub', $publication), $formcontinue, $formcancel);
}

}
Loading

0 comments on commit 4676eaf

Please sign in to comment.