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


PHP grade_outcome::insert方法代码示例

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


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

示例1: array

                } else {
                    $scale_data['courseid'] = 0;
                    // 'global' : scale use '0', outcomes use null
                }
                $scale = new grade_scale($scale_data);
                $scale_id = $scale->insert();
            }
        }
        // add outcome
        $outcome_data = array('shortname' => $csv_data[$imported_headers['outcome_shortname']], 'fullname' => $csv_data[$imported_headers['outcome_name']], 'scaleid' => $scale_id, 'description' => $csv_data[$imported_headers['outcome_description']], 'usermodified' => $USER->id);
        if ($local_scope) {
            $outcome_data['courseid'] = $courseid;
        } else {
            $outcome_data['courseid'] = null;
            // 'global' : scale use '0', outcomes use null
        }
        $outcome = new grade_outcome($outcome_data);
        $outcome_id = $outcome->insert();
        $outcome_success_strings = new StdClass();
        $outcome_success_strings->name = $outcome_data['fullname'];
        $outcome_success_strings->id = $outcome_id;
        echo $OUTPUT->box(get_string('importoutcomesuccess', 'grades', $outcome_success_strings));
    }
} else {
    echo $OUTPUT->box(get_string('importoutcomenofile', 'grades', 0));
}
// finish
fclose($handle);
// delete temp file
unlink($imported_file);
echo $OUTPUT->footer();
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:31,代码来源:import.php

示例2: restore_create_gradebook

/**
 * This function creates all the gradebook data from xml
 */
function restore_create_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;
    }
    if (empty($CFG->disablegradehistory) and isset($info->gradebook_histories) and $info->gradebook_histories == "true") {
        $restore_histories = true;
    } else {
        $restore_histories = false;
    }
    // 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 or already exist
    $importing = !empty($SESSION->restore->importing);
    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 - course item or category already exist
        if (count($prev_grade_items) > 1 or count($prev_grade_cats) > 1) {
            $restoreall = false;
        }
        unset($prev_grade_items);
        unset($prev_grade_cats);
        if ($restoreall) {
            if ($recs = get_records_select("backup_ids", "table_name = 'grade_items' AND backup_code = {$restore->backup_unique_code}", "", "old_id")) {
                foreach ($recs as $rec) {
                    if ($data = backup_getid($restore->backup_unique_code, 'grade_items', $rec->old_id)) {
                        $info = $data->info;
                        // do not restore if this grade_item is a mod, and
                        $itemtype = backup_todb($info['GRADE_ITEM']['#']['ITEMTYPE']['0']['#']);
                        if ($itemtype == 'mod') {
                            $olditeminstance = backup_todb($info['GRADE_ITEM']['#']['ITEMINSTANCE']['0']['#']);
                            $itemmodule = backup_todb($info['GRADE_ITEM']['#']['ITEMMODULE']['0']['#']);
                            if (empty($restore->mods[$itemmodule]->granular)) {
                                continue;
                            } else {
                                if (!empty($restore->mods[$itemmodule]->instances[$olditeminstance]->restore)) {
                                    continue;
                                }
                            }
                            // at least one activity should not be restored - do not restore categories and manual items at all
                            $restoreall = false;
                            break;
                        }
                    }
                }
            }
        }
    }
    // Start ul
    if (!defined('RESTORE_SILENTLY')) {
        echo '<ul>';
    }
    // array of restored categories - speedup ;-)
    $cached_categories = array();
    $outcomes = array();
    /// 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_letters' 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_letters', $rec->old_id);
                if ($data) {
                    $info = $data->info;
                    $dbrec = new object();
                    $dbrec->contextid = $context->id;
                    $dbrec->lowerboundary = backup_todb($info['GRADE_LETTER']['#']['LOWERBOUNDARY']['0']['#']);
                    $dbrec->letter = backup_todb($info['GRADE_LETTER']['#']['LETTER']['0']['#']);
                    insert_record('grade_letters', $dbrec);
                }
            }
        }
    }
//.........这里部分代码省略.........
开发者ID:kai707,项目名称:ITSA-backup,代码行数:101,代码来源:restorelib.php

示例3: create_grade_outcome

 /**
  * Create a grade_outcome.
  *
  * @param array|stdClass $record
  * @return stdClass the grade outcome record
  */
 public function create_grade_outcome($record = null)
 {
     global $CFG;
     $this->gradeoutcomecounter++;
     $i = $this->gradeoutcomecounter;
     if (!isset($record['fullname'])) {
         $record['fullname'] = 'Grade outcome ' . $i;
     }
     // For gradelib classes.
     require_once $CFG->libdir . '/gradelib.php';
     // Create new grading outcome in this course.
     $gradeoutcome = new grade_outcome($record, false);
     $gradeoutcome->insert();
     $gradeoutcome->update_from_db();
     return $gradeoutcome->get_record_data();
 }
开发者ID:pzhu2004,项目名称:moodle,代码行数:22,代码来源:data_generator.php

示例4: load_test_data

 /**
  * Load initial test information
  *
  * @param  string $assignmentname   Assignment name
  * @param  int $student1rawgrade    Student 1 grade
  * @param  int $student2rawgrade    Student 2 grade
  * @return array                    Array of vars with test information
  */
 protected function load_test_data($assignmentname, $student1rawgrade, $student2rawgrade)
 {
     global $DB;
     // Adds a course, a teacher, 2 students, an assignment and grades for the students.
     $course = $this->getDataGenerator()->create_course();
     $coursecontext = context_course::instance($course->id);
     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
     $student1 = $this->getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($student1->id, $course->id, $studentrole->id);
     $student2 = $this->getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($student2->id, $course->id, $studentrole->id);
     $teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher'));
     $teacher = $this->getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($teacher->id, $course->id, $teacherrole->id);
     $parent = $this->getDataGenerator()->create_user();
     $this->setUser($parent);
     $student1context = context_user::instance($student1->id);
     // Creates a new role, gives it the capability and gives $USER that role.
     $parentroleid = $this->assignUserCapability('moodle/grade:viewall', $student1context->id);
     // Enrol the user in the course using the new role.
     $this->getDataGenerator()->enrol_user($parent->id, $course->id, $parentroleid);
     $assignment = $this->getDataGenerator()->create_module('assign', array('name' => $assignmentname, 'course' => $course->id));
     $modcontext = get_coursemodule_from_instance('assign', $assignment->id, $course->id);
     $assignment->cmidnumber = $modcontext->id;
     $student1grade = array('userid' => $student1->id, 'rawgrade' => $student1rawgrade);
     $student2grade = array('userid' => $student2->id, 'rawgrade' => $student2rawgrade);
     $studentgrades = array($student1->id => $student1grade, $student2->id => $student2grade);
     assign_grade_item_update($assignment, $studentgrades);
     // Insert a custom grade scale to be used by an outcome.
     $gradescale = new grade_scale();
     $gradescale->name = 'unittestscale3';
     $gradescale->courseid = $course->id;
     $gradescale->userid = 0;
     $gradescale->scale = 'Distinction, Very Good, Good, Pass, Fail';
     $gradescale->description = 'This scale is used to mark standard assignments.';
     $gradescale->insert();
     // Insert an outcome.
     $data = new stdClass();
     $data->courseid = $course->id;
     $data->fullname = 'Team work';
     $data->shortname = 'Team work';
     $data->scaleid = $gradescale->id;
     $outcome = new grade_outcome($data, false);
     $outcome->insert();
     $outcomegradeitem = new grade_item();
     $outcomegradeitem->itemname = $outcome->shortname;
     $outcomegradeitem->itemtype = 'mod';
     $outcomegradeitem->itemmodule = 'assign';
     $outcomegradeitem->iteminstance = $assignment->id;
     $outcomegradeitem->outcomeid = $outcome->id;
     $outcomegradeitem->cmid = 0;
     $outcomegradeitem->courseid = $course->id;
     $outcomegradeitem->aggregationcoef = 0;
     $outcomegradeitem->itemnumber = 1;
     // The activity's original grade item will be 0.
     $outcomegradeitem->gradetype = GRADE_TYPE_SCALE;
     $outcomegradeitem->scaleid = $outcome->scaleid;
     // This next two values for testing that returns parameters are correcly formatted.
     $outcomegradeitem->set_locked(true);
     $outcomegradeitem->hidden = '';
     $outcomegradeitem->insert();
     $assignmentgradeitem = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'assign', 'iteminstance' => $assignment->id, 'itemnumber' => 0, 'courseid' => $course->id));
     $outcomegradeitem->set_parent($assignmentgradeitem->categoryid);
     $outcomegradeitem->move_after_sortorder($assignmentgradeitem->sortorder);
     return array($course, $assignment, $student1, $student2, $teacher, $parent);
 }
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:74,代码来源:grades_externallib_test.php

示例5: test_get_course_module

 /**
  * Test get_course_module
  */
 public function test_get_course_module()
 {
     global $DB;
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $course = self::getDataGenerator()->create_course();
     $record = array('course' => $course->id, 'name' => 'First Assignment');
     $options = array('idnumber' => 'ABC', 'visible' => 0);
     // Hidden activity.
     $assign = self::getDataGenerator()->create_module('assign', $record, $options);
     $outcomescale = 'Distinction, Very Good, Good, Pass, Fail';
     // Insert a custom grade scale to be used by an outcome.
     $gradescale = new grade_scale();
     $gradescale->name = 'gettcoursemodulescale';
     $gradescale->courseid = $course->id;
     $gradescale->userid = 0;
     $gradescale->scale = $outcomescale;
     $gradescale->description = 'This scale is used to mark standard assignments.';
     $gradescale->insert();
     // Insert an outcome.
     $data = new stdClass();
     $data->courseid = $course->id;
     $data->fullname = 'Team work';
     $data->shortname = 'Team work';
     $data->scaleid = $gradescale->id;
     $outcome = new grade_outcome($data, false);
     $outcome->insert();
     $outcomegradeitem = new grade_item();
     $outcomegradeitem->itemname = $outcome->shortname;
     $outcomegradeitem->itemtype = 'mod';
     $outcomegradeitem->itemmodule = 'assign';
     $outcomegradeitem->iteminstance = $assign->id;
     $outcomegradeitem->outcomeid = $outcome->id;
     $outcomegradeitem->cmid = 0;
     $outcomegradeitem->courseid = $course->id;
     $outcomegradeitem->aggregationcoef = 0;
     $outcomegradeitem->itemnumber = 1;
     // The activity's original grade item will be 0.
     $outcomegradeitem->gradetype = GRADE_TYPE_SCALE;
     $outcomegradeitem->scaleid = $outcome->scaleid;
     $outcomegradeitem->insert();
     $assignmentgradeitem = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'assign', 'iteminstance' => $assign->id, 'itemnumber' => 0, 'courseid' => $course->id));
     $outcomegradeitem->set_parent($assignmentgradeitem->categoryid);
     $outcomegradeitem->move_after_sortorder($assignmentgradeitem->sortorder);
     // Test admin user can see the complete hidden activity.
     $result = core_course_external::get_course_module($assign->cmid);
     $result = external_api::clean_returnvalue(core_course_external::get_course_module_returns(), $result);
     $this->assertCount(0, $result['warnings']);
     // Test we retrieve all the fields.
     $this->assertCount(27, $result['cm']);
     $this->assertEquals($record['name'], $result['cm']['name']);
     $this->assertEquals($options['idnumber'], $result['cm']['idnumber']);
     $this->assertEquals(100, $result['cm']['grade']);
     $this->assertEquals(0.0, $result['cm']['gradepass']);
     $this->assertEquals('submissions', $result['cm']['advancedgrading'][0]['area']);
     $this->assertEmpty($result['cm']['advancedgrading'][0]['method']);
     $this->assertEquals($outcomescale, $result['cm']['outcomes'][0]['scale']);
     $student = $this->getDataGenerator()->create_user();
     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
     self::getDataGenerator()->enrol_user($student->id, $course->id, $studentrole->id);
     $this->setUser($student);
     // The user shouldn't be able to see the activity.
     try {
         core_course_external::get_course_module($assign->cmid);
         $this->fail('Exception expected due to invalid permissions.');
     } catch (moodle_exception $e) {
         $this->assertEquals('requireloginerror', $e->errorcode);
     }
     // Make module visible.
     set_coursemodule_visible($assign->cmid, 1);
     // Test student user.
     $result = core_course_external::get_course_module($assign->cmid);
     $result = external_api::clean_returnvalue(core_course_external::get_course_module_returns(), $result);
     $this->assertCount(0, $result['warnings']);
     // Test we retrieve only the few files we can see.
     $this->assertCount(11, $result['cm']);
     $this->assertEquals($assign->cmid, $result['cm']['id']);
     $this->assertEquals($course->id, $result['cm']['course']);
     $this->assertEquals('assign', $result['cm']['modname']);
     $this->assertEquals($assign->id, $result['cm']['instance']);
 }
开发者ID:dg711,项目名称:moodle,代码行数:84,代码来源:externallib_test.php

示例6: test_version1importdeletecoursedeletesassociations

 /**
  * Validate that the version 1 plugin deletes appropriate associations when
  * deleting a course
  */
 public function test_version1importdeletecoursedeletesassociations()
 {
     global $DB, $CFG, $USER;
     require_once $CFG->dirroot . '/user/lib.php';
     require_once $CFG->dirroot . '/lib/gradelib.php';
     require_once $CFG->dirroot . '/group/lib.php';
     require_once $CFG->dirroot . '/lib/conditionlib.php';
     require_once $CFG->dirroot . '/lib/enrollib.php';
     require_once $CFG->dirroot . '/tag/lib.php';
     require_once $CFG->dirroot . '/lib/questionlib.php';
     // Setup.
     $initialnumcontexts = $DB->count_records('context', array('contextlevel' => CONTEXT_COURSE));
     $DB->delete_records('block_instances');
     // Set up the course with one section, including default blocks.
     set_config('defaultblocks_topics', 'search_forums');
     set_config('maxsections', 10, 'moodlecourse');
     $this->run_core_course_import(array('shortname' => 'deleteassociationsshortname', 'numsections' => 1));
     // Create a user record.
     $record = new stdClass();
     $record->username = 'testuser';
     $record->password = 'Testpass!0';
     $userid = user_create_user($record);
     // Create a course-level role.
     $courseid = $DB->get_field('course', 'id', array('shortname' => 'deleteassociationsshortname'));
     $coursecontext = context_course::instance($courseid);
     $roleid = create_role('deleterole', 'deleterole', 'deleterole');
     set_role_contextlevels($roleid, array(CONTEXT_COURSE));
     $enrol = new stdClass();
     $enrol->enrol = 'manual';
     $enrol->courseid = $courseid;
     $enrol->status = ENROL_INSTANCE_ENABLED;
     if (!$DB->record_exists('enrol', (array) $enrol)) {
         $DB->insert_record('enrol', $enrol);
     }
     // Assign the user to the course-level role.
     enrol_try_internal_enrol($courseid, $userid, $roleid);
     // Create a grade item.
     $gradeitem = new grade_item(array('courseid' => $courseid, 'itemtype' => 'manual', 'itemname' => 'testitem'), false);
     $gradeitem->insert();
     $gradegrade = new grade_grade(array('itemid' => $gradeitem->id, 'userid' => $userid), false);
     // Assign the user a grade.
     $gradegrade->insert();
     // Create a grade outcome.
     $gradeoutcome = new grade_outcome(array('courseid' => $courseid, 'shortname' => 'bogusshortname', 'fullname' => 'bogusfullname'));
     $gradeoutcome->insert();
     // Create a grade scale.
     $gradescale = new grade_scale(array('courseid' => $courseid, 'name' => 'bogusname', 'userid' => $userid, 'scale' => 'bogusscale', 'description' => 'bogusdescription'));
     $gradescale->insert();
     // Set a grade setting value.
     grade_set_setting($courseid, 'bogus', 'bogus');
     // Set up a grade letter.
     $gradeletter = new stdClass();
     $gradeletter->contextid = $coursecontext->id;
     $gradeletter->lowerboundary = 80;
     $gradeletter->letter = 'A';
     $DB->insert_record('grade_letters', $gradeletter);
     // Set up a forum instance.
     $forum = new stdClass();
     $forum->course = $courseid;
     $forum->intro = 'intro';
     $forum->id = $DB->insert_record('forum', $forum);
     // Add it as a course module.
     $forum->module = $DB->get_field('modules', 'id', array('name' => 'forum'));
     $forum->instance = $forum->id;
     $cmid = add_course_module($forum);
     // Set up a completion record.
     $completion = new stdClass();
     $completion->coursemoduleid = $cmid;
     $completion->completionstate = 0;
     $completion->userid = 9999;
     $completion->timemodified = time();
     $DB->insert_record('course_modules_completion', $completion);
     // Set up a completion condition.
     $forum->id = $cmid;
     $ci = new condition_info($forum, CONDITION_MISSING_EVERYTHING, false);
     $ci->add_completion_condition($cmid, COMPLETION_ENABLED);
     // Set the blocks position.
     $instances = $DB->get_records('block_instances', array('parentcontextid' => $coursecontext->id));
     $page = new stdClass();
     $page->context = $coursecontext;
     $page->pagetype = 'course-view-*';
     $page->subpage = false;
     foreach ($instances as $instance) {
         blocks_set_visibility($instance, $page, 1);
     }
     // Create a group.
     $group = new stdClass();
     $group->name = 'testgroup';
     $group->courseid = $courseid;
     $groupid = groups_create_group($group);
     // Add the user to the group.
     groups_add_member($groupid, $userid);
     // Create a grouping containing our group.
     $grouping = new stdClass();
     $grouping->name = 'testgrouping';
     $grouping->courseid = $courseid;
//.........这里部分代码省略.........
开发者ID:jamesmcq,项目名称:elis,代码行数:101,代码来源:version1_course_import_test.php


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