From 454e8dd965b17a49bdb3bdfd4dcc297c37c5d51d Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Mon, 4 Jan 2010 18:01:29 +0000 Subject: [PATCH] Phases can be switched from the Workshop plan tool There may be more conditions checks written in the future and the explanation added on what can be expected to happen after the phase switch. --- mod/workshop/lang/en_utf8/workshop.php | 13 ++++ mod/workshop/lib.php | 6 +- mod/workshop/locallib.php | 91 +++++++++++++++++++++----- mod/workshop/renderer.php | 18 ++++- mod/workshop/switchphase.php | 63 ++++++++++++++++++ mod/workshop/view.php | 4 -- 6 files changed, 171 insertions(+), 24 deletions(-) create mode 100644 mod/workshop/switchphase.php diff --git a/mod/workshop/lang/en_utf8/workshop.php b/mod/workshop/lang/en_utf8/workshop.php index d6a7cadb30..70cdaf4484 100644 --- a/mod/workshop/lang/en_utf8/workshop.php +++ b/mod/workshop/lang/en_utf8/workshop.php @@ -25,6 +25,12 @@ defined('MOODLE_INTERNAL') || die(); +$string[''] = ''; +$string[''] = ''; +$string[''] = ''; +$string[''] = ''; +$string[''] = ''; +$string[''] = ''; $string[''] = ''; $string[''] = ''; $string[''] = ''; @@ -124,6 +130,13 @@ $string['submissionsettings'] = 'Submission settings'; $string['submissionstart'] = 'Start of submission phase'; $string['submission'] = 'Submission'; $string['submissiontitle'] = 'Title'; +$string['switchingphase'] = 'Switching phase'; +$string['switchphase'] = 'Switch phase'; +$string['switchphase10info'] = 'You are going to switch the Workshop into the Setup phase. (TODO: explain what the participants and moderators will do in the new phase)'; +$string['switchphase20info'] = 'You are going to switch the Workshop into the Submission phase. (TODO: explain what the participants and moderators will do in the new phase)'; +$string['switchphase30info'] = 'You are going to switch the Workshop into the Assessment phase. (TODO: explain what the participants and moderators will do in the new phase)'; +$string['switchphase40info'] = 'You are going to switch the Workshop into the Grading evaluation phase. (TODO: explain what the participants and moderators will do in the new phase)'; +$string['switchphase50info'] = 'You are going to close the Workshop. (TODO: explain what the participants and moderators will do in the new phase)'; $string['taskassesspeers'] = 'Assess peers'; $string['taskassesspeersdetails'] = 'total: $a->total
pending: $a->todo'; $string['taskassessself'] = 'Assess yourself'; diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php index 016f254a09..c212f37102 100644 --- a/mod/workshop/lib.php +++ b/mod/workshop/lib.php @@ -82,9 +82,11 @@ function workshop_supports($feature) { * @return int The id of the newly inserted workshop record */ function workshop_add_instance($data) { - global $DB; + global $CFG, $DB; + require_once(dirname(__FILE__) . '/locallib.php'); - $data->timecreated = time(); + $data->phase = workshop::PHASE_SETUP; + $data->timecreated = time(); $data->timemodified = $data->timecreated; return $DB->insert_record('workshop', $data); diff --git a/mod/workshop/locallib.php b/mod/workshop/locallib.php index 80f7d8ceda..bed1b6a995 100644 --- a/mod/workshop/locallib.php +++ b/mod/workshop/locallib.php @@ -563,7 +563,7 @@ class workshop { } /** - * @return stdClass {@link moodle_url} the URL of this workshop's view page + * @return moodle_url of this workshop's view page */ public function view_url() { global $CFG; @@ -571,7 +571,7 @@ class workshop { } /** - * @return stdClass {@link moodle_url} the URL of the page for editing this workshop's grading form + * @return moodle_url of the page for editing this workshop's grading form */ public function editform_url() { global $CFG; @@ -579,7 +579,7 @@ class workshop { } /** - * @return stdClass {@link moodle_url} the URL of the page for previewing this workshop's grading form + * @return moodle_url of the page for previewing this workshop's grading form */ public function previewform_url() { global $CFG; @@ -588,15 +588,16 @@ class workshop { /** * @param int $assessmentid The ID of assessment record - * @return stdClass {@link moodle_url} the URL of the assessment page + * @return moodle_url of the assessment page */ public function assess_url($assessmentid) { global $CFG; + $assessmentid = clean_param($assessmentid, PARAM_INT); return new moodle_url($CFG->wwwroot . '/mod/workshop/assessment.php', array('asid' => $assessmentid)); } /** - * @return stdClass {@link moodle_url} the URL of the page to view own submission + * @return moodle_url of the page to view own submission */ public function submission_url() { global $CFG; @@ -604,18 +605,31 @@ class workshop { } /** - * @return stdClass {@link moodle_url} the URL of the mod_edit form + * @return moodle_url of the mod_edit form */ public function updatemod_url() { global $CFG; return new moodle_url($CFG->wwwroot . '/course/modedit.php', array('update' => $this->cm->id, 'return' => 1)); } + /** + * @return moodle_url to the allocation page + */ public function allocation_url() { global $CFG; return new moodle_url($CFG->wwwroot . '/mod/workshop/allocation.php', array('cmid' => $this->cm->id)); } + /** + * @param int $phasecode The internal phase code + * @return moodle_url of the script to change the current phase to $phasecode + */ + public function switchphase_url($phasecode) { + global $CFG; + $phasecode = clean_param($phasecode, PARAM_INT); + return new moodle_url($CFG->wwwroot . '/mod/workshop/switchphase.php', array('cmid' => $this->cm->id, 'phase' => $phasecode)); + } + /** * Returns an object containing all data to display the user's full name and picture * @@ -674,6 +688,13 @@ class workshop { $task->completed = !(trim(strip_tags($this->intro)) == ''); $phase->tasks['intro'] = $task; } + if (has_capability('moodle/course:manageactivities', $this->context, $userid)) { + $task = new stdClass(); + $task->title = get_string('taskinstructauthors', 'workshop'); + $task->link = $this->updatemod_url(); + $task->completed = !(trim(strip_tags($this->instructauthors)) == ''); + $phase->tasks['instructauthors'] = $task; + } if (has_capability('mod/workshop:editdimensions', $this->context, $userid)) { $task = new stdClass(); $task->title = get_string('editassessmentform', 'workshop'); @@ -685,17 +706,6 @@ class workshop { } $phase->tasks['editform'] = $task; } - if (has_capability('moodle/course:manageactivities', $this->context, $userid)) { - $task = new stdClass(); - $task->title = get_string('taskinstructauthors', 'workshop'); - $task->link = $this->updatemod_url(); - if (trim(strip_tags($this->instructauthors))) { - $task->completed = true; - } elseif ($this->phase >= self::PHASE_SUBMISSION) { - $task->completed = false; - } - $phase->tasks['instructauthors'] = $task; - } if (empty($phase->tasks) and $this->phase == self::PHASE_SETUP) { // if we are in the setup phase and there is no task (typical for students), let us // display some explanation what is going on @@ -841,6 +851,9 @@ class workshop { } else { $phase->active = false; } + if (!isset($phase->actions)) { + $phase->actions = array(); + } foreach ($phase->tasks as $taskcode => $task) { $task->title = isset($task->title) ? $task->title : ''; @@ -849,6 +862,19 @@ class workshop { $task->completed = isset($task->completed) ? $task->completed : null; } } + + // Add phase swithing actions + if (has_capability('mod/workshop:switchphase', $this->context, $userid)) { + foreach ($phases as $phasecode => $phase) { + if (! $phase->active) { + $action = new stdClass(); + $action->type = 'switchphase'; + $action->url = $this->switchphase_url($phasecode); + $phase->actions[] = $action; + } + } + } + return $phases; } @@ -861,4 +887,35 @@ class workshop { return $this->grading_strategy_instance()->form_ready(); } + /** + * @return array of available workshop phases + */ + protected function available_phases() { + return array( + self::PHASE_SETUP => true, + self::PHASE_SUBMISSION => true, + self::PHASE_ASSESSMENT => true, + self::PHASE_EVALUATION => true, + self::PHASE_CLOSED => true, + ); + } + + /** + * Switch to a new workshop phase + * + * Modifies the underlying database record. You should terminate the script shortly after calling this. + * + * @param int $newphase new phase code + * @return bool true if success, false otherwise + */ + public function switch_phase($newphase) { + global $DB; + + $known = $this->available_phases(); + if (!isset($known[$newphase])) { + return false; + } + $DB->set_field('workshop', 'phase', $newphase, array('id' => $this->id)); + return true; + } } diff --git a/mod/workshop/renderer.php b/mod/workshop/renderer.php index 305967d0ca..b18486e830 100644 --- a/mod/workshop/renderer.php +++ b/mod/workshop/renderer.php @@ -258,7 +258,23 @@ class moodle_mod_workshop_renderer extends moodle_renderer_base { $row = new html_table_row(); $row->set_classes('phasetasks'); foreach ($plan as $phasecode => $phase) { - $table->head[] = $this->output->container($this->output->output_tag('span', array(), $phase->title)); + $title = $this->output->output_tag('span', array(), $phase->title); + $actions = ''; + foreach ($phase->actions as $action) { + switch ($action->type) { + case 'switchphase': + $icon = new moodle_action_icon(); + $icon->image->src = $this->old_icon_url('i/marker'); + $icon->image->alt = get_string('switchphase', 'workshop'); + $icon->link->url = $action->url; + $actions .= $this->output->action_icon($icon); + break; + } + } + if (!empty($actions)) { + $actions = $this->output->container($actions, 'actions'); + } + $table->head[] = $this->output->container($title . $actions); $classes = 'phase' . $phasecode; if ($phase->active) { $classes .= ' active'; diff --git a/mod/workshop/switchphase.php b/mod/workshop/switchphase.php new file mode 100644 index 0000000000..199b05545f --- /dev/null +++ b/mod/workshop/switchphase.php @@ -0,0 +1,63 @@ +. + +/** + * Change the current phase of the workshop + * + * @package mod-workshop + * @copyright 2009 David Mudrak + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); +require_once(dirname(__FILE__).'/locallib.php'); + +$cmid = required_param('cmid', PARAM_INT); // course module +$phase = required_param('phase', PARAM_INT); // the code of the new page +$confirm = optional_param('confirm', false, PARAM_BOOL); // confirmation + +$PAGE->set_url('mod/workshop/switchphase.php', array('cmid' => $cmid, 'phase' => $phase)); + +$cm = get_coursemodule_from_id('workshop', $cmid, 0, false, MUST_EXIST); +$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); +$workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST); +$workshop = new workshop($workshop, $cm, $course); + +require_login($course, false, $cm); +require_capability('mod/workshop:switchphase', $PAGE->context); + +if ($confirm) { + if (!confirm_sesskey()) { + throw new moodle_exception('confirmsesskeybad'); + } + if (!$workshop->switch_phase($phase)) { + print_error('errorswitchingphase', 'workshop', $workshop->view_url()); + } + redirect($workshop->view_url()); +} + +$PAGE->set_title($workshop->name); +$PAGE->set_heading($course->fullname); +$PAGE->navbar->add(get_string('switchingphase', 'workshop')); + +// +// Output starts here +// +echo $OUTPUT->header(); +echo $OUTPUT->confirm(get_string('switchphase' . $phase . 'info', 'workshop'), + new moodle_url($PAGE->url, array('confirm' => 1)), $workshop->view_url()); +echo $OUTPUT->footer(); diff --git a/mod/workshop/view.php b/mod/workshop/view.php index 2fbdcddd5f..337c3155ef 100644 --- a/mod/workshop/view.php +++ b/mod/workshop/view.php @@ -75,13 +75,9 @@ $wsoutput = $PAGE->theme->get_renderer('mod_workshop', $PAGE); echo $OUTPUT->header(); include(dirname(__FILE__) . '/tabs.php'); - echo $OUTPUT->heading(format_string($workshop->name)); - -$workshop->phase = 10; // todo xxx devel hack echo $wsoutput->user_plan($workshop->prepare_user_plan($USER->id)); - switch ($workshop->phase) { case workshop::PHASE_SETUP: // print workshop name and description -- 2.39.5