defined('MOODLE_INTERNAL') || die();
+$string[''] = '';
+$string[''] = '';
+$string[''] = '';
+$string[''] = '';
+$string[''] = '';
+$string[''] = '';
$string[''] = '';
$string[''] = '';
$string[''] = '';
$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';
* @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);
}
/**
- * @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;
}
/**
- * @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;
}
/**
- * @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;
/**
* @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;
}
/**
- * @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
*
$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');
}
$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
} else {
$phase->active = false;
}
+ if (!isset($phase->actions)) {
+ $phase->actions = array();
+ }
foreach ($phase->tasks as $taskcode => $task) {
$task->title = isset($task->title) ? $task->title : '';
$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;
}
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;
+ }
}
$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';
--- /dev/null
+<?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();
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