/**
  * 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.
  *
  * @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;
 }
Ejemplo n.º 5
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.
  *
  * @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;
 }
 /**
  * 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 $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.
  *
  * @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 $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;
 }
 /**
  * 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);
 }
Ejemplo n.º 13
0
/**
 * Serves seplment submissions and other files.
 *
 * @param mixed $course course or id of the course
 * @param mixed $cm course module or id of the course module
 * @param context $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - just send the file
 */
function seplsubmission_onlinetext_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload)
{
    global $DB, $CFG;
    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }
    require_login($course, false, $cm);
    $itemid = (int) array_shift($args);
    $record = $DB->get_record('sepl_submission', array('id' => $itemid), 'userid, seplment, groupid', MUST_EXIST);
    $userid = $record->userid;
    $groupid = $record->groupid;
    require_once $CFG->dirroot . '/mod/sepl/locallib.php';
    $sepl = new sepl($context, $cm, $course);
    if ($sepl->get_instance()->id != $record->seplment) {
        return false;
    }
    if ($sepl->get_instance()->teamsubmission && !$sepl->can_view_group_submission($groupid)) {
        return false;
    }
    if (!$sepl->get_instance()->teamsubmission && !$sepl->can_view_submission($userid)) {
        return false;
    }
    $relativepath = implode('/', $args);
    $fullpath = "/{$context->id}/seplsubmission_onlinetext/{$filearea}/{$itemid}/{$relativepath}";
    $fs = get_file_storage();
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) || $file->is_directory()) {
        return false;
    }
    // Download MUST be forced - security!
    send_stored_file($file, 0, 0, true);
}
Ejemplo n.º 14
0
 /**
  * Test delivery of grade notifications as controlled by marking workflow.
  */
 public function test_markingworkflow_cron()
 {
     // First run cron so there are no messages waiting to be sent (from other tests).
     cron_setup_user();
     sepl::cron();
     // Now create an seplment with marking workflow enabled.
     $this->setUser($this->editingteachers[0]);
     $sepl = $this->create_instance(array('sendstudentnotifications' => 1, 'markingworkflow' => 1));
     // Simulate adding a grade.
     $this->setUser($this->teachers[0]);
     $data = new stdClass();
     $data->grade = '50.0';
     // This student will not receive notification.
     $data->workflowstate = ASSIGN_MARKING_WORKFLOW_STATE_READYFORRELEASE;
     $sepl->testable_apply_grade_to_user($data, $this->students[0]->id, 0);
     // This student will receive notification.
     $data->workflowstate = ASSIGN_MARKING_WORKFLOW_STATE_RELEASED;
     $sepl->testable_apply_grade_to_user($data, $this->students[1]->id, 0);
     // Now run cron and see that one message was sent.
     $this->preventResetByRollback();
     $sink = $this->redirectMessages();
     cron_setup_user();
     $this->expectOutputRegex('/Done processing 1 seplment submissions/');
     sepl::cron();
     $messages = $sink->get_messages();
     $this->assertEquals(1, count($messages));
     $this->assertEquals($messages[0]->useridto, $this->students[1]->id);
     $this->assertEquals($sepl->get_instance()->name, $messages[0]->contexturlname);
 }
Ejemplo n.º 15
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;
 }
Ejemplo n.º 16
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;
 }
 public function test_upgrade_offline_seplment()
 {
     global $DB, $CFG;
     $commentconfig = false;
     if (!empty($CFG->usecomments)) {
         $commentconfig = $CFG->usecomments;
     }
     $CFG->usecomments = false;
     $this->setUser($this->editingteachers[0]);
     $generator = $this->getDataGenerator()->get_plugin_generator('mod_seplment');
     $params = array('course' => $this->course->id, 'seplmenttype' => 'offline');
     $seplment = $generator->create_instance($params);
     $this->setAdminUser();
     $log = '';
     $upgrader = new sepl_upgrade_manager();
     $this->assertTrue($upgrader->upgrade_seplment($seplment->id, $log));
     $record = $DB->get_record('sepl', array('course' => $this->course->id));
     $cm = get_coursemodule_from_instance('sepl', $record->id);
     $context = context_module::instance($cm->id);
     $sepl = new sepl($context, $cm, $this->course);
     $plugin = $sepl->get_submission_plugin_by_type('onlinetext');
     $this->assertEmpty($plugin->is_enabled());
     $plugin = $sepl->get_submission_plugin_by_type('comments');
     $this->assertEmpty($plugin->is_enabled());
     $plugin = $sepl->get_submission_plugin_by_type('file');
     $this->assertEmpty($plugin->is_enabled());
     $plugin = $sepl->get_feedback_plugin_by_type('comments');
     $this->assertNotEmpty($plugin->is_enabled());
     $plugin = $sepl->get_feedback_plugin_by_type('file');
     $this->assertEmpty($plugin->is_enabled());
     $plugin = $sepl->get_feedback_plugin_by_type('offline');
     $this->assertEmpty($plugin->is_enabled());
     $CFG->usecomments = $commentconfig;
     course_delete_module($cm->id);
 }
 /**
  * Test reveal_identities
  */
 public function test_reveal_identities()
 {
     global $DB, $USER;
     $this->resetAfterTest(true);
     // Create a course and seplment and users.
     $course = self::getDataGenerator()->create_course();
     $teacher = self::getDataGenerator()->create_user();
     $teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
     $this->getDataGenerator()->enrol_user($teacher->id, $course->id, $teacherrole->id);
     $this->setUser($teacher);
     $generator = $this->getDataGenerator()->get_plugin_generator('mod_sepl');
     $params['course'] = $course->id;
     $params['submissiondrafts'] = 1;
     $params['sendnotifications'] = 0;
     $params['blindmarking'] = 1;
     $instance = $generator->create_instance($params);
     $cm = get_coursemodule_from_instance('sepl', $instance->id);
     $context = context_module::instance($cm->id);
     $sepl = new sepl($context, $cm, $course);
     $student1 = self::getDataGenerator()->create_user();
     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
     $this->getDataGenerator()->enrol_user($student1->id, $course->id, $studentrole->id);
     $this->setUser($student1);
     $this->setExpectedException('required_capability_exception');
     $result = mod_sepl_external::reveal_identities($instance->id);
     $result = external_api::clean_returnvalue(mod_sepl_external::reveal_identities_returns(), $result);
     $this->assertEquals(1, count($result));
     $this->assertEquals(true, $sepl->is_blind_marking());
     $this->setUser($teacher);
     $result = mod_sepl_external::reveal_identities($instance->id);
     $result = external_api::clean_returnvalue(mod_sepl_external::reveal_identities_returns(), $result);
     $this->assertEquals(0, count($result));
     $this->assertEquals(false, $sepl->is_blind_marking());
     $generator = $this->getDataGenerator()->get_plugin_generator('mod_sepl');
     $params['course'] = $course->id;
     $params['submissiondrafts'] = 1;
     $params['sendnotifications'] = 0;
     $params['blindmarking'] = 0;
     $instance = $generator->create_instance($params);
     $cm = get_coursemodule_from_instance('sepl', $instance->id);
     $context = context_module::instance($cm->id);
     $sepl = new sepl($context, $cm, $course);
     $result = mod_sepl_external::reveal_identities($instance->id);
     $result = external_api::clean_returnvalue(mod_sepl_external::reveal_identities_returns(), $result);
     $this->assertEquals(1, count($result));
     $this->assertEquals(false, $sepl->is_blind_marking());
 }
Ejemplo n.º 19
0
 /**
  * Any data processing needed before the form is displayed
  * (needed to set up draft areas for editor and filemanager elements)
  * @param array $defaultvalues
  */
 public function data_preprocessing(&$defaultvalues)
 {
     global $DB;
     $ctx = null;
     if ($this->current && $this->current->coursemodule) {
         $cm = get_coursemodule_from_instance('sepl', $this->current->id, 0, false, MUST_EXIST);
         $ctx = context_module::instance($cm->id);
     }
     $seplment = new sepl($ctx, null, null);
     if ($this->current && $this->current->course) {
         if (!$ctx) {
             $ctx = context_course::instance($this->current->course);
         }
         $course = $DB->get_record('course', array('id' => $this->current->course), '*', MUST_EXIST);
         $seplment->set_course($course);
     }
     $draftitemid = file_get_submitted_draft_itemid('introattachments');
     file_prepare_draft_area($draftitemid, $ctx->id, 'mod_sepl', ASSIGN_INTROATTACHMENT_FILEAREA, 0, array('subdirs' => 0));
     $defaultvalues['introattachments'] = $draftitemid;
     $seplment->plugin_data_preprocessing($defaultvalues);
 }
Ejemplo n.º 20
0
 /**
  * Fetch the plugin by its type.
  *
  * @return sepl_submission_plugin
  */
 protected function get_submission_plugin()
 {
     global $CFG;
     if (!$this->plugin || !$this->cmid) {
         return null;
     }
     require_once $CFG->dirroot . '/mod/sepl/locallib.php';
     $context = context_module::instance($this->cmid);
     $seplment = new sepl($context, null, null);
     return $seplment->get_submission_plugin_by_type($this->plugin);
 }
Ejemplo n.º 21
0
 */
use seplfeedback_editpdf\document_services;
use seplfeedback_editpdf\page_editor;
use seplfeedback_editpdf\comments_quick_list;
define('AJAX_SCRIPT', true);
require '../../../../config.php';
require_once $CFG->dirroot . '/mod/sepl/locallib.php';
require_sesskey();
$action = optional_param('action', '', PARAM_ALPHANUM);
$seplmentid = required_param('seplmentid', PARAM_INT);
$userid = required_param('userid', PARAM_INT);
$attemptnumber = required_param('attemptnumber', PARAM_INT);
$readonly = optional_param('readonly', false, PARAM_BOOL);
$cm = \get_coursemodule_from_instance('sepl', $seplmentid, 0, false, MUST_EXIST);
$context = \context_module::instance($cm->id);
$seplment = new \sepl($context, null, null);
require_login($seplment->get_course(), false, $cm);
if (!$seplment->can_view_submission($userid)) {
    print_error('nopermission');
}
if ($action == 'loadallpages') {
    $draft = true;
    if (!has_capability('mod/sepl:grade', $context)) {
        $draft = false;
        $readonly = true;
        // A student always sees the readonly version.
        require_capability('mod/sepl:submit', $context);
    }
    // Whoever is viewing the readonly version should not use the drafts, but the actual annotations.
    if ($readonly) {
        $draft = false;
Ejemplo n.º 22
0
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * Displays information about all the seplment modules in the requested course
 *
 * @package   mod_sepl
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once "../../config.php";
require_once $CFG->dirroot . '/mod/sepl/locallib.php';
// For this type of page this is the course id.
$id = required_param('id', PARAM_INT);
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
require_login($course);
$PAGE->set_url('/mod/sepl/index.php', array('id' => $id));
$PAGE->set_pagelayout('incourse');
\mod_sepl\event\course_module_instance_list_viewed::create_from_course($course)->trigger();
// Print the header.
$strplural = get_string("modulenameplural", "sepl");
$PAGE->navbar->add($strplural);
$PAGE->set_title($strplural);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($strplural));
$context = context_course::instance($course->id);
require_capability('mod/sepl:view', $context);
$sepl = new sepl($context, null, $course);
// Get the sepl to render the page.
echo $sepl->view('viewcourseindex');
Ejemplo n.º 23
0
/**
 * Serves intro attachment files.
 *
 * @param mixed $course course or id of the course
 * @param mixed $cm course module or id of the course module
 * @param context $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @param array $options additional options affecting the file serving
 * @return bool false if file not found, does not return if found - just send the file
 */
function sepl_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $CFG;
    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }
    require_login($course, false, $cm);
    if (!has_capability('mod/sepl:view', $context)) {
        return false;
    }
    require_once $CFG->dirroot . '/mod/sepl/locallib.php';
    $sepl = new sepl($context, $cm, $course);
    if ($filearea !== ASSIGN_INTROATTACHMENT_FILEAREA) {
        return false;
    }
    if (!$sepl->show_intro()) {
        return false;
    }
    $itemid = (int) array_shift($args);
    if ($itemid != 0) {
        return false;
    }
    $relativepath = implode('/', $args);
    $fullpath = "/{$context->id}/mod_sepl/{$filearea}/{$itemid}/{$relativepath}";
    $fs = get_file_storage();
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
        return false;
    }
    send_stored_file($file, 0, 0, $forcedownload, $options);
}
Ejemplo n.º 24
0
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * This file is the entry point to the sepl module. All pages are rendered from here
 *
 * @package   mod_sepl
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once '../../config.php';
require_once $CFG->dirroot . '/mod/sepl/locallib.php';
$id = required_param('id', PARAM_INT);
$urlparams = array('id' => $id, 'action' => optional_param('action', '', PARAM_TEXT), 'rownum' => optional_param('rownum', 0, PARAM_INT), 'useridlistid' => optional_param('action', 0, PARAM_INT));
$url = new moodle_url('/mod/sepl/view.php', $urlparams);
list($course, $cm) = get_course_and_cm_from_cmid($id, 'sepl');
require_login($course, true, $cm);
$PAGE->set_url($url);
$context = context_module::instance($cm->id);
require_capability('mod/sepl:view', $context);
$sepl = new sepl($context, $cm, $course);
$completion = new completion_info($course);
$completion->set_module_viewed($cm);
// Get the sepl class to
// render the page.
echo $sepl->view(optional_param('action', '', PARAM_TEXT));
Ejemplo n.º 25
0
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
define('AJAX_SCRIPT', true);
// To be able to process concurrent ajax request with the generate pdf ajax request we can not use cookie.
define('NO_MOODLE_COOKIES', true);
use seplfeedback_editpdf\document_services;
require_once '../../../../config.php';
try {
    $seplmentid = required_param('seplmentid', PARAM_INT);
    $userid = required_param('userid', PARAM_INT);
    $attemptnumber = required_param('attemptnumber', PARAM_INT);
    // Retrieve the seplments.
    require_once $CFG->dirroot . '/mod/sepl/locallib.php';
    $cm = get_coursemodule_from_instance('sepl', $seplmentid, 0, false, MUST_EXIST);
    $context = context_module::instance($cm->id);
    $seplment = new sepl($context, null, null);
    // Get the generated images from file API call.
    $grade = $seplment->get_user_grade($userid, false, $attemptnumber);
    // Check we found a grade.
    if (empty($grade)) {
        throw new coding_exception('grade not found');
    }
    // No need to handle the readonly files here, the should be already generated.
    $component = 'seplfeedback_editpdf';
    $filearea = document_services::PAGE_IMAGE_FILEAREA;
    $filepath = '/';
    $fs = get_file_storage();
    $files = $fs->get_directory_files($context->id, $component, $filearea, $grade->id, $filepath);
    // The important security part: we ONLY RETURN the total NUMBER of generated images.
    echo $OUTPUT->header();
    echo json_encode(count($files));
Ejemplo n.º 26
0
 public function testable_view_batch_markingallocation($selectedusers)
 {
     $mform = $this->testable_grading_batch_operations_form('setmarkingallocation', $selectedusers);
     return parent::view_batch_markingallocation($mform);
 }
Ejemplo n.º 27
0
 /**
  * Return things to the renderer.
  *
  * @return bool Can this user view all grades (the gradebook)
  */
 public function can_view_all_grades()
 {
     $context = $this->seplment->get_course_context();
     return has_capability('gradereport/grader:view', $context) && has_capability('moodle/grade:viewall', $context);
 }
Ejemplo n.º 28
0
/**
 * Callback called by comment::get_comments() and comment::add(). Gives an opportunity to enforce blind-marking.
 *
 * @param array $comments
 * @param stdClass $options
 * @return array
 * @throws comment_exception
 */
function seplsubmission_comments_comment_display($comments, $options)
{
    global $CFG, $DB, $USER;
    if ($options->commentarea != 'submission_comments' && $options->commentarea != 'submission_comments_upgrade') {
        throw new comment_exception('invalidcommentarea');
    }
    if (!($submission = $DB->get_record('sepl_submission', array('id' => $options->itemid)))) {
        throw new comment_exception('invalidcommentitemid');
    }
    $context = $options->context;
    $cm = $options->cm;
    $course = $options->courseid;
    require_once $CFG->dirroot . '/mod/sepl/locallib.php';
    $seplment = new sepl($context, $cm, $course);
    if ($seplment->get_instance()->id != $submission->seplment) {
        throw new comment_exception('invalidcontext');
    }
    if ($seplment->is_blind_marking() && !empty($comments)) {
        // Blind marking is being used, may need to map unique anonymous ids to the comments.
        $usermappings = array();
        $hiddenuserstr = trim(get_string('hiddenuser', 'sepl'));
        $guestuser = guest_user();
        foreach ($comments as $comment) {
            // Anonymize the comments.
            if (empty($usermappings[$comment->userid])) {
                // The blind-marking information for this commenter has not been generated; do so now.
                $anonid = $seplment->get_uniqueid_for_user($comment->userid);
                $commenter = new stdClass();
                $commenter->firstname = $hiddenuserstr;
                $commenter->lastname = $anonid;
                $commenter->picture = 0;
                $commenter->id = $guestuser->id;
                $commenter->email = $guestuser->email;
                $commenter->imagealt = $guestuser->imagealt;
                // Temporarily store blind-marking information for use in later comments if necessary.
                $usermappings[$comment->userid]->fullname = fullname($commenter);
                $usermappings[$comment->userid]->avatar = $seplment->get_renderer()->user_picture($commenter, array('size' => 18, 'link' => false));
            }
            // Set blind-marking information for this comment.
            $comment->fullname = $usermappings[$comment->userid]->fullname;
            $comment->avatar = $usermappings[$comment->userid]->avatar;
            $comment->profileurl = null;
        }
    }
    return $comments;
}
Ejemplo n.º 29
0
 /**
  * Trigger the grading_table_viewed event.
  *
  * @param int $seplid the sepl instance id
  * @return array of warnings and status result
  * @since Moodle 3.0
  * @throws moodle_exception
  */
 public static function view_grading_table($seplid)
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . "/mod/sepl/locallib.php";
     $params = self::validate_parameters(self::view_grading_table_parameters(), array('seplid' => $seplid));
     $warnings = array();
     // Request and permission validation.
     $sepl = $DB->get_record('sepl', array('id' => $params['seplid']), 'id', MUST_EXIST);
     list($course, $cm) = get_course_and_cm_from_instance($sepl, 'sepl');
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     require_capability('mod/sepl:view', $context);
     $sepl = new sepl($context, null, null);
     $sepl->require_view_grades();
     \mod_sepl\event\grading_table_viewed::create_from_sepl($sepl)->trigger();
     $result = array();
     $result['status'] = true;
     $result['warnings'] = $warnings;
     return $result;
 }
Ejemplo n.º 30
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;
 }