course publication MDL-19315 add screenshots management + fix CSS for gallery for form element (Kudo to Sam for this CSS nightmare)

This commit is contained in:
jerome mouneyrac
2010-06-10 03:42:44 +00:00
parent 42e5b74426
commit 82bca83db5
4 changed files with 58 additions and 12 deletions
+33 -2
View File
@@ -86,7 +86,7 @@ class hub_publish_selector_form extends moodleform {
class course_publication_form extends moodleform {
public function definition() {
global $CFG, $DB, $USER;
global $CFG, $DB, $USER, $OUTPUT;
$strrequired = get_string('required');
$mform =& $this->_form;
@@ -124,6 +124,7 @@ class course_publication_form extends moodleform {
if (!empty($publishedcourses)) {
$publishedcourse = $publishedcourses[0];
$hubcourseid = $publishedcourse['id'];
$defaultfullname = $publishedcourse['fullname'];
$defaultshortname = $publishedcourse['shortname'];
$defaultsummary = $publishedcourse['description'];
@@ -138,6 +139,8 @@ class course_publication_form extends moodleform {
$defaultaudience = $publishedcourse['audience'];
$defaulteducationallevel = $publishedcourse['educationallevel'];
$defaultcreatornotes = $publishedcourse['creatornotes'];
$screenshotsnumber = $publishedcourse['screenshotsids'];
$privacy = $publishedcourse['privacy'];
} else {
$defaultfullname = $course->fullname;
@@ -163,6 +166,7 @@ class course_publication_form extends moodleform {
$defaultaudience = HUB_AUDIENCE_STUDENTS;
$defaulteducationallevel = HUB_EDULEVEL_TERTIARY;
$defaultcreatornotes = '';
$screenshotsnumber = 0;
}
@@ -302,7 +306,34 @@ class course_publication_form extends moodleform {
$mform->setType('creatornotes', PARAM_CLEANHTML);
$mform->addHelpButton('creatornotes', 'creatornotes', 'hub');
$mform->addElement('filemanager', 'screenshots', get_string('screenshots','hub'), null,
if (!empty($screenshotsnumber)) {
if (!empty($privacy)) {
$images = array();
$baseurl = new moodle_url($huburl.'/local/hub/webservice/download.php', array('courseid' => $hubcourseid, 'filetype' => HUB_SCREENSHOT_FILE_TYPE));
for ($i = 1; $i <= $screenshotsnumber; $i = $i + 1) {
$params['screenshotnumber'] = $i;
$images[] = array(
'thumburl' => new moodle_url($baseurl, array('screenshotnumber' => $i)),
'imageurl' => new moodle_url($baseurl, array('screenshotnumber' => $i, 'imagewidth' => 'original')),
'title' => $defaultfullname,
'alt' => $defaultfullname
);
}
$imagegallery = new image_gallery($images, $defaultshortname);
$imagegallery->displayfirstimageonly = true;
$screenshothtml = $OUTPUT->render($imagegallery);
} else {
$screenshothtml = get_string('existingscreenshotnumber', 'hub', $screenshotsnumber);
}
$mform->addElement('static', 'existingscreenshots', get_string('existingscreenshots', 'hub'), $screenshothtml);
$mform->addHelpButton('existingscreenshots', 'deletescreenshots', 'hub');
$mform->addElement('checkbox', 'deletescreenshots', '', ' '.get_string('deletescreenshots', 'hub'));
}
$mform->addElement('hidden', 'existingscreenshotnumber', $screenshotsnumber);
$mform->addElement('filemanager', 'screenshots', get_string('addscreenshots','hub'), null,
array('subdirs'=>0,
'maxbytes'=>1000000,
'maxfiles'=>3
+16 -7
View File
@@ -89,6 +89,9 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE,
$courseinfo->creatornotes = $creatornotes['text'];
$courseinfo->creatornotesformat = $creatornotes['format'];
$courseinfo->sitecourseid = $id;
if (!empty($fromform->deletescreenshots)) {
$courseinfo->deletescreenshots = $fromform->deletescreenshots;
}
if ($share) {
$courseinfo->demourl = $fromform->demourl;
$courseinfo->enrollable = false;
@@ -133,18 +136,19 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE,
//save into screenshots field the references to the screenshot content hash
//(it will be like a unique id from the hub perspective)
if (!empty($fromform->deletescreenshots)) {
$courseinfo->screenshotsids = 0;
} else {
$courseinfo->screenshotsids = $fromform->existingscreenshotnumber;
}
if (!empty($fromform->screenshots)) {
$screenshots = $fromform->screenshots;
$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 = count($files)-1; //minus the ./ directory
} else {
$courseinfo->screenshotsids = 0;
$courseinfo->screenshotsids = $courseinfo->screenshotsids + count($files)-1; //minus the ./ directory
}
} else {
$courseinfo->screenshotsids = 0;
}
}
// BACKUP ACTION
if ($share) {
@@ -191,7 +195,12 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE,
// send screenshots
if (!empty($fromform->screenshots)) {
require_once($CFG->dirroot. "/lib/filelib.php");
$screenshotnumber = 0;
if (!empty($fromform->deletescreenshots)) {
$screenshotnumber = 0;
} else {
$screenshotnumber = $fromform->existingscreenshotnumber;
}
foreach ($files as $file) {
if ($file->is_valid_image()) {
$screenshotnumber = $screenshotnumber + 1;
+8 -3
View File
@@ -25,6 +25,7 @@
*/
$string['addedtoblock'] = 'Course added to block';
$string['addscreenshots'] = 'Add screenshots';
$string['advertise'] = 'Advertise this course for people to join';
$string['advertised'] = 'Advertised';
$string['advertiseon'] = 'Advertise this course on {$a}';
@@ -69,6 +70,8 @@ $string['creatorname'] = 'Creator';
$string['creatorname_help'] = 'The creator is the course creator.';
$string['creatornotes'] = 'Creator notes';
$string['creatornotes_help'] = 'Creator notes are a guide for teacher on how to use the course.';
$string['deletescreenshots'] = 'Delete these screenshots';
$string['deletescreenshots_help'] = 'Delete all the currently uploaded screenshots.';
$string['demourl'] = 'Demo URL';
$string['demourl_help'] = 'Enter the demo URL of your course. By default it is the URL of your course. The demo url is displayed as a link in a search result.';
$string['description'] = 'Description';
@@ -90,6 +93,8 @@ $string['emailalert_help'] = 'Set to yes, the hub administrator will send you em
$string['enrollable'] = 'Enrollable';
$string['errorbadimageheightwidth'] = 'The image should have a maximum size of {$a->width} X {$a->height}';
$string['errorlangnotrecognized'] = 'Language code is unknown by Moodle. Please contact {$a}';
$string['existingscreenshotnumber'] = '{$a} existing screenshots. You will be able to see these screenshots on this page, only once the hub administrator enables your course.';
$string['existingscreenshots'] = 'Existing screenshots';
$string['geolocation'] = 'latitude - longitude';
$string['geolocation_help'] = 'A geolocation code like you can find on Google Map or Twitter (example: -31.947884,115.871285)';
$string['hub'] = 'Hub';
@@ -156,7 +161,7 @@ $string['registrationupdatedfailed'] = 'Registration update failed.';
$string['resourcesnumber'] = 'Number of resources ({$a})';
$string['roleassignmentsnumber'] = 'Number of role assignments ({$a})';
$string['screenshots'] = 'Screenshots';
$string['screenshots_help'] = 'Screenshots will displayed during search results.';
$string['screenshots_help'] = 'Add screenshots that will be displayed during search results.';
$string['search'] = 'Search';
$string['selecthub'] = 'Select hub';
$string['selecthubinfo'] = 'A community hub is a server that lists courses. You can only publish your courses on hubs that this Moodle site is registered with. If the hub you want is not listed below, please contact your site administrator.';
@@ -179,8 +184,8 @@ $string['sitecountry_help'] = 'Country of this site';
$string['sitecreated'] = 'Site created';
$string['sitedesc'] = 'Description';
$string['sitedesc_help'] = 'Description shown on the site listing.';
$string['sitegeolocation'] = 'latitude - longitude';
$string['sitegeolocation_help'] = 'A geolocation code like you can find on Google Map or Twitter (example: -31.947884,115.871285)';
$string['sitegeolocation'] = 'Geolocation';
$string['sitegeolocation_help'] = 'Lattitude-longitude value like you can find on Google Map or Twitter (example: -31.947884,115.871285)';
$string['siteemail'] = 'Email address';
$string['siteemail_help'] = 'Email address you to contact you. It will be kept private following the privacy choosen.';
$string['sitelang'] = 'Language';
+1
View File
@@ -591,6 +591,7 @@ body.tag .managelink {padding: 5px;}
.image_gallery.oneimageonly a.imagelink {display:none;}
.image_gallery.oneimageonly a#imagelink1 {display:inline;}
.mform .image_gallery.oneimageonly a.imagelink {float:left;}
/**
* Registration