From: moodler Date: Thu, 1 Jul 2004 12:52:15 +0000 (+0000) Subject: Added new feature to restrict time for this activity. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=d30772b256a9e410b0ec8bb548a5f9873adb7045;p=moodle.git Added new feature to restrict time for this activity. Cleaned up logic by adding a separate menu for publishing vs privacy. --- diff --git a/mod/choice/lib.php b/mod/choice/lib.php index 6b7554ffaa..e867d5512f 100644 --- a/mod/choice/lib.php +++ b/mod/choice/lib.php @@ -15,10 +15,10 @@ define("CHOICE_RELEASE_ALWAYS", "3"); $CHOICE_PUBLISH = array (CHOICE_PUBLISH_ANONYMOUS => get_string("publishanonymous", "choice"), CHOICE_PUBLISH_NAMES => get_string("publishnames", "choice")); -$CHOICE_RELEASE = array (CHOICE_RELEASE_NOT => get_string("releasenot", "choice"), - CHOICE_RELEASE_AFTER_ANSWER => get_string("releaseafteranswer", "choice"), - CHOICE_RELEASE_AFTER_CLOSE => get_string("releaseafterclose", "choice"), - CHOICE_RELEASE_ALWAYS => get_string("releasealways", "choice")); +$CHOICE_RELEASE = array (CHOICE_RELEASE_NOT => get_string("publishnot", "choice"), + CHOICE_RELEASE_AFTER_ANSWER => get_string("publishafteranswer", "choice"), + CHOICE_RELEASE_AFTER_CLOSE => get_string("publishafterclose", "choice"), + CHOICE_RELEASE_ALWAYS => get_string("publishalways", "choice")); /// Standard functions ///////////////////////////////////////////////////////// @@ -52,6 +52,16 @@ function choice_add_instance($choice) { $choice->timemodified = time(); + if ($choice->timerestrict) { + $choice->timeopen = make_timestamp($choice->openyear, $choice->openmonth, $choice->openday, + $choice->openhour, $choice->openminute, 0); + $choice->timeclose = make_timestamp($choice->closeyear, $choice->closemonth, $choice->closeday, + $choice->closehour, $choice->closeminute, 0); + } else { + $choice->timeopen = 0; + $choice->timeclose = 0; + } + return insert_record("choice", $choice); } @@ -64,6 +74,19 @@ function choice_update_instance($choice) { $choice->id = $choice->instance; $choice->timemodified = time(); + + if ($choice->timerestrict) { + $choice->timeopen = make_timestamp($choice->openyear, $choice->openmonth, $choice->openday, + $choice->openhour, $choice->openminute, 0); + $choice->timeclose = make_timestamp($choice->closeyear, $choice->closemonth, $choice->closeday, + $choice->closehour, $choice->closeminute, 0); + } else { + $choice->timeopen = 0; + $choice->timeclose = 0; + } + +// global $db; $db->debug=true; + return update_record("choice", $choice); } diff --git a/mod/choice/mod.html b/mod/choice/mod.html index 64c5c32cdc..f69d662eb0 100644 --- a/mod/choice/mod.html +++ b/mod/choice/mod.html @@ -26,9 +26,24 @@ if (empty($form->answer6)) { $form->answer6 = ""; } + if (empty($form->timeopen)) { + $form->timeopen = ""; + $form->timerestrict = 0; + } else { + $form->timerestrict = 1; + } + if (empty($form->timeclose)) { + $form->timeclose = ""; + } if (empty($form->publish)) { $form->publish = 0; } + if (empty($form->release)) { + $form->release = 0; + } + if (empty($form->allowupdate)) { + $form->allowupdate = 0; + } if (empty($form->showunanswered)) { $form->showunanswered = 0; } @@ -127,16 +142,113 @@ + + +

:

+ + + + timerestrict) echo "checked"; ?> > + + + + +

 

+ + + + + + + + + + + +

:

+ + timeopen and $course->format == "weeks") { + $form->timeopen = $course->startdate + (($form->section - 1) * 608400); + } + print_date_selector("openday", "openmonth", "openyear", $form->timeopen); + print_time_selector("openhour", "openminute", $form->timeopen); + ?> + + + + + + +

:

+ + timeclose and $course->format == "weeks") { + $form->timeclose = $course->startdate + (($form->section) * 608400); + } + print_date_selector("closeday", "closemonth", "closeyear", $form->timeclose); + print_time_selector("closehour", "closeminute", $form->timeclose); + ?> + + + + + + + + timerestrict) { + echo "\n"; + } + ?> + +
+ + + +

:

dirroot/mod/choice/lib.php"); + require_once("$CFG->dirroot/mod/choice/lib.php"); + choose_from_menu($CHOICE_RELEASE, "release", "$form->release", ""); + ?> +
+ + + + +

:

+ + dirroot/mod/choice/lib.php"); choose_from_menu($CHOICE_PUBLISH, "publish", "$form->publish", ""); ?>
+ + + +

:

+ + allowupdate", ""); + ?> +
+ + + +

:

diff --git a/mod/choice/view.php b/mod/choice/view.php index 05c92e05e2..1d4b8dc49e 100644 --- a/mod/choice/view.php +++ b/mod/choice/view.php @@ -52,7 +52,7 @@ add_to_log($course->id, "choice", "choose", "view.php?id=$cm->id", $choice->id, $cm->id); } } - redirect("$CFG->wwwroot/course/view.php?id=$course->id"); + redirect("view.php?id=$cm->id"); exit; } @@ -88,9 +88,20 @@ notice(get_string("activityiscurrentlyhidden")); } - print_simple_box( text_to_html($choice->text) , "center"); + print_simple_box( format_text($choice->text) , "center"); - if (!$current or !$choice->publish) { // They haven't made their choice yet + + // print the form + + if ($choice->timeopen > time() ) { + print_simple_box(get_string("notopenyet", "choice", userdate($choice->timeopen)), "center"); + print_footer(); + exit; + } + + if ( (!$current or $choice->allowupdate) and ($choice->timeclose >= time() or $choice->timeclose == 0) ) { + // They haven't made their choice yet or updates allowed and choice is open + echo "

"; echo ""; @@ -105,13 +116,21 @@ echo "
"; echo "id\">"; - if (!isguest()) { + if (isstudent($course->id) or isteacher($course->id, 0, false)) { echo ""; } echo "

"; - } else { // Print results. + } + + + // print the results + + if ( $choice->release == CHOICE_RELEASE_ALWAYS or + ( $choice->release == CHOICE_RELEASE_AFTER_ANSWER and $current ) or + ( $choice->release == CHOICE_RELEASE_AFTER_CLOSE and $choice->timeclose <= time() ) ) { + print_heading(get_string("responses", "choice")); if ($currentgroup) {