Skip to content

Commit

Permalink
course publication MDL-19315 add screenshots management + fix CSS for…
Browse files Browse the repository at this point in the history
… gallery for form element (Kudo to Sam for this CSS nightmare)
  • Loading branch information
mouneyrac committed Jun 10, 2010
1 parent 42e5b74 commit 82bca83
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 12 deletions.
35 changes: 33 additions & 2 deletions course/publish/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function definition() {
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;
Expand Down Expand Up @@ -124,6 +124,7 @@ public function definition() {

if (!empty($publishedcourses)) {
$publishedcourse = $publishedcourses[0];
$hubcourseid = $publishedcourse['id'];
$defaultfullname = $publishedcourse['fullname'];
$defaultshortname = $publishedcourse['shortname'];
$defaultsummary = $publishedcourse['description'];
Expand All @@ -138,6 +139,8 @@ public function definition() {
$defaultaudience = $publishedcourse['audience'];
$defaulteducationallevel = $publishedcourse['educationallevel'];
$defaultcreatornotes = $publishedcourse['creatornotes'];
$screenshotsnumber = $publishedcourse['screenshotsids'];
$privacy = $publishedcourse['privacy'];

} else {
$defaultfullname = $course->fullname;
Expand All @@ -163,6 +166,7 @@ public function definition() {
$defaultaudience = HUB_AUDIENCE_STUDENTS;
$defaulteducationallevel = HUB_EDULEVEL_TERTIARY;
$defaultcreatornotes = '';
$screenshotsnumber = 0;
}


Expand Down Expand Up @@ -302,7 +306,34 @@ public function definition() {
$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
Expand Down
23 changes: 16 additions & 7 deletions course/publish/metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
$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;
Expand Down Expand Up @@ -133,18 +136,19 @@

//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) {
Expand Down Expand Up @@ -191,7 +195,12 @@
// 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;
Expand Down
11 changes: 8 additions & 3 deletions lang/en/hub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}';
Expand Down Expand Up @@ -69,6 +70,8 @@
$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';
Expand All @@ -90,6 +93,8 @@
$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';
Expand Down Expand Up @@ -156,7 +161,7 @@
$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.';
Expand All @@ -179,8 +184,8 @@
$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';
Expand Down
1 change: 1 addition & 0 deletions theme/base/style/core.css
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 82bca83

Please sign in to comment.