if (empty($formdata->attachment)) {
            // explicit cast to zero integer
            $formdata->attachment = 0;
        }
        // store the updated values or re-save the new example (re-saving needed because URLs are now rewritten)
        $DB->update_record('teamwork_submissions', $formdata);
        redirect($teamwork->exsubmission_url($formdata->id));
    }
}
// Output starts here
echo $output->header();
echo $output->heading(format_string($teamwork->name), 2);
// show instructions for submitting as they may contain some list of questions and we need to know them
// while reading the submitted answer
if (trim($teamwork->instructauthors)) {
    $instructions = file_rewrite_pluginfile_urls($teamwork->instructauthors, 'pluginfile.php', $PAGE->context->id, 'mod_teamwork', 'instructauthors', 0, teamwork::instruction_editors_options($PAGE->context));
    print_collapsible_region_start('', 'teamwork-viewlet-instructauthors', get_string('instructauthors', 'teamwork'));
    echo $output->box(format_text($instructions, $teamwork->instructauthorsformat, array('overflowdiv' => true)), array('generalbox', 'instructions'));
    print_collapsible_region_end();
}
// if in edit mode, display the form to edit the example
if ($edit and $canmanage) {
    $mform->display();
    echo $output->footer();
    die;
}
// else display the example...
if ($example->id) {
    if ($canmanage and $delete) {
        echo $output->confirm(get_string('exampledeleteconfirm', 'teamwork'), new moodle_url($PAGE->url, array('delete' => 1, 'confirm' => 1)), $teamwork->view_url());
    }
Exemple #2
0
 /**
  * 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 teamwork - 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_teamwork', 'instructauthors', 0, teamwork::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_teamwork', 'instructreviewers', 0, teamwork::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_teamwork', 'conclusion', 0, teamwork::instruction_editors_options($this->context), $data['conclusion']);
         $data['conclusioneditor']['format'] = $data['conclusionformat'];
         $data['conclusioneditor']['itemid'] = $draftitemid;
     } else {
         // adding a new teamwork instance
         $draftitemid = file_get_submitted_draft_itemid('instructauthors');
         file_prepare_draft_area($draftitemid, null, 'mod_teamwork', '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_teamwork', '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_teamwork', 'conclusion', 0);
         // no context yet, itemid not used
         $data['conclusioneditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
     }
 }
Exemple #3
0
/**
 * Given an object containing all the necessary data,
 * (defined by the form in mod_form.php) this function
 * will update an existing instance with new data.
 *
 * @param stdClass $teamwork An object from the form in mod_form.php
 * @return bool success
 */
function teamwork_update_instance(stdclass $teamwork)
{
    global $CFG, $DB;
    require_once dirname(__FILE__) . '/locallib.php';
    $teamwork->timemodified = time();
    $teamwork->id = $teamwork->instance;
    $teamwork->useexamples = (int) (!empty($teamwork->useexamples));
    $teamwork->usepeerassessment = 1;
    $teamwork->useselfassessment = (int) (!empty($teamwork->useselfassessment));
    $teamwork->latesubmissions = (int) (!empty($teamwork->latesubmissions));
    $teamwork->phaseswitchassessment = (int) (!empty($teamwork->phaseswitchassessment));
    // todo - if the grading strategy is being changed, we may want to replace all aggregated peer grades with nulls
    $DB->update_record('teamwork', $teamwork);
    $context = context_module::instance($teamwork->coursemodule);
    // process the custom wysiwyg editors
    if ($draftitemid = $teamwork->instructauthorseditor['itemid']) {
        $teamwork->instructauthors = file_save_draft_area_files($draftitemid, $context->id, 'mod_teamwork', 'instructauthors', 0, teamwork::instruction_editors_options($context), $teamwork->instructauthorseditor['text']);
        $teamwork->instructauthorsformat = $teamwork->instructauthorseditor['format'];
    }
    if ($draftitemid = $teamwork->instructreviewerseditor['itemid']) {
        $teamwork->instructreviewers = file_save_draft_area_files($draftitemid, $context->id, 'mod_teamwork', 'instructreviewers', 0, teamwork::instruction_editors_options($context), $teamwork->instructreviewerseditor['text']);
        $teamwork->instructreviewersformat = $teamwork->instructreviewerseditor['format'];
    }
    if ($draftitemid = $teamwork->conclusioneditor['itemid']) {
        $teamwork->conclusion = file_save_draft_area_files($draftitemid, $context->id, 'mod_teamwork', 'conclusion', 0, teamwork::instruction_editors_options($context), $teamwork->conclusioneditor['text']);
        $teamwork->conclusionformat = $teamwork->conclusioneditor['format'];
    }
    // re-save the record with the replaced URLs in editor fields
    $DB->update_record('teamwork', $teamwork);
    // update gradebook items
    teamwork_grade_item_update($teamwork);
    teamwork_grade_item_category_update($teamwork);
    // update calendar events
    teamwork_calendar_update($teamwork, $teamwork->coursemodule);
    return true;
}