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


PHP grade_item::fetch方法代码示例

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


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

示例1: definition_after_data

 function definition_after_data()
 {
     global $CFG, $COURSE;
     $mform =& $this->_form;
     if ($id = $mform->getElementValue('id')) {
         $grade_item = grade_item::fetch(array('id' => $id));
         //remove the aggregation coef element if not needed
         if ($grade_item->is_course_item()) {
             $mform->removeElement('aggregationcoef');
         } else {
             if ($grade_item->is_category_item()) {
                 $category = $grade_item->get_item_category();
                 $parent_category = $category->get_parent_category();
                 if (!$parent_category->is_aggregationcoef_used()) {
                     $mform->removeElement('aggregationcoef');
                 }
             } else {
                 $parent_category = $grade_item->get_parent_category();
                 if (!$parent_category->is_aggregationcoef_used()) {
                     $mform->removeElement('aggregationcoef');
                 }
             }
         }
     } else {
         $course_category = grade_category::fetch_course_category($COURSE->id);
         if (!$course_category->is_aggregationcoef_used()) {
             $mform->removeElement('aggregationcoef');
         }
     }
 }
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:30,代码来源:outcomeitem_form.php

示例2: fill_table

 function fill_table()
 {
     global $CFG;
     $numusers = $this->get_numusers();
     if ($courses = get_courses('all', null, 'c.id, c.shortname')) {
         foreach ($courses as $course) {
             // Get course grade_item
             $grade_item = grade_item::fetch(array('itemtype' => 'course', 'courseid' => $course->id));
             // Get the grade
             $finalgrade = get_field('grade_grades', 'finalgrade', 'itemid', $grade_item->id, 'userid', $this->user->id);
             /// prints rank
             if ($finalgrade) {
                 /// find the number of users with a higher grade
                 $sql = "SELECT COUNT(DISTINCT(userid))\n                            FROM {$CFG->prefix}grade_grades\n                            WHERE finalgrade > {$finalgrade}\n                            AND itemid = {$grade_item->id}";
                 $rank = count_records_sql($sql) + 1;
                 $rankdata = "{$rank}/{$numusers}";
             } else {
                 // no grade, no rank
                 $rankdata = "-";
             }
             $courselink = '<a href="' . $CFG->wwwroot . '/grade/report/user/index.php?id=' . $course->id . '">' . $course->shortname . '</a>';
             $this->table->add_data(array($courselink, round(grade_to_percentage($finalgrade, $grade_item->grademin, $grade_item->grademax), 1) . '%', $rankdata));
         }
         return true;
     } else {
         notify(get_string('nocourses', 'grades'));
         return false;
     }
 }
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:29,代码来源:lib.php

示例3: test_duplicate

 /**
  * Tests the backup and restore of single activity to same course (duplicate)
  * when it contains fields and views.
  */
 public function test_duplicate()
 {
     global $DB, $CFG;
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $generator = $this->getDataGenerator();
     $dataformgenerator = $generator->get_plugin_generator('mod_dataform');
     // Create a course.
     $course = $generator->create_course();
     // DATAFORM 1.
     $params = array('course' => $course->id, 'grade' => 100);
     $dataform1 = $dataformgenerator->create_instance($params);
     $df1 = mod_dataform_dataform::instance($dataform1->id);
     // Add fields.
     $fieldtypes = array_keys(core_component::get_plugin_list('dataformfield'));
     $fieldtypescount = count($fieldtypes);
     foreach ($fieldtypes as $type) {
         $df1->field_manager->add_field($type);
     }
     // Add views.
     $viewtypes = array_keys(core_component::get_plugin_list('dataformview'));
     $viewtypescount = count($viewtypes);
     foreach ($viewtypes as $type) {
         $df1->view_manager->add_view($type);
     }
     // Fetch the grade item.
     $params = array('itemtype' => 'mod', 'itemmodule' => 'dataform', 'iteminstance' => $dataform1->id, 'courseid' => $course->id, 'itemnumber' => 0);
     $gradeitem1 = grade_item::fetch($params);
     // Check number of dataforms.
     $this->assertEquals(1, $DB->count_records('dataform'));
     // Check number of fields.
     $this->assertEquals($fieldtypescount, $DB->count_records('dataform_fields'));
     $this->assertEquals($fieldtypescount, $DB->count_records('dataform_fields', array('dataid' => $dataform1->id)));
     // Check number of views.
     $this->assertEquals($viewtypescount, $DB->count_records('dataform_views'));
     $this->assertEquals($viewtypescount, $DB->count_records('dataform_views', array('dataid' => $dataform1->id)));
     // Check number of filters.
     // $this->assertEquals(2, $DB->count_records('dataform_filters'));
     // $this->assertEquals(2, $DB->count_records('dataform_filters', array('dataid' => $dataform1->id)));.
     // DUPLICATE the dataform instance.
     $dataform2 = $dataformgenerator->duplicate_instance($course, $dataform1->cmid);
     // Check number of dataforms.
     $this->assertEquals(2, $DB->count_records('dataform'));
     // Check duplication of fields.
     $this->assertEquals($fieldtypescount * 2, $DB->count_records('dataform_fields'));
     $this->assertEquals($fieldtypescount, $DB->count_records('dataform_fields', array('dataid' => $dataform1->id)));
     $this->assertEquals($fieldtypescount, $DB->count_records('dataform_fields', array('dataid' => $dataform2->id)));
     // Check duplication of views.
     $this->assertEquals($viewtypescount * 2, $DB->count_records('dataform_views'));
     $this->assertEquals($viewtypescount, $DB->count_records('dataform_views', array('dataid' => $dataform1->id)));
     $this->assertEquals($viewtypescount, $DB->count_records('dataform_views', array('dataid' => $dataform2->id)));
     // Check number of filters.
     // $this->assertEquals(4, $DB->count_records('dataform_filters');
     // $this->assertEquals(2, $DB->count_records('dataform_filters', array('dataid' => $dataform1->id));
     // $this->assertEquals(2, $DB->count_records('dataform_filters', array('dataid' => $dataform2->id));.
     // Dataform cleanup.
     $dataformgenerator->delete_all_instances();
 }
开发者ID:parksandwildlife,项目名称:learning,代码行数:62,代码来源:backup_restore_test.php

示例4: test_process_data

 /**
  * Tests grade_report_grader::process_data()
  *
  * process_data() processes submitted grade and feedback data
  */
 public function test_process_data()
 {
     global $DB, $CFG;
     $this->resetAfterTest(true);
     $course = $this->getDataGenerator()->create_course();
     // Create and enrol a student.
     $student = $this->getDataGenerator()->create_user(array('username' => 'Student Sam'));
     $role = $DB->get_record('role', array('shortname' => 'student'), '*', MUST_EXIST);
     $this->getDataGenerator()->enrol_user($student->id, $course->id, $role->id);
     // Test with limited grades.
     $CFG->unlimitedgrades = 0;
     $forummax = 80;
     $forum1 = $this->getDataGenerator()->create_module('forum', array('assessed' => 1, 'scale' => $forummax, 'course' => $course->id));
     // Switch the stdClass instance for a grade item instance.
     $forum1 = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'forum', 'iteminstance' => $forum1->id, 'courseid' => $course->id));
     $report = $this->create_report($course);
     $testgrade = 60.0;
     $data = new stdClass();
     $data->id = $course->id;
     $data->report = 'grader';
     $data->timepageload = time();
     $data->grade = array();
     $data->grade[$student->id] = array();
     $data->grade[$student->id][$forum1->id] = $testgrade;
     $warnings = $report->process_data($data);
     $this->assertEquals(count($warnings), 0);
     $studentgrade = grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id));
     $this->assertEquals($studentgrade->finalgrade, $testgrade);
     // Grade above max. Should be pulled down to max.
     $toobig = 200.0;
     $data->grade[$student->id][$forum1->id] = $toobig;
     $data->timepageload = time();
     $warnings = $report->process_data($data);
     $this->assertEquals(count($warnings), 1);
     $studentgrade = grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id));
     $this->assertEquals($studentgrade->finalgrade, $forummax);
     // Grade below min. Should be pulled up to min.
     $toosmall = -10.0;
     $data->grade[$student->id][$forum1->id] = $toosmall;
     $data->timepageload = time();
     $warnings = $report->process_data($data);
     $this->assertEquals(count($warnings), 1);
     $studentgrade = grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id));
     $this->assertEquals($studentgrade->finalgrade, 0);
     // Test unlimited grades so we can give a student a grade about max.
     $CFG->unlimitedgrades = 1;
     $data->grade[$student->id][$forum1->id] = $toobig;
     $data->timepageload = time();
     $warnings = $report->process_data($data);
     $this->assertEquals(count($warnings), 0);
     $studentgrade = grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id));
     $this->assertEquals($studentgrade->finalgrade, $toobig);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:58,代码来源:report_graderlib_test.php

示例5: execute

 public function execute()
 {
     global $DB;
     $TIMELIMITHOURS = 8;
     $timebound = time() - $TIMELIMITHOURS * 60 * 60;
     $sql = 'SELECT id, itemid, userid FROM {grade_grades} WHERE locked = 0 AND overridden > 0 AND overridden < ?';
     $records = $DB->get_records_sql($sql, array($timebound));
     foreach ($records as $record) {
         $gradeitem = \grade_item::fetch(array('id' => $record->itemid));
         $grades = \grade_grade::fetch_users_grades($gradeitem, array($record->userid));
         $grades[$record->userid]->set_locked(1);
     }
 }
开发者ID:ispedals,项目名称:moodle-local_gradelock,代码行数:13,代码来源:lock_grades.php

示例6: 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

示例7: validation

 function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     $mform =& $this->_form;
     // check the calculation formula
     if ($data['calculation'] != '') {
         $grade_item = grade_item::fetch(array('id' => $data['id'], 'courseid' => $data['courseid']));
         $calculation = calc_formula::unlocalize(stripslashes($data['calculation']));
         $result = $grade_item->validate_formula($calculation);
         if ($result !== true) {
             $errors['calculation'] = $result;
         }
     }
     return $errors;
 }
开发者ID:janeklb,项目名称:moodle,代码行数:15,代码来源:calculation_form.php

示例8: validation

 function validation($data)
 {
     $errors = array();
     $mform =& $this->_form;
     // check the calculation formula
     if ($data['calculation'] != '') {
         $grade_item = grade_item::fetch(array('id' => $data['id'], 'courseid' => $data['courseid']));
         $calculation = calc_formula::unlocalize(stripslashes($data['calculation']));
         $result = $grade_item->validate_formula($calculation);
         if ($result !== true) {
             $errors['calculation'] = $result;
         }
     }
     if (0 == count($errors)) {
         return true;
     } else {
         return $errors;
     }
 }
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:19,代码来源:calculation_form.php

示例9: update_require_specific_grade

 /**
  * Updates activity completion status.
  *
  * @return void
  */
 public static function update_require_specific_grade(\core\event\base $event)
 {
     global $DB;
     $entryuserid = $event->relateduserid;
     $giid = $event->other['itemid'];
     if (!($gitem = \grade_item::fetch(array('id' => $giid, 'itemmodule' => 'dataform')))) {
         return;
     }
     $dataformid = $gitem->iteminstance;
     $df = \mod_dataform_dataform::instance($dataformid);
     // Currently only completion by require entries.
     if ($df->completionspecificgrade) {
         $completion = new \completion_info($df->course);
         if ($completion->is_enabled($df->cm) != COMPLETION_TRACKING_AUTOMATIC) {
             return;
         }
         $completion->update_state($df->cm, COMPLETION_UNKNOWN, $entryuserid);
     }
 }
开发者ID:parksandwildlife,项目名称:learning,代码行数:24,代码来源:completion.php

示例10: execute

 /**
  * Adds a grade category and moves the specified item into it.
  * Uses locks to prevent race conditions (see MDL-37055).
  */
 public function execute()
 {
     $customdata = $this->get_custom_data();
     // Get lock timeout.
     $timeout = 5;
     // A namespace for the locks.
     $locktype = 'block_mhaairs_add_category';
     // Resource key - course id and category name.
     $resource = "course: {$customdata->courseid}; catname: {$customdata->catname}";
     // Get an instance of the currently configured lock_factory.
     $lockfactory = \core\lock\lock_config::get_lock_factory($locktype);
     // Open a lock.
     $lock = $lockfactory->get_lock($resource, $timeout);
     // Add the category.
     $catparams = array('fullname' => $customdata->catname, 'courseid' => $customdata->courseid);
     if (!($category = \grade_category::fetch($catparams))) {
         // If the category does not exist we create it.
         $gradeaggregation = get_config('core', 'grade_aggregation');
         if ($gradeaggregation === false) {
             $gradeaggregation = GRADE_AGGREGATE_WEIGHTED_MEAN2;
         }
         // Parent category is automatically added(created) during insert.
         $catparams['hidden'] = false;
         $catparams['aggregation'] = $gradeaggregation;
         try {
             $category = new \grade_category($catparams, false);
             $category->id = $category->insert();
         } catch (Exception $e) {
             // Must release the locks.
             $lock->release();
             // Rethrow to reschedule task.
             throw $e;
         }
     }
     // Release locks.
     $lock->release();
     // Add the item to the category.
     $gitem = \grade_item::fetch(array('id' => $customdata->itemid));
     $gitem->categoryid = $category->id;
     $gitem->update();
 }
开发者ID:itamart,项目名称:moodle-block_mhaairs,代码行数:45,代码来源:add_grade_category_task.php

示例11: test_event

 /**
  * Tests the event details.
  */
 public function test_event()
 {
     global $CFG;
     require_once "{$CFG->libdir}/gradelib.php";
     $this->resetAfterTest();
     $course = $this->getDataGenerator()->create_course();
     $user = $this->getDataGenerator()->create_user();
     $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id));
     // Create a grade item for the quiz.
     $grade = array();
     $grade['userid'] = $user->id;
     $grade['rawgrade'] = 50;
     grade_update('mod/quiz', $course->id, 'mod', 'quiz', $quiz->id, 0, $grade);
     // Get the grade item and override it.
     $gradeitem = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'quiz', 'iteminstance' => $quiz->id, 'courseid' => $course->id));
     $gradeitem->update_final_grade($user->id, 10, 'gradebook');
     // Get the grade_grade object.
     $gradegrade = new grade_grade(array('userid' => $user->id, 'itemid' => $gradeitem->id), true);
     $gradegrade->grade_item = $gradeitem;
     // Trigger the event.
     $sink = $this->redirectEvents();
     course_delete_module($quiz->cmid);
     $events = $sink->get_events();
     $event = reset($events);
     $sink->close();
     // Check the event details are correct.
     $grade = $event->get_grade();
     $this->assertInstanceOf('grade_grade', $grade);
     $this->assertInstanceOf('\\core\\event\\grade_deleted', $event);
     $this->assertEquals(context_course::instance($course->id), $event->get_context());
     $this->assertSame($event->objecttable, 'grade_grades');
     $this->assertEquals($event->objectid, $gradegrade->id);
     $this->assertEquals($event->other['itemid'], $gradeitem->id);
     $this->assertTrue($event->other['overridden']);
     $this->assertEquals(10, $event->other['finalgrade']);
     $this->assertEventContextNotUsed($event);
     $this->assertEquals($gradegrade->id, $grade->id);
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:41,代码来源:event_grade_deleted_test.php

示例12: grade_get_grades

/**
 * Returns grading information for given activity, optionally with user grades
 * Manual, course or category items can not be queried.
 *
 * @category grade
 * @param int    $courseid ID of course
 * @param string $itemtype Type of grade item. For example, 'mod' or 'block'
 * @param string $itemmodule More specific then $itemtype. For example, 'forum' or 'quiz'. May be NULL for some item types
 * @param int    $iteminstance ID of the item module
 * @param mixed  $userid_or_ids Either a single user ID, an array of user IDs or null. If user ID or IDs are not supplied returns information about grade_item
 * @return array Array of grade information objects (scaleid, name, grade and locked status, etc.) indexed with itemnumbers
 */
function grade_get_grades($courseid, $itemtype, $itemmodule, $iteminstance, $userid_or_ids = null)
{
    global $CFG;
    $return = new stdClass();
    $return->items = array();
    $return->outcomes = array();
    $course_item = grade_item::fetch_course_item($courseid);
    $needsupdate = array();
    if ($course_item->needsupdate) {
        $result = grade_regrade_final_grades($courseid);
        if ($result !== true) {
            $needsupdate = array_keys($result);
        }
    }
    if ($grade_items = grade_item::fetch_all(array('itemtype' => $itemtype, 'itemmodule' => $itemmodule, 'iteminstance' => $iteminstance, 'courseid' => $courseid))) {
        foreach ($grade_items as $grade_item) {
            $decimalpoints = null;
            if (empty($grade_item->outcomeid)) {
                // prepare information about grade item
                $item = new stdClass();
                $item->itemnumber = $grade_item->itemnumber;
                $item->scaleid = $grade_item->scaleid;
                $item->name = $grade_item->get_name();
                $item->grademin = $grade_item->grademin;
                $item->grademax = $grade_item->grademax;
                $item->gradepass = $grade_item->gradepass;
                $item->locked = $grade_item->is_locked();
                $item->hidden = $grade_item->is_hidden();
                $item->grades = array();
                switch ($grade_item->gradetype) {
                    case GRADE_TYPE_NONE:
                        continue;
                    case GRADE_TYPE_VALUE:
                        $item->scaleid = 0;
                        break;
                    case GRADE_TYPE_TEXT:
                        $item->scaleid = 0;
                        $item->grademin = 0;
                        $item->grademax = 0;
                        $item->gradepass = 0;
                        break;
                }
                if (empty($userid_or_ids)) {
                    $userids = array();
                } else {
                    if (is_array($userid_or_ids)) {
                        $userids = $userid_or_ids;
                    } else {
                        $userids = array($userid_or_ids);
                    }
                }
                if ($userids) {
                    $grade_grades = grade_grade::fetch_users_grades($grade_item, $userids, true);
                    foreach ($userids as $userid) {
                        $grade_grades[$userid]->grade_item =& $grade_item;
                        $grade = new stdClass();
                        $grade->grade = $grade_grades[$userid]->finalgrade;
                        $grade->locked = $grade_grades[$userid]->is_locked();
                        $grade->hidden = $grade_grades[$userid]->is_hidden();
                        $grade->overridden = $grade_grades[$userid]->overridden;
                        $grade->feedback = $grade_grades[$userid]->feedback;
                        $grade->feedbackformat = $grade_grades[$userid]->feedbackformat;
                        $grade->usermodified = $grade_grades[$userid]->usermodified;
                        $grade->datesubmitted = $grade_grades[$userid]->get_datesubmitted();
                        $grade->dategraded = $grade_grades[$userid]->get_dategraded();
                        // create text representation of grade
                        if ($grade_item->gradetype == GRADE_TYPE_TEXT or $grade_item->gradetype == GRADE_TYPE_NONE) {
                            $grade->grade = null;
                            $grade->str_grade = '-';
                            $grade->str_long_grade = $grade->str_grade;
                        } else {
                            if (in_array($grade_item->id, $needsupdate)) {
                                $grade->grade = false;
                                $grade->str_grade = get_string('error');
                                $grade->str_long_grade = $grade->str_grade;
                            } else {
                                if (is_null($grade->grade)) {
                                    $grade->str_grade = '-';
                                    $grade->str_long_grade = $grade->str_grade;
                                } else {
                                    $grade->str_grade = grade_format_gradevalue($grade->grade, $grade_item);
                                    if ($grade_item->gradetype == GRADE_TYPE_SCALE or $grade_item->get_displaytype() != GRADE_DISPLAY_TYPE_REAL) {
                                        $grade->str_long_grade = $grade->str_grade;
                                    } else {
                                        $a = new stdClass();
                                        $a->grade = $grade->str_grade;
                                        $a->max = grade_format_gradevalue($grade_item->grademax, $grade_item);
                                        $grade->str_long_grade = get_string('gradelong', 'grades', $a);
//.........这里部分代码省略.........
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:101,代码来源:gradelib.php

示例13: std_meta

 /**
  * Return standard meta data for module
  *
  * @param cm_info $mod
  * @param string $timeopenfld
  * @param string $timeclosefld
  * @param string $keyfield
  * @param string $submissiontable
  * @param string $submittedonfld
  * @param string $submitstrkey
  * @param bool $isgradeable
  * @param string $submitselect - sql to further filter submission row select statement - e.g. st.status='finished'
  * @return bool | \theme_snap\activity_meta
  */
 protected static function std_meta(\cm_info $mod, $timeopenfld, $timeclosefld, $keyfield, $submissiontable, $submittedonfld, $submitstrkey, $isgradeable = false, $submitselect = '')
 {
     global $USER;
     $courseid = $mod->course;
     // Create meta data object.
     $meta = new \theme_snap\activity_meta();
     $meta->submitstrkey = $submitstrkey;
     $meta->submittedstr = get_string($submitstrkey, 'theme_snap');
     $meta->notsubmittedstr = get_string('not' . $submitstrkey, 'theme_snap');
     if (get_string_manager()->string_exists($mod->modname . 'draft', 'theme_snap')) {
         $meta->draftstr = get_string($mod->modname . 'draft', 'theme_snap');
     } else {
         $meta->drafstr = get_string('draft', 'theme_snap');
     }
     if (get_string_manager()->string_exists($mod->modname . 'reopened', 'theme_snap')) {
         $meta->reopenedstr = get_string($mod->modname . 'reopened', 'theme_snap');
     } else {
         $meta->reopenedstr = get_string('reopened', 'theme_snap');
     }
     // If module is not visible to the user then don't bother getting meta data.
     if (!$mod->uservisible) {
         return $meta;
     }
     $activitydates = self::instance_activity_dates($courseid, $mod, $timeopenfld, $timeclosefld);
     $meta->timeopen = $activitydates->timeopen;
     $meta->timeclose = $activitydates->timeclose;
     // TODO: use activity specific "teacher" capabilities.
     if (has_capability('mod/assign:grade', \context_course::instance($courseid))) {
         $meta->isteacher = true;
         // Teacher - useful teacher meta data.
         $methodnsubmissions = $mod->modname . '_num_submissions';
         $methodnungraded = $mod->modname . '_num_submissions_ungraded';
         if (method_exists('theme_snap\\activity', $methodnsubmissions)) {
             $meta->numsubmissions = call_user_func('theme_snap\\activity::' . $methodnsubmissions, $courseid, $mod->instance);
         }
         if (method_exists('theme_snap\\activity', $methodnungraded)) {
             $meta->numrequiregrading = call_user_func('theme_snap\\activity::' . $methodnungraded, $courseid, $mod->instance);
         }
     } else {
         // Student - useful student meta data - only display if activity is available.
         if (empty($activitydates->timeopen) || usertime($activitydates->timeopen) <= time()) {
             $submissionrow = self::get_submission_row($courseid, $mod, $submissiontable, $keyfield, $submitselect);
             if (!empty($submissionrow)) {
                 if ($submissionrow->status) {
                     switch ($submissionrow->status) {
                         case 'draft':
                             $meta->draft = true;
                             break;
                         case 'reopened':
                             $meta->reopened = true;
                             break;
                         case 'submitted':
                             $meta->submitted = true;
                             break;
                     }
                 } else {
                     $meta->submitted = true;
                     $meta->timesubmitted = !empty($submissionrow->{$submittedonfld}) ? $submissionrow->{$submittedonfld} : null;
                 }
                 // If submitted on field uses modified field then fall back to timecreated if modified is 0.
                 if (empty($meta->timesubmitted) && ($submittedonfld = 'timemodified')) {
                     if (isset($submissionrow->timemodified)) {
                         $meta->timesubmitted = $submissionrow->timemodified;
                     } else {
                         $meta->timesubmitted = $submissionrow->timecreated;
                     }
                 }
             }
         }
         $graderow = false;
         if ($isgradeable) {
             $graderow = self::grade_row($courseid, $mod);
         }
         if ($graderow) {
             $gradeitem = \grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $mod->modname, 'iteminstance' => $mod->instance));
             $grade = new \grade_grade(array('itemid' => $gradeitem->id, 'userid' => $USER->id));
             $coursecontext = \context_course::instance($courseid);
             $canviewhiddengrade = has_capability('moodle/grade:viewhidden', $coursecontext);
             if (!$grade->is_hidden() || $canviewhiddengrade) {
                 $meta->grade = true;
             }
         }
     }
     return $meta;
 }
开发者ID:nbartley,项目名称:moodle-theme_snap,代码行数:99,代码来源:activity.php

示例14: test_get_attempt_access_information

 /**
  * Test get_attempt_access_information
  */
 public function test_get_attempt_access_information()
 {
     global $DB;
     // Create a new quiz with attempts.
     $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
     $data = array('course' => $this->course->id, 'sumgrades' => 2);
     $quiz = $quizgenerator->create_instance($data);
     // Create some questions.
     $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
     $cat = $questiongenerator->create_question_category();
     $question = $questiongenerator->create_question('numerical', null, array('category' => $cat->id));
     quiz_add_quiz_question($question->id, $quiz);
     $question = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id));
     quiz_add_quiz_question($question->id, $quiz);
     // Add new question types in the category (for the random one).
     $question = $questiongenerator->create_question('truefalse', null, array('category' => $cat->id));
     $question = $questiongenerator->create_question('essay', null, array('category' => $cat->id));
     $question = $questiongenerator->create_question('random', null, array('category' => $cat->id));
     quiz_add_quiz_question($question->id, $quiz);
     $quizobj = quiz::create($quiz->id, $this->student->id);
     // Set grade to pass.
     $item = grade_item::fetch(array('courseid' => $this->course->id, 'itemtype' => 'mod', 'itemmodule' => 'quiz', 'iteminstance' => $quiz->id, 'outcomeid' => null));
     $item->gradepass = 80;
     $item->update();
     $this->setUser($this->student);
     // Default restrictions (none).
     $result = mod_quiz_external::get_attempt_access_information($quiz->id);
     $result = external_api::clean_returnvalue(mod_quiz_external::get_attempt_access_information_returns(), $result);
     $expected = array('isfinished' => false, 'preventnewattemptreasons' => [], 'warnings' => []);
     $this->assertEquals($expected, $result);
     // Limited attempts.
     $quiz->attempts = 1;
     $DB->update_record('quiz', $quiz);
     // Now, do one attempt.
     $quba = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
     $quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour);
     $timenow = time();
     $attempt = quiz_create_attempt($quizobj, 1, false, $timenow, false, $this->student->id);
     quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow);
     quiz_attempt_save_started($quizobj, $quba, $attempt);
     // Process some responses from the student.
     $attemptobj = quiz_attempt::create($attempt->id);
     $tosubmit = array(1 => array('answer' => '3.14'));
     $attemptobj->process_submitted_actions($timenow, false, $tosubmit);
     // Finish the attempt.
     $attemptobj = quiz_attempt::create($attempt->id);
     $this->assertTrue($attemptobj->has_response_to_at_least_one_graded_question());
     $attemptobj->process_finish($timenow, false);
     // Can we start a new attempt? We shall not!
     $result = mod_quiz_external::get_attempt_access_information($quiz->id, $attempt->id);
     $result = external_api::clean_returnvalue(mod_quiz_external::get_attempt_access_information_returns(), $result);
     // Now new attemps allowed.
     $this->assertCount(1, $result['preventnewattemptreasons']);
     $this->assertFalse($result['ispreflightcheckrequired']);
     $this->assertEquals(get_string('nomoreattempts', 'quiz'), $result['preventnewattemptreasons'][0]);
 }
开发者ID:reconnectmedia,项目名称:moodle,代码行数:59,代码来源:external_test.php

示例15: restore_migrate_old_gradebook

/**
 * This function migrades all the pre 1.9 gradebook data from xml
 */
function restore_migrate_old_gradebook($restore, $xml_file)
{
    global $CFG;
    $status = true;
    //Check it exists
    if (!file_exists($xml_file)) {
        return false;
    }
    // Get info from xml
    // info will contain the number of record to process
    $info = restore_read_xml_gradebook($restore, $xml_file);
    // If we have info, then process
    if (empty($info)) {
        return $status;
    }
    // make sure top course category exists
    $course_category = grade_category::fetch_course_category($restore->course_id);
    $course_category->load_grade_item();
    // we need to know if all grade items that were backed up are being restored
    // if that is not the case, we do not restore grade categories nor gradeitems of category type or course type
    // i.e. the aggregated grades of that category
    $restoreall = true;
    // set to false if any grade_item is not selected/restored
    $importing = !empty($SESSION->restore->importing);
    // there should not be a way to import old backups, but anyway ;-)
    if ($importing) {
        $restoreall = false;
    } else {
        $prev_grade_items = grade_item::fetch_all(array('courseid' => $restore->course_id));
        $prev_grade_cats = grade_category::fetch_all(array('courseid' => $restore->course_id));
        // if any categories already present, skip restore of categories from backup
        if (count($prev_grade_items) > 1 or count($prev_grade_cats) > 1) {
            $restoreall = false;
        }
        unset($prev_grade_items);
        unset($prev_grade_cats);
    }
    // force creation of all grade_items - the course_modules already exist
    grade_force_full_regrading($restore->course_id);
    grade_grab_course_grades($restore->course_id);
    // Start ul
    if (!defined('RESTORE_SILENTLY')) {
        echo '<ul>';
    }
    /// Process letters
    $context = get_context_instance(CONTEXT_COURSE, $restore->course_id);
    // respect current grade letters if defined
    if ($status and $restoreall and !record_exists('grade_letters', 'contextid', $context->id)) {
        if (!defined('RESTORE_SILENTLY')) {
            echo '<li>' . get_string('gradeletters', 'grades') . '</li>';
        }
        // Fetch recordset_size records in each iteration
        $recs = get_records_select("backup_ids", "table_name = 'grade_letter' AND backup_code = {$restore->backup_unique_code}", "", "old_id");
        if ($recs) {
            foreach ($recs as $rec) {
                // Get the full record from backup_ids
                $data = backup_getid($restore->backup_unique_code, 'grade_letter', $rec->old_id);
                if ($data) {
                    $info = $data->info;
                    $dbrec = new object();
                    $dbrec->contextid = $context->id;
                    $dbrec->lowerboundary = backup_todb($info['GRADE_LETTER']['#']['GRADE_LOW']['0']['#']);
                    $dbrec->letter = backup_todb($info['GRADE_LETTER']['#']['LETTER']['0']['#']);
                    insert_record('grade_letters', $dbrec);
                }
            }
        }
    }
    if (!defined('RESTORE_SILENTLY')) {
        echo '<li>' . get_string('categories', 'grades') . '</li>';
    }
    //Fetch recordset_size records in each iteration
    $recs = get_records_select("backup_ids", "table_name = 'grade_category' AND backup_code = {$restore->backup_unique_code}", "old_id", "old_id");
    $cat_count = count($recs);
    if ($recs) {
        foreach ($recs as $rec) {
            //Get the full record from backup_ids
            $data = backup_getid($restore->backup_unique_code, 'grade_category', $rec->old_id);
            if ($data) {
                //Now get completed xmlized object
                $info = $data->info;
                if ($restoreall) {
                    if ($cat_count == 1) {
                        $course_category->fullname = backup_todb($info['GRADE_CATEGORY']['#']['NAME']['0']['#'], false);
                        $course_category->droplow = backup_todb($info['GRADE_CATEGORY']['#']['DROP_X_LOWEST']['0']['#'], false);
                        $course_category->aggregation = GRADE_AGGREGATE_WEIGHTED_MEAN2;
                        $course_category->aggregateonlygraded = 0;
                        $course_category->update('restore');
                        $grade_category = $course_category;
                    } else {
                        $grade_category = new grade_category();
                        $grade_category->courseid = $restore->course_id;
                        $grade_category->fullname = backup_todb($info['GRADE_CATEGORY']['#']['NAME']['0']['#'], false);
                        $grade_category->droplow = backup_todb($info['GRADE_CATEGORY']['#']['DROP_X_LOWEST']['0']['#'], false);
                        $grade_category->aggregation = GRADE_AGGREGATE_WEIGHTED_MEAN2;
                        $grade_category->aggregateonlygraded = 0;
                        $grade_category->insert('restore');
//.........这里部分代码省略.........
开发者ID:kai707,项目名称:ITSA-backup,代码行数:101,代码来源:restorelib.php


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