当前位置: 首页>>代码示例>>PHP>>正文


PHP assign::get_instance方法代码示例

本文整理汇总了PHP中assign::get_instance方法的典型用法代码示例。如果您正苦于以下问题:PHP assign::get_instance方法的具体用法?PHP assign::get_instance怎么用?PHP assign::get_instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在assign的用法示例。


在下文中一共展示了assign::get_instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: assignsubmission_onenote_pluginfile

/**
 * Serves assignment 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 assignsubmission_onenote_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('assign_submission', array('id' => $itemid), 'userid, assignment, groupid', MUST_EXIST);
    $userid = $record->userid;
    $groupid = $record->groupid;
    require_once $CFG->dirroot . '/mod/assign/locallib.php';
    $assign = new assign($context, $cm, $course);
    if ($assign->get_instance()->id != $record->assignment) {
        return false;
    }
    if ($assign->get_instance()->teamsubmission && !$assign->can_view_group_submission($groupid)) {
        return false;
    }
    if (!$assign->get_instance()->teamsubmission && !$assign->can_view_submission($userid)) {
        return false;
    }
    $relativepath = implode('/', $args);
    $fullpath = "/{$context->id}/assignsubmission_onenote/{$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);
}
开发者ID:eugeneventer,项目名称:o365-moodle,代码行数:42,代码来源:lib.php

示例2: test_grade_edit_tree_column_range_get_item_cell

 public function test_grade_edit_tree_column_range_get_item_cell()
 {
     global $DB, $CFG;
     $this->resetAfterTest(true);
     // Make some things we need.
     $scale = $this->getDataGenerator()->create_scale();
     $course = $this->getDataGenerator()->create_course();
     $assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
     $modulecontext = context_module::instance($assign->id);
     // The generator returns a dummy object, lets get the real assign object.
     $assign = new assign($modulecontext, false, false);
     $cm = $assign->get_course_module();
     // Get range column.
     $column = grade_edit_tree_column::factory('range');
     $gradeitemparams = array('itemtype' => 'mod', 'itemmodule' => $cm->modname, 'iteminstance' => $cm->instance, 'courseid' => $cm->course, 'itemnumber' => 0);
     // Lets set the grade to something we know.
     $instance = $assign->get_instance();
     $instance->grade = 70;
     $instance->instance = $instance->id;
     $assign->update_instance($instance);
     $gradeitem = grade_item::fetch($gradeitemparams);
     $cell = $column->get_item_cell($gradeitem, array());
     $this->assertEquals(GRADE_TYPE_VALUE, $gradeitem->gradetype);
     $this->assertEquals(null, $gradeitem->scaleid);
     $this->assertEquals(70.0, (double) $cell->text, "Grade text is 70", 0.01);
     // Now change it to a scale.
     $instance = $assign->get_instance();
     $instance->grade = -$scale->id;
     $instance->instance = $instance->id;
     $assign->update_instance($instance);
     $gradeitem = grade_item::fetch($gradeitemparams);
     $cell = $column->get_item_cell($gradeitem, array());
     // Make the expected scale text.
     $scaleitems = null;
     $scaleitems = explode(',', $scale->scale);
     $scalestring = end($scaleitems) . ' (' . count($scaleitems) . ')';
     $this->assertEquals(GRADE_TYPE_SCALE, $gradeitem->gradetype);
     $this->assertEquals($scale->id, $gradeitem->scaleid);
     $this->assertEquals($scalestring, $cell->text, "Grade text matches scale");
     // Now change it to no grade.
     $instance = $assign->get_instance();
     $instance->grade = 0;
     $instance->instance = $instance->id;
     $assign->update_instance($instance);
     $gradeitem = grade_item::fetch($gradeitemparams);
     $cell = $column->get_item_cell($gradeitem, array());
     $this->assertEquals(GRADE_TYPE_TEXT, $gradeitem->gradetype);
     $this->assertEquals(null, $gradeitem->scaleid);
     $this->assertEquals(' - ', $cell->text, 'Grade text matches empty value of " - "');
 }
开发者ID:covex-nn,项目名称:moodle,代码行数:50,代码来源:edittreelib_test.php

示例3: assignsubmission_comments_comment_permissions

/**
 * Permission control method for submission plugin ---- required method for AJAXmoodle based comment API
 *
 * @param stdClass $options
 * @return array
 */
function assignsubmission_comments_comment_permissions(stdClass $options) {
    global $USER, $CFG, $DB;

    if ($options->commentarea != 'submission_comments' &&
            $options->commentarea != 'submission_comments_upgrade') {
        throw new comment_exception('invalidcommentarea');
    }
    if (!$submission = $DB->get_record('assign_submission', array('id'=>$options->itemid))) {
        throw new comment_exception('invalidcommentitemid');
    }
    $context = $options->context;

    require_once($CFG->dirroot . '/mod/assign/locallib.php');
    $assignment = new assign($context, null, null);

    if ($assignment->get_instance()->id != $submission->assignment) {
        throw new comment_exception('invalidcontext');
    }
    if (!has_capability('mod/assign:grade', $context)) {
        if (!has_capability('mod/assign:submit', $context)) {
            return array('post' => false, 'view' => false);
        } else if ($submission->userid != $USER->id) {
            return array('post' => false, 'view' => false);
        }
    }

    return array('post' => true, 'view' => true);
}
开发者ID:ncsu-delta,项目名称:moodle,代码行数:34,代码来源:lib.php

示例4: get_config

 /**
  * Get a configuration value for this plugin
  *
  * @param mixed $setting The config key (string) or null
  * @return mixed string | false
  */
 public final function get_config($setting = null)
 {
     global $DB;
     if ($setting) {
         if (!$this->assignment->has_instance()) {
             return false;
         }
         $assignment = $this->assignment->get_instance();
         if ($assignment) {
             $dbparams = array('assignment' => $assignment->id, 'subtype' => $this->get_subtype(), 'plugin' => $this->get_type(), 'name' => $setting);
             $result = $DB->get_record('assign_plugin_config', $dbparams, '*', IGNORE_MISSING);
             if ($result) {
                 return $result->value;
             }
         }
         return false;
     }
     $dbparams = array('assignment' => $this->assignment->get_instance()->id, 'subtype' => $this->get_subtype(), 'plugin' => $this->get_type());
     $results = $DB->get_records('assign_plugin_config', $dbparams);
     $config = new stdClass();
     if (is_array($results)) {
         foreach ($results as $setting) {
             $name = $setting->name;
             $config->{$name} = $setting->value;
         }
     }
     return $config;
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:34,代码来源:assignmentplugin.php

示例5: create_from_submission

 /**
  * Create instance of event.
  *
  * @param \assign $assign
  * @param \stdClass $submission
  * @return submission_viewed
  */
 public static function create_from_submission(\assign $assign, \stdClass $submission)
 {
     $data = array('objectid' => $submission->id, 'relateduserid' => $submission->userid, 'context' => $assign->get_context(), 'other' => array('assignid' => $assign->get_instance()->id));
     /** @var submission_viewed $event */
     $event = self::create($data);
     $event->set_assign($assign);
     $event->add_record_snapshot('assign_submission', $submission);
     return $event;
 }
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:16,代码来源:submission_viewed.php

示例6: create_from_assign

 /**
  * Create instance of event.
  *
  * @param \assign $assign
  * @return batch_set_marker_allocation_viewed
  */
 public static function create_from_assign(\assign $assign)
 {
     $data = array('context' => $assign->get_context(), 'other' => array('assignid' => $assign->get_instance()->id));
     self::$preventcreatecall = false;
     /** @var batch_set_marker_allocation_viewed $event */
     $event = self::create($data);
     self::$preventcreatecall = true;
     $event->set_assign($assign);
     return $event;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:16,代码来源:batch_set_marker_allocation_viewed.php

示例7: create_from_assign

 /**
  * Create instance of event.
  *
  * @since Moodle 2.7
  *
  * @param \assign $assign
  * @return all_submissions_downloaded
  */
 public static function create_from_assign(\assign $assign)
 {
     $data = array('context' => $assign->get_context(), 'objectid' => $assign->get_instance()->id);
     self::$preventcreatecall = false;
     /** @var submission_graded $event */
     $event = self::create($data);
     self::$preventcreatecall = true;
     $event->set_assign($assign);
     return $event;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:18,代码来源:all_submissions_downloaded.php

示例8: get_sort_columns

 /**
  * Always return a valid sort - even if the userid column is missing.
  * @return array column name => SORT_... constant.
  */
 public function get_sort_columns()
 {
     $result = parent::get_sort_columns();
     $assignment = $this->assignment->get_instance();
     if (empty($assignment->blindmarking)) {
         $result = array_merge($result, array('userid' => SORT_ASC));
     } else {
         $result = array_merge($result, ['COALESCE(s.timecreated, ' . time() . ')' => SORT_ASC, 'COALESCE(s.id, ' . PHP_INT_MAX . ')' => SORT_ASC, 'um.id' => SORT_ASC]);
     }
     return $result;
 }
开发者ID:lucaboesch,项目名称:moodle,代码行数:15,代码来源:gradingtable.php

示例9: create_from_user

 /**
  * Create instance of event.
  *
  * @since Moodle 2.7
  *
  * @param \assign $assign
  * @param \stdClass $user
  * @return submission_locked
  */
 public static function create_from_user(\assign $assign, \stdClass $user)
 {
     $data = array('context' => $assign->get_context(), 'objectid' => $assign->get_instance()->id, 'relateduserid' => $user->id);
     self::$preventcreatecall = false;
     /** @var submission_locked $event */
     $event = self::create($data);
     self::$preventcreatecall = true;
     $event->set_assign($assign);
     $event->add_record_snapshot('user', $user);
     return $event;
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:20,代码来源:submission_locked.php

示例10: array

 static function unplag_reset_file($id)
 {
     global $DB, $CFG;
     $plagiarismfile = $DB->get_record('plagiarism_unplag_files', array('id' => $id), '*', MUST_EXIST);
     if ($plagiarismfile->statuscode == UNPLAG_STATUSCODE_PROCESSED || $plagiarismfile->statuscode == UNPLAG_STATUSCODE_ACCEPTED) {
         // Sanity Check.
         return true;
     }
     // Set some new values.
     $plagiarismfile->statuscode = 'pending';
     $plagiarismfile->attempt = 0;
     $plagiarismfile->timesubmitted = time();
     $cm = get_coursemodule_from_id('', $plagiarismfile->cm);
     $modulecontext = context_module::instance($plagiarismfile->cm);
     $fs = get_file_storage();
     if ($cm->modname == 'assignment') {
         $submission = $DB->get_record('assignment_submissions', array('assignment' => $cm->instance, 'userid' => $plagiarismfile->userid));
         $files = $fs->get_area_files($modulecontext->id, 'mod_assignment', 'submission', $submission->id);
         foreach ($files as $file) {
             if ($file->get_contenthash() == $plagiarismfile->identifier) {
                 $DB->update_record('plagiarism_unplag_files', $plagiarismfile);
                 // Update before trying to send again.
                 return self::unplag_send_file($plagiarismfile->cm, $plagiarismfile->userid, $file, self::get_settings());
             }
         }
     } else {
         if ($cm->modname == 'assign') {
             require_once $CFG->dirroot . '/mod/assign/locallib.php';
             $assign = new assign($modulecontext, null, null);
             $submissionplugins = $assign->get_submission_plugins();
             $dbparams = array('assignment' => $assign->get_instance()->id, 'userid' => $plagiarismfile->userid);
             $submissions = $DB->get_records('assign_submission', $dbparams);
             foreach ($submissions as $submission) {
                 foreach ($submissionplugins as $submissionplugin) {
                     $component = $submissionplugin->get_subtype() . '_' . $submissionplugin->get_type();
                     $fileareas = $submissionplugin->get_file_areas();
                     foreach ($fileareas as $filearea => $name) {
                         $files = $fs->get_area_files($assign->get_context()->id, $component, $filearea, $submission->id, "timemodified", false);
                         foreach ($files as $file) {
                             if ($file->get_contenthash() == $plagiarismfile->identifier) {
                                 $DB->update_record('plagiarism_unplag_files', $plagiarismfile);
                                 // Update before trying to send again.
                                 return self::unplag_send_file($plagiarismfile->cm, $plagiarismfile->userid, $file, plagiarism_plugin_unplag::get_settings());
                             }
                         }
                     }
                 }
             }
         } else {
             if ($cm->modname == 'workshop') {
                 require_once $CFG->dirroot . '/mod/workshop/locallib.php';
                 $cm = get_coursemodule_from_id('workshop', $plagiarismfile->cm, 0, false, MUST_EXIST);
                 $workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
                 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
                 $workshop = new workshop($workshop, $cm, $course);
                 $submissions = $workshop->get_submissions($plagiarismfile->userid);
                 foreach ($submissions as $submission) {
                     $files = $fs->get_area_files($workshop->context->id, 'mod_workshop', 'submission_attachment', $submission->id);
                     foreach ($files as $file) {
                         if ($file->get_contenthash() == $plagiarismfile->identifier) {
                             $DB->update_record('plagiarism_unplag_files', $plagiarismfile);
                             // Update before trying to send again.
                             return self::unplag_send_file($plagiarismfile->cm, $plagiarismfile->userid, $file, plagiarism_plugin_unplag::get_settings());
                         }
                     }
                 }
             } else {
                 if ($cm->modname == 'forum') {
                     require_once $CFG->dirroot . '/mod/forum/lib.php';
                     $cm = get_coursemodule_from_id('forum', $plagiarismfile->cm, 0, false, MUST_EXIST);
                     $posts = forum_get_user_posts($cm->instance, $plagiarismfile->userid);
                     foreach ($posts as $post) {
                         $files = $fs->get_area_files($modulecontext->id, 'mod_forum', 'attachment', $post->id, "timemodified", false);
                         foreach ($files as $file) {
                             if ($file->get_contenthash() == $plagiarismfile->identifier) {
                                 $DB->update_record('plagiarism_unplag_files', $plagiarismfile);
                                 // Update before trying to send again.
                                 return self::unplag_send_file($plagiarismfile->cm, $plagiarismfile->userid, $file, plagiarism_plugin_unplag::get_settings());
                             }
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:POETGroup,项目名称:moodle-plagiarism_unplag,代码行数:86,代码来源:lib.php

示例11: test_list_participants_blind_marking

 public function test_list_participants_blind_marking()
 {
     global $DB;
     $this->resetAfterTest(true);
     $course = $this->getDataGenerator()->create_course();
     $roles = $DB->get_records('role', null, '', 'shortname, id');
     $teacher = $this->getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($teacher->id, $course->id, $roles['teacher']->id);
     $this->setUser($teacher);
     // Enrol two students.
     $students = [];
     for ($i = 0; $i < 2; $i++) {
         $student = $this->getDataGenerator()->create_user();
         $this->getDataGenerator()->enrol_user($student->id, $course->id, $roles['student']->id);
         $students[$student->id] = $student;
     }
     $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
     $instance = $generator->create_instance(['course' => $course->id, 'blindmarking' => 1]);
     $cm = get_coursemodule_from_instance('assign', $instance->id);
     $context = context_module::instance($cm->id);
     $assign = new assign($context, $cm, $course);
     // Allocate IDs now.
     // We're testing whether the IDs are correct after allocation.
     assign::allocate_unique_ids($assign->get_instance()->id);
     $participants = $assign->list_participants(null, false);
     // There should be exactly two participants and they should be the students.
     $this->assertCount(2, $participants);
     foreach ($participants as $participant) {
         $this->assertArrayHasKey($participant->id, $students);
     }
     $keys = array_keys($participants);
     // Create a grading table, and query the DB This should have the same order.
     $table = new assign_grading_table($assign, 10, '', 0, false);
     $table->setup();
     $table->query_db(10);
     $this->assertEquals($keys, array_keys($table->rawdata));
     // Submit a file for the second student.
     $data = new stdClass();
     $data->onlinetext_editor = array('itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', 'format' => FORMAT_MOODLE);
     static::helper_add_submission($assign, $participants[$keys[1]], $data, 'onlinetext');
     // Assign has a private cache. The easiest way to clear this is to create a new instance.
     $assign = new assign($context, $cm, $course);
     $newparticipants = $assign->list_participants(null, false);
     // There should be exactly two participants and they should be the students.
     $this->assertCount(2, $newparticipants);
     foreach ($newparticipants as $participant) {
         $this->assertArrayHasKey($participant->id, $students);
     }
     $newkeys = array_keys($newparticipants);
     // The user who submitted first should now be listed first.
     $this->assertEquals($participants[$keys[1]]->id, $newparticipants[$newkeys[0]]->id);
     $this->assertEquals($participants[$keys[0]]->id, $newparticipants[$newkeys[1]]->id);
     // Submit for the other student.
     static::helper_add_submission($assign, $participants[$keys[0]], $data, 'onlinetext');
     $assign = new assign($context, $cm, $course);
     $newparticipants = $assign->list_participants(null, false);
     // The users should still be listed in order of the first submission
     $this->assertEquals($participants[$keys[1]]->id, $newparticipants[$newkeys[0]]->id);
     $this->assertEquals($participants[$keys[0]]->id, $newparticipants[$newkeys[1]]->id);
     // The updated grading table should have the same order as the updated participant list.
     $table->query_db(10);
     $this->assertEquals($newkeys, array_keys($table->rawdata));
 }
开发者ID:gabrielrosset,项目名称:moodle,代码行数:63,代码来源:locallib_participants_test.php

示例12: view_course_index

    /**
     * View a summary listing of all assignments in the current course.
     *
     * @return string
     */
    private function view_course_index() {
        global $USER;

        $o = '';

        $course = $this->get_course();
        $strplural = get_string('modulenameplural', 'assign');

        if (!$cms = get_coursemodules_in_course('assign', $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 assign_course_index_summary($usesections, $strsectionname);

        $timenow = time();

        $currentsection = '';
        foreach ($modinfo->instances['assign'] 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);

            $assignment = new assign($context, $cm, $course);

            // Apply overrides.
            $assignment->update_effective_access($USER->id);
            $timedue = $assignment->get_instance()->duedate;

            if (has_capability('mod/assign:grade', $context)) {
                $submitted = $assignment->count_submissions_with_status(ASSIGN_SUBMISSION_STATUS_SUBMITTED);

            } else if (has_capability('mod/assign:submit', $context)) {
                $usersubmission = $assignment->get_user_submission($USER->id, false);

                if (!empty($usersubmission->status)) {
                    $submitted = get_string('submissionstatus_' . $usersubmission->status, 'assign');
                } else {
                    $submitted = get_string('submissionstatus_', 'assign');
                }
            }
            $gradinginfo = grade_get_grades($course->id, 'mod', 'assign', $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_assign_info($cm->id, $cm->get_formatted_name(), $sectionname, $timedue, $submitted, $grade);

        }

        $o .= $this->get_renderer()->render($courseindexsummary);
        $o .= $this->view_footer();

        return $o;
    }
开发者ID:EsdrasCaleb,项目名称:moodle,代码行数:82,代码来源:locallib.php

示例13: assignsubmission_comments_comment_display

/**
 * 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 assignsubmission_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('assign_submission', array('id' => $options->itemid)))) {
        throw new comment_exception('invalidcommentitemid');
    }
    $context = $options->context;
    $cm = $options->cm;
    $course = $options->courseid;
    require_once $CFG->dirroot . '/mod/assign/locallib.php';
    $assignment = new assign($context, $cm, $course);
    if ($assignment->get_instance()->id != $submission->assignment) {
        throw new comment_exception('invalidcontext');
    }
    if ($assignment->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', 'assign'));
        $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 = $assignment->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 = $assignment->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;
}
开发者ID:pzhu2004,项目名称:moodle,代码行数:54,代码来源:lib.php

示例14: event_handler


//.........这里部分代码省略.........
                     require_once "{$CFG->dirroot}/mod/assign/submission/file/locallib.php";
                     $modulecontext = context_module::instance($eventdata->cmid);
                     $fs = get_file_storage();
                     if ($files = $fs->get_area_files($modulecontext->id, 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $eventdata->itemid, "id", false)) {
                         foreach ($files as $file) {
                             $sendresult = urkund_send_file($cmid, $eventdata->userid, $file, $plagiarismsettings);
                             $result = $result && $sendresult;
                         }
                     }
                     $submission = $DB->get_record('assignsubmission_onlinetext', array('submission' => $eventdata->itemid));
                     if (!empty($submission)) {
                         $eventdata->content = trim(format_text($submission->onlinetext, $submission->onlineformat, array('context' => $modulecontext)));
                         $file = urkund_create_temp_file($cmid, $eventdata);
                         $sendresult = urkund_send_file($cmid, $eventdata->userid, $file, $plagiarismsettings);
                         $result = $result && $sendresult;
                         unlink($file->filepath);
                         // Delete temp file.
                     }
                 }
             }
         }
         return $result;
     }
     if (isset($plagiarismvalues['urkund_draft_submit']) && $plagiarismvalues['urkund_draft_submit'] == PLAGIARISM_URKUND_DRAFTSUBMIT_FINAL) {
         // Assignment-specific functionality:
         // Files should only be sent for checking once "finalized".
         return true;
     }
     // Text is attached.
     $result = true;
     if (!empty($eventdata->content)) {
         $file = urkund_create_temp_file($cmid, $eventdata);
         $sendresult = urkund_send_file($cmid, $eventdata->userid, $file, $plagiarismsettings);
         $result = $result && $sendresult;
         unlink($file->filepath);
         // Delete temp file.
     }
     // Normal situation: 1 or more assessable files attached to event, ready to be checked.
     if (!empty($eventdata->pathnamehashes)) {
         foreach ($eventdata->pathnamehashes as $hash) {
             $fs = get_file_storage();
             $efile = $fs->get_file_by_hash($hash);
             if (empty($efile)) {
                 mtrace("nofilefound!");
                 continue;
             } else {
                 if ($efile->get_filename() === '.') {
                     // This 'file' is actually a directory - nothing to submit.
                     continue;
                 }
             }
             // Check if assign group submission is being used.
             if ($eventdata->modulename == 'assign') {
                 require_once "{$CFG->dirroot}/mod/assign/locallib.php";
                 $modulecontext = context_module::instance($eventdata->cmid);
                 $assign = new assign($modulecontext, false, false);
                 if (!empty($assign->get_instance()->teamsubmission)) {
                     $mygroups = groups_get_user_groups($assign->get_course()->id, $eventdata->userid);
                     if (count($mygroups) == 1) {
                         $groupid = reset($mygroups)[0];
                         // Only users with single groups are supported - otherwise just use the normal userid on this record.
                         // Get all users from this group.
                         $userids = array();
                         $users = groups_get_members($groupid, 'u.id');
                         foreach ($users as $u) {
                             $userids[] = $u->id;
                         }
                         // Find the earliest plagiarism record for this cm with any of these users.
                         $sql = 'cm = ? AND userid IN (' . implode(',', $userids) . ')';
                         $previousfiles = $DB->get_records_select('plagiarism_urkund_files', $sql, array($eventdata->cmid), 'id');
                         $sanitycheckusers = 10;
                         // Search through this number of users to find a valid previous submission.
                         $i = 0;
                         foreach ($previousfiles as $pf) {
                             if ($pf->userid == $eventdata->userid) {
                                 break;
                                 // The submission comes from this user so break.
                             }
                             // Sanity Check to make sure the user isn't in multiple groups.
                             $pfgroups = groups_get_user_groups($assign->get_course()->id, $pf->userid);
                             if (count($pfgroups) == 1) {
                                 // This user made the first valid submission so use their id when sending the file.
                                 $eventdata->userid = $pf->userid;
                                 break;
                             }
                             if ($i >= $sanitycheckusers) {
                                 // don't cause a massive loop here and break at a sensible limit.
                                 break;
                             }
                             $i++;
                         }
                     }
                 }
             }
             $sendresult = urkund_send_file($cmid, $eventdata->userid, $efile, $plagiarismsettings);
             $result = $result && $sendresult;
         }
     }
     return $result;
 }
开发者ID:edmiranda,项目名称:moodle-plagiarism_urkund,代码行数:101,代码来源:lib.php

示例15: plagiarism_urkund_check_group

function plagiarism_urkund_check_group($plagiarismfile)
{
    global $DB, $CFG;
    require_once "{$CFG->dirroot}/mod/assign/locallib.php";
    $modulecontext = context_module::instance($plagiarismfile->cm);
    $assign = new assign($modulecontext, false, false);
    if (!empty($assign->get_instance()->teamsubmission)) {
        mtrace("URKUND fileid:" . $plagiarismfile->id . " Group submission detected.");
        $mygroups = groups_get_user_groups($assign->get_course()->id, $plagiarismfile->userid);
        if (count($mygroups) == 1) {
            $groupid = reset($mygroups)[0];
            // Only users with single groups are supported - otherwise just use the normal userid on this record.
            // Get all users from this group.
            $userids = array();
            $users = groups_get_members($groupid, 'u.id');
            foreach ($users as $u) {
                $userids[] = $u->id;
            }
            if (!empty($userids)) {
                // Find the earliest plagiarism record for this cm with any of these users.
                $sql = 'cm = ? AND userid IN (' . implode(',', $userids) . ')';
                $previousfiles = $DB->get_records_select('plagiarism_urkund_files', $sql, array($plagiarismfile->cm), 'id');
                $sanitycheckusers = 10;
                // Search through this number of users to find a valid previous submission.
                $i = 0;
                foreach ($previousfiles as $pf) {
                    if ($pf->userid == $plagiarismfile->userid) {
                        return $plagiarismfile;
                    }
                    // Sanity Check to make sure the user isn't in multiple groups.
                    $pfgroups = groups_get_user_groups($assign->get_course()->id, $pf->userid);
                    if (count($pfgroups) == 1) {
                        // This user made the first valid submission so use their id when sending the file.
                        $plagiarismfile->userid = $pf->userid;
                        mtrace("URKUND: Group submission by newuser, modify to use original userid:" . $pf->userid . " id:" . $plagiarismfile->id);
                        return $plagiarismfile;
                    }
                    if ($i >= $sanitycheckusers) {
                        // Don't cause a massive loop here and break at a sensible limit.
                        return $plagiarismfile;
                    }
                    $i++;
                }
            }
        }
    }
    return $plagiarismfile;
}
开发者ID:henrikthorn,项目名称:moodle-plagiarism_urkund,代码行数:48,代码来源:lib.php


注:本文中的assign::get_instance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。