예제 #1
0
 /**
  *
  */
 public function update_content($entry, array $values = null, $savenew = false)
 {
     global $DB;
     $entryid = $entry->id;
     $fieldid = $this->id;
     $contentid = isset($entry->{"c{$fieldid}_id"}) ? $entry->{"c{$fieldid}_id"} : null;
     // Delete if old content but not new.
     if ($contentid and empty($values)) {
         return $this->delete_content($entry->id);
     }
     $rec = new stdClass();
     $rec->fieldid = $fieldid;
     $rec->entryid = $entryid;
     if (!($rec->id = $contentid) or $savenew) {
         $rec->id = $DB->insert_record('dataform_contents', $rec);
     }
     if ($this->is_editor()) {
         // Editor content.
         $data = (object) $values;
         $data->{'editor_editor'} = $data->editor;
         $data = file_postupdate_standard_editor($data, 'editor', $this->editoroptions, $this->df->context, 'mod_dataform', 'content', $rec->id);
         $rec->content = $data->editor;
         $rec->content1 = $data->{'editorformat'};
     } else {
         // Text area content.
         $value = reset($values);
         if (is_array($value)) {
             // Import: One value as array of text,format,trust, so take the text.
             $value = reset($value);
         }
         $rec->content = clean_param($value, PARAM_NOTAGS);
     }
     return $DB->update_record('dataform_contents', $rec);
 }
예제 #2
0
 public function update($properties, $context = null, $maxbytes = null)
 {
     global $DB, $PAGE;
     $properties->id = $this->properties->id;
     $properties->lessonid = $this->lesson->id;
     if (empty($properties->qoption)) {
         $properties->qoption = '0';
     }
     $properties->timemodified = time();
     $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $PAGE->course->maxbytes), context_module::instance($PAGE->cm->id), 'mod_lesson', 'page_contents', $properties->id);
     $DB->update_record("lesson_pages", $properties);
     $answers = $this->get_answers();
     if (count($answers) > 1) {
         $answer = array_shift($answers);
         foreach ($answers as $a) {
             $DB->delete_record('lesson_answers', array('id' => $a->id));
         }
     } else {
         if (count($answers) == 1) {
             $answer = array_shift($answers);
         } else {
             $answer = new stdClass();
         }
     }
     $answer->timemodified = time();
     if (isset($properties->jumpto[0])) {
         $answer->jumpto = $properties->jumpto[0];
     }
     if (isset($properties->score[0])) {
         $answer->score = $properties->score[0];
     }
     if (!empty($answer->id)) {
         $DB->update_record("lesson_answers", $answer->properties());
     } else {
         $DB->insert_record("lesson_answers", $answer);
     }
     return true;
 }
예제 #3
0
     if (isset($usernew->email) and $user->email != $usernew->email && !has_capability('moodle/user:update', $systemcontext)) {
         $a = new stdClass();
         $a->newemail = $usernew->preference_newemail = $usernew->email;
         $usernew->preference_newemailkey = random_string(20);
         $usernew->preference_newemailattemptsleft = 3;
         $a->oldemail = $usernew->email = $user->email;
         $emailchangedhtml = $OUTPUT->box(get_string('auth_changingemailaddress', 'auth', $a), 'generalbox', 'notice');
         $emailchangedhtml .= $OUTPUT->continue_button($returnurl);
         $emailchanged = true;
     }
 }
 $authplugin = get_auth_plugin($user->auth);
 $usernew->timemodified = time();
 // Description editor element may not exist!
 if (isset($usernew->description_editor) && isset($usernew->description_editor['format'])) {
     $usernew = file_postupdate_standard_editor($usernew, 'description', $editoroptions, $personalcontext, 'user', 'profile', 0);
 }
 // Pass a true old $user here.
 if (!$authplugin->user_update($user, $usernew)) {
     // Auth update failed.
     print_error('cannotupdateprofile');
 }
 // Update user with new profile data.
 user_update_user($usernew, false, false);
 // Update preferences.
 useredit_update_user_preference($usernew);
 // Update interests.
 if (isset($usernew->interests)) {
     useredit_update_interests($usernew, $usernew->interests);
 }
 // Update user picture.
예제 #4
0
파일: locallib.php 프로젝트: nfreear/moodle
 /**
  * Updates this entry in the database. Access control checks must be done by calling code.
  *
  * @param mform $form Used for attachments
  * @return void
  */
 public function edit($params = array(), $form = null, $summaryoptions = array(), $attachmentoptions = array())
 {
     global $CFG, $USER, $DB, $PAGE;
     $sitecontext = get_context_instance(CONTEXT_SYSTEM);
     $entry = $this;
     $this->form = $form;
     foreach ($params as $var => $val) {
         $entry->{$var} = $val;
     }
     $entry = file_postupdate_standard_editor($entry, 'summary', $summaryoptions, $sitecontext, 'blog', 'post', $entry->id);
     $entry = file_postupdate_standard_filemanager($entry, 'attachment', $attachmentoptions, $sitecontext, 'blog', 'attachment', $entry->id);
     if (!empty($CFG->useblogassociations)) {
         $entry->add_associations();
     }
     $entry->lastmodified = time();
     // Update record
     $DB->update_record('post', $entry);
     tag_set('post', $entry->id, $entry->tags);
     add_to_log(SITEID, 'blog', 'update', 'index.php?userid=' . $USER->id . '&entryid=' . $entry->id, $entry->subject);
 }
예제 #5
0
파일: lib.php 프로젝트: nuckey/moodle
    public function get_data() {
        $data = parent::get_data();

        if (!empty($this->_customdata->submission->id)) {
            $itemid = $this->_customdata->submission->id;
        } else {
            $itemid = null; //TODO: this is wrong, itemid MUST be known when saving files!! (skodak)
        }

        if ($data) {
            $editoroptions = $this->get_editor_options();
            switch ($this->_customdata->assignment->assignmenttype) {
                case 'upload' :
                case 'uploadsingle' :
                    $data = file_postupdate_standard_filemanager($data, 'files', $editoroptions, $this->_customdata->context, 'mod_assignment', 'response', $itemid);
                    break;
                default :
                    break;
            }
            $data = file_postupdate_standard_editor($data, 'submissioncomment', $editoroptions, $this->_customdata->context, $editoroptions['component'], $editoroptions['filearea'], $itemid);
        }
        return $data;
    }
예제 #6
0
 /**
  * Updates a lesson page and its answers within the database
  *
  * @param object $properties
  * @return bool
  */
 public function update($properties, $context = null, $maxbytes = null)
 {
     global $DB, $PAGE;
     $answers = $this->get_answers();
     $properties->id = $this->properties->id;
     $properties->lessonid = $this->lesson->id;
     if (empty($properties->qoption)) {
         $properties->qoption = '0';
     }
     if (empty($context)) {
         $context = $PAGE->context;
     }
     if ($maxbytes === null) {
         $maxbytes = get_user_max_upload_file_size($context);
     }
     $properties->timemodified = time();
     $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $maxbytes), $context, 'mod_lesson', 'page_contents', $properties->id);
     $DB->update_record("lesson_pages", $properties);
     for ($i = 0; $i < $this->lesson->maxanswers; $i++) {
         if (!array_key_exists($i, $this->answers)) {
             $this->answers[$i] = new stdClass();
             $this->answers[$i]->lessonid = $this->lesson->id;
             $this->answers[$i]->pageid = $this->id;
             $this->answers[$i]->timecreated = $this->timecreated;
         }
         if (!empty($properties->answer_editor[$i]) && is_array($properties->answer_editor[$i])) {
             $this->answers[$i]->answer = $properties->answer_editor[$i]['text'];
             $this->answers[$i]->answerformat = $properties->answer_editor[$i]['format'];
         }
         if (!empty($properties->response_editor[$i]) && is_array($properties->response_editor[$i])) {
             $this->answers[$i]->response = $properties->response_editor[$i]['text'];
             $this->answers[$i]->responseformat = $properties->response_editor[$i]['format'];
         }
         // we don't need to check for isset here because properties called it's own isset method.
         if ($this->answers[$i]->answer != '') {
             if (isset($properties->jumpto[$i])) {
                 $this->answers[$i]->jumpto = $properties->jumpto[$i];
             }
             if ($this->lesson->custom && isset($properties->score[$i])) {
                 $this->answers[$i]->score = $properties->score[$i];
             }
             if (!isset($this->answers[$i]->id)) {
                 $this->answers[$i]->id = $DB->insert_record("lesson_answers", $this->answers[$i]);
             } else {
                 $DB->update_record("lesson_answers", $this->answers[$i]->properties());
             }
             // Save files in answers and responses.
             $this->save_answers_files($context, $maxbytes, $this->answers[$i], $properties->answer_editor[$i], $properties->response_editor[$i]);
         } else {
             if (isset($this->answers[$i]->id)) {
                 $DB->delete_records('lesson_answers', array('id' => $this->answers[$i]->id));
                 unset($this->answers[$i]);
             }
         }
     }
     return true;
 }
예제 #7
0
    } else {
        if (is_null($assessment->grade)) {
            $workshop->log('add example assessment', $workshop->exassess_url($assessment->id), $assessment->submissionid);
        } else {
            $workshop->log('update example assessment', $workshop->exassess_url($assessment->id), $assessment->submissionid);
        }
    }

    // Let the grading strategy subplugin save its data.
    $rawgrade = $strategy->save_assessment($assessment, $data);

    // Store the data managed by the workshop core.
    $coredata = (object)array('id' => $assessment->id);
    if (isset($data->feedbackauthor_editor)) {
        $coredata->feedbackauthor_editor = $data->feedbackauthor_editor;
        $coredata = file_postupdate_standard_editor($coredata, 'feedbackauthor', $workshop->overall_feedback_content_options(),
            $workshop->context, 'mod_workshop', 'overallfeedback_content', $assessment->id);
        unset($coredata->feedbackauthor_editor);
    }
    if (isset($data->feedbackauthorattachment_filemanager)) {
        $coredata->feedbackauthorattachment_filemanager = $data->feedbackauthorattachment_filemanager;
        $coredata = file_postupdate_standard_filemanager($coredata, 'feedbackauthorattachment',
            $workshop->overall_feedback_attachment_options(), $workshop->context, 'mod_workshop', 'overallfeedback_attachment',
            $assessment->id);
        unset($coredata->feedbackauthorattachment_filemanager);
        if (empty($coredata->feedbackauthorattachment)) {
            $coredata->feedbackauthorattachment = 0;
        }
    }
    if ($canmanage) {
        // Remember the last one who edited the reference assessment.
        $coredata->reviewerid = $USER->id;
예제 #8
0
파일: lib.php 프로젝트: JP-Git/moodle
 /**
  * Either saves the rubric definition into the database or check if it has been changed.
  * Returns the level of changes:
  * 0 - no changes
  * 1 - only texts or criteria sortorders are changed, students probably do not require re-grading
  * 2 - added levels but maximum score on rubric is the same, students still may not require re-grading
  * 3 - removed criteria or added levels or changed number of points, students require re-grading but may be re-graded automatically
  * 4 - removed levels - students require re-grading and not all students may be re-graded automatically
  * 5 - added criteria - all students require manual re-grading
  *
  * @param stdClass $newdefinition rubric definition data as coming from gradingform_rubric_editrubric::get_data()
  * @param int|null $usermodified optional userid of the author of the definition, defaults to the current user
  * @param boolean $doupdate if true actually updates DB, otherwise performs a check
  *
  */
 public function update_or_check_rubric(stdClass $newdefinition, $usermodified = null, $doupdate = false)
 {
     global $DB;
     // firstly update the common definition data in the {grading_definition} table
     if ($this->definition === false) {
         if (!$doupdate) {
             // if we create the new definition there is no such thing as re-grading anyway
             return 5;
         }
         // if definition does not exist yet, create a blank one
         // (we need id to save files embedded in description)
         parent::update_definition(new stdClass(), $usermodified);
         parent::load_definition();
     }
     if (!isset($newdefinition->rubric['options'])) {
         $newdefinition->rubric['options'] = self::get_default_options();
     }
     $newdefinition->options = json_encode($newdefinition->rubric['options']);
     $editoroptions = self::description_form_field_options($this->get_context());
     $newdefinition = file_postupdate_standard_editor($newdefinition, 'description', $editoroptions, $this->get_context(), 'grading', 'description', $this->definition->id);
     // reload the definition from the database
     $currentdefinition = $this->get_definition(true);
     // update rubric data
     $haschanges = array();
     if (empty($newdefinition->rubric['criteria'])) {
         $newcriteria = array();
     } else {
         $newcriteria = $newdefinition->rubric['criteria'];
         // new ones to be saved
     }
     $currentcriteria = $currentdefinition->rubric_criteria;
     $criteriafields = array('sortorder', 'description', 'descriptionformat');
     $levelfields = array('score', 'definition', 'definitionformat');
     foreach ($newcriteria as $id => $criterion) {
         // get list of submitted levels
         $levelsdata = array();
         if (array_key_exists('levels', $criterion)) {
             $levelsdata = $criterion['levels'];
         }
         $criterionmaxscore = null;
         if (preg_match('/^NEWID\\d+$/', $id)) {
             // insert criterion into DB
             $data = array('definitionid' => $this->definition->id, 'descriptionformat' => FORMAT_MOODLE);
             // TODO format is not supported yet
             foreach ($criteriafields as $key) {
                 if (array_key_exists($key, $criterion)) {
                     $data[$key] = $criterion[$key];
                 }
             }
             if ($doupdate) {
                 $id = $DB->insert_record('gradingform_rubric_criteria', $data);
             }
             $haschanges[5] = true;
         } else {
             // update criterion in DB
             $data = array();
             foreach ($criteriafields as $key) {
                 if (array_key_exists($key, $criterion) && $criterion[$key] != $currentcriteria[$id][$key]) {
                     $data[$key] = $criterion[$key];
                 }
             }
             if (!empty($data)) {
                 // update only if something is changed
                 $data['id'] = $id;
                 if ($doupdate) {
                     $DB->update_record('gradingform_rubric_criteria', $data);
                 }
                 $haschanges[1] = true;
             }
             // remove deleted levels from DB and calculate the maximum score for this criteria
             foreach ($currentcriteria[$id]['levels'] as $levelid => $currentlevel) {
                 if ($criterionmaxscore === null || $criterionmaxscore < $currentlevel['score']) {
                     $criterionmaxscore = $currentlevel['score'];
                 }
                 if (!array_key_exists($levelid, $levelsdata)) {
                     if ($doupdate) {
                         $DB->delete_records('gradingform_rubric_levels', array('id' => $levelid));
                     }
                     $haschanges[4] = true;
                 }
             }
         }
         foreach ($levelsdata as $levelid => $level) {
             if (isset($level['score'])) {
                 $level['score'] = (double) $level['score'];
                 if ($level['score'] < 0) {
                     // TODO why we can't allow negative score for rubric?
                     $level['score'] = 0;
                 }
             }
             if (preg_match('/^NEWID\\d+$/', $levelid)) {
                 // insert level into DB
                 $data = array('criterionid' => $id, 'definitionformat' => FORMAT_MOODLE);
                 // TODO format is not supported yet
                 foreach ($levelfields as $key) {
                     if (array_key_exists($key, $level)) {
                         $data[$key] = $level[$key];
                     }
                 }
                 if ($doupdate) {
                     $levelid = $DB->insert_record('gradingform_rubric_levels', $data);
                 }
                 if ($criterionmaxscore !== null && $criterionmaxscore >= $level['score']) {
                     // new level is added but the maximum score for this criteria did not change, re-grading may not be necessary
                     $haschanges[2] = true;
                 } else {
                     $haschanges[3] = true;
                 }
             } else {
                 // update level in DB
                 $data = array();
                 foreach ($levelfields as $key) {
                     if (array_key_exists($key, $level) && $level[$key] != $currentcriteria[$id]['levels'][$levelid][$key]) {
                         $data[$key] = $level[$key];
                     }
                 }
                 if (!empty($data)) {
                     // update only if something is changed
                     $data['id'] = $levelid;
                     if ($doupdate) {
                         $DB->update_record('gradingform_rubric_levels', $data);
                     }
                     if (isset($data['score'])) {
                         $haschanges[3] = true;
                     }
                     $haschanges[1] = true;
                 }
             }
         }
     }
     // remove deleted criteria from DB
     foreach (array_keys($currentcriteria) as $id) {
         if (!array_key_exists($id, $newcriteria)) {
             if ($doupdate) {
                 $DB->delete_records('gradingform_rubric_criteria', array('id' => $id));
                 $DB->delete_records('gradingform_rubric_levels', array('criterionid' => $id));
             }
             $haschanges[3] = true;
         }
     }
     foreach (array('status', 'description', 'descriptionformat', 'name', 'options') as $key) {
         if (isset($newdefinition->{$key}) && $newdefinition->{$key} != $this->definition->{$key}) {
             $haschanges[1] = true;
         }
     }
     if ($usermodified && $usermodified != $this->definition->usermodified) {
         $haschanges[1] = true;
     }
     if (!count($haschanges)) {
         return 0;
     }
     if ($doupdate) {
         parent::update_definition($newdefinition, $usermodified);
         $this->load_definition();
     }
     // return the maximum level of changes
     $changelevels = array_keys($haschanges);
     sort($changelevels);
     return array_pop($changelevels);
 }
예제 #9
0
 function view()
 {
     global $OUTPUT, $CFG, $USER, $PAGE;
     $edit = optional_param('edit', 0, PARAM_BOOL);
     $saved = optional_param('saved', 0, PARAM_BOOL);
     $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
     require_capability('mod/assignment:view', $context);
     $submission = $this->get_submission($USER->id, false);
     //Guest can not submit nor edit an assignment (bug: 4604)
     if (!is_enrolled($this->context, $USER, 'mod/assignment:submit')) {
         $editable = false;
     } else {
         $editable = $this->isopen() && (!$submission || $this->assignment->resubmit || !$submission->timemarked);
     }
     $editmode = ($editable and $edit);
     if ($editmode) {
         // prepare form and process submitted data
         $editoroptions = array('noclean' => false, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $this->course->maxbytes);
         $data = new stdClass();
         $data->id = $this->cm->id;
         $data->edit = 1;
         if ($submission) {
             $data->sid = $submission->id;
             $data->text = $submission->data1;
             $data->textformat = $submission->data2;
         } else {
             $data->sid = NULL;
             $data->text = '';
             $data->textformat = NULL;
         }
         $data = file_prepare_standard_editor($data, 'text', $editoroptions, $this->context, 'mod_assignment', $this->filearea, $data->sid);
         $mform = new mod_assignment_online_edit_form(null, array($data, $editoroptions));
         if ($mform->is_cancelled()) {
             redirect($PAGE->url);
         }
         if ($data = $mform->get_data()) {
             $submission = $this->get_submission($USER->id, true);
             //create the submission if needed & its id
             $data = file_postupdate_standard_editor($data, 'text', $editoroptions, $this->context, 'mod_assignment', $this->filearea, $submission->id);
             $submission = $this->update_submission($data);
             //TODO fix log actions - needs db upgrade
             add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a=' . $this->assignment->id, $this->assignment->id, $this->cm->id);
             $this->email_teachers($submission);
             //redirect to get updated submission date and word count
             redirect(new moodle_url($PAGE->url, array('saved' => 1)));
         }
     }
     add_to_log($this->course->id, "assignment", "view", "view.php?id={$this->cm->id}", $this->assignment->id, $this->cm->id);
     /// print header, etc. and display form if needed
     if ($editmode) {
         $this->view_header(get_string('editmysubmission', 'assignment'));
     } else {
         $this->view_header();
     }
     $this->view_intro();
     $this->view_dates();
     if ($saved) {
         echo $OUTPUT->notification(get_string('submissionsaved', 'assignment'), 'notifysuccess');
     }
     if (is_enrolled($this->context, $USER)) {
         if ($editmode) {
             echo $OUTPUT->box_start('generalbox', 'onlineenter');
             $mform->display();
         } else {
             echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter', 'online');
             if ($submission && has_capability('mod/assignment:exportownsubmission', $this->context)) {
                 $text = file_rewrite_pluginfile_urls($submission->data1, 'pluginfile.php', $this->context->id, 'mod_assignment', $this->filearea, $submission->id);
                 echo format_text($text, $submission->data2, array('overflowdiv' => true));
                 if ($CFG->enableportfolios) {
                     require_once $CFG->libdir . '/portfoliolib.php';
                     $button = new portfolio_add_button();
                     $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id), '/mod/assignment/locallib.php');
                     $fs = get_file_storage();
                     if ($files = $fs->get_area_files($this->context->id, 'mod_assignment', $this->filearea, $submission->id, "timemodified", false)) {
                         $button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
                     } else {
                         $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML);
                     }
                     $button->render();
                 }
             } else {
                 if ($this->isopen()) {
                     //fix for #4206
                     echo '<div style="text-align:center">' . get_string('emptysubmission', 'assignment') . '</div>';
                 }
             }
         }
         echo $OUTPUT->box_end();
         if (!$editmode && $editable) {
             if (!empty($submission)) {
                 $submitbutton = "editmysubmission";
             } else {
                 $submitbutton = "addsubmission";
             }
             echo "<div style='text-align:center'>";
             echo $OUTPUT->single_button(new moodle_url('view.php', array('id' => $this->cm->id, 'edit' => '1')), get_string($submitbutton, 'assignment'));
             echo "</div>";
         }
     }
     $this->view_feedback();
     $this->view_footer();
 }
예제 #10
0
파일: lib.php 프로젝트: nicusX/moodle
 /**
  * Either saves the guide definition into the database or check if it has been changed.
  *
  * Returns the level of changes:
  * 0 - no changes
  * 1 - only texts or criteria sortorders are changed, students probably do not require re-grading
  * 2 - added levels but maximum score on guide is the same, students still may not require re-grading
  * 3 - removed criteria or changed number of points, students require re-grading but may be re-graded automatically
  * 4 - removed levels - students require re-grading and not all students may be re-graded automatically
  * 5 - added criteria - all students require manual re-grading
  *
  * @param stdClass $newdefinition guide definition data as coming from gradingform_guide_editguide::get_data()
  * @param int|null $usermodified optional userid of the author of the definition, defaults to the current user
  * @param bool $doupdate if true actually updates DB, otherwise performs a check
  * @return int
  */
 public function update_or_check_guide(stdClass $newdefinition, $usermodified = null, $doupdate = false)
 {
     global $DB;
     // Firstly update the common definition data in the {grading_definition} table.
     if ($this->definition === false) {
         if (!$doupdate) {
             // If we create the new definition there is no such thing as re-grading anyway.
             return 5;
         }
         // If definition does not exist yet, create a blank one
         // (we need id to save files embedded in description).
         parent::update_definition(new stdClass(), $usermodified);
         parent::load_definition();
     }
     if (!isset($newdefinition->guide['options'])) {
         $newdefinition->guide['options'] = self::get_default_options();
     }
     $newdefinition->options = json_encode($newdefinition->guide['options']);
     $editoroptions = self::description_form_field_options($this->get_context());
     $newdefinition = file_postupdate_standard_editor($newdefinition, 'description', $editoroptions, $this->get_context(), 'grading', 'description', $this->definition->id);
     // Reload the definition from the database.
     $currentdefinition = $this->get_definition(true);
     // Update guide data.
     $haschanges = array();
     if (empty($newdefinition->guide['criteria'])) {
         $newcriteria = array();
     } else {
         $newcriteria = $newdefinition->guide['criteria'];
         // New ones to be saved.
     }
     $currentcriteria = $currentdefinition->guide_criteria;
     $criteriafields = array('sortorder', 'description', 'descriptionformat', 'descriptionmarkers', 'descriptionmarkersformat', 'shortname', 'maxscore');
     foreach ($newcriteria as $id => $criterion) {
         if (preg_match('/^NEWID\\d+$/', $id)) {
             // Insert criterion into DB.
             $data = array('definitionid' => $this->definition->id, 'descriptionformat' => FORMAT_MOODLE, 'descriptionmarkersformat' => FORMAT_MOODLE);
             // TODO format is not supported yet.
             foreach ($criteriafields as $key) {
                 if (array_key_exists($key, $criterion)) {
                     $data[$key] = $criterion[$key];
                 }
             }
             if ($doupdate) {
                 $id = $DB->insert_record('gradingform_guide_criteria', $data);
             }
             $haschanges[5] = true;
         } else {
             // Update criterion in DB.
             $data = array();
             foreach ($criteriafields as $key) {
                 if (array_key_exists($key, $criterion) && $criterion[$key] != $currentcriteria[$id][$key]) {
                     $data[$key] = $criterion[$key];
                 }
             }
             if (!empty($data)) {
                 // Update only if something is changed.
                 $data['id'] = $id;
                 if ($doupdate) {
                     $DB->update_record('gradingform_guide_criteria', $data);
                 }
                 $haschanges[1] = true;
             }
         }
     }
     // Remove deleted criteria from DB.
     foreach (array_keys($currentcriteria) as $id) {
         if (!array_key_exists($id, $newcriteria)) {
             if ($doupdate) {
                 $DB->delete_records('gradingform_guide_criteria', array('id' => $id));
             }
             $haschanges[3] = true;
         }
     }
     // Now handle comments.
     if (empty($newdefinition->guide['comments'])) {
         $newcomment = array();
     } else {
         $newcomment = $newdefinition->guide['comments'];
         // New ones to be saved.
     }
     $currentcomments = $currentdefinition->guide_comment;
     $commentfields = array('sortorder', 'description');
     foreach ($newcomment as $id => $comment) {
         if (preg_match('/^NEWID\\d+$/', $id)) {
             // Insert criterion into DB.
             $data = array('definitionid' => $this->definition->id, 'descriptionformat' => FORMAT_MOODLE);
             foreach ($commentfields as $key) {
                 if (array_key_exists($key, $comment)) {
                     $data[$key] = $comment[$key];
                 }
             }
             if ($doupdate) {
                 $id = $DB->insert_record('gradingform_guide_comments', $data);
             }
         } else {
             // Update criterion in DB.
             $data = array();
             foreach ($commentfields as $key) {
                 if (array_key_exists($key, $comment) && $comment[$key] != $currentcomments[$id][$key]) {
                     $data[$key] = $comment[$key];
                 }
             }
             if (!empty($data)) {
                 // Update only if something is changed.
                 $data['id'] = $id;
                 if ($doupdate) {
                     $DB->update_record('gradingform_guide_comments', $data);
                 }
             }
         }
     }
     // Remove deleted criteria from DB.
     foreach (array_keys($currentcomments) as $id) {
         if (!array_key_exists($id, $newcomment)) {
             if ($doupdate) {
                 $DB->delete_records('gradingform_guide_comments', array('id' => $id));
             }
         }
     }
     // End comments handle.
     foreach (array('status', 'description', 'descriptionformat', 'name', 'options') as $key) {
         if (isset($newdefinition->{$key}) && $newdefinition->{$key} != $this->definition->{$key}) {
             $haschanges[1] = true;
         }
     }
     if ($usermodified && $usermodified != $this->definition->usermodified) {
         $haschanges[1] = true;
     }
     if (!count($haschanges)) {
         return 0;
     }
     if ($doupdate) {
         parent::update_definition($newdefinition, $usermodified);
         $this->load_definition();
     }
     // Return the maximum level of changes.
     $changelevels = array_keys($haschanges);
     sort($changelevels);
     return array_pop($changelevels);
 }
 function postupdate($item)
 {
     global $DB;
     $context = get_context_instance(CONTEXT_MODULE, $item->cmid);
     $item = file_postupdate_standard_editor($item, 'presentation', $this->presentationoptions, $context, 'mod_feedback', 'item', $item->id);
     // $item = new stdClass();
     // $item->id = $data->id
     $DB->update_record('feedback_item', $item);
     return $item->id;
 }
예제 #12
0
if ($cohort->id) {
    // edit existing
    $cohort = file_prepare_standard_editor($cohort, 'description', $editoroptions, $context);
    $strheading = get_string('editcohort', 'cohort');
} else {
    // add new
    $cohort = file_prepare_standard_editor($cohort, 'description', $editoroptions, $context);
    $strheading = get_string('addcohort', 'cohort');
}
$PAGE->set_title($strheading);
$PAGE->set_heading($COURSE->fullname);
$PAGE->navbar->add($strheading);
$editform = new cohort_edit_form(null, array('editoroptions' => $editoroptions, 'data' => $cohort));
if ($editform->is_cancelled()) {
    redirect($returnurl);
} else {
    if ($data = $editform->get_data()) {
        $data = file_postupdate_standard_editor($data, 'description', $editoroptions, $context);
        if ($data->id) {
            cohort_update_cohort($data);
        } else {
            cohort_add_cohort($data);
        }
        // use new context id, it could have been changed
        redirect(new moodle_url('/cohort/index.php', array('contextid' => $data->contextid)));
    }
}
echo $OUTPUT->header();
echo $OUTPUT->heading($strheading);
echo $editform->display();
echo $OUTPUT->footer();
 /**
  * Return submitted data if properly submitted or returns NULL if validation fails or
  * if there is no submitted data.
  *
  * @return object submitted data; NULL if not valid or not submitted or cancelled
  */
 function get_data()
 {
     $data = parent::get_data();
     if ($data !== null) {
         $editoroptions = $this->_customdata['editoroptions'];
         if (!empty($data->usedefaultname)) {
             $data->name = null;
         }
         $data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $editoroptions['context'], 'course', 'section', $data->id);
         $course = $this->_customdata['course'];
         foreach (course_get_format($course)->section_format_options() as $option => $unused) {
             // fix issue with unset checkboxes not being returned at all
             if (!isset($data->{$option})) {
                 $data->{$option} = null;
             }
         }
     }
     return $data;
 }
예제 #14
0
파일: edit.php 프로젝트: pzhu2004/moodle
    if ($data = $mform->get_data()) {
        $scale = new grade_scale(array('id' => $id));
        $data->userid = $USER->id;
        if (empty($scale->id)) {
            $data->description = $data->description_editor['text'];
            $data->descriptionformat = $data->description_editor['format'];
            grade_scale::set_properties($scale, $data);
            if (!has_capability('moodle/grade:manage', $systemcontext)) {
                $data->standard = 0;
            }
            $scale->courseid = !empty($data->standard) ? 0 : $courseid;
            $scale->insert();
            $data = file_postupdate_standard_editor($data, 'description', $editoroptions, $systemcontext, 'grade', 'scale', $scale->id);
            $DB->set_field($scale->table, 'description', $data->description, array('id' => $scale->id));
        } else {
            $data = file_postupdate_standard_editor($data, 'description', $editoroptions, $systemcontext, 'grade', 'scale', $id);
            grade_scale::set_properties($scale, $data);
            if (isset($data->standard)) {
                $scale->courseid = !empty($data->standard) ? 0 : $courseid;
            } else {
                unset($scale->courseid);
                // keep previous
            }
            $scale->update();
        }
        redirect($returnurl);
    }
}
print_grade_page_head($COURSE->id, 'scale', null, $heading, false, false, false);
$mform->display();
echo $OUTPUT->footer();
예제 #15
0
    public function postupdate($item) {
        global $DB;

        $context = context_localule::instance($item->cmid);
        $item = file_postupdate_standard_editor($item,
                                                'presentation',
                                                $this->presentationoptions,
                                                $context,
                                                'local_evaluations',
                                                'item',
                                                $item->id);

        $DB->update_record('evaluation_item', $item);
        return $item->id;
    }
예제 #16
0
파일: lib.php 프로젝트: vuchannguyen/web
 /**
  * Save the assessment dimensions into database
  *
  * Saves data into the main strategy form table. If the record->id is null or zero,
  * new record is created. If the record->id is not empty, the existing record is updated. Records with
  * empty 'description' field are removed from database.
  * The passed data object are the raw data returned by the get_data().
  *
  * @uses $DB
  * @param stdClass $data Raw data returned by the dimension editor form
  * @return void
  */
 public function save_edit_strategy_form(stdclass $data)
 {
     global $DB;
     $norepeats = $data->norepeats;
     $layout = $data->config_layout;
     $data = $this->prepare_database_fields($data);
     $deletedims = array();
     // dimension ids to be deleted
     $deletelevs = array();
     // level ids to be deleted
     if ($DB->record_exists('workshopform_rubric_config', array('workshopid' => $this->workshop->id))) {
         $DB->set_field('workshopform_rubric_config', 'layout', $layout, array('workshopid' => $this->workshop->id));
     } else {
         $record = new stdclass();
         $record->workshopid = $this->workshop->id;
         $record->layout = $layout;
         $DB->insert_record('workshopform_rubric_config', $record, false);
     }
     foreach ($data as $record) {
         if (0 == strlen(trim($record->description_editor['text']))) {
             if (!empty($record->id)) {
                 // existing record with empty description - to be deleted
                 $deletedims[] = $record->id;
                 foreach ($record->levels as $level) {
                     if (!empty($level->id)) {
                         $deletelevs[] = $level->id;
                     }
                 }
             }
             continue;
         }
         if (empty($record->id)) {
             // new field
             $record->id = $DB->insert_record('workshopform_rubric', $record);
         } else {
             // exiting field
             $DB->update_record('workshopform_rubric', $record);
         }
         // re-save with correct path to embeded media files
         $record = file_postupdate_standard_editor($record, 'description', $this->descriptionopts, $this->workshop->context, 'workshopform_rubric', 'description', $record->id);
         $DB->update_record('workshopform_rubric', $record);
         // create/update the criterion levels
         foreach ($record->levels as $level) {
             $level->dimensionid = $record->id;
             if (0 == strlen(trim($level->definition))) {
                 if (!empty($level->id)) {
                     $deletelevs[] = $level->id;
                 }
                 continue;
             }
             if (empty($level->id)) {
                 // new field
                 $level->id = $DB->insert_record('workshopform_rubric_levels', $level);
             } else {
                 // exiting field
                 $DB->update_record('workshopform_rubric_levels', $level);
             }
         }
     }
     $DB->delete_records_list('workshopform_rubric_levels', 'id', $deletelevs);
     $this->delete_dimensions($deletedims);
 }
예제 #17
0
     unset($tagnew->rawname);
 } else {
     // They might be trying to change the rawname, make sure it's a change that doesn't affect name
     $norm = tag_normalize($tagnew->rawname, TAG_CASE_LOWER);
     $tagnew->name = array_shift($norm);
     if ($tag->name != $tagnew->name) {
         // The name has changed, let's make sure it's not another existing tag
         if (tag_get_id($tagnew->name)) {
             // Something exists already, so flag an error
             $errorstring = s($tagnew->rawname) . ': ' . get_string('namesalreadybeeingused', 'tag');
         }
     }
 }
 if (empty($errorstring)) {
     // All is OK, let's save it
     $tagnew = file_postupdate_standard_editor($tagnew, 'description', $editoroptions, $systemcontext, 'tag', 'description', $tag->id);
     tag_description_set($tag_id, $tagnew->description, $tagnew->descriptionformat);
     $tagnew->timemodified = time();
     if (has_capability('moodle/tag:manage', $systemcontext)) {
         // rename tag
         if (!tag_rename($tag->id, $tagnew->rawname)) {
             print_error('errorupdatingrecord', 'tag');
         }
     }
     //log tag changes activity
     //if tag name exist from form, renaming is allow.  record log action as rename
     //otherwise, record log action as update
     if (isset($tagnew->name) && $tag->name != $tagnew->name) {
         add_to_log($COURSE->id, 'tag', 'update', 'index.php?id=' . $tag->id, $tag->name . '->' . $tagnew->name);
     } elseif ($tag->description != $tagnew->description) {
         add_to_log($COURSE->id, 'tag', 'update', 'index.php?id=' . $tag->id, $tag->name);
예제 #18
0
    /**
     * Updates the page and its answers
     *
     * @global moodle_database $DB
     * @global moodle_page $PAGE
     * @param stdClass $properties
     * @return bool
     */
    public function update($properties) {
        global $DB, $PAGE;
        $answers  = $this->get_answers();
        $properties->id = $this->properties->id;
        $properties->lessonid = $this->lesson->id;
        $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$PAGE->course->maxbytes), get_context_instance(CONTEXT_MODULE, $PAGE->cm->id), 'mod_lesson', 'page_contents', $properties->id);
        $DB->update_record("lesson_pages", $properties);

        // need to reset offset for correct and wrong responses
        $this->lesson->maxanswers = 2;
        for ($i = 0; $i < $this->lesson->maxanswers; $i++) {
            if (!array_key_exists($i, $this->answers)) {
                $this->answers[$i] = new stdClass;
                $this->answers[$i]->lessonid = $this->lesson->id;
                $this->answers[$i]->pageid = $this->id;
                $this->answers[$i]->timecreated = $this->timecreated;
            }

            if (!empty($properties->answer_editor[$i]) && is_array($properties->answer_editor[$i])) {
                $this->answers[$i]->answer = $properties->answer_editor[$i]['text'];
                $this->answers[$i]->answerformat = $properties->answer_editor[$i]['format'];
            }

            if (!empty($properties->response_editor[$i]) && is_array($properties->response_editor[$i])) {
                $this->answers[$i]->response = $properties->response_editor[$i]['text'];
                $this->answers[$i]->responseformat = $properties->response_editor[$i]['format'];
            }

            // we don't need to check for isset here because properties called it's own isset method.
            if ($this->answers[$i]->answer != '') {
                if (isset($properties->jumpto[$i])) {
                    $this->answers[$i]->jumpto = $properties->jumpto[$i];
                }
                if ($this->lesson->custom && isset($properties->score[$i])) {
                    $this->answers[$i]->score = $properties->score[$i];
                }
                if (!isset($this->answers[$i]->id)) {
                    $this->answers[$i]->id =  $DB->insert_record("lesson_answers", $this->answers[$i]);
                } else {
                    $DB->update_record("lesson_answers", $this->answers[$i]->properties());
                }
            } else if (isset($this->answers[$i]->id)) {
                $DB->delete_records('lesson_answers', array('id'=>$this->answers[$i]->id));
                unset($this->answers[$i]);
            }
        }
        return true;
    }
예제 #19
0
파일: lib.php 프로젝트: numbas/moodle
/**
 * Update a course.
 *
 * Please note this functions does not verify any access control,
 * the calling code is responsible for all validation (usually it is the form definition).
 *
 * @param object $data  - all the data needed for an entry in the 'course' table
 * @param array $editoroptions course description editor options
 * @return void
 */
function update_course($data, $editoroptions = NULL)
{
    global $CFG, $DB;
    $data->timemodified = time();
    $oldcourse = $DB->get_record('course', array('id' => $data->id), '*', MUST_EXIST);
    $context = get_context_instance(CONTEXT_COURSE, $oldcourse->id);
    if ($editoroptions) {
        $data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course', 'summary', 0);
    }
    if (!isset($data->category) or empty($data->category)) {
        // prevent nulls and 0 in category field
        unset($data->category);
    }
    $movecat = (isset($data->category) and $oldcourse->category != $data->category);
    if (!isset($data->visible)) {
        // data not from form, add missing visibility info
        $data->visible = $oldcourse->visible;
    }
    if ($data->visible != $oldcourse->visible) {
        // reset the visibleold flag when manually hiding/unhiding course
        $data->visibleold = $data->visible;
    } else {
        if ($movecat) {
            $newcategory = $DB->get_record('course_categories', array('id' => $data->category));
            if (empty($newcategory->visible)) {
                // make sure when moving into hidden category the course is hidden automatically
                $data->visible = 0;
            }
        }
    }
    // Update with the new data
    $DB->update_record('course', $data);
    $course = $DB->get_record('course', array('id' => $data->id));
    if ($movecat) {
        $newparent = get_context_instance(CONTEXT_COURSECAT, $course->category);
        context_moved($context, $newparent);
    }
    fix_course_sortorder();
    // Test for and remove blocks which aren't appropriate anymore
    blocks_remove_inappropriate($course);
    // Save any custom role names.
    save_local_role_names($course->id, $data);
    // update enrol settings
    enrol_course_updated(false, $course, $data);
    add_to_log($course->id, "course", "update", "edit.php?id={$course->id}", $course->id);
    // Trigger events
    events_trigger('course_updated', $course);
}
예제 #20
0
 /**
  * Updates this entry in the database. Access control checks must be done by calling code.
  *
  * @param array       $params            Entry parameters.
  * @param moodleform  $form              Used for attachments.
  * @param array       $summaryoptions    Summary options.
  * @param array       $attachmentoptions Attachment options.
  *
  * @return void
  */
 public function edit($params = array(), $form = null, $summaryoptions = array(), $attachmentoptions = array())
 {
     global $CFG, $DB;
     $sitecontext = context_system::instance();
     $entry = $this;
     $this->form = $form;
     foreach ($params as $var => $val) {
         $entry->{$var} = $val;
     }
     $entry = file_postupdate_standard_editor($entry, 'summary', $summaryoptions, $sitecontext, 'blog', 'post', $entry->id);
     $entry = file_postupdate_standard_filemanager($entry, 'attachment', $attachmentoptions, $sitecontext, 'blog', 'attachment', $entry->id);
     if (!empty($CFG->useblogassociations)) {
         $entry->add_associations();
     }
     $entry->lastmodified = time();
     // Update record.
     $DB->update_record('post', $entry);
     core_tag_tag::set_item_tags('core', 'post', $entry->id, context_user::instance($this->userid), $entry->tags);
     $event = \core\event\blog_entry_updated::create(array('objectid' => $entry->id, 'relateduserid' => $entry->userid));
     $event->set_blog_entry($entry);
     $event->trigger();
 }
예제 #21
0
 }
 $editoroptions = array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, 'context' => $context);
 $essayinfo = lesson_page_type_essay::extract_useranswer($attempt->useranswer);
 $essayinfo = file_prepare_standard_editor($essayinfo, 'response', $editoroptions, $context, 'mod_lesson', 'essay_responses', $attempt->id);
 $mform = new essay_grading_form(null, array('scoreoptions' => $scoreoptions, 'user' => $user));
 $mform->set_data($essayinfo);
 if ($mform->is_cancelled()) {
     redirect("{$CFG->wwwroot}/mod/lesson/essay.php?id={$cm->id}");
 }
 if ($form = $mform->get_data()) {
     if (!($grades = $DB->get_records('lesson_grades', array("lessonid" => $lesson->id, "userid" => $attempt->userid), 'completed', '*', $attempt->retry, 1))) {
         print_error('cannotfindgrade', 'lesson');
     }
     $essayinfo->graded = 1;
     $essayinfo->score = $form->score;
     $form = file_postupdate_standard_editor($form, 'response', $editoroptions, $context, 'mod_lesson', 'essay_responses', $attempt->id);
     $essayinfo->response = $form->response;
     $essayinfo->responseformat = $form->responseformat;
     $essayinfo->sent = 0;
     if (!$lesson->custom && $essayinfo->score == 1) {
         $attempt->correct = 1;
     } else {
         $attempt->correct = 0;
     }
     $attempt->useranswer = serialize($essayinfo);
     $DB->update_record('lesson_attempts', $attempt);
     // Get grade information
     $grade = current($grades);
     $gradeinfo = lesson_grade($lesson, $attempt->retry, $attempt->userid);
     // Set and update
     $updategrade = new stdClass();
예제 #22
0
/**
 * Update a course.
 *
 * Please note this functions does not verify any access control,
 * the calling code is responsible for all validation (usually it is the form definition).
 *
 * @param object $data  - all the data needed for an entry in the 'course' table
 * @param array $editoroptions course description editor options
 * @return void
 */
function update_course($data, $editoroptions = NULL)
{
    global $DB;
    $data->timemodified = time();
    $oldcourse = course_get_format($data->id)->get_course();
    $context = context_course::instance($oldcourse->id);
    if ($editoroptions) {
        $data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course', 'summary', 0);
    }
    if ($overviewfilesoptions = course_overviewfiles_options($data->id)) {
        $data = file_postupdate_standard_filemanager($data, 'overviewfiles', $overviewfilesoptions, $context, 'course', 'overviewfiles', 0);
    }
    // Check we don't have a duplicate shortname.
    if (!empty($data->shortname) && $oldcourse->shortname != $data->shortname) {
        if ($DB->record_exists_sql('SELECT id from {course} WHERE shortname = ? AND id <> ?', array($data->shortname, $data->id))) {
            throw new moodle_exception('shortnametaken', '', '', $data->shortname);
        }
    }
    // Check we don't have a duplicate idnumber.
    if (!empty($data->idnumber) && $oldcourse->idnumber != $data->idnumber) {
        if ($DB->record_exists_sql('SELECT id from {course} WHERE idnumber = ? AND id <> ?', array($data->idnumber, $data->id))) {
            throw new moodle_exception('courseidnumbertaken', '', '', $data->idnumber);
        }
    }
    if (!isset($data->category) or empty($data->category)) {
        // prevent nulls and 0 in category field
        unset($data->category);
    }
    $changesincoursecat = $movecat = (isset($data->category) and $oldcourse->category != $data->category);
    if (!isset($data->visible)) {
        // data not from form, add missing visibility info
        $data->visible = $oldcourse->visible;
    }
    if ($data->visible != $oldcourse->visible) {
        // reset the visibleold flag when manually hiding/unhiding course
        $data->visibleold = $data->visible;
        $changesincoursecat = true;
    } else {
        if ($movecat) {
            $newcategory = $DB->get_record('course_categories', array('id' => $data->category));
            if (empty($newcategory->visible)) {
                // make sure when moving into hidden category the course is hidden automatically
                $data->visible = 0;
            }
        }
    }
    // Update with the new data
    $DB->update_record('course', $data);
    // make sure the modinfo cache is reset
    rebuild_course_cache($data->id);
    // update course format options with full course data
    course_get_format($data->id)->update_course_format_options($data, $oldcourse);
    $course = $DB->get_record('course', array('id' => $data->id));
    if ($movecat) {
        $newparent = context_coursecat::instance($course->category);
        $context->update_moved($newparent);
    }
    $fixcoursesortorder = $movecat || isset($data->sortorder) && $oldcourse->sortorder != $data->sortorder;
    if ($fixcoursesortorder) {
        fix_course_sortorder();
    }
    // purge appropriate caches in case fix_course_sortorder() did not change anything
    cache_helper::purge_by_event('changesincourse');
    if ($changesincoursecat) {
        cache_helper::purge_by_event('changesincoursecat');
    }
    // Test for and remove blocks which aren't appropriate anymore
    blocks_remove_inappropriate($course);
    // Save any custom role names.
    save_local_role_names($course->id, $data);
    // update enrol settings
    enrol_course_updated(false, $course, $data);
    // Trigger a course updated event.
    $event = \core\event\course_updated::create(array('objectid' => $course->id, 'context' => context_course::instance($course->id), 'other' => array('shortname' => $course->shortname, 'fullname' => $course->fullname)));
    $event->set_legacy_logdata(array($course->id, 'course', 'update', 'edit.php?id=' . $course->id, $course->id));
    $event->trigger();
    if ($oldcourse->format !== $course->format) {
        // Remove all options stored for the previous format
        // We assume that new course format migrated everything it needed watching trigger
        // 'course_updated' and in method format_XXX::update_course_format_options()
        $DB->delete_records('course_format_options', array('courseid' => $course->id, 'format' => $oldcourse->format));
    }
}
예제 #23
0
 public function update($properties, $context = null, $maxbytes = null)
 {
     global $DB, $PAGE;
     $answers = $this->get_answers();
     $properties->id = $this->properties->id;
     $properties->lessonid = $this->lesson->id;
     $properties->timemodified = time();
     $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $PAGE->course->maxbytes), context_module::instance($PAGE->cm->id), 'mod_lesson', 'page_contents', $properties->id);
     $DB->update_record("lesson_pages", $properties);
     if (!array_key_exists(0, $this->answers)) {
         $this->answers[0] = new stdClass();
         $this->answers[0]->lessonid = $this->lesson->id;
         $this->answers[0]->pageid = $this->id;
         $this->answers[0]->timecreated = $this->timecreated;
     }
     if (isset($properties->jumpto[0])) {
         $this->answers[0]->jumpto = $properties->jumpto[0];
     }
     if (isset($properties->score[0])) {
         $this->answers[0]->score = $properties->score[0];
     }
     if (!isset($this->answers[0]->id)) {
         $this->answers[0]->id = $DB->insert_record("lesson_answers", $this->answers[0]);
     } else {
         $DB->update_record("lesson_answers", $this->answers[0]->properties());
     }
     return true;
 }
예제 #24
0
파일: lib.php 프로젝트: alanaipe2015/moodle
 /**
  * Save the assessment dimensions into database
  *
  * Saves data into the main strategy form table. If the record->id is null or zero,
  * new record is created. If the record->id is not empty, the existing record is updated. Records with
  * empty 'description' field are removed from database.
  * The passed data object are the raw data returned by the get_data().
  *
  * @uses $DB
  * @param stdClass $data Raw data returned by the dimension editor form
  * @return void
  */
 public function save_edit_strategy_form(stdclass $data)
 {
     global $DB, $PAGE;
     $workshopid = $data->workshopid;
     $norepeats = $data->norepeats;
     $data = $this->prepare_database_fields($data);
     $records = $data->accumulative;
     // records to be saved into {workshopform_accumulative}
     $todelete = array();
     // dimension ids to be deleted
     for ($i = 0; $i < $norepeats; $i++) {
         $record = $records[$i];
         if (0 == strlen(trim($record->description_editor['text']))) {
             if (!empty($record->id)) {
                 // existing record with empty description - to be deleted
                 $todelete[] = $record->id;
             }
             continue;
         }
         if (empty($record->id)) {
             // new field
             $record->id = $DB->insert_record('workshopform_accumulative', $record);
         } else {
             // exiting field
             $DB->update_record('workshopform_accumulative', $record);
         }
         // re-save with correct path to embeded media files
         $record = file_postupdate_standard_editor($record, 'description', $this->descriptionopts, $PAGE->context, 'workshopform_accumulative', 'description', $record->id);
         $DB->update_record('workshopform_accumulative', $record);
     }
     $this->delete_dimensions($todelete);
 }
예제 #25
0
파일: pagelib.php 프로젝트: Burick/moodle
    protected function print_save() {
        global $CFG, $USER, $OUTPUT, $PAGE;

        $url = $CFG->wwwroot . '/mod/wiki/edit.php?pageid=' . $this->page->id;
        if (!empty($this->section)) {
            $url .= "&section=" . urlencode($this->section);
        }

        $params = array(
            'attachmentoptions' => page_wiki_edit::$attachmentoptions,
            'format' => $this->format,
            'version' => $this->versionnumber,
            'contextid' => $this->modcontext->id
        );

        if ($this->format != 'html') {
            $params['fileitemid'] = $this->page->id;
            $params['component']  = 'mod_wiki';
            $params['filearea']   = 'attachments';
        }

        $form = new mod_wiki_edit_form($url, $params);

        $save = false;
        $data = false;
        if ($data = $form->get_data()) {
            if ($this->format == 'html') {
                $data = file_postupdate_standard_editor($data, 'newcontent', page_wiki_edit::$attachmentoptions, $this->modcontext, 'mod_wiki', 'attachments', $this->subwiki->id);
            }

            if (isset($this->section)) {
                $save = wiki_save_section($this->page, $this->section, $data->newcontent, $USER->id);
            } else {
                $save = wiki_save_page($this->page, $data->newcontent, $USER->id);
            }
        }

        if ($save && $data) {
            if (!empty($CFG->usetags)) {
                tag_set('wiki_pages', $this->page->id, $data->tags);
            }

            $message = '<p>' . get_string('saving', 'wiki') . '</p>';

            if (!empty($save['sections'])) {
                foreach ($save['sections'] as $s) {
                    $message .= '<p>' . get_string('repeatedsection', 'wiki', $s) . '</p>';
                }
            }

            if ($this->versionnumber + 1 != $save['version']) {
                $message .= '<p>' . get_string('wrongversionsave', 'wiki') . '</p>';
            }

            if (isset($errors) && !empty($errors)) {
                foreach ($errors as $e) {
                    $message .= "<p>" . get_string('filenotuploadederror', 'wiki', $e->get_filename()) . "</p>";
                }
            }

            //deleting old locks
            wiki_delete_locks($this->page->id, $USER->id, $this->section);
            $url = new moodle_url('view.php', array('pageid' => $this->page->id, 'group' => $this->subwiki->groupid));
            redirect($url);
        } else {
            print_error('savingerror', 'wiki');
        }
    }
예제 #26
0
        $formdata->title = trim($formdata->title);
        $formdata->content = '';
        // updated later
        $formdata->contentformat = FORMAT_HTML;
        // updated later
        $formdata->contenttrust = 0;
        // updated later
        if (is_null($example->id)) {
            $example->id = $formdata->id = $DB->insert_record('workshop_submissions', $formdata);
        } else {
            if (empty($formdata->id) or empty($example->id) or $formdata->id != $example->id) {
                throw new moodle_exception('err_examplesubmissionid', 'workshop');
            }
        }
        // save and relink embedded images and save attachments
        $formdata = file_postupdate_standard_editor($formdata, 'content', $contentopts, $workshop->context, 'mod_workshop', 'submission_content', $example->id);
        $formdata = file_postupdate_standard_filemanager($formdata, 'attachment', $attachmentopts, $workshop->context, 'mod_workshop', 'submission_attachment', $example->id);
        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('workshop_submissions', $formdata);
        redirect($workshop->exsubmission_url($formdata->id));
    }
}
// Output starts here
echo $output->header();
echo $output->heading(format_string($workshop->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
예제 #27
0
파일: lib.php 프로젝트: nuckey/moodle
    /**
     * Save the assessment dimensions into database
     *
     * Saves data into the main strategy form table. If the record->id is null or zero,
     * new record is created. If the record->id is not empty, the existing record is updated. Records with
     * empty 'description' field are removed from database.
     * The passed data object are the raw data returned by the get_data().
     *
     * @uses $DB
     * @param stdClass $data Raw data returned by the dimension editor form
     * @return void
     */
    public function save_edit_strategy_form(stdclass $data) {
        global $DB, $PAGE;

        $workshopid = $data->workshopid;
        $norepeats  = $data->norepeats;

        $data       = $this->prepare_database_fields($data);
        $records    = $data->numerrors; // data to be saved into {workshopform_numerrors}
        $mappings   = $data->mappings;  // data to be saved into {workshopform_numerrors_map}
        $todelete   = array();          // dimension ids to be deleted

        for ($i=0; $i < $norepeats; $i++) {
            $record = $records[$i];
            if (0 == strlen(trim($record->description_editor['text']))) {
                if (!empty($record->id)) {
                    // existing dimension record with empty description - to be deleted
                    $todelete[] = $record->id;
                }
                continue;
            }
            if (empty($record->id)) {
                // new field
                $record->id = $DB->insert_record('workshopform_numerrors', $record);
            } else {
                // exiting field
                $DB->update_record('workshopform_numerrors', $record);
            }
            // re-save with correct path to embeded media files
            $record = file_postupdate_standard_editor($record, 'description', $this->descriptionopts, $PAGE->context,
                                                      'workshopform_numerrors', 'description', $record->id);
            $DB->update_record('workshopform_numerrors', $record);
        }
        $this->delete_dimensions($todelete);

        // re-save the mappings
        $todelete = array();
        foreach ($data->mappings as $nonegative => $grade) {
            if (is_null($grade)) {
                // no grade set for this number of negative responses
                $todelete[] = $nonegative;
                continue;
            }
            if (isset($this->mappings[$nonegative])) {
                $DB->set_field('workshopform_numerrors_map', 'grade', $grade,
                            array('workshopid' => $this->workshop->id, 'nonegative' => $nonegative));
            } else {
                $DB->insert_record('workshopform_numerrors_map',
                            (object)array('workshopid' => $this->workshop->id, 'nonegative' => $nonegative, 'grade' => $grade));
            }
        }
        // clear mappings that are not valid any more
        if (!empty($todelete)) {
            list($insql, $params) = $DB->get_in_or_equal($todelete, SQL_PARAMS_NAMED);
            $insql = "nonegative $insql OR ";
        } else {
            $insql = '';
        }
        $sql = "DELETE FROM {workshopform_numerrors_map}
                      WHERE (($insql nonegative > :nodimensions) AND (workshopid = :workshopid))";
        $params['nodimensions'] = $norepeats;
        $params['workshopid']   = $this->workshop->id;
        $DB->execute($sql, $params);
    }
예제 #28
0
 /**
  * Updates the page and its answers
  *
  * @global moodle_database $DB
  * @global moodle_page $PAGE
  * @param stdClass $properties
  * @return bool
  */
 public function update($properties, $context = null, $maxbytes = null)
 {
     global $DB, $PAGE;
     $answers = $this->get_answers();
     $properties->id = $this->properties->id;
     $properties->lessonid = $this->lesson->id;
     $properties->timemodified = time();
     $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $PAGE->course->maxbytes), context_module::instance($PAGE->cm->id), 'mod_lesson', 'page_contents', $properties->id);
     $DB->update_record("lesson_pages", $properties);
     // need to add two to offset correct response and wrong response
     $this->lesson->maxanswers += 2;
     for ($i = 0; $i < $this->lesson->maxanswers; $i++) {
         if (!array_key_exists($i, $this->answers)) {
             $this->answers[$i] = new stdClass();
             $this->answers[$i]->lessonid = $this->lesson->id;
             $this->answers[$i]->pageid = $this->id;
             $this->answers[$i]->timecreated = $this->timecreated;
         }
         if (!empty($properties->answer_editor[$i]) && is_array($properties->answer_editor[$i])) {
             $this->answers[$i]->answer = $properties->answer_editor[$i]['text'];
             $this->answers[$i]->answerformat = $properties->answer_editor[$i]['format'];
         }
         if (!empty($properties->response_editor[$i])) {
             $this->answers[$i]->response = $properties->response_editor[$i];
             $this->answers[$i]->responseformat = 0;
         }
         if (isset($properties->jumpto[$i])) {
             $this->answers[$i]->jumpto = $properties->jumpto[$i];
         }
         if ($this->lesson->custom && isset($properties->score[$i])) {
             $this->answers[$i]->score = $properties->score[$i];
         }
         // we don't need to check for isset here because properties called it's own isset method.
         if ($this->answers[$i]->answer != '') {
             if (!isset($this->answers[$i]->id)) {
                 $this->answers[$i]->id = $DB->insert_record("lesson_answers", $this->answers[$i]);
             } else {
                 $DB->update_record("lesson_answers", $this->answers[$i]->properties());
             }
             // Save files in answers (no response_editor for matching questions).
             $this->save_answers_files($context, $maxbytes, $this->answers[$i], $properties->answer_editor[$i]);
         } else {
             if ($i < 2) {
                 if (!isset($this->answers[$i]->id)) {
                     $this->answers[$i]->id = $DB->insert_record("lesson_answers", $this->answers[$i]);
                 } else {
                     $DB->update_record("lesson_answers", $this->answers[$i]->properties());
                 }
                 // Save files in answers (no response_editor for matching questions).
                 $this->save_answers_files($context, $maxbytes, $this->answers[$i], $properties->answer_editor[$i]);
             } else {
                 if (isset($this->answers[$i]->id)) {
                     $DB->delete_records('lesson_answers', array('id' => $this->answers[$i]->id));
                     unset($this->answers[$i]);
                 }
             }
         }
     }
     return true;
 }
예제 #29
0
        $fs = get_file_storage();
        $files = $fs->get_area_files($workshop->context->id, 'mod_workshop', 'submission_attachment', $submission->id);
        $params['other']['content'] = $formdata->content;
        $params['other']['pathnamehashes'] = array_keys($files);
        $event = \mod_workshop\event\assessable_uploaded::create($params);
        $event->set_legacy_logdata($logdata);
        $event->trigger();
        redirect($workshop->submission_url($formdata->id));
    }
}
// load the form to override grade and/or publish the submission and process the submitted data eventually
if (!$edit and ($canoverride or $canpublish)) {
    $options = array('editable' => true, 'editablepublished' => $canpublish, 'overridablegrade' => $canoverride);
    $feedbackform = $workshop->get_feedbackauthor_form($PAGE->url, $submission, $options);
    if ($data = $feedbackform->get_data()) {
        $data = file_postupdate_standard_editor($data, 'feedbackauthor', array(), $workshop->context);
        $record = new stdclass();
        $record->id = $submission->id;
        if ($canoverride) {
            $record->gradeover = $workshop->raw_grade_value($data->gradeover, $workshop->grade);
            $record->gradeoverby = $USER->id;
            $record->feedbackauthor = $data->feedbackauthor;
            $record->feedbackauthorformat = $data->feedbackauthorformat;
        }
        if ($canpublish) {
            $record->published = !empty($data->published);
        }
        $DB->update_record('workshop_submissions', $record);
        redirect($workshop->view_url());
    }
}
 /**
  * Updates the record with either form data or raw data
  *
  * Please note that this function does not verify access control.
  *
  * This function calls coursecat::change_parent_raw if field 'parent' is updated.
  * It also calls coursecat::hide_raw or coursecat::show_raw if 'visible' is updated.
  * Visibility is changed first and then parent is changed. This means that
  * if parent category is hidden, the current category will become hidden
  * too and it may overwrite whatever was set in field 'visible'.
  *
  * Note that fields 'path' and 'depth' can not be updated manually
  * Also coursecat::update() can not directly update the field 'sortoder'
  *
  * @param array|stdClass $data
  * @param array $editoroptions if specified, the data is considered to be
  *    form data and file_postupdate_standard_editor() is being called to
  *    process images in description.
  * @throws moodle_exception
  */
 public function update($data, $editoroptions = null)
 {
     global $DB, $CFG;
     if (!$this->id) {
         // There is no actual DB record associated with root category.
         return;
     }
     $data = (object) $data;
     $newcategory = new stdClass();
     $newcategory->id = $this->id;
     // Copy all description* fields regardless of whether this is form data or direct field update.
     foreach ($data as $key => $value) {
         if (preg_match("/^description/", $key)) {
             $newcategory->{$key} = $value;
         }
     }
     if (isset($data->name) && empty($data->name)) {
         throw new moodle_exception('categorynamerequired');
     }
     if (!empty($data->name) && $data->name !== $this->name) {
         if (core_text::strlen($data->name) > 255) {
             throw new moodle_exception('categorytoolong');
         }
         $newcategory->name = $data->name;
     }
     if (isset($data->idnumber) && $data->idnumber != $this->idnumber) {
         if (core_text::strlen($data->idnumber) > 100) {
             throw new moodle_exception('idnumbertoolong');
         }
         if ($DB->record_exists('course_categories', array('idnumber' => $data->idnumber))) {
             throw new moodle_exception('categoryidnumbertaken');
         }
         $newcategory->idnumber = $data->idnumber;
     }
     if (isset($data->theme) && !empty($CFG->allowcategorythemes)) {
         $newcategory->theme = $data->theme;
     }
     $changes = false;
     if (isset($data->visible)) {
         if ($data->visible) {
             $changes = $this->show_raw();
         } else {
             $changes = $this->hide_raw(0);
         }
     }
     if (isset($data->parent) && $data->parent != $this->parent) {
         if ($changes) {
             cache_helper::purge_by_event('changesincoursecat');
         }
         $parentcat = self::get($data->parent, MUST_EXIST, true);
         $this->change_parent_raw($parentcat);
         fix_course_sortorder();
     }
     $newcategory->timemodified = time();
     $categorycontext = $this->get_context();
     if ($editoroptions) {
         $newcategory = file_postupdate_standard_editor($newcategory, 'description', $editoroptions, $categorycontext, 'coursecat', 'description', 0);
     }
     $DB->update_record('course_categories', $newcategory);
     $event = \core\event\course_category_updated::create(array('objectid' => $newcategory->id, 'context' => $categorycontext));
     $event->trigger();
     fix_course_sortorder();
     // Purge cache even if fix_course_sortorder() did not do it.
     cache_helper::purge_by_event('changesincoursecat');
     // Update all fields in the current object.
     $this->restore();
 }