diff --git a/backup/moodle2/backup_oublog_stepslib.php b/backup/moodle2/backup_oublog_stepslib.php index ee27798..785bc14 100644 --- a/backup/moodle2/backup_oublog_stepslib.php +++ b/backup/moodle2/backup_oublog_stepslib.php @@ -41,7 +41,9 @@ protected function define_structure() { 'maxbytes', 'maxattachments', 'maxvisibility', 'global', 'views', 'completionposts', 'completioncomments', 'reportingemail', 'displayname', 'statblockon', 'allowimport', 'introonpost', 'tags', 'assessed', - 'assesstimestart', 'assesstimefinish', 'scale', 'grading', 'restricttags')); + 'assesstimestart', 'assesstimefinish', 'scale', 'grading', 'restricttags', + 'postfrom', 'postuntil', 'commentfrom', 'commentuntil' + )); $instances = new backup_nested_element('instances'); $instance = new backup_nested_element('instance', array('id'), array( diff --git a/db/access.php b/db/access.php index 81cd3fd..58e9f9a 100644 --- a/db/access.php +++ b/db/access.php @@ -240,4 +240,26 @@ 'manager' => CAP_ALLOW ) ), + + 'mod/oublog:ignorepostperiod' => array( + + 'captype' => 'write', + 'contextlevel' => CONTEXT_MODULE, + 'legacy' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW, + ) + ), + + 'mod/oublog:ignorecommentperiod' => array( + + 'captype' => 'write', + 'contextlevel' => CONTEXT_MODULE, + 'legacy' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW, + ) + ), ); diff --git a/db/install.xml b/db/install.xml index c5512e5..f60c665 100644 --- a/db/install.xml +++ b/db/install.xml @@ -1,5 +1,5 @@ - @@ -34,6 +34,10 @@ + + + + diff --git a/db/upgrade.php b/db/upgrade.php index 0a3f3a0..a7b7be7 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -340,5 +340,47 @@ function xmldb_oublog_upgrade($oldversion=0) { upgrade_mod_savepoint(true, 2014122400, 'oublog'); } + if ($oldversion < 2015090800) { + + // Define field postfrom to be added to oublog. + $table = new xmldb_table('oublog'); + $field = new xmldb_field('postfrom', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'restricttags'); + + // Conditionally launch add field postfrom. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Define field postuntil to be added to oublog. + $table = new xmldb_table('oublog'); + $field = new xmldb_field('postuntil', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'postfrom'); + + // Conditionally launch add field postuntil. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Define field commentfrom to be added to oublog. + $table = new xmldb_table('oublog'); + $field = new xmldb_field('commentfrom', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'postuntil'); + + // Conditionally launch add field commentfrom. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Define field commentuntil to be added to oublog. + $table = new xmldb_table('oublog'); + $field = new xmldb_field('commentuntil', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'commentfrom'); + + // Conditionally launch add field commentuntil. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Oublog savepoint reached. + upgrade_mod_savepoint(true, 2015090800, 'oublog'); + } + return true; } diff --git a/internaldoc/testcase.readonlytime.txt b/internaldoc/testcase.readonlytime.txt new file mode 100644 index 0000000..6547d93 --- /dev/null +++ b/internaldoc/testcase.readonlytime.txt @@ -0,0 +1,132 @@ +This script describes steps to test the read-only facility from a user +perspective. It is intended to cover most of the UI and features. + +NOTE: In this test case, the word 'blog' always refers to the OU blog. + +The test steps in this script follow on from each other and aren't independent. + + +Initial setup +============= + +This test case requires: + +- one test user (US1) with the Student role. +- one test user (admin) with the admin or manager role. + +Test course (admin must have permissions to create/configure activities) + +The test server must have debugging set to DEVELOPER level and to display +errors; during all parts of the test script, there should be no debugging +warnings. + + +POS Posting time limiting +========================= + +POS01 / admin + In your test course, create a blog called POS01-RO, + this should have the 'Posting only allowed from' option under 'Contribution time period' + set to a date in the past and enabled. + Select 'Save and display'. +- Verify no messages displayed above 'New post' button. + +POS02 / admin + Select 'Edit settings' from 'OU Blog administration' 'Administration' block. + Change 'Posting only allowed from' to a date in the future. + Select 'Save and display'. +- Verify message informing that students will not be able to post until the date, + (but you can) is shown above 'New post' button. +- Verify date matches that entered in settings form (dd/mm/yy, hh:mm format). + +POS03 / student (change) + Enter the test course and select link to POS01-RO blog. +- Verify message informing that creating post is not available until date entered previously is shown. +- Verify 'New post button' is not shown. + +POS04 / admin (change) + Enter the test course and select link to POS01-RO blog. + Select 'Edit settings' from 'OU Blog administration' 'Administration' block. + Change 'Posting only allowed until' to enabled and make a date in future (after posting from date). + Select 'Save and display'. +- Verify message informing that students will not be able to post until the date, + (but you can) is shown above 'New post' button. +- Verify message informing that students will not be able to post after the second date, + (but you can) is shown above 'New post' button. +- Verify dates match those entered in settings form (dd/mm/yy, hh:mm format). + +POS05 / student (change) + Enter the test course and select link to POS01-RO blog. +- Verify message informing that creating post is not available until date entered previously is shown. +- Verify message informing that creating post will only be available until date entered previously is shown. +- Verify 'New post button' is not shown. + +POS06 / admin (change) + Enter the test course and select link to POS01-RO blog. + Select 'Edit settings' from 'OU Blog administration' 'Administration' block. + Disable 'Posting only allowed from'. + Change 'Posting only allowed until' to a date in the past. + Select 'Save and display'. +- Verify message informing that students are no longer be able to post after date, + (but you can) is shown above 'New post' button. +- Verify date matches that entered in settings form (dd/mm/yy, hh:mm format). + +POS07 / student (change) + Enter the test course and select link to POS01-RO blog. +- Verify message informing that creating post is not available as after date entered previously is shown. +- Verify 'New post button' is not shown. + +COM Comment time limiting +========================= + +COM01 / admin + Enter the test course and select link to POS01-RO blog. + Select the 'New post' button and add a new post to the blog. + Select 'Edit settings' from 'OU Blog administration' 'Administration' block. + Disable 'Posting only allowed until'. + Enable 'Commenting only allowed from' and set to a date in the future. + Select 'Save and display'. +- Verify message informing that students will not be able to comment on posts until the date, + (but you can) is shown above 'New post' button. +- Verify 'Add your comment' link is shown against the new post. + +COM02 / student (change) + Enter the test course and select link to POS01-RO blog. +- Verify message informing that you are not able to comment on posts until the date, + is shown above 'New post' button. +- Verify 'Add your comment' link is not shown against the new post. + +COM03 / admin (change) + Enter the test course and select link to POS01-RO blog. + Select 'Edit settings' from 'OU Blog administration' 'Administration' block. + Disable 'Commenting only allowed from'. + Change 'Commenting only allowed until' to a date in the past. + Select 'Save and display'. +- Verify message informing that students are no longer be able to comment on posts as past date, + (but you can) is shown above 'New post' button. +- Verify date matches that entered in settings form (dd/mm/yy, hh:mm format). +- Verify 'Add your comment' link is shown against the new post. + +COM04 / student (change) + Enter the test course and select link to POS01-RO blog. +- Verify message informing that you are not able to comment on posts as past date, + is shown above 'New post' button. +- Verify 'Add your comment' link is not shown against the new post. + +COM05 / admin (change) + Enter the test course and select link to POS01-RO blog. + Select 'Edit settings' from 'OU Blog administration' 'Administration' block. + Change 'Commenting only allowed until' to a date in the future. + Select 'Save and display'. +- Verify message informing that students will not be able to comment on posts after date, + (but you can) is shown above 'New post' button. +- Verify date matches that entered in settings form (dd/mm/yy, hh:mm format). +- Verify 'Add your comment' link is shown against the new post. + +COM06 / student (change) + Enter the test course and select link to POS01-RO blog. +- Verify message informing that you will not able to comment on posts after date, + is shown above 'New post' button. +- Verify 'Add your comment' link is shown against the new post. + +End test. diff --git a/lang/en/oublog.php b/lang/en/oublog.php index 1d1eb67..7a0154c 100644 --- a/lang/en/oublog.php +++ b/lang/en/oublog.php @@ -39,6 +39,34 @@ $string['oublog:exportownpost'] = 'Export own post'; $string['oublog:exportpost'] = 'Export post'; $string['oublog:exportposts'] = 'Export posts'; +$string['oublog:ignorepostperiod'] = 'Ignore post time period'; +$string['oublog:ignorecommentperiod'] = 'Ignore comment time period'; + +$string['advancedoptions'] = 'Advanced options'; +$string['limits'] = 'Contribution time period'; +$string['postfrom'] = 'Posting only allowed from'; +$string['postuntil'] = 'Posting only allowed until'; +$string['commentfrom'] = 'Commenting only allowed from'; +$string['commentuntil'] = 'Commenting only allowed until'; +$string['beforestartpost'] = 'You cannot create posts at this time. Post creation is available from {$a}.'; +$string['beforestartpostcapable'] = 'Students cannot create their own posts until {$a}. +
You have access to create posts before this time.'; +$string['beforeendpost'] = 'You can only create posts until {$a}.'; +$string['beforeendpostcapable'] = 'Students are able to create their own posts until {$a}. +
You have access to create posts after this time.'; +$string['afterendpost'] = 'You cannot create posts at this time. Post creation ended on {$a}.'; +$string['afterendpostcapable'] = 'Students were able to create their own posts until {$a}. +
You have access to create posts after this time.'; +$string['beforestartcomment'] = 'You cannot comment on posts at this time. Commenting is available from {$a}.'; +$string['beforestartcommentcapable'] = 'Students cannot comment on posts until {$a}. +
You have access to comment before this time.'; +$string['beforeendcomment'] = 'You can only comment on posts until {$a}.'; +$string['beforeendcommentcapable'] = 'Students are able to comment on posts until {$a}. +
You have access to comment after this time.'; +$string['afterendcomment'] = 'You cannot comment on posts at this time. Commenting ended on {$a}.'; +$string['afterendcommentcapable'] = 'Students were able to comment on posts until {$a}. +
You have access to comment after this time.'; + $string['mustprovidepost'] = 'Must provide postid'; $string['newpost'] = 'New {$a} post'; $string['removeblogs'] = 'Remove all blog entries'; diff --git a/locallib.php b/locallib.php index 76efca3..7c0b222 100644 --- a/locallib.php +++ b/locallib.php @@ -185,6 +185,25 @@ function oublog_check_view_permissions($oublog, $context, $cm=null) { } } +/** + * Checks if user can post to the blog depending on time limits + * @param object $oublog + * @param context $context + * @return bool True if can post + */ +function oublog_can_post_now($oublog, $context) { + if (($oublog->postfrom == 0 || $oublog->postfrom <= time()) && + ($oublog->postuntil == 0 || $oublog->postuntil > time())) { + // Within time limits. + return true; + } + if ($oublog->global && $context->contextlevel != CONTEXT_SYSTEM) { + // Global blog override and check at system context. + $context = context_system::instance(); + } + return has_capability('mod/oublog:ignorepostperiod', $context); +} + /** * Determines whether the user can make a post to the given blog. * @param $oublog Blog object @@ -217,10 +236,12 @@ function oublog_can_post($oublog, $bloguserid=0, $cm=null) { * @param $cm Course-module (null if personal blog) * @param $oublog Blog object * @param $post Post object + * @param bool $ignoretime True to ignore any comment time limits * @return bool True if user is allowed to make comments */ -function oublog_can_comment($cm, $oublog, $post) { +function oublog_can_comment($cm, $oublog, $post, $ignoretime = false) { global $USER; + if ($oublog->global) { // Just need the 'contributepersonal' permission at system level, OR // if you are not logged in but the blog allows public comments. @@ -263,11 +284,22 @@ function oublog_can_comment($cm, $oublog, $post) { // make this make sense, or some other changes. } + // Test comment time period. + $timeok = (($oublog->commentfrom == 0 || $oublog->commentfrom <= time()) && + ($oublog->commentuntil == 0 || $oublog->commentuntil > time())); + if ($ignoretime) { + $timeok = true; + } + if (!$timeok && has_capability('mod/oublog:ignorecommentperiod', + $oublog->global ? context_system::instance() : context_module::instance($cm->id))) { + $timeok = true; + } + // If the blog allows comments, this post must allow comments and either // it allows public comments or you're logged in (and not guest) return $blogok && $post->allowcomments && ($post->allowcomments >= OUBLOG_COMMENTS_ALLOWPUBLIC || - (isloggedin() && !isguestuser())); + (isloggedin() && !isguestuser())) && $timeok; } /** diff --git a/mod_form.php b/mod_form.php index 39252ed..074b88c 100644 --- a/mod_form.php +++ b/mod_form.php @@ -94,10 +94,6 @@ public function definition() { $mform->addHelpButton('maxattachments', 'maxattachments', 'oublog'); $mform->setDefault('maxattachments', $modulesettings->maxattachments); - // Enable the stats block. - $mform->addElement('checkbox', 'statblockon', get_string('statblockon', 'oublog'), '', 0); - $mform->addHelpButton('statblockon', 'statblockon', 'oublog'); - // Show OU Alerts reporting link. if (oublog_oualerts_enabled()) { $mform->addElement('text', 'reportingemail', get_string('reportingemail', 'oublog'), @@ -108,6 +104,12 @@ public function definition() { 'maxlength', 255, 'client'); } + $mform->addElement('header', 'advanced', get_string('advancedoptions', 'oublog')); + + // Enable the stats block. + $mform->addElement('checkbox', 'statblockon', get_string('statblockon', 'oublog'), '', 0); + $mform->addHelpButton('statblockon', 'statblockon', 'oublog'); + $mform->addElement('text', 'displayname', get_string('displayname', 'oublog'), array('size'=>'48')); $mform->addHelpButton('displayname', 'displayname', 'oublog'); @@ -136,6 +138,21 @@ public function definition() { $mform->addElement('select', 'restricttags', get_string('restricttags', 'oublog'), $tagopts); $mform->addHelpButton('restricttags', 'restricttags', 'oublog'); + $mform->addElement('header', 'limits', get_string('limits', 'oublog')); + + // Limiting post/comments dates. + $mform->addElement('date_time_selector', 'postfrom', + get_string('postfrom', 'oublog'), array('optional' => true)); + $mform->addElement('date_time_selector', 'postuntil', + get_string('postuntil', 'oublog'), array('optional' => true)); + $mform->addElement('date_time_selector', 'commentfrom', + get_string('commentfrom', 'oublog'), array('optional' => true)); + $mform->addElement('date_time_selector', 'commentuntil', + get_string('commentuntil', 'oublog'), array('optional' => true)); + + $mform->disabledIf('commentfrom', 'allowcomments', 'eq', 0); + $mform->disabledIf('commentuntil', 'allowcomments', 'eq', 0); + $mform->addElement('header', 'modstandardgrade', get_string('grade')); // Adding the "grading" field. $options = array(OUBLOG_NO_GRADING => get_string('nograde', 'oublog'), @@ -239,6 +256,18 @@ public function get_data() { if (empty($data->restricttags)) { $data->restricttags = 0; } + if (empty($data->postfrom)) { + $data->postfrom = 0; + } + if (empty($data->postuntil)) { + $data->postuntil = 0; + } + if (empty($data->commentfrom)) { + $data->commentfrom = 0; + } + if (empty($data->commentuntil)) { + $data->commentuntil = 0; + } return $data; } diff --git a/renderer.php b/renderer.php index b00bbba..1226aa5 100644 --- a/renderer.php +++ b/renderer.php @@ -436,6 +436,21 @@ public function render_post($cm, $oublog, $post, $baseurl, $blogtype, return $output; } + /** + * Returns output for time limit messages + * @param string $stringname + * @param int $time Unix time when restricted + * @param context $capable Used to alter stringname for moderators if true + * @param string $type 'post' or 'comment' - used for div class + * @return string + */ + public function render_time_limit_msg($stringname, $time, $capable = false, $type = 'post') { + $extra = $capable ? 'capable' : ''; + return html_writer::div(get_string($stringname . $extra, 'oublog', + userdate($time, get_string('strftimedatetimeshort', 'langconfig'))), + "oublog_time_limit_msg oublog_time_limit_msg_$type"); + } + /** * Print all user participation records for display * diff --git a/styles.css b/styles.css index ae829e7..56566b6 100644 --- a/styles.css +++ b/styles.css @@ -699,3 +699,9 @@ div.tagselector_result .tagselector_result_info { .oublog-tag-order { margin-bottom: .5em; } + +.oublog_time_limit_msg { + margin-bottom: 0.5em; + padding: 5px; + border: 1px dotted #555; +} diff --git a/tests/behat/time.period.feature b/tests/behat/time.period.feature new file mode 100644 index 0000000..ef0eb1c --- /dev/null +++ b/tests/behat/time.period.feature @@ -0,0 +1,96 @@ +@ou @ou_vle @mod @mod_oublog @oublog_time +Feature: Test time limited posts and comments + In order to limit students posts and comments to time periods + As a teacher + I need to be able to set time limits + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | student1 | Student1 | 1 | student1@asd.com | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | student1 | C1 | student | + And the following "activities" exist: + | activity | name | intro | course | idnumber | postfrom | postuntil | commentfrom | commentuntil | + | oublog | blog post start past | A blog when posts start in past | C1 | oublog1 | 1262307600 | 0 | 1262307600 | 0 | + | oublog | blog post start future | A blog when posts start in future | C1 | oublog2 | 2524611600 | 0 | 2524611600 | 0 | + | oublog | blog post end past | A blog when posts start in past | C1 | oublog3 | 0 | 1262307600 | 0 | 1262307600 | + | oublog | blog post end future | A blog when posts start in future | C1 | oublog4 | 0 | 2524611600 | 0 | 2524611600 | + Given I log in as "admin" + And I follow "Course 1" + And I follow "blog post start future" + And I press "New blog post" + And I set the field "Message" to "Test" + And I press "Add post" + And I follow "Course 1" + And I follow "blog post end past" + And I press "New blog post" + And I set the field "Message" to "Test" + And I press "Add post" + And I log out + + Scenario: Admin tests timed blogs + Given I log in as "admin" + And I follow "Course 1" + # Test blog1. + When I follow "blog post start past" + Then I should not see "Students cannot create their own posts until" + And I should not see "Students cannot comment on posts until" + And "New blog post" "button" should exist + Given I follow "Course 1" + # Test blog2. + When I follow "blog post start future" + Then I should see "Students cannot create their own posts until" + And I should see "Students cannot comment on posts until" + And "New blog post" "button" should exist + And "Add your comment" "link" should exist + Given I follow "Course 1" + # Test blog3. + When I follow "blog post end past" + Then I should see "Students were able to create their own posts until" + And I should see "Students were able to comment on posts until" + And "New blog post" "button" should exist + And "Add your comment" "link" should exist + Given I follow "Course 1" + # Test blog4. + When I follow "blog post end future" + Then I should see "Students are able to create their own posts until" + # Test no comment message as no posts. + And I should not see "Students are able to comment on posts until" + And "New blog post" "button" should exist + Given I log out + + Scenario: Admin tests timed blogs + Given I log in as "student1" + And I follow "Course 1" + # Test blog1. + When I follow "blog post start past" + Then I should not see "You cannot create posts at this time" + And I should not see "You cannot comment on posts at this time" + And "New blog post" "button" should exist + Given I follow "Course 1" + # Test blog2. + When I follow "blog post start future" + Then I should see "You cannot create posts at this time" + And I should see "You cannot comment on posts at this time" + And "New blog post" "button" should not exist + And "Add your comment" "link" should not exist + Given I follow "Course 1" + # Test blog3. + When I follow "blog post end past" + Then I should see "You cannot create posts at this time" + And I should see "You cannot comment on posts at this time" + And "New blog post" "button" should not exist + And "Add your comment" "link" should not exist + Given I follow "Course 1" + # Test blog4. + When I follow "blog post end future" + Then I should see "You can only create posts until" + # Test no comment message as no posts. + And I should not see "You can only comment on posts until" + And "New blog post" "button" should exist + Given I follow "Course 1" diff --git a/tests/locallib_test.php b/tests/locallib_test.php index 09ec119..6a3cb8d 100644 --- a/tests/locallib_test.php +++ b/tests/locallib_test.php @@ -46,6 +46,7 @@ class oublog_locallib_test extends oublog_test_lib { * Getting a single post * Getting a list of posts * Tags + * Time limited posting // TODO: Unit tests do NOT cover: * Personal blog auto creation on install has worked @@ -1516,4 +1517,41 @@ public function test_oublog_tags() { $this->assertContains('blogtag02', end($restrictedtaglist));// Last in restricted list. } + public function test_oublog_time_limits() { + $this->resetAfterTest(); + $course = $this->get_new_course(); + $stud1 = $this->get_new_user('student', $course->id); + + // Future posts + comments start blog. + $oublog = $this->get_new_oublog($course->id, array('postfrom' => 2524611600, 'commentfrom' => 2524611600)); + // Past posts + comments start blog. + $oublog1 = $this->get_new_oublog($course->id, array('postfrom' => 1262307600, 'commentfrom' => 1262307600)); + // Future posts + comments end blog. + $oublog2 = $this->get_new_oublog($course->id, array('postuntil' => 2524611600, 'commentuntil' => 2524611600)); + // Past posts + comments end blog. + $oublog3 = $this->get_new_oublog($course->id, array('postuntil' => 1262307600, 'commentuntil' => 1262307600)); + + $this->setAdminUser(); + $this->assertTrue(oublog_can_post_now($oublog, context_module::instance($oublog->cm->id))); + $this->assertTrue(oublog_can_post_now($oublog1, context_module::instance($oublog1->cm->id))); + $this->assertTrue(oublog_can_post_now($oublog2, context_module::instance($oublog2->cm->id))); + $this->assertTrue(oublog_can_post_now($oublog3, context_module::instance($oublog3->cm->id))); + $post = (object) array('allowcomments' => true, 'visibility' => OUBLOG_VISIBILITY_COURSEUSER); + $this->assertTrue(oublog_can_comment($oublog->cm, $oublog, $post)); + $this->assertTrue(oublog_can_comment($oublog1->cm, $oublog1, $post)); + $this->assertTrue(oublog_can_comment($oublog2->cm, $oublog2, $post)); + $this->assertTrue(oublog_can_comment($oublog3->cm, $oublog3, $post)); + + $this->setUser($stud1); + $this->assertFalse(oublog_can_post_now($oublog, context_module::instance($oublog->cm->id))); + $this->assertTrue(oublog_can_post_now($oublog1, context_module::instance($oublog1->cm->id))); + $this->assertTrue(oublog_can_post_now($oublog2, context_module::instance($oublog2->cm->id))); + $this->assertFalse(oublog_can_post_now($oublog3, context_module::instance($oublog3->cm->id))); + $post = (object) array('allowcomments' => true, 'visibility' => OUBLOG_VISIBILITY_COURSEUSER); + $this->assertFalse(oublog_can_comment($oublog->cm, $oublog, $post)); + $this->assertTrue(oublog_can_comment($oublog1->cm, $oublog1, $post)); + $this->assertTrue(oublog_can_comment($oublog2->cm, $oublog2, $post)); + $this->assertFalse(oublog_can_comment($oublog3->cm, $oublog3, $post)); + } + } diff --git a/version.php b/version.php index dd50794..3db03d6 100644 --- a/version.php +++ b/version.php @@ -23,8 +23,8 @@ * @package oublog **/ -$plugin->version = 2015072200; +$plugin->version = 2015090800; $plugin->requires = 2014111000; $plugin->component = 'mod_oublog';// Full name of the plugin (used for diagnostics) $plugin->maturity = MATURITY_STABLE; -$plugin->release = '2.8 r2'; +$plugin->release = '2.9 r1'; diff --git a/view.php b/view.php index 1ad8b61..cba12c6 100644 --- a/view.php +++ b/view.php @@ -377,15 +377,58 @@ } // Print the main part of the page. -echo '
'; - // New post button - in group blog, you can only post if a group is selected. if ($oublog->individual && $individualdetails) { $showpostbutton = $canpost; } else { $showpostbutton = $canpost && ($currentgroup || !$groupmode ); } -if ($showpostbutton) { + +// If timed blog posts show info. +$capable = has_capability('mod/oublog:ignorepostperiod', + $oublog->global ? context_system::instance() : $context); + +if (($showpostbutton || $capable) && $oublog->postfrom != 0 && $oublog->postfrom > time()) { + echo $oublogoutput->render_time_limit_msg('beforestartpost', $oublog->postfrom, $capable); +} +if (($showpostbutton || $capable) && $oublog->postuntil != 0) { + if ($oublog->postuntil > time()) { + echo $oublogoutput->render_time_limit_msg('beforeendpost', $oublog->postuntil, $capable); + } else { + echo $oublogoutput->render_time_limit_msg('afterendpost', $oublog->postuntil, $capable); + } +} +// If timed comments show info. +if ($posts) { + $maxpost = (object) array('allowcomments' => false, 'visibility' => OUBLOG_VISIBILITY_COURSEUSER); + foreach ($posts as $apost) { + // Work out if any posts on page allow commenting + max visibility. + if ($apost->allowcomments) { + $maxpost->allowcomments = true; + } + if ($apost->visibility > $maxpost->visibility) { + $maxpost->visibility = $apost->visibility; + } + } + if (oublog_can_comment($cm, $oublog, $maxpost, true)) { + $ccapable = has_capability('mod/oublog:ignorecommentperiod', + $oublog->global ? context_system::instance() : $context); + if ($oublog->commentfrom != 0 && $oublog->commentfrom > time()) { + echo $oublogoutput->render_time_limit_msg('beforestartcomment', $oublog->commentfrom, $capable, 'comment'); + } + if ($oublog->commentuntil != 0) { + if ($oublog->commentuntil > time()) { + echo $oublogoutput->render_time_limit_msg('beforeendcomment', $oublog->commentuntil, $capable, 'comment'); + } else { + echo $oublogoutput->render_time_limit_msg('afterendcomment', $oublog->commentuntil, $capable, 'comment'); + } + } + } +} + +echo '
'; + +if ($showpostbutton && oublog_can_post_now($oublog, $context)) { echo '
'; echo $OUTPUT->single_button(new moodle_url('/mod/oublog/editpost.php', array('blog' => $cm->instance)), $straddpost, 'get');