コード例 #1
0
 /**
  * Does this file exist in any of the current files supported by this plugin for this user?
  *
  * @param sepl $seplment - The seplment instance
  * @param stdClass $user The user matching this uploaded file
  * @param sepl_plugin $plugin The matching plugin from the filename
  * @param string $filename The parsed filename from the zip
  * @param stored_file $fileinfo The info about the extracted file from the zip
  * @return bool - True if the file has been modified or is new
  */
 public function is_file_modified($seplment, $user, $plugin, $filename, $fileinfo)
 {
     $sg = null;
     if ($plugin->get_subtype() == 'seplsubmission') {
         $sg = $seplment->get_user_submission($user->id, false);
     } else {
         if ($plugin->get_subtype() == 'seplfeedback') {
             $sg = $seplment->get_user_grade($user->id, false);
         } else {
             return false;
         }
     }
     if (!$sg) {
         return true;
     }
     foreach ($plugin->get_files($sg, $user) as $pluginfilename => $file) {
         if ($pluginfilename == $filename) {
             // Extract the file and compare hashes.
             $contenthash = '';
             if (is_array($file)) {
                 $content = reset($file);
                 $contenthash = sha1($content);
             } else {
                 $contenthash = $file->get_contenthash();
             }
             if ($contenthash != $fileinfo->get_contenthash()) {
                 return true;
             } else {
                 return false;
             }
         }
     }
     return true;
 }
コード例 #2
0
 /**
  * Test submit_for_grading
  */
 public function test_submit_for_grading()
 {
     global $DB, $USER;
     $this->resetAfterTest(true);
     // Create a course and seplment and users.
     $course = self::getDataGenerator()->create_course();
     set_config('submissionreceipts', 0, 'sepl');
     $generator = $this->getDataGenerator()->get_plugin_generator('mod_sepl');
     $params['course'] = $course->id;
     $params['seplsubmission_onlinetext_enabled'] = 1;
     $params['submissiondrafts'] = 1;
     $params['sendnotifications'] = 0;
     $params['requiresubmissionstatement'] = 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);
     // Create a student1 with an online text submission.
     // Simulate a submission.
     $this->setUser($student1);
     $submission = $sepl->get_user_submission($student1->id, true);
     $data = new stdClass();
     $data->onlinetext_editor = array('itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', 'format' => FORMAT_MOODLE);
     $plugin = $sepl->get_submission_plugin_by_type('onlinetext');
     $plugin->save($submission, $data);
     $result = mod_sepl_external::submit_for_grading($instance->id, false);
     $result = external_api::clean_returnvalue(mod_sepl_external::submit_for_grading_returns(), $result);
     // Should be 1 fail because the submission statement was not aceptted.
     $this->assertEquals(1, count($result));
     $result = mod_sepl_external::submit_for_grading($instance->id, true);
     $result = external_api::clean_returnvalue(mod_sepl_external::submit_for_grading_returns(), $result);
     // Check for 0 warnings.
     $this->assertEquals(0, count($result));
     $submission = $sepl->get_user_submission($student1->id, false);
     $this->assertEquals(ASSIGN_SUBMISSION_STATUS_SUBMITTED, $submission->status);
 }
コード例 #3
0
 /**
  * Format the submission and feedback columns.
  *
  * @param string $colname The column name
  * @param stdClass $row The submission row
  * @return mixed string or NULL
  */
 public function other_cols($colname, $row)
 {
     // For extra user fields the result is already in $row.
     if (empty($this->plugincache[$colname])) {
         return $row->{$colname};
     }
     // This must be a plugin field.
     $plugincache = $this->plugincache[$colname];
     $plugin = $plugincache[0];
     $field = null;
     if (isset($plugincache[1])) {
         $field = $plugincache[1];
     }
     if ($plugin->is_visible() && $plugin->is_enabled()) {
         if ($plugin->get_subtype() == 'seplsubmission') {
             if ($this->seplment->get_instance()->teamsubmission) {
                 $group = false;
                 $submission = false;
                 $this->get_group_and_submission($row->id, $group, $submission, -1);
                 if ($submission) {
                     if ($submission->status == ASSIGN_SUBMISSION_STATUS_REOPENED) {
                         // For a newly reopened submission - we want to show the previous submission in the table.
                         $this->get_group_and_submission($row->id, $group, $submission, $submission->attemptnumber - 1);
                     }
                     if (isset($field)) {
                         return $plugin->get_editor_text($field, $submission->id);
                     }
                     return $this->format_plugin_summary_with_link($plugin, $submission, 'grading', array());
                 }
             } else {
                 if ($row->submissionid) {
                     if ($row->status == ASSIGN_SUBMISSION_STATUS_REOPENED) {
                         // For a newly reopened submission - we want to show the previous submission in the table.
                         $submission = $this->seplment->get_user_submission($row->userid, false, $row->attemptnumber - 1);
                     } else {
                         $submission = new stdClass();
                         $submission->id = $row->submissionid;
                         $submission->timecreated = $row->firstsubmission;
                         $submission->timemodified = $row->timesubmitted;
                         $submission->seplment = $this->seplment->get_instance()->id;
                         $submission->userid = $row->userid;
                         $submission->attemptnumber = $row->attemptnumber;
                     }
                     // Field is used for only for import/export and refers the the fieldname for the text editor.
                     if (isset($field)) {
                         return $plugin->get_editor_text($field, $submission->id);
                     }
                     return $this->format_plugin_summary_with_link($plugin, $submission, 'grading', array());
                 }
             }
         } else {
             $grade = null;
             if (isset($field)) {
                 return $plugin->get_editor_text($field, $row->gradeid);
             }
             if ($row->gradeid) {
                 $grade = new stdClass();
                 $grade->id = $row->gradeid;
                 $grade->timecreated = $row->firstmarked;
                 $grade->timemodified = $row->timemarked;
                 $grade->seplment = $this->seplment->get_instance()->id;
                 $grade->userid = $row->userid;
                 $grade->grade = $row->grade;
                 $grade->mailed = $row->mailed;
                 $grade->attemptnumber = $row->attemptnumber;
             }
             if ($this->quickgrading && $plugin->supports_quickgrading()) {
                 return $plugin->get_quickgrading_html($row->userid, $grade);
             } else {
                 if ($grade) {
                     return $this->format_plugin_summary_with_link($plugin, $grade, 'grading', array());
                 }
             }
         }
     }
     return '';
 }
コード例 #4
0
ファイル: lib.php プロジェクト: krzpassrl/SRL_Moodle_Baseline
/**
 * Obtains the automatic completion state for this module based on any conditions
 * in sepl settings.
 *
 * @param object $course Course
 * @param object $cm Course-module
 * @param int $userid User ID
 * @param bool $type Type of comparison (or/and; can be used as return value if no conditions)
 * @return bool True if completed, false if not, $type if conditions not set.
 */
function sepl_get_completion_state($course, $cm, $userid, $type)
{
    global $CFG, $DB;
    require_once $CFG->dirroot . '/mod/sepl/locallib.php';
    $sepl = new sepl(null, $cm, $course);
    // If completion option is enabled, evaluate it and return true/false.
    if ($sepl->get_instance()->completionsubmit) {
        $submission = $sepl->get_user_submission($userid, false);
        return $submission && $submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED;
    } else {
        // Completion option is not enabled so just return $type.
        return $type;
    }
}
コード例 #5
0
 /**
  * View a summary listing of all seplments in the current course.
  *
  * @return string
  */
 private function view_course_index()
 {
     global $USER;
     $o = '';
     $course = $this->get_course();
     $strplural = get_string('modulenameplural', 'sepl');
     if (!($cms = get_coursemodules_in_course('sepl', $course->id, 'm.duedate'))) {
         $o .= $this->get_renderer()->notification(get_string('thereareno', 'moodle', $strplural));
         $o .= $this->get_renderer()->continue_button(new moodle_url('/course/view.php', array('id' => $course->id)));
         return $o;
     }
     $strsectionname = '';
     $usesections = course_format_uses_sections($course->format);
     $modinfo = get_fast_modinfo($course);
     if ($usesections) {
         $strsectionname = get_string('sectionname', 'format_' . $course->format);
         $sections = $modinfo->get_section_info_all();
     }
     $courseindexsummary = new sepl_course_index_summary($usesections, $strsectionname);
     $timenow = time();
     $currentsection = '';
     foreach ($modinfo->instances['sepl'] as $cm) {
         if (!$cm->uservisible) {
             continue;
         }
         $timedue = $cms[$cm->id]->duedate;
         $sectionname = '';
         if ($usesections && $cm->sectionnum) {
             $sectionname = get_section_name($course, $sections[$cm->sectionnum]);
         }
         $submitted = '';
         $context = context_module::instance($cm->id);
         $seplment = new sepl($context, $cm, $course);
         if (has_capability('mod/sepl:grade', $context)) {
             $submitted = $seplment->count_submissions_with_status(ASSIGN_SUBMISSION_STATUS_SUBMITTED);
         } else {
             if (has_capability('mod/sepl:submit', $context)) {
                 $usersubmission = $seplment->get_user_submission($USER->id, false);
                 if (!empty($usersubmission->status)) {
                     $submitted = get_string('submissionstatus_' . $usersubmission->status, 'sepl');
                 } else {
                     $submitted = get_string('submissionstatus_', 'sepl');
                 }
             }
         }
         $gradinginfo = grade_get_grades($course->id, 'mod', 'sepl', $cm->instance, $USER->id);
         if (isset($gradinginfo->items[0]->grades[$USER->id]) && !$gradinginfo->items[0]->grades[$USER->id]->hidden) {
             $grade = $gradinginfo->items[0]->grades[$USER->id]->str_grade;
         } else {
             $grade = '-';
         }
         $courseindexsummary->add_sepl_info($cm->id, $cm->name, $sectionname, $timedue, $submitted, $grade);
     }
     $o .= $this->get_renderer()->render($courseindexsummary);
     $o .= $this->view_footer();
     return $o;
 }