Permalink
Browse files

Comments are now optional and the second column is only displayed whe…

…n appropriate.

Instance setting allows comments to be disabled. The second column is
only displayed if the layout is for captions to be on the right of the
image and/or comments are allowed.
  • Loading branch information...
1 parent 18956d5 commit 0d7eb9ded7420fac702c9c722a106e850a98c9fc John committed Dec 29, 2012
Showing with 93 additions and 59 deletions.
  1. +49 −45 comments.php
  2. +4 −3 db/install.xml
  3. +15 −0 db/upgrade.php
  4. +2 −0 lang/en/slideshow.php
  5. +3 −0 mod_form.php
  6. +1 −1 version.php
  7. +19 −10 view.php
View
@@ -12,68 +12,72 @@
if ($a) { // Two ways to specify the module
$slideshow = $DB->get_record('slideshow', array('id'=>$a), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('slideshow', $slideshow->id, $slideshow->course, false, MUST_EXIST);
-
} else {
$cm = get_coursemodule_from_id('slideshow', $id, 0, false, MUST_EXIST);
$slideshow = $DB->get_record('slideshow', array('id'=>$cm->instance), '*', MUST_EXIST);
}
+ $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
+ require_login($course->id);
+ add_to_log($course->id, "slideshow", "comments", "comments.php?id=$cm->id", "$slideshow->id");
- $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
- require_login($course->id);
- add_to_log($course->id, "slideshow", "comments", "comments.php?id=$cm->id", "$slideshow->id");
-
- $form = data_submitted();
- if ($form) {
+ $form = data_submitted();
+ if ($form && $slideshow->commentsallowed) {
if (isset($form->cancel)) {
redirect("view.php?id=$id");
die;
}
slideshow_write_comment($form, $slideshow);
redirect("view.php?id=$id&img_num=$form->slidenumber");
die;
- }
- add_to_log($course->id, "slideshow", "comments", "comments.php?id=$cm->id", "$slideshow->id");
-/// Print header.
- $PAGE->set_url('/mod/slideshow/comments.php',array('id' => $cm->id));
- $PAGE->navbar->add($slideshow->name);
- echo $OUTPUT->header();
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
-/// Print the main part of the page
- $img_count = 0;
- if(has_capability('moodle/course:update',$coursecontext)){
- $conditions = array('contextid'=>$context->id, 'component'=>'mod_slideshow','filearea'=>'content','itemid'=>0);
- $file_records = $DB->get_records('files', $conditions);
- $captions = array();
- foreach ($file_records as $filerecord) {
- $filename = $filerecord->filename;
- if ( preg_match("#\.jpe?g$#i", $filename) || preg_match("#\.gif$#i", $filename) || preg_match("#\.png$#i", $filename)) {
- if (preg_match("#^thumb_?#i", $filename)) {
- continue;
- }
- if (preg_match("#^resized_#i", $filename)) {
- if ($slideshow->keeporiginals) {
+ }
+ add_to_log($course->id, "slideshow", "comments", "comments.php?id=$cm->id", "$slideshow->id");
+
+ /// Print header.
+ $PAGE->set_url('/mod/slideshow/comments.php',array('id' => $cm->id));
+ $PAGE->navbar->add($slideshow->name);
+ echo $OUTPUT->header();
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
+ $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+
+ /// Print the main part of the page
+ if($slideshow->commentsallowed) {
+ $img_count = 0;
+ if(has_capability('moodle/course:update',$coursecontext)){
+ $conditions = array('contextid'=>$context->id, 'component'=>'mod_slideshow','filearea'=>'content','itemid'=>0);
+ $file_records = $DB->get_records('files', $conditions);
+ $captions = array();
+ foreach ($file_records as $filerecord) {
+ $filename = $filerecord->filename;
+ if ( preg_match("#\.jpe?g$#i", $filename) || preg_match("#\.gif$#i", $filename) || preg_match("#\.png$#i", $filename)) {
+ if (preg_match("#^thumb_?#i", $filename)) {
continue;
- }else{
- $filename = str_replace('resized_','',$filename);
}
+ if (preg_match("#^resized_#i", $filename)) {
+ if ($slideshow->keeporiginals) {
+ continue;
+ }else{
+ $filename = str_replace('resized_','',$filename);
+ }
+ }
+ $image = slideshow_filetidy($filename);
+ $captions[$image] = slideshow_caption_array($slideshow->id,$image);
}
- $image = slideshow_filetidy($filename);
- $captions[$image] = slideshow_caption_array($slideshow->id,$image);
}
- }
- sort($captions);
+ sort($captions);
- // Display the actual form.
- require_once('edit_form.php');
- echo $OUTPUT->heading(get_string('comment_add', 'slideshow'));
- echo get_string('comment_instructions', 'slideshow');
- $htmledit = isset($slideshow->htmlcaptions) ? $slideshow->htmlcaptions:0;
- $mform = new mod_slideshow_comment_form('comments.php', array('htmledit' => $htmledit, 'context' => $context, 'slideshowid' => $slideshow->id, 'slidenumber' => $img_num));
- $mform->display();
- } else {
- echo get_string('noauth','slideshow','');
- }
+ // Display the actual form.
+ require_once('edit_form.php');
+ echo $OUTPUT->heading(get_string('comment_add', 'slideshow'));
+ echo get_string('comment_instructions', 'slideshow');
+ $htmledit = isset($slideshow->htmlcaptions) ? $slideshow->htmlcaptions:0;
+ $mform = new mod_slideshow_comment_form('comments.php', array('htmledit' => $htmledit, 'context' => $context, 'slideshowid' => $slideshow->id, 'slidenumber' => $img_num));
+ $mform->display();
+ } else {
+ echo get_string('noauth','slideshow','');
+ }
+ } else {
+ echo get_string('comments_not_allowed', 'slideshow');
+ }
/// Finish the page
echo $OUTPUT->footer($course);
?>
View
@@ -16,8 +16,9 @@
<FIELD NAME="centred" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="delaytime" NEXT="autobgcolor"/>
<FIELD NAME="autobgcolor" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="centred" NEXT="timemodified"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="autobgcolor" NEXT="htmlcaptions"/>
- <FIELD NAME="htmlcaptions" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="timemodified" NEXT="keeporiginals"/>
- <FIELD NAME="keeporiginals" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="htmlcaptions"/>
+ <FIELD NAME="htmlcaptions" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="timemodified" NEXT="commentsallowed"/>
+ <FIELD NAME="commentsallowed" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="htmlcaptions" NEXT="keeporiginals"/>
+ <FIELD NAME="keeporiginals" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="commentsallowed"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
@@ -91,4 +92,4 @@
</INDEXES>
</TABLE>
</TABLES>
-</XMLDB>
+</XMLDB>
View
@@ -91,6 +91,21 @@ function xmldb_slideshow_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2012122800, 'slideshow');
}
+ if ($oldversion < 2012122900) {
+
+ // Define field commentsallowed to be added to slideshow
+ $table = new xmldb_table('slideshow');
+ $field = new xmldb_field('commentsallowed', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '1', 'htmlcaptions');
+
+ // Conditionally launch add field commentsallowed
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ // slideshow savepoint reached
+ upgrade_mod_savepoint(true, 2012122900, 'slideshow');
+ }
+
return true;
}
View
@@ -23,6 +23,7 @@
$string['showtime'] = 'Slideshow popup delay time:';
$string['noautoplay'] = 'No autoplay';
$string['htmlcaptions'] = 'HTML editor for captions?';
+$string['comments'] = 'Allow comments?';
// for view.php
$string['none_found'] = 'No images found in main files directory';
@@ -52,6 +53,7 @@
$string['comment_add'] = 'Add a comment to this slide';
$string['comment_instructions'] = 'Comments are public and viewable by all.';
$string['comments_header'] = 'Comments';
+$string['comments_not_allowed'] = 'Comments are disabled for this slideshow.';
// for media
$string['media'] = 'Media';
View
@@ -45,6 +45,9 @@ function definition() {
$mform->setDefault('centred', 1);
$mform->addElement('select', 'htmlcaptions', get_string("htmlcaptions", "slideshow"),$ynopts);
$mform->setDefault('htmlcaptions', 1);
+ $mform->addElement('select', 'commentsallowed', get_string("comments", "slideshow"),$ynopts);
+ $mform->setDefault('commentsallowed', 1);
+
$dtimes = array (0=>get_string("noautoplay", "slideshow"),
5=>'5s',
10=>'10s',
View
@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();
-$module->version = 2012122800;
+$module->version = 2012122900;
$module->requires = 2010112400; // Moodle 2.0
$module->component = 'mod_slideshow';
$module->cron = 0;
View
@@ -152,7 +152,11 @@
sort($filearray);
if ($slideshow->centred){
- $container_width = $CFG->slideshow_maxwidth + 320;
+ $container_width = $CFG->slideshow_maxwidth;
+ // Add space for second column if comments are allowed or if captions are displayed to the right.
+ if($slideshow->commentsallowed || $slideshow->filename == 3) {
+ $container_width += 320;
+ }
echo '<div style="width: ' . $container_width . 'px; margin: 0px auto;">';
}
@@ -263,15 +267,18 @@
echo '</div>';
}
- // Comments column.
- echo '<div style="float: left; width: 350px; margin: 70px 0 0 20px;">';
- if($slideshow->filename == 3) {
- echo '<p>' . $captionstring . '</p>';
- }
- echo ' <h3>' . get_string('comments_header', 'slideshow') . '</h3>';
- echo ' <ul style="list-style: none;">';
+ // Second column only displayed if comments are allowed or captions are shown to the right.
+ if($slideshow->commentsallowed || $slideshow->filename==3) {
+ // Fixed width because, depending on user's resolution, maxwidth could cause the second column to be very narrow.
+ // In that case it makes more sense for the column to be cleared under the image.
+ echo '<div style="float: left; width: 350px; margin: 70px 0 0 20px;">';
+ if($slideshow->filename == 3) {
+ echo '<p>' . $captionstring . '</p>';
+ }
- // Show comments, if there are any.
+ if($slideshow->commentsallowed) {
+ echo '<h3>' . get_string('comments_header', 'slideshow') . '</h3>';
+ echo '<ul style="list-style: none;">';
$comments = array();
$comments = slideshow_slide_comments_array($slideshow->id, $img_num);
@@ -288,8 +295,10 @@
}
echo '</ul>';
- echo ' <a href="comments.php?id=' . $cm->id . '&img_num=' . $img_num . '">' . get_string('comment_add', 'slideshow') . '</a>';
+ echo '<a href="comments.php?id=' . $cm->id . '&img_num=' . $img_num . '">' . get_string('comment_add', 'slideshow') . '</a>';
echo '</div>';
+ }
+ }
} else {
echo '<p>'.get_string('none_found', 'slideshow').' <b>'.$showdir.'</b></p>';

0 comments on commit 0d7eb9d

Please sign in to comment.