+++ /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/>.
-
-/**
- * Workshop development toolkit
- *
- * Provides some tools that may be useful during the workshop development
- * and debugging. This is not intended for productive enviroments.
- *
- * @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__).'/lib.php');
-require_once(dirname(__FILE__).'/locallib.php');
-
-$cmid = required_param('cmid', PARAM_INT); // course module id
-$tool = optional_param('tool', 'menu', PARAM_ALPHA); // toolkit action
-
-//debugging('', DEBUG_DEVELOPER) || die('For development purposes only');
-//has_capability('moodle/site:config', get_system_context()) || die('You are not allowed to run this');
-
-$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); // wrap the record with a full API
-
-require_login($course, false, $cm);
-
-$PAGE->set_url('mod/workshop/develtools.php', array('cmid' => $cm->id));
-$PAGE->set_title($workshop->name);
-$PAGE->set_heading($course->fullname);
-$PAGE->set_button($OUTPUT->update_module_button($cm->id, 'workshop'));
-$PAGE->navbar->add('Development tools');
-
-if ($tool == 'mksubmissions') {
- $authors = $workshop->get_potential_authors(false);
- $authorswithsubmission = $workshop->get_potential_authors(true);
- $authors = array_diff_key($authors, $authorswithsubmission);
- echo $OUTPUT->header();
- $c = 0; // counter
- foreach ($authors as $authorid => $author) {
- $timenow = time() - rand(0, 60 * 60 * 24 * 7); // submitted sometimes during last week
- $submission = new stdClass();
- $submission->workshopid = $workshop->id;
- $submission->example = 0;
- $submission->authorid = $authorid;
- $submission->timecreated = $timenow;
- $submission->timemodified = $timenow;
- $submission->title = $author->firstname . '\'s submission';
- $submission->content = "<p>Pellentesque habitant morbi tristique " .
- "senectus et netus et malesuada fames ac " .
- "turpis egestas. Sed posuere volutpat nunc " .
- "semper ultricies! Aenean elementum metus in " .
- "lorem volutpat eu volutpat neque vulputate? " .
- "Pellentesque sit amet sem leo. In hac " .
- "habitasse platea dictumst. Proin quis " .
- "accumsan elit. Nulla quis libero ac nunc " .
- "elementum commodo at et sem. Vestibulum " .
- "eget euismod felis. Lorem ipsum dolor sit " .
- "amet, consectetur adipiscing elit. Aliquam " .
- "id tellus vel velit aliquet volutpat at " .
- "quis arcu. Nulla laoreet tincidunt sodales. " .
- "Suspendisse potenti. Curabitur sagittis " .
- "arcu nec erat aliquet imperdiet. Aenean at " .
- "mi ut est molestie posuere a vitae mauris.</p>";
-
- $submission->contentformat = FORMAT_HTML;
- $submission->contenttrust = 0;
- $submission->id = $DB->insert_record('workshop_submissions', $submission);
- echo "<pre>Added submission by " . fullname($author) . "</pre>\n";
- $c++;
- }
- if ($c == 0) {
- echo "<pre>No submission added</pre>\n";
- }
- echo $OUTPUT->continue_button($PAGE->url->out());
- echo $OUTPUT->footer();
- exit;
-}
-
-if ($tool == 'mkassessments') {
- $diminfo = $workshop->grading_strategy_instance()->get_dimensions_info();
-
- $sql = 'SELECT a.id
- FROM {workshop_assessments} a
- INNER JOIN {workshop_submissions} s ON (a.submissionid = s.id)
- WHERE s.example = 0 AND s.workshopid = :workshopid';
- $params = array('workshopid' => $workshop->id);
- $assessments = $DB->get_records_sql($sql, $params);
-
- foreach ($assessments as $assessment) {
- foreach ($diminfo as $dimension) {
- if (! $DB->record_exists('workshop_grades', array('assessmentid'=>$assessment->id, 'strategy'=>$workshop->strategy, 'dimensionid'=>$dimension->id))) {
- $grade = new stdClass();
- $grade->assessmentid = $assessment->id;
- $grade->strategy = $workshop->strategy;
- $grade->dimensionid = $dimension->id;
- $grade->grade = rand($dimension->min, $dimension->max);
- $DB->insert_record('workshop_grades', $grade, false, true);
- }
- }
- // to make this script work, make the update_peer_grade() a public method of the strategy class
- $workshop->grading_strategy_instance()->update_peer_grade($assessment);
- }
-
- echo $OUTPUT->header();
- echo $OUTPUT->heading('Submissions graded');
- echo $OUTPUT->continue_button($PAGE->url->out());
- echo $OUTPUT->footer();
- exit;
-}
-
-// no known $tool selected
-echo $OUTPUT->header();
-$currenttab = 'develtools';
-include(dirname(__FILE__) . '/tabs.php');
-echo $OUTPUT->heading('Workshop development tools', 1);
-echo '<ul>';
-echo '<li><a href="' . $PAGE->url->out(false, array('tool' => 'mksubmissions')) . '">Fake submissions</a></li>';
-echo '<li><a href="' . $PAGE->url->out(false, array('tool' => 'mkassessments')) . '">Fake assessments (see the source code of this script)</a></li>';
-echo '</ul>';
-echo $OUTPUT->footer();
--- /dev/null
+<?php
+
+/**
+ * Temporary script to log-in as a random workshop participant - useful for testing
+ */
+
+require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
+require_once(dirname(__FILE__).'/locallib.php');
+
+$cmid = required_param('cmid', PARAM_INT); // course_module ID, or
+
+$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);
+
+require_login($course, true, $cm);
+require_capability('moodle/user:loginas', get_context_instance(CONTEXT_COURSE, $course->id));
+
+$workshop = new workshop($workshop, $cm, $course);
+
+$authors = $workshop->get_potential_authors(false);
+$reviewers = $workshop->get_potential_reviewers(false);
+$participants = array_intersect_key($authors, $reviewers);
+$randomid = array_rand($participants);
+
+redirect("{$CFG->wwwroot}/course/loginas.php?id={$course->id}&user={$randomid}&return=1&sesskey=" . sesskey());