]> git.mjollnir.org Git - moodle.git/commitdiff
Phases can be switched from the Workshop plan tool
authorDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 18:01:29 +0000 (18:01 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 18:01:29 +0000 (18:01 +0000)
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
mod/workshop/lib.php
mod/workshop/locallib.php
mod/workshop/renderer.php
mod/workshop/switchphase.php [new file with mode: 0644]
mod/workshop/view.php

index d6a7cadb306c79dc4f39b0f4a205601a30950858..70cdaf44848fe7a87528ce713ab70dfcc240d145 100644 (file)
 
 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 <strong>Setup phase</strong>. (TODO: explain what the participants and moderators will do in the new phase)';
+$string['switchphase20info'] = 'You are going to switch the Workshop into the <strong>Submission phase</strong>. (TODO: explain what the participants and moderators will do in the new phase)';
+$string['switchphase30info'] = 'You are going to switch the Workshop into the <strong>Assessment phase</strong>. (TODO: explain what the participants and moderators will do in the new phase)';
+$string['switchphase40info'] = 'You are going to switch the Workshop into the <strong>Grading evaluation phase</strong>. (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<br />pending: $a->todo';
 $string['taskassessself'] = 'Assess yourself';
index 016f254a090a317c074e40f923e95cce7d8c375c..c212f371020395e2f4ca714cfd155fa21003ab7c 100644 (file)
@@ -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);
index 80f7d8cedada949b1ae183a47473fbe0d5db4abf..bed1b6a995d65c98131bec4d5329ea6740f084d3 100644 (file)
@@ -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;
+    }
 }
index 305967d0ca30380caf46eea4a6ba88fe2d8b5abe..b18486e83076140217dae6ba22313bbe5c891eb2 100644 (file)
@@ -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 (file)
index 0000000..199b055
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Change the current phase of the workshop
+ *
+ * @package   mod-workshop
+ * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
+ * @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();
index 2fbdcddd5fbbae8ab1e703900115cf565986c197..337c3155ef6f04051b4fc0e4967f8ba39fefb446 100644 (file)
@@ -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