/**
  * Default implementation of file_get_info for plugins.
  * This is used by the filebrowser to browse a plugins file areas.
  *
  * This implementation should work for most plugins but can be overridden if required.
  * @param file_browser $browser
  * @param string $filearea
  * @param int $itemid
  * @param string $filepath
  * @param string $filename
  * @return file_info_stored
  */
 public function get_file_info($browser, $filearea, $itemid, $filepath, $filename)
 {
     global $CFG, $DB, $USER;
     $urlbase = $CFG->wwwroot . '/pluginfile.php';
     // Permission check on the itemid.
     if ($this->get_subtype() == 'seplsubmission') {
         if ($itemid) {
             $record = $DB->get_record('sepl_submission', array('id' => $itemid), 'userid', IGNORE_MISSING);
             if (!$record) {
                 return null;
             }
             if (!$this->seplment->can_view_submission($record->userid)) {
                 return null;
             }
         }
     } else {
         // Not supported for feedback plugins.
         return null;
     }
     $fs = get_file_storage();
     $filepath = is_null($filepath) ? '/' : $filepath;
     $filename = is_null($filename) ? '.' : $filename;
     if (!($storedfile = $fs->get_file($this->seplment->get_context()->id, $this->get_subtype() . '_' . $this->get_type(), $filearea, $itemid, $filepath, $filename))) {
         return null;
     }
     $client = (new SphereEngine\Api("dadeea82cdd4b840cbde18858d9f17d6fb11a957", "v3", "endpoint"))->getProblemsClient();
     $r = rand(1000, 9999);
     # $testClient = $client->problems->create('TEST', 'Test');
     //$aaa = 'test123';
     //var_dump($aaa);
     $testClient = $client->submissions->create('SEPLTEST_123', 'int main() {};', 11);
     #create('int main() {}', 11, 'Robsontest');/
     return new file_info_stored($browser, $this->seplment->get_context(), $storedfile, $urlbase, $filearea, $itemid, true, true, false);
 }
 /**
  * Create instance of event.
  *
  * @param \sepl $sepl
  * @param \stdClass $grade
  * @return feedback_viewed
  */
 public static function create_from_grade(\sepl $sepl, \stdClass $grade)
 {
     $data = array('objectid' => $grade->id, 'relateduserid' => $grade->userid, 'context' => $sepl->get_context(), 'other' => array('seplid' => $sepl->get_instance()->id));
     /** @var feedback_viewed $event */
     $event = self::create($data);
     $event->set_sepl($sepl);
     $event->add_record_snapshot('sepl_grades', $grade);
     return $event;
 }
 /**
  * Create instance of event.
  *
  * @since Moodle 2.7
  *
  * @param \sepl $sepl
  * @param \stdClass $submission
  * @return submission_status_updated
  */
 public static function create_from_submission(\sepl $sepl, \stdClass $submission)
 {
     $data = array('context' => $sepl->get_context(), 'objectid' => $submission->id, 'relateduserid' => $sepl->get_instance()->teamsubmission ? null : $submission->userid, 'other' => array('newstatus' => $submission->status));
     /** @var submission_status_updated $event */
     $event = self::create($data);
     $event->set_sepl($sepl);
     $event->add_record_snapshot('sepl_submission', $submission);
     return $event;
 }
 /**
  * Create instance of event.
  *
  * @since Moodle 2.7
  *
  * @param \sepl $sepl
  * @return identities_revealed
  */
 public static function create_from_sepl(\sepl $sepl)
 {
     $data = array('context' => $sepl->get_context(), 'objectid' => $sepl->get_instance()->id);
     self::$preventcreatecall = false;
     /** @var identities_revealed $event */
     $event = self::create($data);
     self::$preventcreatecall = true;
     $event->set_sepl($sepl);
     return $event;
 }
 /**
  * Create instance of event.
  *
  * @since Moodle 2.7
  *
  * @param \sepl $sepl
  * @param int $userid
  * @return extension_granted
  */
 public static function create_from_sepl(\sepl $sepl, $userid)
 {
     $data = array('context' => $sepl->get_context(), 'objectid' => $sepl->get_instance()->id, 'relateduserid' => $userid);
     self::$preventcreatecall = false;
     /** @var extension_granted $event */
     $event = self::create($data);
     self::$preventcreatecall = true;
     $event->set_sepl($sepl);
     return $event;
 }
Пример #6
0
 /**
  * Set sepl instance for this event.
  * @param \sepl $sepl
  * @throws \coding_exception
  */
 public function set_sepl(\sepl $sepl)
 {
     if ($this->is_triggered()) {
         throw new \coding_exception('set_sepl() must be done before triggerring of event');
     }
     if ($sepl->get_context()->id != $this->get_context()->id) {
         throw new \coding_exception('Invalid sepl isntance supplied!');
     }
     $this->sepl = $sepl;
 }
 /**
  * Create instance of event.
  *
  * @param \sepl $sepl
  * @return reveal_identities_confirmation_page_viewed
  */
 public static function create_from_sepl(\sepl $sepl)
 {
     $data = array('context' => $sepl->get_context(), 'other' => array('seplid' => $sepl->get_instance()->id));
     self::$preventcreatecall = false;
     /** @var reveal_identities_confirmation_page_viewed $event */
     $event = self::create($data);
     self::$preventcreatecall = true;
     $event->set_sepl($sepl);
     return $event;
 }
 /**
  * Create instance of event.
  *
  * @since Moodle 2.7
  *
  * @param \sepl $sepl
  * @param \stdClass $user
  * @return submission_unlocked
  */
 public static function create_from_user(\sepl $sepl, \stdClass $user)
 {
     $data = array('context' => $sepl->get_context(), 'objectid' => $sepl->get_instance()->id, 'relateduserid' => $user->id);
     self::$preventcreatecall = false;
     /** @var submission_unlocked $event */
     $event = self::create($data);
     self::$preventcreatecall = true;
     $event->set_sepl($sepl);
     $event->add_record_snapshot('user', $user);
     return $event;
 }
 /**
  * Create instance of event.
  *
  * @since Moodle 2.7
  *
  * @param \sepl $sepl
  * @param \stdClass $submission
  * @return submission_duplicated
  */
 public static function create_from_submission(\sepl $sepl, \stdClass $submission)
 {
     $data = array('objectid' => $submission->id, 'context' => $sepl->get_context());
     self::$preventcreatecall = false;
     /** @var submission_duplicated $event */
     $event = self::create($data);
     self::$preventcreatecall = true;
     $event->set_sepl($sepl);
     $event->add_record_snapshot('sepl_submission', $submission);
     return $event;
 }
 /**
  * Create instance of event.
  *
  * @param \sepl $sepl
  * @param \stdClass $user
  * @return grading_form_viewed
  */
 public static function create_from_user(\sepl $sepl, \stdClass $user)
 {
     $data = array('relateduserid' => $user->id, 'context' => $sepl->get_context(), 'other' => array('seplid' => $sepl->get_instance()->id));
     self::$preventcreatecall = false;
     /** @var grading_form_viewed $event */
     $event = self::create($data);
     self::$preventcreatecall = true;
     $event->set_sepl($sepl);
     $event->add_record_snapshot('user', $user);
     return $event;
 }
 /**
  * Create instance of event.
  *
  * @since Moodle 2.7
  *
  * @param \sepl $sepl
  * @param \stdClass $grade
  * @return submission_graded
  */
 public static function create_from_grade(\sepl $sepl, \stdClass $grade)
 {
     $data = array('context' => $sepl->get_context(), 'objectid' => $grade->id, 'relateduserid' => $grade->userid);
     self::$preventcreatecall = false;
     /** @var submission_graded $event */
     $event = self::create($data);
     self::$preventcreatecall = true;
     $event->set_sepl($sepl);
     $event->add_record_snapshot('sepl_grades', $grade);
     return $event;
 }
 /**
  * Create instance of event.
  *
  * @since Moodle 2.7
  *
  * @param \sepl $sepl
  * @param \stdClass $submission
  * @param bool $editable
  * @return assessable_submitted
  */
 public static function create_from_submission(\sepl $sepl, \stdClass $submission, $editable)
 {
     global $USER;
     $data = array('context' => $sepl->get_context(), 'objectid' => $submission->id, 'other' => array('submission_editable' => $editable));
     if (!empty($submission->userid) && $submission->userid != $USER->id) {
         $data['relateduserid'] = $submission->userid;
     }
     /** @var assessable_submitted $event */
     $event = self::create($data);
     $event->set_sepl($sepl);
     $event->add_record_snapshot('sepl_submission', $submission);
     return $event;
 }
Пример #13
0
 /**
  * list current marker
  *
  * @param stdClass $row - The row of data
  * @return id the user->id of the marker.
  */
 public function col_allocatedmarker(stdClass $row)
 {
     static $markers = null;
     static $markerlist = array();
     if ($markers === null) {
         list($sort, $params) = users_order_by_sql();
         $markers = get_users_by_capability($this->seplment->get_context(), 'mod/sepl:grade', '', $sort);
         $markerlist[0] = get_string('choosemarker', 'sepl');
         foreach ($markers as $marker) {
             $markerlist[$marker->id] = fullname($marker);
         }
     }
     if (empty($markerlist)) {
         // TODO: add some form of notification here that no markers are available.
         return '';
     }
     if ($this->is_downloading()) {
         if (isset($markers[$row->allocatedmarker])) {
             return fullname($markers[$row->allocatedmarker]);
         } else {
             return '';
         }
     }
     if ($this->quickgrading && has_capability('mod/sepl:manageallocations', $this->seplment->get_context()) && (empty($row->workflowstate) || $row->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_INMARKING || $row->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED)) {
         $name = 'quickgrade_' . $row->id . '_allocatedmarker';
         return html_writer::select($markerlist, $name, $row->allocatedmarker, false);
     } else {
         if (!empty($row->allocatedmarker)) {
             $output = '';
             if ($this->quickgrading) {
                 // Add hidden field for quickgrading page.
                 $name = 'quickgrade_' . $row->id . '_allocatedmarker';
                 $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $name, 'value' => $row->allocatedmarker));
             }
             $output .= $markerlist[$row->allocatedmarker];
             return $output;
         }
     }
 }
Пример #14
0
 /**
  * Process an uploaded zip file
  *
  * @param sepl $seplment - The seplment instance
  * @param sepl_feedback_file $fileplugin - The file feedback plugin
  * @return string - The html response
  */
 public function import_zip_files($seplment, $fileplugin)
 {
     global $CFG, $PAGE, $DB;
     core_php_time_limit::raise(ASSIGNFEEDBACK_FILE_MAXFILEUNZIPTIME);
     $packer = get_file_packer('application/zip');
     $feedbackfilesupdated = 0;
     $feedbackfilesadded = 0;
     $userswithnewfeedback = array();
     $contextid = $seplment->get_context()->id;
     $fs = get_file_storage();
     $files = $this->get_import_files($contextid);
     $currentgroup = groups_get_activity_group($seplment->get_course_module(), true);
     $allusers = $seplment->list_participants($currentgroup, false);
     $participants = array();
     foreach ($allusers as $user) {
         $participants[$seplment->get_uniqueid_for_user($user->id)] = $user;
     }
     foreach ($files as $unzippedfile) {
         // Set the timeout for unzipping each file.
         $user = null;
         $plugin = null;
         $filename = '';
         if ($this->is_valid_filename_for_import($seplment, $unzippedfile, $participants, $user, $plugin, $filename)) {
             if ($this->is_file_modified($seplment, $user, $plugin, $filename, $unzippedfile)) {
                 $grade = $seplment->get_user_grade($user->id, true);
                 if ($oldfile = $fs->get_file($contextid, 'seplfeedback_file', ASSIGNFEEDBACK_FILE_FILEAREA, $grade->id, '/', $filename)) {
                     // Update existing feedback file.
                     $oldfile->replace_file_with($unzippedfile);
                     $feedbackfilesupdated++;
                 } else {
                     // Create a new feedback file.
                     $newfilerecord = new stdClass();
                     $newfilerecord->contextid = $contextid;
                     $newfilerecord->component = 'seplfeedback_file';
                     $newfilerecord->filearea = ASSIGNFEEDBACK_FILE_FILEAREA;
                     $newfilerecord->filename = $filename;
                     $newfilerecord->filepath = '/';
                     $newfilerecord->itemid = $grade->id;
                     $fs->create_file_from_storedfile($newfilerecord, $unzippedfile);
                     $feedbackfilesadded++;
                 }
                 $userswithnewfeedback[$user->id] = 1;
                 // Update the number of feedback files for this user.
                 $fileplugin->update_file_count($grade);
                 // Update the last modified time on the grade which will trigger student notifications.
                 $seplment->notify_grade_modified($grade);
             }
         }
     }
     require_once $CFG->dirroot . '/mod/sepl/feedback/file/renderable.php';
     $importsummary = new seplfeedback_file_import_summary($seplment->get_course_module()->id, count($userswithnewfeedback), $feedbackfilesadded, $feedbackfilesupdated);
     $seplrenderer = $seplment->get_renderer();
     $renderer = $PAGE->get_renderer('seplfeedback_file');
     $o = '';
     $o .= $seplrenderer->render(new sepl_header($seplment->get_instance(), $seplment->get_context(), false, $seplment->get_course_module()->id, get_string('uploadzipsummary', 'seplfeedback_file')));
     $o .= $renderer->render($importsummary);
     $o .= $seplrenderer->render_footer();
     return $o;
 }
Пример #15
0
 /**
  * This function converts all of the base settings for an instance of
  * the old seplment to the new format. Then it calls each of the plugins
  * to see if they can help upgrade this seplment.
  * @param int $oldseplmentid (don't rely on the old seplment type even being installed)
  * @param string $log This string gets appended to during the conversion process
  * @return bool true or false
  */
 public function upgrade_seplment($oldseplmentid, &$log)
 {
     global $DB, $CFG, $USER;
     // Steps to upgrade an seplment.
     core_php_time_limit::raise(ASSIGN_MAX_UPGRADE_TIME_SECS);
     // Get the module details.
     $oldmodule = $DB->get_record('modules', array('name' => 'seplment'), '*', MUST_EXIST);
     $params = array('module' => $oldmodule->id, 'instance' => $oldseplmentid);
     $oldcoursemodule = $DB->get_record('course_modules', $params, '*', MUST_EXIST);
     $oldcontext = context_module::instance($oldcoursemodule->id);
     // We used to check for admin capability, but since Moodle 2.7 this is called
     // during restore of a mod_seplment module.
     // Also note that we do not check for any mod_seplment capabilities, because they can
     // be removed so that users don't add new instances of the broken old thing.
     if (!has_capability('mod/sepl:addinstance', $oldcontext)) {
         $log = get_string('couldnotcreatenewseplmentinstance', 'mod_sepl');
         return false;
     }
     // First insert an sepl instance to get the id.
     $oldseplment = $DB->get_record('seplment', array('id' => $oldseplmentid), '*', MUST_EXIST);
     $oldversion = get_config('seplment_' . $oldseplment->seplmenttype, 'version');
     $data = new stdClass();
     $data->course = $oldseplment->course;
     $data->name = $oldseplment->name;
     $data->intro = $oldseplment->intro;
     $data->introformat = $oldseplment->introformat;
     $data->alwaysshowdescription = 1;
     $data->sendnotifications = $oldseplment->emailteachers;
     $data->sendlatenotifications = $oldseplment->emailteachers;
     $data->duedate = $oldseplment->timedue;
     $data->allowsubmissionsfromdate = $oldseplment->timeavailable;
     $data->grade = $oldseplment->grade;
     $data->submissiondrafts = $oldseplment->resubmit;
     $data->requiresubmissionstatement = 0;
     $data->markingworkflow = 0;
     $data->markingallocation = 0;
     $data->cutoffdate = 0;
     // New way to specify no late submissions.
     if ($oldseplment->preventlate) {
         $data->cutoffdate = $data->duedate;
     }
     $data->teamsubmission = 0;
     $data->requireallteammemberssubmit = 0;
     $data->teamsubmissiongroupingid = 0;
     $data->blindmarking = 0;
     $data->attemptreopenmethod = 'none';
     $data->maxattempts = ASSIGN_UNLIMITED_ATTEMPTS;
     $newseplment = new sepl(null, null, null);
     if (!$newseplment->add_instance($data, false)) {
         $log = get_string('couldnotcreatenewseplmentinstance', 'mod_sepl');
         return false;
     }
     // Now create a new coursemodule from the old one.
     $newmodule = $DB->get_record('modules', array('name' => 'sepl'), '*', MUST_EXIST);
     $newcoursemodule = $this->duplicate_course_module($oldcoursemodule, $newmodule->id, $newseplment->get_instance()->id);
     if (!$newcoursemodule) {
         $log = get_string('couldnotcreatenewcoursemodule', 'mod_sepl');
         return false;
     }
     // Convert the base database tables (seplment, submission, grade).
     // These are used to store information in case a rollback is required.
     $gradingarea = null;
     $gradingdefinitions = null;
     $gradeidmap = array();
     $completiondone = false;
     $gradesdone = false;
     // From this point we want to rollback on failure.
     $rollback = false;
     try {
         $newseplment->set_context(context_module::instance($newcoursemodule->id));
         // The course module has now been created - time to update the core tables.
         // Copy intro files.
         $newseplment->copy_area_files_for_upgrade($oldcontext->id, 'mod_seplment', 'intro', 0, $newseplment->get_context()->id, 'mod_sepl', 'intro', 0);
         // Get the plugins to do their bit.
         foreach ($newseplment->get_submission_plugins() as $plugin) {
             if ($plugin->can_upgrade($oldseplment->seplmenttype, $oldversion)) {
                 $plugin->enable();
                 if (!$plugin->upgrade_settings($oldcontext, $oldseplment, $log)) {
                     $rollback = true;
                 }
             } else {
                 $plugin->disable();
             }
         }
         foreach ($newseplment->get_feedback_plugins() as $plugin) {
             if ($plugin->can_upgrade($oldseplment->seplmenttype, $oldversion)) {
                 $plugin->enable();
                 if (!$plugin->upgrade_settings($oldcontext, $oldseplment, $log)) {
                     $rollback = true;
                 }
             } else {
                 $plugin->disable();
             }
         }
         // See if there is advanced grading upgrades required.
         $gradingarea = $DB->get_record('grading_areas', array('contextid' => $oldcontext->id, 'areaname' => 'submission'), '*', IGNORE_MISSING);
         if ($gradingarea) {
             $params = array('id' => $gradingarea->id, 'contextid' => $newseplment->get_context()->id, 'component' => 'mod_sepl', 'areaname' => 'submissions');
             $DB->update_record('grading_areas', $params);
             $gradingdefinitions = $DB->get_records('grading_definitions', array('areaid' => $gradingarea->id));
         }
         // Upgrade availability data.
         \core_availability\info::update_dependency_id_across_course($newcoursemodule->course, 'course_modules', $oldcoursemodule->id, $newcoursemodule->id);
         // Upgrade completion data.
         $DB->set_field('course_modules_completion', 'coursemoduleid', $newcoursemodule->id, array('coursemoduleid' => $oldcoursemodule->id));
         $allcriteria = $DB->get_records('course_completion_criteria', array('moduleinstance' => $oldcoursemodule->id));
         foreach ($allcriteria as $criteria) {
             $criteria->module = 'sepl';
             $criteria->moduleinstance = $newcoursemodule->id;
             $DB->update_record('course_completion_criteria', $criteria);
         }
         $completiondone = true;
         // Migrate log entries so we don't lose them.
         $logparams = array('cmid' => $oldcoursemodule->id, 'course' => $oldcoursemodule->course);
         $DB->set_field('log', 'module', 'sepl', $logparams);
         $DB->set_field('log', 'cmid', $newcoursemodule->id, $logparams);
         // Copy all the submission data (and get plugins to do their bit).
         $oldsubmissions = $DB->get_records('seplment_submissions', array('seplment' => $oldseplmentid));
         foreach ($oldsubmissions as $oldsubmission) {
             $submission = new stdClass();
             $submission->seplment = $newseplment->get_instance()->id;
             $submission->userid = $oldsubmission->userid;
             $submission->timecreated = $oldsubmission->timecreated;
             $submission->timemodified = $oldsubmission->timemodified;
             $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
             // Because in mod_seplment there could only be one submission per student, it is always the latest.
             $submission->latest = 1;
             $submission->id = $DB->insert_record('sepl_submission', $submission);
             if (!$submission->id) {
                 $log .= get_string('couldnotinsertsubmission', 'mod_sepl', $submission->userid);
                 $rollback = true;
             }
             foreach ($newseplment->get_submission_plugins() as $plugin) {
                 if ($plugin->can_upgrade($oldseplment->seplmenttype, $oldversion)) {
                     if (!$plugin->upgrade($oldcontext, $oldseplment, $oldsubmission, $submission, $log)) {
                         $rollback = true;
                     }
                 }
             }
             if ($oldsubmission->timemarked) {
                 // Submission has been graded - create a grade record.
                 $grade = new stdClass();
                 $grade->seplment = $newseplment->get_instance()->id;
                 $grade->userid = $oldsubmission->userid;
                 $grade->grader = $oldsubmission->teacher;
                 $grade->timemodified = $oldsubmission->timemarked;
                 $grade->timecreated = $oldsubmission->timecreated;
                 $grade->grade = $oldsubmission->grade;
                 if ($oldsubmission->mailed) {
                     // The mailed flag goes in the flags table.
                     $flags = new stdClass();
                     $flags->userid = $oldsubmission->userid;
                     $flags->seplment = $newseplment->get_instance()->id;
                     $flags->mailed = 1;
                     $DB->insert_record('sepl_user_flags', $flags);
                 }
                 $grade->id = $DB->insert_record('sepl_grades', $grade);
                 if (!$grade->id) {
                     $log .= get_string('couldnotinsertgrade', 'mod_sepl', $grade->userid);
                     $rollback = true;
                 }
                 // Copy any grading instances.
                 if ($gradingarea) {
                     $gradeidmap[$grade->id] = $oldsubmission->id;
                     foreach ($gradingdefinitions as $definition) {
                         $params = array('definitionid' => $definition->id, 'itemid' => $oldsubmission->id);
                         $DB->set_field('grading_instances', 'itemid', $grade->id, $params);
                     }
                 }
                 foreach ($newseplment->get_feedback_plugins() as $plugin) {
                     if ($plugin->can_upgrade($oldseplment->seplmenttype, $oldversion)) {
                         if (!$plugin->upgrade($oldcontext, $oldseplment, $oldsubmission, $grade, $log)) {
                             $rollback = true;
                         }
                     }
                 }
             }
         }
         $newseplment->update_calendar($newcoursemodule->id);
         // Reassociate grade_items from the old seplment instance to the new sepl instance.
         // This includes outcome linked grade_items.
         $params = array('sepl', $newseplment->get_instance()->id, 'seplment', $oldseplment->id);
         $sql = 'UPDATE {grade_items} SET itemmodule = ?, iteminstance = ? WHERE itemmodule = ? AND iteminstance = ?';
         $DB->execute($sql, $params);
         // Create a mapping record to map urls from the old to the new seplment.
         $mapping = new stdClass();
         $mapping->oldcmid = $oldcoursemodule->id;
         $mapping->oldinstance = $oldseplment->id;
         $mapping->newcmid = $newcoursemodule->id;
         $mapping->newinstance = $newseplment->get_instance()->id;
         $mapping->timecreated = time();
         $DB->insert_record('seplment_upgrade', $mapping);
         $gradesdone = true;
     } catch (Exception $exception) {
         $rollback = true;
         $log .= get_string('conversionexception', 'mod_sepl', $exception->getMessage());
     }
     if ($rollback) {
         // Roll back the grades changes.
         if ($gradesdone) {
             // Reassociate grade_items from the new sepl instance to the old seplment instance.
             $params = array('seplment', $oldseplment->id, 'sepl', $newseplment->get_instance()->id);
             $sql = 'UPDATE {grade_items} SET itemmodule = ?, iteminstance = ? WHERE itemmodule = ? AND iteminstance = ?';
             $DB->execute($sql, $params);
         }
         // Roll back the completion changes.
         if ($completiondone) {
             $DB->set_field('course_modules_completion', 'coursemoduleid', $oldcoursemodule->id, array('coursemoduleid' => $newcoursemodule->id));
             $allcriteria = $DB->get_records('course_completion_criteria', array('moduleinstance' => $newcoursemodule->id));
             foreach ($allcriteria as $criteria) {
                 $criteria->module = 'seplment';
                 $criteria->moduleinstance = $oldcoursemodule->id;
                 $DB->update_record('course_completion_criteria', $criteria);
             }
         }
         // Roll back the log changes.
         $logparams = array('cmid' => $newcoursemodule->id, 'course' => $newcoursemodule->course);
         $DB->set_field('log', 'module', 'seplment', $logparams);
         $DB->set_field('log', 'cmid', $oldcoursemodule->id, $logparams);
         // Roll back the advanced grading update.
         if ($gradingarea) {
             foreach ($gradeidmap as $newgradeid => $oldsubmissionid) {
                 foreach ($gradingdefinitions as $definition) {
                     $DB->set_field('grading_instances', 'itemid', $oldsubmissionid, array('definitionid' => $definition->id, 'itemid' => $newgradeid));
                 }
             }
             $params = array('id' => $gradingarea->id, 'contextid' => $oldcontext->id, 'component' => 'mod_seplment', 'areaname' => 'submission');
             $DB->update_record('grading_areas', $params);
         }
         $newseplment->delete_instance();
         return false;
     }
     // Delete the old seplment (use object delete).
     $cm = get_coursemodule_from_id('', $oldcoursemodule->id, $oldcoursemodule->course);
     if ($cm) {
         course_delete_module($cm->id);
     }
     rebuild_course_cache($oldcoursemodule->course);
     return true;
 }
Пример #16
0
/**
 * File browsing support for sepl module.
 *
 * @param file_browser $browser
 * @param object $areas
 * @param object $course
 * @param object $cm
 * @param object $context
 * @param string $filearea
 * @param int $itemid
 * @param string $filepath
 * @param string $filename
 * @return object file_info instance or null if not found
 */
function sepl_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename)
{
    global $CFG;
    require_once $CFG->dirroot . '/mod/sepl/locallib.php';
    if ($context->contextlevel != CONTEXT_MODULE) {
        return null;
    }
    $urlbase = $CFG->wwwroot . '/pluginfile.php';
    $fs = get_file_storage();
    $filepath = is_null($filepath) ? '/' : $filepath;
    $filename = is_null($filename) ? '.' : $filename;
    // Need to find where this belongs to.
    $seplment = new sepl($context, $cm, $course);
    if ($filearea === ASSIGN_INTROATTACHMENT_FILEAREA) {
        if (!has_capability('moodle/course:managefiles', $context)) {
            // Students can not peak here!
            return null;
        }
        if (!($storedfile = $fs->get_file($seplment->get_context()->id, 'mod_sepl', $filearea, 0, $filepath, $filename))) {
            return null;
        }
        return new file_info_stored($browser, $seplment->get_context(), $storedfile, $urlbase, $filearea, $itemid, true, true, false);
    }
    $pluginowner = null;
    foreach ($seplment->get_submission_plugins() as $plugin) {
        if ($plugin->is_visible()) {
            $pluginareas = $plugin->get_file_areas();
            if (array_key_exists($filearea, $pluginareas)) {
                $pluginowner = $plugin;
                break;
            }
        }
    }
    if (!$pluginowner) {
        foreach ($seplment->get_feedback_plugins() as $plugin) {
            if ($plugin->is_visible()) {
                $pluginareas = $plugin->get_file_areas();
                if (array_key_exists($filearea, $pluginareas)) {
                    $pluginowner = $plugin;
                    break;
                }
            }
        }
    }
    if (!$pluginowner) {
        return null;
    }
    $result = $pluginowner->get_file_info($browser, $filearea, $itemid, $filepath, $filename);
    return $result;
}
Пример #17
0
 /**
  * Returns submissions for the requested seplment ids
  *
  * @param int[] $seplmentids
  * @param string $status only return submissions with this status
  * @param int $since only return submissions with timemodified >= since
  * @param int $before only return submissions with timemodified <= before
  * @return array of submissions for each requested seplment
  * @since Moodle 2.5
  */
 public static function get_submissions($seplmentids, $status = '', $since = 0, $before = 0)
 {
     global $DB, $CFG;
     require_once "{$CFG->dirroot}/mod/sepl/locallib.php";
     $params = self::validate_parameters(self::get_submissions_parameters(), array('seplmentids' => $seplmentids, 'status' => $status, 'since' => $since, 'before' => $before));
     $warnings = array();
     $seplments = array();
     // Check the user is allowed to get the submissions for the seplments requested.
     $placeholders = array();
     list($inorequalsql, $placeholders) = $DB->get_in_or_equal($params['seplmentids'], SQL_PARAMS_NAMED);
     $sql = "SELECT cm.id, cm.instance FROM {course_modules} cm JOIN {modules} md ON md.id = cm.module " . "WHERE md.name = :modname AND cm.instance " . $inorequalsql;
     $placeholders['modname'] = 'sepl';
     $cms = $DB->get_records_sql($sql, $placeholders);
     $sepls = array();
     foreach ($cms as $cm) {
         try {
             $context = context_module::instance($cm->id);
             self::validate_context($context);
             require_capability('mod/sepl:grade', $context);
             $sepl = new sepl($context, null, null);
             $sepls[] = $sepl;
         } catch (Exception $e) {
             $warnings[] = array('item' => 'seplment', 'itemid' => $cm->instance, 'warningcode' => '1', 'message' => 'No access rights in module context');
         }
     }
     foreach ($sepls as $sepl) {
         $submissions = array();
         $submissionplugins = $sepl->get_submission_plugins();
         $placeholders = array('seplid1' => $sepl->get_instance()->id, 'seplid2' => $sepl->get_instance()->id);
         $submissionmaxattempt = 'SELECT mxs.userid, MAX(mxs.attemptnumber) AS maxattempt
                                  FROM {sepl_submission} mxs
                                  WHERE mxs.seplment = :seplid1 GROUP BY mxs.userid';
         $sql = "SELECT mas.id, mas.seplment,mas.userid," . "mas.timecreated,mas.timemodified,mas.status,mas.groupid,mas.attemptnumber " . "FROM {sepl_submission} mas " . "JOIN ( " . $submissionmaxattempt . " ) smx ON mas.userid = smx.userid " . "WHERE mas.seplment = :seplid2 AND mas.attemptnumber = smx.maxattempt";
         if (!empty($params['status'])) {
             $placeholders['status'] = $params['status'];
             $sql = $sql . " AND mas.status = :status";
         }
         if (!empty($params['before'])) {
             $placeholders['since'] = $params['since'];
             $placeholders['before'] = $params['before'];
             $sql = $sql . " AND mas.timemodified BETWEEN :since AND :before";
         } else {
             $placeholders['since'] = $params['since'];
             $sql = $sql . " AND mas.timemodified >= :since";
         }
         $submissionrecords = $DB->get_records_sql($sql, $placeholders);
         if (!empty($submissionrecords)) {
             $fs = get_file_storage();
             foreach ($submissionrecords as $submissionrecord) {
                 $submission = array('id' => $submissionrecord->id, 'userid' => $submissionrecord->userid, 'timecreated' => $submissionrecord->timecreated, 'timemodified' => $submissionrecord->timemodified, 'status' => $submissionrecord->status, 'attemptnumber' => $submissionrecord->attemptnumber, 'groupid' => $submissionrecord->groupid);
                 foreach ($submissionplugins as $submissionplugin) {
                     $plugin = array('name' => $submissionplugin->get_name(), 'type' => $submissionplugin->get_type());
                     // Subtype is 'seplsubmission', type is currently 'file' or 'onlinetext'.
                     $component = $submissionplugin->get_subtype() . '_' . $submissionplugin->get_type();
                     $fileareas = $submissionplugin->get_file_areas();
                     foreach ($fileareas as $filearea => $name) {
                         $fileareainfo = array('area' => $filearea);
                         $files = $fs->get_area_files($sepl->get_context()->id, $component, $filearea, $submissionrecord->id, "timemodified", false);
                         foreach ($files as $file) {
                             $filepath = $file->get_filepath() . $file->get_filename();
                             $fileurl = file_encode_url($CFG->wwwroot . '/webservice/pluginfile.php', '/' . $sepl->get_context()->id . '/' . $component . '/' . $filearea . '/' . $submissionrecord->id . $filepath);
                             $fileinfo = array('filepath' => $filepath, 'fileurl' => $fileurl);
                             $fileareainfo['files'][] = $fileinfo;
                         }
                         $plugin['fileareas'][] = $fileareainfo;
                     }
                     $editorfields = $submissionplugin->get_editor_fields();
                     foreach ($editorfields as $name => $description) {
                         $editorfieldinfo = array('name' => $name, 'description' => $description, 'text' => $submissionplugin->get_editor_text($name, $submissionrecord->id), 'format' => $submissionplugin->get_editor_format($name, $submissionrecord->id));
                         $plugin['editorfields'][] = $editorfieldinfo;
                     }
                     $submission['plugins'][] = $plugin;
                 }
                 $submissions[] = $submission;
             }
         } else {
             $warnings[] = array('item' => 'module', 'itemid' => $sepl->get_instance()->id, 'warningcode' => '3', 'message' => 'No submissions found');
         }
         $seplments[] = array('seplmentid' => $sepl->get_instance()->id, 'submissions' => $submissions);
     }
     $result = array('seplments' => $seplments, 'warnings' => $warnings);
     return $result;
 }
Пример #18
0
 /**
  * Copy annotations, comments, pages, and other required content from the source user to the current group member
  * being procssed when using applytoall.
  *
  * @param int|\sepl $seplment
  * @param stdClass $grade
  * @param int $sourceuserid
  * @return bool
  */
 public static function copy_drafts_from_to($seplment, $grade, $sourceuserid)
 {
     global $DB;
     // Delete any existing annotations and comments from current user.
     $DB->delete_records('seplfeedback_editpdf_annot', array('gradeid' => $grade->id));
     $DB->delete_records('seplfeedback_editpdf_cmnt', array('gradeid' => $grade->id));
     // Get gradeid, annotations and comments from sourceuserid.
     $sourceusergrade = $seplment->get_user_grade($sourceuserid, true, $grade->attemptnumber);
     $annotations = $DB->get_records('seplfeedback_editpdf_annot', array('gradeid' => $sourceusergrade->id, 'draft' => 1));
     $comments = $DB->get_records('seplfeedback_editpdf_cmnt', array('gradeid' => $sourceusergrade->id, 'draft' => 1));
     $contextid = $seplment->get_context()->id;
     $sourceitemid = $sourceusergrade->id;
     // Add annotations and comments to current user to generate feedback file.
     foreach ($annotations as $annotation) {
         $annotation->gradeid = $grade->id;
         $DB->insert_record('seplfeedback_editpdf_annot', $annotation);
     }
     foreach ($comments as $comment) {
         $comment->gradeid = $grade->id;
         $DB->insert_record('seplfeedback_editpdf_cmnt', $comment);
     }
     $fs = get_file_storage();
     // Copy the stamp files.
     self::replace_files_from_to($fs, $contextid, $sourceitemid, $grade->id, document_services::STAMPS_FILEAREA, true);
     // Copy the PAGE_IMAGE_FILEAREA files.
     self::replace_files_from_to($fs, $contextid, $sourceitemid, $grade->id, document_services::PAGE_IMAGE_FILEAREA);
     return true;
 }