function definition()
 {
     $mform = $this->_form;
     $current = $this->_customdata['current'];
     $workshopplus = $this->_customdata['workshopplus'];
     $editoropts = $this->_customdata['editoropts'];
     $options = $this->_customdata['options'];
     $mform->addElement('header', 'assessmentsettings', get_string('assessmentsettings', 'workshopplus'));
     if (!empty($options['editableweight'])) {
         $mform->addElement('select', 'weight', get_string('assessmentweight', 'workshopplus'), workshopplus::available_assessment_weights_list());
         $mform->setDefault('weight', 1);
     }
     $mform->addElement('static', 'gradinggrade', get_string('gradinggradecalculated', 'workshopplus'));
     if (!empty($options['overridablegradinggrade'])) {
         $grades = array('' => get_string('notoverridden', 'workshopplus'));
         for ($i = (int) $workshopplus->gradinggrade; $i >= 0; $i--) {
             $grades[$i] = $i;
         }
         $mform->addElement('select', 'gradinggradeover', get_string('gradinggradeover', 'workshopplus'), $grades);
         $mform->addElement('editor', 'feedbackreviewer_editor', get_string('feedbackreviewer', 'workshopplus'), null, $editoropts);
         $mform->setType('feedbackreviewer_editor', PARAM_RAW);
     }
     $mform->addElement('hidden', 'asid');
     $mform->setType('asid', PARAM_INT);
     $mform->addElement('submit', 'save', get_string('saveandclose', 'workshopplus'));
     $this->set_data($current);
 }
 /**
  * Define the elements to be displayed at the form
  *
  * Called by the parent::definition()
  *
  * @return void
  */
 protected function definition_inner(&$mform)
 {
     $norepeats = $this->_customdata['norepeats'];
     // number of dimensions to display
     $descriptionopts = $this->_customdata['descriptionopts'];
     // wysiwyg fields options
     $current = $this->_customdata['current'];
     // current data to be set
     $mform->addElement('hidden', 'norepeats', $norepeats);
     $mform->setType('norepeats', PARAM_INT);
     // value not to be overridden by submitted value
     $mform->setConstants(array('norepeats' => $norepeats));
     for ($i = 0; $i < $norepeats; $i++) {
         $mform->addElement('header', 'dimension' . $i, get_string('dimensionnumber', 'workshopplusform_accumulative', $i + 1));
         $mform->addElement('hidden', 'dimensionid__idx_' . $i);
         $mform->setType('dimensionid__idx_' . $i, PARAM_INT);
         $mform->addElement('editor', 'description__idx_' . $i . '_editor', get_string('dimensiondescription', 'workshopplusform_accumulative'), '', $descriptionopts);
         // todo replace modgrade with an advanced element (usability issue discussed with Olli)
         $mform->addElement('modgrade', 'grade__idx_' . $i, get_string('dimensionmaxgrade', 'workshopplusform_accumulative'), null, true);
         $mform->setDefault('grade__idx_' . $i, 10);
         $mform->addElement('select', 'weight__idx_' . $i, get_string('dimensionweight', 'workshopplusform_accumulative'), workshopplus::available_dimension_weights_list());
         $mform->setDefault('weight__idx_' . $i, 1);
     }
     $mform->registerNoSubmitButton('noadddims');
     $mform->addElement('submit', 'noadddims', get_string('addmoredimensions', 'workshopplusform_accumulative', workshopplus_accumulative_strategy::ADDDIMS));
     $mform->closeHeaderBefore('noadddims');
     $this->set_data($current);
 }
 /**
  * Define the elements to be displayed at the form
  *
  * Called by the parent::definition()
  *
  * @return void
  */
 protected function definition_inner(&$mform)
 {
     $plugindefaults = get_config('workshopplusform_numerrors');
     $nodimensions = $this->_customdata['nodimensions'];
     // number of currently filled dimensions
     $norepeats = $this->_customdata['norepeats'];
     // number of dimensions to display
     $descriptionopts = $this->_customdata['descriptionopts'];
     // wysiwyg fields options
     $current = $this->_customdata['current'];
     // current data to be set
     $mform->addElement('hidden', 'norepeats', $norepeats);
     $mform->setType('norepeats', PARAM_INT);
     // value not to be overridden by submitted value
     $mform->setConstants(array('norepeats' => $norepeats));
     for ($i = 0; $i < $norepeats; $i++) {
         $mform->addElement('header', 'dimension' . $i, get_string('dimensionnumber', 'workshopplusform_numerrors', $i + 1));
         $mform->addElement('hidden', 'dimensionid__idx_' . $i);
         // the id in workshopplus_forms
         $mform->setType('dimensionid__idx_' . $i, PARAM_INT);
         $mform->addElement('editor', 'description__idx_' . $i . '_editor', get_string('dimensiondescription', 'workshopplusform_numerrors'), '', $descriptionopts);
         $mform->addElement('text', 'grade0__idx_' . $i, get_string('grade0', 'workshopplusform_numerrors'), array('size' => '15'));
         $mform->setDefault('grade0__idx_' . $i, $plugindefaults->grade0);
         $mform->setType('grade0__idx_' . $i, PARAM_TEXT);
         $mform->addElement('text', 'grade1__idx_' . $i, get_string('grade1', 'workshopplusform_numerrors'), array('size' => '15'));
         $mform->setDefault('grade1__idx_' . $i, $plugindefaults->grade1);
         $mform->setType('grade1__idx_' . $i, PARAM_TEXT);
         $mform->addElement('select', 'weight__idx_' . $i, get_string('dimensionweight', 'workshopplusform_numerrors'), workshopplus::available_dimension_weights_list());
         $mform->setDefault('weight__idx_' . $i, 1);
     }
     $mform->addElement('header', 'mappingheader', get_string('grademapping', 'workshopplusform_numerrors'));
     $mform->addElement('static', 'mappinginfo', get_string('maperror', 'workshopplusform_numerrors'), get_string('mapgrade', 'workshopplusform_numerrors'));
     // get the total weight of all items == maximum weighted number of errors
     $totalweight = 0;
     for ($i = 0; $i < $norepeats; $i++) {
         if (!empty($current->{'weight__idx_' . $i})) {
             $totalweight += $current->{'weight__idx_' . $i};
         }
     }
     $totalweight = max($totalweight, $nodimensions);
     $percents = array();
     $percents[''] = '';
     for ($i = 100; $i >= 0; $i--) {
         $percents[$i] = get_string('percents', 'workshopplusform_numerrors', $i);
     }
     $mform->addElement('static', 'mappingzero', 0, get_string('percents', 'workshopplusform_numerrors', 100));
     for ($i = 1; $i <= $totalweight; $i++) {
         $selects = array();
         $selects[] = $mform->createElement('select', 'map__idx_' . $i, $i, $percents);
         $selects[] = $mform->createElement('static', 'mapdefault__idx_' . $i, '', get_string('percents', 'workshopplusform_numerrors', floor(100 - $i * 100 / $totalweight)));
         $mform->addGroup($selects, 'grademapping' . $i, $i, array(' '), false);
         $mform->setDefault('map__idx_' . $i, '');
     }
     $mform->registerNoSubmitButton('noadddims');
     $mform->addElement('submit', 'noadddims', get_string('addmoredimensions', 'workshopplusform_numerrors', workshopplus_numerrors_strategy::ADDDIMS));
     $mform->closeHeaderBefore('noadddims');
     $this->set_data($current);
 }
 /**
  * Add the fields that are common for all grading strategies.
  *
  * If the strategy does not support all these fields, then you can override
  * this method and remove the ones you don't want with
  * $mform->removeElement().
  * Strategy subclassess should define their own fields in definition_inner()
  *
  * @return void
  */
 public function definition()
 {
     global $CFG;
     $mform = $this->_form;
     $this->mode = $this->_customdata['mode'];
     // influences the save buttons
     $this->strategy = $this->_customdata['strategy'];
     // instance of the strategy api class
     $this->workshopplus = $this->_customdata['workshopplus'];
     // instance of the workshopplus api class
     $this->options = $this->_customdata['options'];
     // array with addiotional options
     // Disable shortforms
     $mform->setDisableShortforms();
     // add the strategy-specific fields
     $this->definition_inner($mform);
     // add the data common for all subplugins
     $mform->addElement('hidden', 'strategy', $this->workshopplus->strategy);
     $mform->setType('strategy', PARAM_PLUGIN);
     if ($this->workshopplus->overallfeedbackmode and $this->is_editable()) {
         $mform->addElement('header', 'overallfeedbacksection', get_string('overallfeedback', 'mod_workshopplus'));
         $mform->addElement('editor', 'feedbackauthor_editor', get_string('feedbackauthor', 'mod_workshopplus'), null, $this->workshopplus->overall_feedback_content_options());
         if ($this->workshopplus->overallfeedbackmode == 2) {
             $mform->addRule('feedbackauthor_editor', null, 'required', null, 'client');
         }
         if ($this->workshopplus->overallfeedbackfiles) {
             $mform->addElement('filemanager', 'feedbackauthorattachment_filemanager', get_string('feedbackauthorattachment', 'mod_workshopplus'), null, $this->workshopplus->overall_feedback_attachment_options());
         }
     }
     if (!empty($this->options['editableweight']) and $this->is_editable()) {
         $mform->addElement('header', 'assessmentsettings', get_string('assessmentweight', 'workshopplus'));
         $mform->addElement('select', 'weight', get_string('assessmentweight', 'workshopplus'), workshopplus::available_assessment_weights_list());
         //set the default weight to 10, by Morteza
         $mform->setDefault('weight', 10);
     }
     $buttonarray = array();
     if ($this->mode == 'preview') {
         $buttonarray[] = $mform->createElement('cancel', 'backtoeditform', get_string('backtoeditform', 'workshopplus'));
     }
     if ($this->mode == 'assessment') {
         if (!empty($this->options['pending'])) {
             $buttonarray[] = $mform->createElement('submit', 'saveandshownext', get_string('saveandshownext', 'workshopplus'));
         }
         $buttonarray[] = $mform->createElement('submit', 'saveandclose', get_string('saveandclose', 'workshopplus'));
         $buttonarray[] = $mform->createElement('submit', 'saveandcontinue', get_string('saveandcontinue', 'workshopplus'));
         $buttonarray[] = $mform->createElement('cancel');
     }
     $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
     $mform->closeHeaderBefore('buttonar');
 }
 /**
  * Triggered when the '\mod_workshopplus\event\course_module_viewed' event is triggered.
  *
  * This does the same job as {@link workshopplusallocation_scheduled_cron()} but for the
  * single workshopplus. The idea is that we do not need to wait for cron to execute.
  * Displaying the workshopplus main view.php can trigger the scheduled allocation, too.
  *
  * @param \mod_workshopplus\event\course_module_viewed $event
  * @return bool
  */
 public static function workshopplus_viewed($event)
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/mod/workshopplus/locallib.php';
     $workshopplus = $event->get_record_snapshot('workshopplus', $event->objectid);
     $course = $event->get_record_snapshot('course', $event->courseid);
     $cm = $event->get_record_snapshot('course_modules', $event->contextinstanceid);
     $workshopplus = new \workshopplus($workshopplus, $cm, $course);
     $now = time();
     // Non-expensive check to see if the scheduled allocation can even happen.
     if ($workshopplus->phase == \workshopplus::PHASE_SUBMISSION and $workshopplus->submissionend > 0 and $workshopplus->submissionend < $now) {
         // Make sure the scheduled allocation has been configured for this workshopplus, that it has not
         // been executed yet and that the passed workshopplus record is still valid.
         $sql = "SELECT a.id\n                      FROM {workshopplusallocation_sch} a\n                      JOIN {workshopplus} w ON a.workshopplusid = w.id\n                     WHERE w.id = :workshopplusid\n                           AND a.enabled = 1\n                           AND w.phase = :phase\n                           AND w.submissionend > 0\n                           AND w.submissionend < :now\n                           AND (a.timeallocated IS NULL OR a.timeallocated < w.submissionend)";
         $params = array('workshopplusid' => $workshopplus->id, 'phase' => \workshopplus::PHASE_SUBMISSION, 'now' => $now);
         if ($DB->record_exists_sql($sql, $params)) {
             // Allocate submissions for assessments.
             $allocator = $workshopplus->allocator_instance('scheduled');
             $result = $allocator->execute();
             // Todo inform the teachers about the results.
         }
     }
     return true;
 }
 * @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';
$asid = required_param('asid', PARAM_INT);
// assessment id
$assessment = $DB->get_record('workshopplus_assessments', array('id' => $asid), '*', MUST_EXIST);
$submission = $DB->get_record('workshopplus_submissions', array('id' => $assessment->submissionid, 'example' => 0), '*', MUST_EXIST);
$workshopplus = $DB->get_record('workshopplus', array('id' => $submission->workshopplusid), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $workshopplus->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('workshopplus', $workshopplus->id, $course->id, false, MUST_EXIST);
require_login($course, false, $cm);
if (isguestuser()) {
    print_error('guestsarenotallowed');
}
$workshopplus = new workshopplus($workshopplus, $cm, $course);
$PAGE->set_url($workshopplus->assess_url($assessment->id));
$PAGE->set_title($workshopplus->name);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add(get_string('assessingsubmission', 'workshopplus'));
$canviewallassessments = has_capability('mod/workshopplus:viewallassessments', $workshopplus->context);
$canviewallsubmissions = has_capability('mod/workshopplus:viewallsubmissions', $workshopplus->context);
$cansetassessmentweight = has_capability('mod/workshopplus:allocate', $workshopplus->context);
$canoverridegrades = has_capability('mod/workshopplus:overridegrades', $workshopplus->context);
$isreviewer = $USER->id == $assessment->reviewerid;
$isauthor = $USER->id == $submission->authorid;
if ($canviewallsubmissions) {
    // check this flag against the group membership yet
    if (groups_get_activity_groupmode($workshopplus->cm) == SEPARATEGROUPS) {
        // user must have accessallgroups or share at least one group with the submission author
        if (!has_capability('moodle/site:accessallgroups', $workshopplus->context)) {
 /**
  * Returns example submissions to be assessed by the owner of the planner
  *
  * This is here to cache the DB query because the same list is needed later in view.php
  *
  * @see workshopplus::get_examples_for_reviewer() for the format of returned value
  * @return array
  */
 public function get_examples()
 {
     if (is_null($this->examples)) {
         $this->examples = $this->workshopplus->get_examples_for_reviewer($this->userid);
     }
     return $this->examples;
 }
 /**
  * Prepares the form before data are set
  *
  * Additional wysiwyg editor are prepared here, the introeditor is prepared automatically by core.
  * Grade items are set here because the core modedit supports single grade item only.
  *
  * @param array $data to be set
  * @return void
  */
 public function data_preprocessing(&$data)
 {
     if ($this->current->instance) {
         // editing an existing workshopplus - let us prepare the added editor elements (intro done automatically)
         $draftitemid = file_get_submitted_draft_itemid('instructauthors');
         $data['instructauthorseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_workshopplus', 'instructauthors', 0, workshopplus::instruction_editors_options($this->context), $data['instructauthors']);
         $data['instructauthorseditor']['format'] = $data['instructauthorsformat'];
         $data['instructauthorseditor']['itemid'] = $draftitemid;
         $draftitemid = file_get_submitted_draft_itemid('instructreviewers');
         $data['instructreviewerseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_workshopplus', 'instructreviewers', 0, workshopplus::instruction_editors_options($this->context), $data['instructreviewers']);
         $data['instructreviewerseditor']['format'] = $data['instructreviewersformat'];
         $data['instructreviewerseditor']['itemid'] = $draftitemid;
         $draftitemid = file_get_submitted_draft_itemid('conclusion');
         $data['conclusioneditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_workshopplus', 'conclusion', 0, workshopplus::instruction_editors_options($this->context), $data['conclusion']);
         $data['conclusioneditor']['format'] = $data['conclusionformat'];
         $data['conclusioneditor']['itemid'] = $draftitemid;
     } else {
         // adding a new workshopplus instance
         $draftitemid = file_get_submitted_draft_itemid('instructauthors');
         file_prepare_draft_area($draftitemid, null, 'mod_workshopplus', 'instructauthors', 0);
         // no context yet, itemid not used
         $data['instructauthorseditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
         $draftitemid = file_get_submitted_draft_itemid('instructreviewers');
         file_prepare_draft_area($draftitemid, null, 'mod_workshopplus', 'instructreviewers', 0);
         // no context yet, itemid not used
         $data['instructreviewerseditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
         $draftitemid = file_get_submitted_draft_itemid('conclusion');
         file_prepare_draft_area($draftitemid, null, 'mod_workshopplus', 'conclusion', 0);
         // no context yet, itemid not used
         $data['conclusioneditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
     }
 }
 * @package    mod
 * @subpackage workshopplus
 * @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';
require_once dirname(__FILE__) . '/allocation/lib.php';
$cmid = required_param('cmid', PARAM_INT);
// course module
$method = optional_param('method', 'manual', PARAM_ALPHA);
// method to use
$cm = get_coursemodule_from_id('workshopplus', $cmid, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$workshopplus = $DB->get_record('workshopplus', array('id' => $cm->instance), '*', MUST_EXIST);
$workshopplus = new workshopplus($workshopplus, $cm, $course);
$PAGE->set_url($workshopplus->allocation_url($method));
require_login($course, false, $cm);
$context = $PAGE->context;
require_capability('mod/workshopplus:allocate', $context);
$PAGE->set_title($workshopplus->name);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add(get_string('allocation', 'workshopplus'));
$allocator = $workshopplus->allocator_instance($method);
$initresult = $allocator->init();
//
// Output starts here
//
$output = $PAGE->get_renderer('mod_workshopplus');
echo $output->header();
echo $OUTPUT->heading(format_string($workshopplus->name));
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
require_once dirname(__FILE__) . '/locallib.php';
$cmid = required_param('cmid', PARAM_INT);
// course module id
$sid = required_param('sid', PARAM_INT);
// example submission id
$aid = required_param('aid', PARAM_INT);
// the user's assessment id
$cm = get_coursemodule_from_id('workshopplus', $cmid, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
require_login($course, false, $cm);
if (isguestuser()) {
    print_error('guestsarenotallowed');
}
$workshopplus = $DB->get_record('workshopplus', array('id' => $cm->instance), '*', MUST_EXIST);
$workshopplus = new workshopplus($workshopplus, $cm, $course);
$strategy = $workshopplus->grading_strategy_instance();
$PAGE->set_url($workshopplus->excompare_url($sid, $aid));
$example = $workshopplus->get_example_by_id($sid);
$assessment = $workshopplus->get_assessment_by_id($aid);
if ($assessment->submissionid != $example->id) {
    print_error('invalidarguments');
}
$mformassessment = $strategy->get_assessment_form($PAGE->url, 'assessment', $assessment, false);
if ($refasid = $DB->get_field('workshopplus_assessments', 'id', array('submissionid' => $example->id, 'weight' => 1))) {
    $reference = $workshopplus->get_assessment_by_id($refasid);
    $mformreference = $strategy->get_assessment_form($PAGE->url, 'assessment', $reference, false);
}
$canmanage = has_capability('mod/workshopplus:manageexamples', $workshopplus->context);
$isreviewer = $USER->id == $assessment->reviewerid;
if ($canmanage) {
 /**
  * Renders the workshopplus grading report
  *
  * @param workshopplus_grading_report $gradingreport
  * @return string html code
  */
 protected function render_workshopplus_grading_report(workshopplus_grading_report $gradingreport)
 {
     $data = $gradingreport->get_data();
     $options = $gradingreport->get_options();
     $grades = $data->grades;
     $userinfo = $data->userinfo;
     if (empty($grades)) {
         return '';
     }
     $table = new html_table();
     $table->attributes['class'] = 'grading-report';
     $sortbyfirstname = $this->helper_sortable_heading(get_string('firstname'), 'firstname', $options->sortby, $options->sorthow);
     $sortbylastname = $this->helper_sortable_heading(get_string('lastname'), 'lastname', $options->sortby, $options->sorthow);
     if (self::fullname_format() == 'lf') {
         $sortbyname = $sortbylastname . ' / ' . $sortbyfirstname;
     } else {
         $sortbyname = $sortbyfirstname . ' / ' . $sortbylastname;
     }
     $table->head = array();
     $table->head[] = $sortbyname;
     $table->head[] = $this->helper_sortable_heading(get_string('submission', 'workshopplus'), 'submissiontitle', $options->sortby, $options->sorthow);
     $table->head[] = $this->helper_sortable_heading(get_string('receivedgrades', 'workshopplus'));
     if ($options->showsubmissiongrade) {
         $table->head[] = $this->helper_sortable_heading(get_string('submissiongradeof', 'workshopplus', $data->maxgrade), 'submissiongrade', $options->sortby, $options->sorthow);
     }
     $table->head[] = $this->helper_sortable_heading(get_string('givengrades', 'workshopplus'));
     if ($options->showgradinggrade) {
         $table->head[] = $this->helper_sortable_heading(get_string('gradinggradeof', 'workshopplus', $data->maxgradinggrade), 'gradinggrade', $options->sortby, $options->sorthow);
     }
     $table->rowclasses = array();
     $table->colclasses = array();
     $table->data = array();
     foreach ($grades as $participant) {
         $numofreceived = count($participant->reviewedby);
         $numofgiven = count($participant->reviewerof);
         $published = $participant->submissionpublished;
         // compute the number of <tr> table rows needed to display this participant
         if ($numofreceived > 0 and $numofgiven > 0) {
             $numoftrs = workshopplus::lcm($numofreceived, $numofgiven);
             $spanreceived = $numoftrs / $numofreceived;
             $spangiven = $numoftrs / $numofgiven;
         } elseif ($numofreceived == 0 and $numofgiven > 0) {
             $numoftrs = $numofgiven;
             $spanreceived = $numoftrs;
             $spangiven = $numoftrs / $numofgiven;
         } elseif ($numofreceived > 0 and $numofgiven == 0) {
             $numoftrs = $numofreceived;
             $spanreceived = $numoftrs / $numofreceived;
             $spangiven = $numoftrs;
         } else {
             $numoftrs = 1;
             $spanreceived = 1;
             $spangiven = 1;
         }
         for ($tr = 0; $tr < $numoftrs; $tr++) {
             $row = new html_table_row();
             if ($published) {
                 $row->attributes['class'] = 'published';
             }
             // column #1 - participant - spans over all rows
             if ($tr == 0) {
                 $cell = new html_table_cell();
                 $cell->text = $this->helper_grading_report_participant($participant, $userinfo);
                 $cell->rowspan = $numoftrs;
                 $cell->attributes['class'] = 'participant';
                 $row->cells[] = $cell;
             }
             // column #2 - submission - spans over all rows
             if ($tr == 0) {
                 $cell = new html_table_cell();
                 $cell->text = $this->helper_grading_report_submission($participant);
                 $cell->rowspan = $numoftrs;
                 $cell->attributes['class'] = 'submission';
                 $row->cells[] = $cell;
             }
             // column #3 - received grades
             if ($tr % $spanreceived == 0) {
                 $idx = intval($tr / $spanreceived);
                 $assessment = self::array_nth($participant->reviewedby, $idx);
                 $cell = new html_table_cell();
                 $cell->text = $this->helper_grading_report_assessment($assessment, $options->showreviewernames, $userinfo, get_string('gradereceivedfrom', 'workshopplus'));
                 $cell->rowspan = $spanreceived;
                 $cell->attributes['class'] = 'receivedgrade';
                 if (is_null($assessment) or is_null($assessment->grade)) {
                     $cell->attributes['class'] .= ' null';
                 } else {
                     $cell->attributes['class'] .= ' notnull';
                 }
                 $row->cells[] = $cell;
             }
             // column #4 - total grade for submission
             if ($options->showsubmissiongrade and $tr == 0) {
                 $cell = new html_table_cell();
                 $cell->text = $this->helper_grading_report_grade($participant->submissiongrade, $participant->submissiongradeover);
                 $cell->rowspan = $numoftrs;
                 $cell->attributes['class'] = 'submissiongrade';
                 $row->cells[] = $cell;
             }
             // column #5 - given grades
             if ($tr % $spangiven == 0) {
                 $idx = intval($tr / $spangiven);
                 $assessment = self::array_nth($participant->reviewerof, $idx);
                 $cell = new html_table_cell();
                 $cell->text = $this->helper_grading_report_assessment($assessment, $options->showauthornames, $userinfo, get_string('gradegivento', 'workshopplus'));
                 $cell->rowspan = $spangiven;
                 $cell->attributes['class'] = 'givengrade';
                 if (is_null($assessment) or is_null($assessment->grade)) {
                     $cell->attributes['class'] .= ' null';
                 } else {
                     $cell->attributes['class'] .= ' notnull';
                 }
                 $row->cells[] = $cell;
             }
             // column #6 - total grade for assessment
             if ($options->showgradinggrade and $tr == 0) {
                 $cell = new html_table_cell();
                 $cell->text = $this->helper_grading_report_grade($participant->gradinggrade);
                 $cell->rowspan = $numoftrs;
                 $cell->attributes['class'] = 'gradinggrade';
                 $row->cells[] = $cell;
             }
             $table->data[] = $row;
         }
     }
     return html_writer::table($table);
 }
$cmid = required_param('cmid', PARAM_INT);
// course module id
$id = optional_param('id', 0, PARAM_INT);
// submission id
$edit = optional_param('edit', false, PARAM_BOOL);
// open for editing?
$assess = optional_param('assess', false, PARAM_BOOL);
// instant assessment required
$cm = get_coursemodule_from_id('workshopplus', $cmid, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
require_login($course, false, $cm);
if (isguestuser()) {
    print_error('guestsarenotallowed');
}
$workshopplus = $DB->get_record('workshopplus', array('id' => $cm->instance), '*', MUST_EXIST);
$workshopplus = new workshopplus($workshopplus, $cm, $course);
$PAGE->set_url($workshopplus->submission_url(), array('cmid' => $cmid, 'id' => $id));
if ($edit) {
    $PAGE->url->param('edit', $edit);
}
if ($id) {
    // submission is specified
    $submission = $workshopplus->get_submission_by_id($id);
    $workshopplus->log('view submission', $workshopplus->submission_url($submission->id), $submission->id);
} else {
    // no submission specified
    if (!($submission = $workshopplus->get_submission_by_author($USER->id))) {
        $submission = new stdclass();
        $submission->id = null;
        $submission->authorid = $USER->id;
        $submission->example = 0;
 * Edit grading form in for a particular instance of workshopplus
 *
 * @package    mod
 * @subpackage workshopplus
 * @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);
$cm = get_coursemodule_from_id('workshopplus', $cmid, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
require_login($course, false, $cm);
require_capability('mod/workshopplus:editdimensions', $PAGE->context);
$workshopplus = $DB->get_record('workshopplus', array('id' => $cm->instance), '*', MUST_EXIST);
$workshopplus = new workshopplus($workshopplus, $cm, $course);
// todo: check if there already is some assessment done and do not allowed the change of the form
// once somebody already used it to assess
$PAGE->set_url($workshopplus->editform_url());
$PAGE->set_title($workshopplus->name);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add(get_string('editingassessmentform', 'workshopplus'));
// load the grading strategy logic
$strategy = $workshopplus->grading_strategy_instance();
// load the form to edit the grading strategy dimensions
$mform = $strategy->get_edit_strategy_form($PAGE->url);
if ($mform->is_cancelled()) {
    redirect($workshopplus->view_url());
} elseif ($data = $mform->get_data()) {
    if ($data->workshopplusid != $workshopplus->id or $data->strategy != $workshopplus->strategy) {
        // this may happen if someone changes the workshopplus setting while the user had the
 * @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';
$asid = required_param('asid', PARAM_INT);
// assessment id
$assessment = $DB->get_record('workshopplus_assessments', array('id' => $asid), '*', MUST_EXIST);
$example = $DB->get_record('workshopplus_submissions', array('id' => $assessment->submissionid, 'example' => 1), '*', MUST_EXIST);
$workshopplus = $DB->get_record('workshopplus', array('id' => $example->workshopplusid), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $workshopplus->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('workshopplus', $workshopplus->id, $course->id, false, MUST_EXIST);
require_login($course, false, $cm);
if (isguestuser()) {
    print_error('guestsarenotallowed');
}
$workshopplus = new workshopplus($workshopplus, $cm, $course);
$PAGE->set_url($workshopplus->exassess_url($assessment->id));
$PAGE->set_title($workshopplus->name);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add(get_string('assessingexample', 'workshopplus'));
$currenttab = 'assessment';
$canmanage = has_capability('mod/workshopplus:manageexamples', $workshopplus->context);
$isreviewer = $USER->id == $assessment->reviewerid;
if ($isreviewer or $canmanage) {
    // such a user can continue
} else {
    print_error('nopermissions', 'error', $workshopplus->view_url(), 'assess example submission');
}
// only the reviewer is allowed to modify the assessment
if ($canmanage and $assessment->weight == 1 or $isreviewer and $workshopplus->assessing_examples_allowed()) {
    $assessmenteditable = true;
 * @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
$confirm = optional_param('confirm', false, PARAM_BOOL);
// confirmation
// the params to be re-passed to view.php
$page = optional_param('page', 0, PARAM_INT);
$sortby = optional_param('sortby', 'lastname', PARAM_ALPHA);
$sorthow = optional_param('sorthow', 'ASC', PARAM_ALPHA);
$cm = get_coursemodule_from_id('workshopplus', $cmid, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$workshopplus = $DB->get_record('workshopplus', array('id' => $cm->instance), '*', MUST_EXIST);
$workshopplus = new workshopplus($workshopplus, $cm, $course);
$PAGE->set_url($workshopplus->aggregate_url(), compact('confirm', 'page', 'sortby', 'sorthow'));
require_login($course, false, $cm);
require_capability('mod/workshopplus:overridegrades', $PAGE->context);
// load and init the grading evaluator
$evaluator = $workshopplus->grading_evaluation_instance();
$settingsform = $evaluator->get_settings_form($PAGE->url);
if ($settingsdata = $settingsform->get_data()) {
    $workshopplus->aggregate_submission_grades();
    // updates 'grade' in {workshopplus_submissions}
    $evaluator->update_grading_grades($settingsdata);
    // updates 'gradinggrade' in {workshopplus_assessments}
    $workshopplus->aggregate_grading_grades();
    // updates 'gradinggrade' in {workshopplus_aggregations}
    $workshopplus->log('update aggregate grades');
}
                 $buttontext = get_string('assess', 'workshopplus');
             } else {
                 $class = ' graded';
                 $submission->status = 'graded';
                 $buttontext = get_string('reassess', 'workshopplus');
             }
             echo $output->box_start('generalbox assessment-summary' . $class);
             echo $output->render($workshopplus->prepare_submission_summary($submission, $shownames));
             echo $output->box_end();
         }
         print_collapsible_region_end();
     }
     break;
 case workshopplus::PHASE_CLOSED:
     if (trim($workshopplus->conclusion)) {
         $conclusion = file_rewrite_pluginfile_urls($workshopplus->conclusion, 'pluginfile.php', $workshopplus->context->id, 'mod_workshopplus', 'conclusion', 0, workshopplus::instruction_editors_options($workshopplus->context));
         print_collapsible_region_start('', 'workshopplus-viewlet-conclusion', get_string('conclusion', 'workshopplus'));
         echo $output->box(format_text($conclusion, $workshopplus->conclusionformat, array('overflowdiv' => true)), array('generalbox', 'conclusion'));
         print_collapsible_region_end();
     }
     $finalgrades = $workshopplus->get_gradebook_grades($USER->id);
     if (!empty($finalgrades)) {
         print_collapsible_region_start('', 'workshopplus-viewlet-yourgrades', get_string('yourgrades', 'workshopplus'));
         echo $output->box_start('generalbox grades-yourgrades');
         echo $output->render($finalgrades);
         echo $output->box_end();
         print_collapsible_region_end();
     }
     if (has_capability('mod/workshopplus:viewallassessments', $PAGE->context)) {
         $perpage = get_user_preferences('workshopplus_perpage', 10);
         $groupid = groups_get_activity_group($workshopplus->cm, true);
$edit = optional_param('edit', false, PARAM_BOOL);
// open for editing?
$delete = optional_param('delete', false, PARAM_BOOL);
// example removal requested
$confirm = optional_param('confirm', false, PARAM_BOOL);
// example removal request confirmed
$assess = optional_param('assess', false, PARAM_BOOL);
// assessment required
$cm = get_coursemodule_from_id('workshopplus', $cmid, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
require_login($course, false, $cm);
if (isguestuser()) {
    print_error('guestsarenotallowed');
}
$workshopplus = $DB->get_record('workshopplus', array('id' => $cm->instance), '*', MUST_EXIST);
$workshopplus = new workshopplus($workshopplus, $cm, $course);
$PAGE->set_url($workshopplus->exsubmission_url($id), array('edit' => $edit));
$PAGE->set_title($workshopplus->name);
$PAGE->set_heading($course->fullname);
if ($edit) {
    $PAGE->navbar->add(get_string('exampleediting', 'workshopplus'));
} else {
    $PAGE->navbar->add(get_string('example', 'workshopplus'));
}
$output = $PAGE->get_renderer('mod_workshopplus');
if ($id) {
    // example is specified
    $example = $workshopplus->get_example_by_id($id);
    $workshopplus->log('view example', $workshopplus->exsubmission_url($example->id), $example->id);
} else {
    // no example specified - create new one
 * @subpackage workshopplus
 * @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 phase
$confirm = optional_param('confirm', false, PARAM_BOOL);
// confirmation
$cm = get_coursemodule_from_id('workshopplus', $cmid, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$workshopplus = $DB->get_record('workshopplus', array('id' => $cm->instance), '*', MUST_EXIST);
$workshopplus = new workshopplus($workshopplus, $cm, $course);
$PAGE->set_url($workshopplus->switchphase_url($phase), array('cmid' => $cmid, 'phase' => $phase));
require_login($course, false, $cm);
require_capability('mod/workshopplus:switchphase', $PAGE->context);
if ($confirm) {
    if (!confirm_sesskey()) {
        throw new moodle_exception('confirmsesskeybad');
    }
    if (!$workshopplus->switch_phase($phase)) {
        print_error('errorswitchingphase', 'workshopplus', $workshopplus->view_url());
    }
    $workshopplus->log('update switch phase', $workshopplus->view_url(), $workshopplus->phase);
    redirect($workshopplus->view_url());
}
$PAGE->set_title($workshopplus->name);
$PAGE->set_heading($course->fullname);
 require_once $CFG->dirroot . '/mod/workshopplus/locallib.php';
 $grades = workshopplus::available_maxgrades_list();
 $settings->add(new admin_setting_configselect('workshopplus/grade', get_string('submissiongrade', 'workshopplus'), get_string('configgrade', 'workshopplus'), 80, $grades));
 $settings->add(new admin_setting_configselect('workshopplus/gradinggrade', get_string('gradinggrade', 'workshopplus'), get_string('configgradinggrade', 'workshopplus'), 20, $grades));
 $options = array();
 for ($i = 5; $i >= 0; $i--) {
     $options[$i] = $i;
 }
 $settings->add(new admin_setting_configselect('workshopplus/gradedecimals', get_string('gradedecimals', 'workshopplus'), get_string('configgradedecimals', 'workshopplus'), 0, $options));
 if (isset($CFG->maxbytes)) {
     $maxbytes = get_config('workshopplus', 'maxbytes');
     $options = get_max_upload_sizes($CFG->maxbytes, 0, 0, $maxbytes);
     $settings->add(new admin_setting_configselect('workshopplus/maxbytes', get_string('maxbytes', 'workshopplus'), get_string('configmaxbytes', 'workshopplus'), 0, $options));
 }
 $settings->add(new admin_setting_configselect('workshopplus/strategy', get_string('strategy', 'workshopplus'), get_string('configstrategy', 'workshopplus'), 'accumulative', workshopplus::available_strategies_list()));
 $options = workshopplus::available_example_modes_list();
 $settings->add(new admin_setting_configselect('workshopplus/examplesmode', get_string('examplesmode', 'workshopplus'), get_string('configexamplesmode', 'workshopplus'), workshopplus::EXAMPLES_VOLUNTARY, $options));
 // include the settings of allocation subplugins
 $allocators = core_component::get_plugin_list('workshopplusallocation');
 foreach ($allocators as $allocator => $path) {
     if (file_exists($settingsfile = $path . '/settings.php')) {
         $settings->add(new admin_setting_heading('workshopplusallocationsetting' . $allocator, get_string('allocation', 'workshopplus') . ' - ' . get_string('pluginname', 'workshopplusallocation_' . $allocator), ''));
         include $settingsfile;
     }
 }
 // include the settings of grading strategy subplugins
 $strategies = core_component::get_plugin_list('workshopplusform');
 foreach ($strategies as $strategy => $path) {
     if (file_exists($settingsfile = $path . '/settings.php')) {
         $settings->add(new admin_setting_heading('workshopplusformsetting' . $strategy, get_string('strategy', 'workshopplus') . ' - ' . get_string('pluginname', 'workshopplusform_' . $strategy), ''));
         include $settingsfile;
 public function aggregate_grading_grades_process(array $assessments, $timegraded = null)
 {
     parent::aggregate_grading_grades_process($assessments, $timegraded);
 }
 /**
  * Definition of the setting form elements
  */
 public function definition()
 {
     global $OUTPUT;
     $mform = $this->_form;
     $workshopplus = $this->_customdata['workshopplus'];
     $current = $this->_customdata['current'];
     if (!empty($workshopplus->submissionend)) {
         $strtimeexpected = workshopplus::timestamp_formats($workshopplus->submissionend);
     }
     if (!empty($current->timeallocated)) {
         $strtimeexecuted = workshopplus::timestamp_formats($current->timeallocated);
     }
     $mform->addElement('header', 'scheduledallocationsettings', get_string('scheduledallocationsettings', 'workshopplusallocation_scheduled'));
     $mform->addHelpButton('scheduledallocationsettings', 'scheduledallocationsettings', 'workshopplusallocation_scheduled');
     $mform->addElement('checkbox', 'enablescheduled', get_string('enablescheduled', 'workshopplusallocation_scheduled'), get_string('enablescheduledinfo', 'workshopplusallocation_scheduled'), 1);
     $mform->addElement('header', 'scheduledallocationinfo', get_string('currentstatus', 'workshopplusallocation_scheduled'));
     if ($current === false) {
         $mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'workshopplusallocation_scheduled'), get_string('resultdisabled', 'workshopplusallocation_scheduled') . ' ' . html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/invalid'))));
     } else {
         if (!empty($current->timeallocated)) {
             $mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'workshopplusallocation_scheduled'), get_string('currentstatusexecution1', 'workshopplusallocation_scheduled', $strtimeexecuted) . ' ' . html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/valid'))));
             if ($current->resultstatus == workshopplus_allocation_result::STATUS_EXECUTED) {
                 $strstatus = get_string('resultexecuted', 'workshopplusallocation_scheduled') . ' ' . html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/valid')));
             } else {
                 if ($current->resultstatus == workshopplus_allocation_result::STATUS_FAILED) {
                     $strstatus = get_string('resultfailed', 'workshopplusallocation_scheduled') . ' ' . html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/invalid')));
                 } else {
                     $strstatus = get_string('resultvoid', 'workshopplusallocation_scheduled') . ' ' . html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/invalid')));
                 }
             }
             if (!empty($current->resultmessage)) {
                 $strstatus .= html_writer::empty_tag('br') . $current->resultmessage;
                 // yes, this is ugly. better solution suggestions are welcome.
             }
             $mform->addElement('static', 'inforesult', get_string('currentstatusresult', 'workshopplusallocation_scheduled'), $strstatus);
             if ($current->timeallocated < $workshopplus->submissionend) {
                 $mform->addElement('static', 'infoexpected', get_string('currentstatusnext', 'workshopplusallocation_scheduled'), get_string('currentstatusexecution2', 'workshopplusallocation_scheduled', $strtimeexpected) . ' ' . html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/caution'))));
                 $mform->addHelpButton('infoexpected', 'currentstatusnext', 'workshopplusallocation_scheduled');
             } else {
                 $mform->addElement('checkbox', 'reenablescheduled', get_string('currentstatusreset', 'workshopplusallocation_scheduled'), get_string('currentstatusresetinfo', 'workshopplusallocation_scheduled'));
                 $mform->addHelpButton('reenablescheduled', 'currentstatusreset', 'workshopplusallocation_scheduled');
             }
         } else {
             if (empty($current->enabled)) {
                 $mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'workshopplusallocation_scheduled'), get_string('resultdisabled', 'workshopplusallocation_scheduled') . ' ' . html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/invalid'))));
             } else {
                 if ($workshopplus->phase != workshopplus::PHASE_SUBMISSION) {
                     $mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'workshopplusallocation_scheduled'), get_string('resultfailed', 'workshopplusallocation_scheduled') . ' ' . html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/invalid'))) . html_writer::empty_tag('br') . get_string('resultfailedphase', 'workshopplusallocation_scheduled'));
                 } else {
                     if (empty($workshopplus->submissionend)) {
                         $mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'workshopplusallocation_scheduled'), get_string('resultfailed', 'workshopplusallocation_scheduled') . ' ' . html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/invalid'))) . html_writer::empty_tag('br') . get_string('resultfaileddeadline', 'workshopplusallocation_scheduled'));
                     } else {
                         if ($workshopplus->submissionend < time()) {
                             // next cron will execute it
                             $mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'workshopplusallocation_scheduled'), get_string('currentstatusexecution4', 'workshopplusallocation_scheduled') . ' ' . html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/caution'))));
                         } else {
                             $mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'workshopplusallocation_scheduled'), get_string('currentstatusexecution3', 'workshopplusallocation_scheduled', $strtimeexpected) . ' ' . html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/caution'))));
                         }
                     }
                 }
             }
         }
     }
     parent::definition();
     $mform->addHelpButton('randomallocationsettings', 'randomallocationsettings', 'workshopplusallocation_scheduled');
 }
/**
 * Regular jobs to execute via cron
 */
function workshopplusallocation_scheduled_cron()
{
    global $CFG, $DB;
    $sql = "SELECT w.*\n              FROM {workshopplusallocation_sch} a\n              JOIN {workshopplus} w ON a.workshopplusid = w.id\n             WHERE a.enabled = 1\n                   AND w.phase = 20\n                   AND w.submissionend > 0\n                   AND w.submissionend < ?\n                   AND (a.timeallocated IS NULL OR a.timeallocated < w.submissionend)";
    $workshoppluss = $DB->get_records_sql($sql, array(time()));
    if (empty($workshoppluss)) {
        mtrace('... no workshoppluss awaiting scheduled allocation. ', '');
        return;
    }
    mtrace('... executing scheduled allocation in ' . count($workshoppluss) . ' workshopplus(s) ... ', '');
    // let's have some fun!
    require_once $CFG->dirroot . '/mod/workshopplus/locallib.php';
    foreach ($workshoppluss as $workshopplus) {
        $cm = get_coursemodule_from_instance('workshopplus', $workshopplus->id, $workshopplus->course, false, MUST_EXIST);
        $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
        $workshopplus = new workshopplus($workshopplus, $cm, $course);
        $allocator = $workshopplus->allocator_instance('scheduled');
        $result = $allocator->execute();
        // todo inform the teachers about the results
    }
}
/**
 * Regular jobs to execute via cron
 *
 * @return boolean true on success, false otherwise
 */
function workshopplus_cron()
{
    global $CFG, $DB;
    $now = time();
    mtrace(' processing workshopplus subplugins ...');
    cron_execute_plugin_type('workshopplusallocation', 'workshopplus allocation methods');
    // now when the scheduled allocator had a chance to do its job, check if there
    // are some workshoppluss to switch into the assessment phase
    $workshoppluss = $DB->get_records_select("workshopplus", "phase = 20 AND phaseswitchassessment = 1 AND submissionend > 0 AND submissionend < ?", array($now));
    if (!empty($workshoppluss)) {
        mtrace('Processing automatic assessment phase switch in ' . count($workshoppluss) . ' workshopplus(s) ... ', '');
        require_once $CFG->dirroot . '/mod/workshopplus/locallib.php';
        foreach ($workshoppluss as $workshopplus) {
            $cm = get_coursemodule_from_instance('workshopplus', $workshopplus->id, $workshopplus->course, false, MUST_EXIST);
            $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
            $workshopplus = new workshopplus($workshopplus, $cm, $course);
            $workshopplus->switch_phase(workshopplus::PHASE_ASSESSMENT);
            $workshopplus->log('update switch phase', $workshopplus->view_url(), $workshopplus->phase);
            // disable the automatic switching now so that it is not executed again by accident
            // if the teacher changes the phase back to the submission one
            $DB->set_field('workshopplus', 'phaseswitchassessment', 0, array('id' => $workshopplus->id));
            // todo inform the teachers
        }
        mtrace('done');
    }
    return true;
}
 *
 * @package    mod
 * @subpackage workshopplus
 * @copyright  2010 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';
$id = required_param('id', PARAM_INT);
// course_module ID
$tool = required_param('tool', PARAM_ALPHA);
$cm = get_coursemodule_from_id('workshopplus', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$workshopplus = $DB->get_record('workshopplus', array('id' => $cm->instance), '*', MUST_EXIST);
require_login($course, false, $cm);
$workshopplus = new workshopplus($workshopplus, $cm, $course);
require_sesskey();
switch ($tool) {
    case 'clearaggregatedgrades':
        require_capability('mod/workshopplus:overridegrades', $workshopplus->context);
        $workshopplus->log('update clear aggregated grades');
        $workshopplus->clear_submission_grades();
        $workshopplus->clear_grading_grades();
        break;
    case 'clearassessments':
        require_capability('mod/workshopplus:overridegrades', $workshopplus->context);
        $workshopplus->log('update clear assessments');
        $workshopplus->clear_assessments();
        break;
}
redirect($workshopplus->view_url());
require_once dirname(__FILE__) . '/allocation/lib.php';
//require_once(dirname(__FILE__).'/mapping_students_ta_form.php');
//require_once(dirname(__FILE__).'/mapping_students_list_ta_form.php');
//
//// List of required moodle form classes
//require_once(dirname(__FILE__).'/mapping_ta_students_list_of_tas_form.php');
//require_once(dirname(__FILE__).'/mapping_ta_students_list_of_students_for_ta_form.php');
//require_once(dirname(__FILE__).'/mapping_ta_students_list_of_unassigned_students_form.php');
$cmid = required_param('cmid', PARAM_INT);
// course module
$method = optional_param('method', 'manual', PARAM_ALPHA);
// method to use
$cm = get_coursemodule_from_id('workshopplus', $cmid, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$workshopplus = $DB->get_record('workshopplus', array('id' => $cm->instance), '*', MUST_EXIST);
$workshopplus = new workshopplus($workshopplus, $cm, $course);
global $PAGE, $DB;
$PAGE->set_url($workshopplus->allocation_url($method));
require_login($course, false, $cm);
$context = $PAGE->context;
require_capability('mod/workshopplus:allocate', $context);
$PAGE->set_title($workshopplus->name);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add('Map students to TAs');
$allocator = $workshopplus->allocator_instance($method);
$initresult = $allocator->init();
//
// Output starts here
//
$output = $PAGE->get_renderer('mod_workshopplus');
echo $output->header();
 * @package    mod
 * @subpackage workshopplus
 * @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);
$cm = get_coursemodule_from_id('workshopplus', $cmid, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$workshopplus = $DB->get_record('workshopplus', array('id' => $cm->instance), '*', MUST_EXIST);
require_login($course, false, $cm);
if (isguestuser()) {
    print_error('guestsarenotallowed');
}
$workshopplus = new workshopplus($workshopplus, $cm, $course);
require_capability('mod/workshopplus:editdimensions', $workshopplus->context);
$PAGE->set_url($workshopplus->previewform_url());
$PAGE->set_title($workshopplus->name);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add(get_string('editingassessmentform', 'workshopplus'), $workshopplus->editform_url(), navigation_node::TYPE_CUSTOM);
$PAGE->navbar->add(get_string('previewassessmentform', 'workshopplus'));
$currenttab = 'editform';
// load the grading strategy logic
$strategy = $workshopplus->grading_strategy_instance();
// load the assessment form
$mform = $strategy->get_assessment_form($workshopplus->editform_url(), 'preview');
// output starts here
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($workshopplus->name));
echo $OUTPUT->heading(get_string('assessmentform', 'workshopplus'), 3);