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


PHP grade_category::insert方法代码示例

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


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

示例1: stdClass

 function test_grade_category_construct()
 {
     $course_category = grade_category::fetch_course_category($this->courseid);
     $params = new stdClass();
     $params->courseid = $this->courseid;
     $params->fullname = 'unittestcategory4';
     $grade_category = new grade_category($params, false);
     $grade_category->insert();
     $this->assertEqual($params->courseid, $grade_category->courseid);
     $this->assertEqual($params->fullname, $grade_category->fullname);
     $this->assertEqual(2, $grade_category->depth);
     $this->assertEqual("/{$course_category->id}/{$grade_category->id}/", $grade_category->path);
     $parentpath = $grade_category->path;
     // Test a child category
     $params->parent = $grade_category->id;
     $params->fullname = 'unittestcategory5';
     $grade_category = new grade_category($params, false);
     $grade_category->insert();
     $this->assertEqual(3, $grade_category->depth);
     $this->assertEqual($parentpath . $grade_category->id . "/", $grade_category->path);
     $parentpath = $grade_category->path;
     // Test a third depth category
     $params->parent = $grade_category->id;
     $params->fullname = 'unittestcategory6';
     $grade_category = new grade_category($params, false);
     $grade_category->insert();
     $this->assertEqual(4, $grade_category->depth);
     $this->assertEqual($parentpath . $grade_category->id . "/", $grade_category->path);
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:29,代码来源:testgradecategory.php

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

示例3: test_update_item_multiple_categories

 /**
  * Tests the gradebookservice update grade function for adding an item in a category,
  * where multiple categories with the same name already exist. The item should be assigned
  * to the oldest category. When moved to a category with a different name, the item should
  * be assigned to the new category. No tasks should be created and no locking should be triggered.
  *
  * @return void
  */
 public function test_update_item_multiple_categories()
 {
     global $DB, $CFG;
     $this->set_user('admin');
     // No tasks.
     $this->assertEquals(0, $DB->count_records('task_adhoc'));
     $catname = 'testcat';
     $catname1 = 'testcat1';
     $catparams = array('fullname' => $catname, 'courseid' => $this->course->id, 'hidden' => false);
     // Create category.
     $category = new \grade_category($catparams, false);
     $categoryid1 = $category->insert();
     // Create second category with the same name.
     $category = new \grade_category($catparams, false);
     $categoryid2 = $category->insert();
     // Create another category with the different name.
     $catparams['fullname'] = $catname1;
     $category = new \grade_category($catparams, false);
     $categoryid3 = $category->insert();
     // Add item 101 to $catname.
     $this->add_grade_item('101', $catname);
     // No tasks.
     $this->assertEquals(0, $DB->count_records('task_adhoc'));
     // The items should be assigned to category 1.
     $params = array('iteminstance' => '101', 'categoryid' => $categoryid1, 'courseid' => $this->course->id);
     $this->assertEquals(1, $DB->count_records('grade_items', $params));
     // Add item 102 to $catname.
     $this->add_grade_item('102', $catname);
     // No tasks.
     $this->assertEquals(0, $DB->count_records('task_adhoc'));
     // The item should be assigned to the category 1.
     $params = array('iteminstance' => '102', 'categoryid' => $categoryid1, 'courseid' => $this->course->id);
     $this->assertEquals(1, $DB->count_records('grade_items', $params));
     // Add item 103 to $catname1.
     $this->add_grade_item('103', $catname1);
     // No tasks.
     $this->assertEquals(0, $DB->count_records('task_adhoc'));
     // The item should be assigned to the category 3.
     $params = array('iteminstance' => '103', 'categoryid' => $categoryid3, 'courseid' => $this->course->id);
     $this->assertEquals(1, $DB->count_records('grade_items', $params));
     // Move item 102 to $catname1.
     $this->add_grade_item('102', $catname1);
     // No tasks.
     $this->assertEquals(0, $DB->count_records('task_adhoc'));
     // There should be two items assigned to the category 3.
     $params = array('categoryid' => $categoryid3, 'courseid' => $this->course->id);
     $this->assertEquals(2, $DB->count_records('grade_items', $params));
     // The item should be assigned to the category 3.
     $params['iteminstance'] = '102';
     $this->assertEquals(1, $DB->count_records('grade_items', $params));
 }
开发者ID:itamart,项目名称:moodle-block_mhaairs,代码行数:59,代码来源:gradebookservice_update_item_category_test.php

示例4: edit_module_post_actions

/**
 * Common create/update module module actions that need to be processed as soon as a module is created/updaded.
 * For example:create grade parent category, add outcomes, rebuild caches, regrade, save plagiarism settings...
 * Please note this api does not trigger events as of MOODLE 2.6. Please trigger events before calling this api.
 *
 * @param object $moduleinfo the module info
 * @param object $course the course of the module
 *
 * @return object moduleinfo update with grading management info
 */
function edit_module_post_actions($moduleinfo, $course)
{
    global $CFG;
    require_once $CFG->libdir . '/gradelib.php';
    $modcontext = context_module::instance($moduleinfo->coursemodule);
    $hasgrades = plugin_supports('mod', $moduleinfo->modulename, FEATURE_GRADE_HAS_GRADE, false);
    $hasoutcomes = plugin_supports('mod', $moduleinfo->modulename, FEATURE_GRADE_OUTCOMES, true);
    // Sync idnumber with grade_item.
    if ($hasgrades && ($grade_item = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $moduleinfo->modulename, 'iteminstance' => $moduleinfo->instance, 'itemnumber' => 0, 'courseid' => $course->id)))) {
        if ($grade_item->idnumber != $moduleinfo->cmidnumber) {
            $grade_item->idnumber = $moduleinfo->cmidnumber;
            $grade_item->update();
        }
    }
    if ($hasgrades) {
        $items = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => $moduleinfo->modulename, 'iteminstance' => $moduleinfo->instance, 'courseid' => $course->id));
    } else {
        $items = array();
    }
    // Create parent category if requested and move to correct parent category.
    if ($items and isset($moduleinfo->gradecat)) {
        if ($moduleinfo->gradecat == -1) {
            $grade_category = new grade_category();
            $grade_category->courseid = $course->id;
            $grade_category->fullname = $moduleinfo->name;
            $grade_category->insert();
            if ($grade_item) {
                $parent = $grade_item->get_parent_category();
                $grade_category->set_parent($parent->id);
            }
            $moduleinfo->gradecat = $grade_category->id;
        }
        $gradecategory = $grade_item->get_parent_category();
        foreach ($items as $itemid => $unused) {
            $items[$itemid]->set_parent($moduleinfo->gradecat);
            if ($itemid == $grade_item->id) {
                // Use updated grade_item.
                $grade_item = $items[$itemid];
            }
            if (!empty($moduleinfo->add)) {
                if (grade_category::aggregation_uses_aggregationcoef($gradecategory->aggregation)) {
                    if ($gradecategory->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
                        $grade_item->aggregationcoef = 1;
                    } else {
                        $grade_item->aggregationcoef = 0;
                    }
                    $grade_item->update();
                }
            }
        }
    }
    require_once $CFG->libdir . '/grade/grade_outcome.php';
    // Add outcomes if requested.
    if ($hasoutcomes && ($outcomes = grade_outcome::fetch_all_available($course->id))) {
        $grade_items = array();
        // Outcome grade_item.itemnumber start at 1000, there is nothing above outcomes.
        $max_itemnumber = 999;
        if ($items) {
            foreach ($items as $item) {
                if ($item->itemnumber > $max_itemnumber) {
                    $max_itemnumber = $item->itemnumber;
                }
            }
        }
        foreach ($outcomes as $outcome) {
            $elname = 'outcome_' . $outcome->id;
            if (property_exists($moduleinfo, $elname) and $moduleinfo->{$elname}) {
                // So we have a request for new outcome grade item?
                if ($items) {
                    $outcomeexists = false;
                    foreach ($items as $item) {
                        if ($item->outcomeid == $outcome->id) {
                            $outcomeexists = true;
                            break;
                        }
                    }
                    if ($outcomeexists) {
                        continue;
                    }
                }
                $max_itemnumber++;
                $outcome_item = new grade_item();
                $outcome_item->courseid = $course->id;
                $outcome_item->itemtype = 'mod';
                $outcome_item->itemmodule = $moduleinfo->modulename;
                $outcome_item->iteminstance = $moduleinfo->instance;
                $outcome_item->itemnumber = $max_itemnumber;
                $outcome_item->itemname = $outcome->fullname;
                $outcome_item->outcomeid = $outcome->id;
                $outcome_item->gradetype = GRADE_TYPE_SCALE;
//.........这里部分代码省略.........
开发者ID:abhilash1994,项目名称:moodle,代码行数:101,代码来源:modlib.php

示例5: RWSUQGrades

function RWSUQGrades($r_qiz)
{
    $r_gi = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $r_qiz->modulename, 'iteminstance' => $r_qiz->instance, 'itemnumber' => 0, 'courseid' => $r_qiz->course));
    if ($r_gi && $r_gi->idnumber != $r_qiz->cmidnumber) {
        $r_gi->idnumber = $r_qiz->cmidnumber;
        $r_gi->update();
    }
    $r_its = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => $r_qiz->modulename, 'iteminstance' => $r_qiz->instance, 'courseid' => $r_qiz->course));
    if ($r_its && isset($r_qiz->gradecat)) {
        if ($r_qiz->gradecat == -1) {
            $r_gcat = new grade_category();
            $r_gcat->courseid = $r_qiz->course;
            $r_gcat->fullname = $r_qiz->name;
            $r_gcat->insert();
            if ($r_gi) {
                $r_par = $r_gi->get_parent_category();
                $r_gcat->set_parent($r_par->id);
            }
            $r_qiz->gradecat = $r_gcat->id;
        }
        foreach ($r_its as $r_iti => $r_un) {
            $r_its[$r_iti]->set_parent($r_qiz->gradecat);
            if ($r_iti == $r_gi->id) {
                $r_gi = $r_its[$r_iti];
            }
        }
    }
    if ($r_ocs = grade_outcome::fetch_all_available($r_qiz->course)) {
        $r_gis = array();
        $r_mit = 999;
        if ($r_its) {
            foreach ($r_its as $r_it) {
                if ($r_it->itemnumber > $r_mit) {
                    $r_mit = $r_it->itemnumber;
                }
            }
        }
        foreach ($r_ocs as $r_oc) {
            $r_eln = 'outcome_' . $r_oc->id;
            if (property_exists($r_qiz, $r_eln) and $r_qiz->{$r_eln}) {
                if ($r_its) {
                    foreach ($r_its as $r_it) {
                        if ($r_it->outcomeid == $r_oc->id) {
                            continue 2;
                        }
                    }
                }
                $r_mit++;
                $r_oi = new grade_item();
                $r_oi->courseid = $r_qiz->course;
                $r_oi->itemtype = 'mod';
                $r_oi->itemmodule = $r_qiz->modulename;
                $r_oi->iteminstance = $r_qiz->instance;
                $r_oi->itemnumber = $r_mit;
                $r_oi->itemname = $r_oc->fullname;
                $r_oi->outcomeid = $r_oc->id;
                $r_oi->gradetype = GRADE_TYPE_SCALE;
                $r_oi->scaleid = $r_oc->scaleid;
                $r_oi->insert();
                if ($r_gi) {
                    $r_oi->set_parent($r_gi->categoryid);
                    $r_oi->move_after_sortorder($r_gi->sortorder);
                } else {
                    if (isset($r_qiz->gradecat)) {
                        $r_oi->set_parent($r_qiz->gradecat);
                    }
                }
            }
        }
    }
}
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:71,代码来源:servicelib.php

示例6: test_grade_grade_min_max_with_category_item

 public function test_grade_grade_min_max_with_category_item()
 {
     global $CFG, $DB;
     $initialminmaxtouse = $CFG->grade_minmaxtouse;
     $this->setAdminUser();
     $course = $this->getDataGenerator()->create_course();
     $user = $this->getDataGenerator()->create_user();
     $coursegi = grade_item::fetch_course_item($course->id);
     // Create a category item.
     $gc = new grade_category(array('courseid' => $course->id, 'fullname' => 'test'), false);
     $gc->insert();
     $gi = $gc->get_grade_item();
     $gi->grademax = 100;
     $gi->grademin = 0;
     $gi->update();
     // Fetch the category item.
     $giparams = array('itemtype' => 'category', 'iteminstance' => $gc->id);
     $gi = grade_item::fetch($giparams);
     $this->assertEquals(0, $gi->grademin);
     $this->assertEquals(100, $gi->grademax);
     // Give a grade to the student.
     $gi->update_final_grade($user->id, 10);
     // Check the grade min/max stored in gradebook.
     $gg = grade_grade::fetch(array('userid' => $user->id, 'itemid' => $gi->id));
     $this->assertEquals(0, $gg->get_grade_min());
     $this->assertEquals(100, $gg->get_grade_max());
     // Change the min/max grade of the item.
     $gi->grademin = 2;
     $gi->grademax = 50;
     $gi->update();
     // Fetch the updated item.
     $gi = grade_item::fetch($giparams);
     // Now check the grade grade min/max with system setting.
     $CFG->grade_minmaxtouse = GRADE_MIN_MAX_FROM_GRADE_ITEM;
     grade_set_setting($course->id, 'minmaxtouse', null);
     // Ensure no course setting.
     $gg = grade_grade::fetch(array('userid' => $user->id, 'itemid' => $gi->id));
     $this->assertEquals(0, $gg->get_grade_min());
     $this->assertEquals(100, $gg->get_grade_max());
     // Now with other system setting.
     $CFG->grade_minmaxtouse = GRADE_MIN_MAX_FROM_GRADE_GRADE;
     grade_set_setting($course->id, 'minmaxtouse', null);
     // Ensure no course setting, and reset static cache.
     $gg = grade_grade::fetch(array('userid' => $user->id, 'itemid' => $gi->id));
     $this->assertEquals(0, $gg->get_grade_min());
     $this->assertEquals(100, $gg->get_grade_max());
     // Now with overriden setting in course.
     $CFG->grade_minmaxtouse = GRADE_MIN_MAX_FROM_GRADE_ITEM;
     grade_set_setting($course->id, 'minmaxtouse', GRADE_MIN_MAX_FROM_GRADE_GRADE);
     $gg = grade_grade::fetch(array('userid' => $user->id, 'itemid' => $gi->id));
     $this->assertEquals(0, $gg->get_grade_min());
     $this->assertEquals(100, $gg->get_grade_max());
     $CFG->grade_minmaxtouse = GRADE_MIN_MAX_FROM_GRADE_GRADE;
     grade_set_setting($course->id, 'minmaxtouse', GRADE_MIN_MAX_FROM_GRADE_ITEM);
     $gg = grade_grade::fetch(array('userid' => $user->id, 'itemid' => $gi->id));
     $this->assertEquals(0, $gg->get_grade_min());
     $this->assertEquals(100, $gg->get_grade_max());
     $CFG->grade_minmaxtouse = $initialminmaxtouse;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:59,代码来源:grade_grade_test.php

示例7: test_update_item_with_manual_item

 /**
  * Tests update grade service with existing regular manual items with the same name
  * as requested. Should update the first item and turn it into mhaairs item. Should not change
  * any item property other than the item instance.
  *
  * @return void
  */
 public function test_update_item_with_manual_item()
 {
     global $DB;
     $this->set_user('admin');
     $this->assertEquals(0, $DB->count_records('grade_items'));
     $catname = 'Existing grade category';
     $itemname = 'Existing grade item';
     // Create category.
     $catparams = array('fullname' => $catname, 'courseid' => $this->course->id, 'hidden' => false);
     $category = new \grade_category($catparams, false);
     $category->id = $category->insert();
     // Add two manual grade item directly.
     $itemparams = array('courseid' => $this->course->id, 'itemtype' => 'manual', 'itemname' => $itemname, 'categoryid' => $category->id);
     $gitem = new \grade_item($itemparams, false);
     $gitem->insert('manual');
     $gitem = new \grade_item($itemparams, false);
     $gitem->insert('manual');
     // There should be 4 items (including course and category items).
     $itemcount = $DB->count_records('grade_items');
     $this->assertEquals(4, $itemcount);
     $service = 'block_mhaairs_gradebookservice_external::update_grade';
     $itemdetails = array('itemname' => $itemname, 'grademax' => 90, 'useexisting' => 1, 'categoryid' => 'New grade category');
     $itemdetailsjson = urlencode(json_encode($itemdetails));
     // Update item via service.
     $servicedata = array();
     $servicedata['source'] = 'mhaairs';
     $servicedata['courseid'] = 'tc1';
     $servicedata['itemtype'] = 'manual';
     $servicedata['itemmodule'] = 'mhaairs';
     $servicedata['iteminstance'] = 345;
     $servicedata['itemnumber'] = 0;
     $servicedata['grades'] = null;
     $servicedata['itemdetails'] = $itemdetailsjson;
     $result = call_user_func_array($service, $servicedata);
     // 2 grade categories overall.
     $itemcount = $DB->count_records('grade_categories');
     $this->assertEquals(2, $itemcount);
     // 4 grade items overall.
     $itemcount = $DB->count_records('grade_items');
     $this->assertEquals(4, $itemcount);
     // 2 manual items remaining.
     $itemcount = $DB->count_records('grade_items', array('itemtype' => 'manual'));
     $this->assertEquals(2, $itemcount);
     // 1 mhaairs item.
     $itemcount = $DB->count_records('grade_items', array('itemtype' => 'manual', 'itemmodule' => 'mhaairs'));
     $this->assertEquals(1, $itemcount);
     // 1 mhaairs item with the item instance and original grade.
     $itemcount = $DB->count_records('grade_items', array('itemtype' => 'manual', 'itemmodule' => 'mhaairs', 'iteminstance' => 345, 'grademax' => 100.0, 'categoryid' => $category->id));
     $this->assertEquals(1, $itemcount);
 }
开发者ID:itamart,项目名称:moodle-block_mhaairs,代码行数:57,代码来源:gradebookservice_useexisting_test.php

示例8: sub_test_grade_category_generate_grades

 /**
  * Tests the calculation of grades using the various aggregation methods with and without hidden grades
  * This will not work entirely until MDL-11837 is done
  * @global type $DB
  */
 protected function sub_test_grade_category_generate_grades()
 {
     global $DB;
     //inserting some special grade items to make testing the final grade calculation easier
     $params->courseid = $this->courseid;
     $params->fullname = 'unittestgradecalccategory';
     $params->aggregation = GRADE_AGGREGATE_MEAN;
     $params->aggregateonlygraded = 0;
     $grade_category = new grade_category($params, false);
     $grade_category->insert();
     $this->assertTrue(method_exists($grade_category, 'generate_grades'));
     $grade_category->load_grade_item();
     $cgi = $grade_category->get_grade_item();
     $cgi->grademin = 0;
     $cgi->grademax = 20;
     //3 grade items out of 10 but category is out of 20 to force scaling to occur
     $cgi->update();
     //3 grade items each with a maximum grade of 10
     $grade_items = array();
     for ($i = 0; $i < 3; $i++) {
         $grade_items[$i] = new grade_item();
         $grade_items[$i]->courseid = $this->courseid;
         $grade_items[$i]->categoryid = $grade_category->id;
         $grade_items[$i]->itemname = 'manual grade_item ' . $i;
         $grade_items[$i]->itemtype = 'manual';
         $grade_items[$i]->itemnumber = 0;
         $grade_items[$i]->needsupdate = false;
         $grade_items[$i]->gradetype = GRADE_TYPE_VALUE;
         $grade_items[$i]->grademin = 0;
         $grade_items[$i]->grademax = 10;
         $grade_items[$i]->iteminfo = 'Manual grade item used for unit testing';
         $grade_items[$i]->timecreated = time();
         $grade_items[$i]->timemodified = time();
         //used as the weight by weighted mean and as extra credit by mean with extra credit
         //Will be 0, 1 and 2
         $grade_items[$i]->aggregationcoef = $i;
         $grade_items[$i]->insert();
     }
     //a grade for each grade item
     $grade_grades = array();
     for ($i = 0; $i < 3; $i++) {
         $grade_grades[$i] = new grade_grade();
         $grade_grades[$i]->itemid = $grade_items[$i]->id;
         $grade_grades[$i]->userid = $this->userid;
         $grade_grades[$i]->rawgrade = ($i + 1) * 2;
         //produce grade grades of 2, 4 and 6
         $grade_grades[$i]->finalgrade = ($i + 1) * 2;
         $grade_grades[$i]->timecreated = time();
         $grade_grades[$i]->timemodified = time();
         $grade_grades[$i]->information = '1 of 2 grade_grades';
         $grade_grades[$i]->informationformat = FORMAT_PLAIN;
         $grade_grades[$i]->feedback = 'Good, but not good enough..';
         $grade_grades[$i]->feedbackformat = FORMAT_PLAIN;
         $grade_grades[$i]->insert();
     }
     //3 grade items with 1 grade_grade each.
     //grade grades have the values 2, 4 and 6
     //First correct answer is the aggregate with all 3 grades
     //Second correct answer is with the first grade (value 2) hidden
     $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_MEDIAN, 'GRADE_AGGREGATE_MEDIAN', 8, 8);
     $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_MAX, 'GRADE_AGGREGATE_MAX', 12, 12);
     $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_MODE, 'GRADE_AGGREGATE_MODE', 12, 12);
     //weighted mean. note grade totals are rounded to an int to prevent rounding discrepancies. correct final grade isnt actually exactly 10
     //3 items with grades 2, 4 and 6 with weights 0, 1 and 2 and all out of 10. then doubled to be out of 20.
     $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_WEIGHTED_MEAN, 'GRADE_AGGREGATE_WEIGHTED_MEAN', 10, 10);
     //simple weighted mean
     //3 items with grades 2, 4 and 6 equally weighted and all out of 10. then doubled to be out of 20.
     $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_WEIGHTED_MEAN2, 'GRADE_AGGREGATE_WEIGHTED_MEAN2', 8, 10);
     //mean of grades with extra credit
     //3 items with grades 2, 4 and 6 with extra credit 0, 1 and 2 equally weighted and all out of 10. then doubled to be out of 20.
     $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_EXTRACREDIT_MEAN, 'GRADE_AGGREGATE_EXTRACREDIT_MEAN', 10, 13);
     //aggregation tests the are affected by a hidden grade currently dont work as we dont store the altered grade in the database
     //instead an in memory recalculation is done. This should be remedied by MDL-11837
     //fails with 1 grade hidden. still reports 8 as being correct
     $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_MEAN, 'GRADE_AGGREGATE_MEAN', 8, 10);
     //fails with 1 grade hidden. still reports 4 as being correct
     $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_MIN, 'GRADE_AGGREGATE_MIN', 4, 8);
     //fails with 1 grade hidden. still reports 12 as being correct
     $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_SUM, 'GRADE_AGGREGATE_SUM', 12, 10);
 }
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:85,代码来源:grade_category_test.php

示例9: create_grade_category

 private function create_grade_category($course)
 {
     static $cnt = 0;
     $cnt++;
     $grade_category = new grade_category(array('courseid' => $course->id, 'fullname' => 'Cat ' . $cnt), false);
     $grade_category->apply_default_settings();
     $grade_category->apply_forced_settings();
     $grade_category->insert();
     return $grade_category;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:10,代码来源:report_graderlib_test.php

示例10: foreach

 }
 // sync idnumber with grade_item
 if ($grade_item = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $fromform->modulename, 'iteminstance' => $fromform->instance, 'itemnumber' => 0, 'courseid' => $course->id))) {
     if ($grade_item->idnumber != $fromform->cmidnumber) {
         $grade_item->idnumber = $fromform->cmidnumber;
         $grade_item->update();
     }
 }
 $items = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => $fromform->modulename, 'iteminstance' => $fromform->instance, 'courseid' => $course->id));
 // create parent category if requested and move to correct parent category
 if ($items and isset($fromform->gradecat)) {
     if ($fromform->gradecat == -1) {
         $grade_category = new grade_category();
         $grade_category->courseid = $course->id;
         $grade_category->fullname = $fromform->name;
         $grade_category->insert();
         if ($grade_item) {
             $parent = $grade_item->get_parent_category();
             $grade_category->set_parent($parent->id);
         }
         $fromform->gradecat = $grade_category->id;
     }
     foreach ($items as $itemid => $unused) {
         $items[$itemid]->set_parent($fromform->gradecat);
         if ($itemid == $grade_item->id) {
             // use updated grade_item
             $grade_item = $items[$itemid];
         }
     }
 }
 // add outcomes if requested
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:31,代码来源:modedit.php

示例11: create_grade_category

 /**
  * Create a grade_category.
  *
  * @param array|stdClass $record
  * @return stdClass the grade category record
  */
 public function create_grade_category($record = null)
 {
     global $CFG;
     $this->gradecategorycounter++;
     $i = $this->gradecategorycounter;
     if (!isset($record['fullname'])) {
         $record['fullname'] = 'Grade category ' . $i;
     }
     // For gradelib classes.
     require_once $CFG->libdir . '/gradelib.php';
     // Create new grading category in this course.
     $gradecategory = new grade_category($record, false);
     $gradecategory->apply_default_settings();
     $gradecategory->apply_forced_settings();
     $gradecategory->insert();
     // This creates a default grade item for the category
     $gradeitem = $gradecategory->load_grade_item();
     if (isset($record->parentcategory)) {
         $gradecategory->set_parent($data->parentcategory);
     }
     $gradecategory->update_from_db();
     return $gradecategory->get_record_data();
 }
开发者ID:abhilash1994,项目名称:moodle,代码行数:29,代码来源:data_generator.php

示例12: test_upgrade_calculated_grade_items

    /**
     * Test the upgrade function for flagging courses with calculated grade item problems.
     */
    public function test_upgrade_calculated_grade_items() {
        global $DB, $CFG;
        $this->resetAfterTest();

        // Create a user.
        $user = $this->getDataGenerator()->create_user();

        // Create a couple of courses.
        $course1 = $this->getDataGenerator()->create_course();
        $course2 = $this->getDataGenerator()->create_course();
        $course3 = $this->getDataGenerator()->create_course();

        // Enrol the user in the courses.
        $studentrole = $DB->get_record('role', array('shortname' => 'student'));
        $maninstance1 = $DB->get_record('enrol', array('courseid' => $course1->id, 'enrol' => 'manual'), '*', MUST_EXIST);
        $maninstance2 = $DB->get_record('enrol', array('courseid' => $course2->id, 'enrol' => 'manual'), '*', MUST_EXIST);
        $maninstance3 = $DB->get_record('enrol', array('courseid' => $course3->id, 'enrol' => 'manual'), '*', MUST_EXIST);
        $manual = enrol_get_plugin('manual');
        $manual->enrol_user($maninstance1, $user->id, $studentrole->id);
        $manual->enrol_user($maninstance2, $user->id, $studentrole->id);
        $manual->enrol_user($maninstance3, $user->id, $studentrole->id);

        // To create the data we need we freeze the grade book to use the old behaviour.
        set_config('gradebook_calculations_freeze_' . $course1->id, 20150627);
        set_config('gradebook_calculations_freeze_' . $course2->id, 20150627);
        set_config('gradebook_calculations_freeze_' . $course3->id, 20150627);
        $CFG->grade_minmaxtouse = 2;

        // Creating a category for a grade item.
        $gradecategory = new grade_category();
        $gradecategory->fullname = 'calculated grade category';
        $gradecategory->courseid = $course1->id;
        $gradecategory->insert();
        $gradecategoryid = $gradecategory->id;

        // This is a manual grade item.
        $gradeitem = new grade_item();
        $gradeitem->itemname = 'grade item one';
        $gradeitem->itemtype = 'manual';
        $gradeitem->categoryid = $gradecategoryid;
        $gradeitem->courseid = $course1->id;
        $gradeitem->idnumber = 'gi1';
        $gradeitem->insert();

        // Changing the category into a calculated grade category.
        $gradecategoryitem = grade_item::fetch(array('iteminstance' => $gradecategory->id));
        $gradecategoryitem->calculation = '=##gi' . $gradeitem->id . '##/2';
        $gradecategoryitem->update();

        // Setting a grade for the student.
        $grade = $gradeitem->get_grade($user->id, true);
        $grade->finalgrade = 50;
        $grade->update();
        // Creating all the grade_grade items.
        grade_regrade_final_grades($course1->id);
        // Updating the grade category to a new grade max and min.
        $gradecategoryitem->grademax = 50;
        $gradecategoryitem->grademin = 5;
        $gradecategoryitem->update();

        // Different manual grade item for course 2. We are creating a course with a calculated grade item that has a grade max of
        // 50. The grade_grade will have a rawgrademax of 100 regardless.
        $gradeitem = new grade_item();
        $gradeitem->itemname = 'grade item one';
        $gradeitem->itemtype = 'manual';
        $gradeitem->courseid = $course2->id;
        $gradeitem->idnumber = 'gi1';
        $gradeitem->grademax = 25;
        $gradeitem->insert();

        // Calculated grade item for course 2.
        $calculatedgradeitem = new grade_item();
        $calculatedgradeitem->itemname = 'calculated grade';
        $calculatedgradeitem->itemtype = 'manual';
        $calculatedgradeitem->courseid = $course2->id;
        $calculatedgradeitem->calculation = '=##gi' . $gradeitem->id . '##*2';
        $calculatedgradeitem->grademax = 50;
        $calculatedgradeitem->insert();

        // Assigning a grade for the user.
        $grade = $gradeitem->get_grade($user->id, true);
        $grade->finalgrade = 10;
        $grade->update();

        // Setting all of the grade_grade items.
        grade_regrade_final_grades($course2->id);

        // Different manual grade item for course 3. We are creating a course with a calculated grade item that has a grade max of
        // 50. The grade_grade will have a rawgrademax of 100 regardless.
        $gradeitem = new grade_item();
        $gradeitem->itemname = 'grade item one';
        $gradeitem->itemtype = 'manual';
        $gradeitem->courseid = $course3->id;
        $gradeitem->idnumber = 'gi1';
        $gradeitem->grademax = 25;
        $gradeitem->insert();

//.........这里部分代码省略.........
开发者ID:riawarra,项目名称:moodle,代码行数:101,代码来源:upgradelib_test.php

示例13: save_gradebook

 /**
  * Saves a gradebook (a set of grade items and scores related to a course),
  * also creates the categories based on the item type
  *
  * @param object $gradebook an object with at least course_id and items set
  * items should contain grade_items (courseid. categoryid, name, scores)
  * scores should contain grade_grade (user_id, score)
  * @return stdClass the saved gradebook with all items and scores in the same structure,
  * errors are recorded as grade_item->errors and score->error
  * @throws InvalidArgumentException
  */
 public static function save_gradebook($gradebook)
 {
     global $CFG;
     if (!$gradebook) {
         throw new InvalidArgumentException("gradebook must be set");
     }
     if (!isset($gradebook->course_id)) {
         throw new InvalidArgumentException("gradebook->course_id must be set");
     }
     if (!isset($gradebook->items) || empty($gradebook->items)) {
         throw new InvalidArgumentException("gradebook->items must be set and include items");
     }
     $gb_saved = new stdClass();
     $gb_saved->items = array();
     $gb_saved->course_id = $gradebook->course_id;
     $course = self::get_course($gradebook->course_id);
     if (!$course) {
         throw new InvalidArgumentException("No course found with course_id ({$gradebook->course_id})");
     }
     $gb_saved->course = $course;
     // extra permissions check on gradebook manage/update
     $user_id = self::require_user();
     if (class_exists('context_course')) {
         // for Moodle 2.2+
         $context = context_course::instance($course->id);
     } else {
         /** @noinspection PhpDeprecationInspection */
         $context = get_context_instance(CONTEXT_COURSE, $course->id);
         // deprecated
     }
     if (!$context || !has_capability('moodle/grade:manage', $context, $user_id)) {
         throw new InvalidArgumentException("User ({$user_id}) cannot manage the gradebook in course id={$course->id} (" . var_export($course, true) . "), context: " . var_export($context, true));
     }
     // attempt to get the default iclicker category first
     $default_iclicker_category = grade_category::fetch(array('courseid' => $gradebook->course_id, 'fullname' => self::GRADE_CATEGORY_NAME));
     $default_iclicker_category_id = $default_iclicker_category ? $default_iclicker_category->id : null;
     //echo "\n\nGRADEBOOK: ".var_export($gradebook);
     // iterate through and save grade items by calling other method
     if (!empty($gradebook->items)) {
         $saved_items = array();
         $number = 0;
         foreach ($gradebook->items as $grade_item) {
             // check for this category
             $item_category_name = self::GRADE_CATEGORY_NAME;
             if (!empty($grade_item->type) && self::GRADE_CATEGORY_NAME != $grade_item->type) {
                 $item_category_name = $grade_item->type;
                 $item_category = grade_category::fetch(array('courseid' => $gradebook->course_id, 'fullname' => $item_category_name));
                 if (!$item_category) {
                     // create the category
                     $params = array('courseid' => $gradebook->course_id, 'fullname' => $item_category_name);
                     $grade_category = new grade_category($params, false);
                     // Use default aggregation type.
                     $grade_category->aggregation = $CFG->grade_aggregation;
                     $grade_category->insert(self::GRADE_LOCATION_STR);
                     $item_category_id = $grade_category->id;
                 } else {
                     $item_category_id = $item_category->id;
                 }
             } else {
                 // use default
                 if (!$default_iclicker_category_id) {
                     // create the category
                     $params = array('courseid' => $gradebook->course_id, 'fullname' => self::GRADE_CATEGORY_NAME);
                     $grade_category = new grade_category($params, false);
                     // Use default aggregation type.
                     $grade_category->aggregation = $CFG->grade_aggregation;
                     $grade_category->insert(self::GRADE_LOCATION_STR);
                     $default_iclicker_category_id = $grade_category->id;
                 }
                 $item_category_id = $default_iclicker_category_id;
             }
             $grade_item->categoryid = $item_category_id;
             $grade_item->typename = $item_category_name;
             $grade_item->courseid = $gradebook->course_id;
             $grade_item->item_number = $number;
             $saved_grade_item = self::save_grade_item($grade_item);
             $saved_items[] = $saved_grade_item;
             $number++;
         }
         $gb_saved->items = $saved_items;
     }
     $gb_saved->default_category_id = $default_iclicker_category_id;
     //echo "\n\nRESULT: ".var_export($gb_saved);
     return $gb_saved;
 }
开发者ID:dirkcgrunwald,项目名称:iclicker-moodle2-integrate,代码行数:96,代码来源:iclicker_service.php

示例14: execute


//.........这里部分代码省略.........
            }
         
         
                     } else {
            // Set it to default if no good scale could be found/used.
            $gradeid = 0;
            $scaleid = 0;
            overnight::tlog('No \'gradetype\' found, so using defaults instead.', 'info');
                     }
         
         
                     // You may get errors here (unknown index IIRC) if no scalename is generated because a scale (or anything) hasn't been set
                     // for that course (e.g. 'cos it's a new course). Catch this earlier!
                     $logging['grade_types'][strtolower($course->scalename)]++;
         
                     /**
         * Category checking: create or skip.
         */
         if ($DB->get_record('grade_categories', array('courseid' => $course->id, 'fullname' => CATNAME))) {
             // Category exists, so skip creation.
             overnight::tlog('Category \'' . CATNAME . '\' already exists for course ' . $course->id . '.', 'skip');
         } else {
             $grade_category = new \grade_category();
             // Create a category for this course.
             $grade_category->courseid = $course->id;
             // Course id.
             $grade_category->fullname = CATNAME;
             // Set the category name (no description).
             $grade_category->sortorder = 1;
             // Need a better way of changing column order.
             $grade_category->hidden = 1;
             // Attempting to hide the totals.
             // Save all that...
             if (!($gc = $grade_category->insert())) {
                 overnight::tlog('Category \'' . CATNAME . '\' could not be inserted for course ' . $course->id . '.', 'EROR');
                 return false;
             } else {
                 overnight::tlog('Category \'' . CATNAME . '\' (' . $gc . ') created for course ' . $course->id . '.');
             }
         }
         // We've either checked a category exists or created one, so this *should* always work.
         $cat_id = $DB->get_record('grade_categories', array('courseid' => $course->id, 'fullname' => CATNAME));
         $cat_id = $cat_id->id;
         // One thing we need to do is set 'gradetype' to 0 on that newly created category, which prevents a category total showing
         // and the grades counting towards the total course grade.
         $DB->set_field_select('grade_items', 'gradetype', 0, "courseid = " . $course->id . " AND itemtype = 'category' AND iteminstance = " . $cat_id);
         /**
          * Column checking: create or update.
          */
         // Step through each column name.
         foreach ($column_names as $col_name => $col_desc) {
             // Need to check for previously-created columns and force an update if they already exist.
             //if ( $DB->get_record('grade_items', array( 'courseid' => $course->id, 'itemname' => $col_name, 'itemtype' => 'manual' ) ) ) {
             //    // Column exists, so update instead.
             //    overnight::tlog('- Column \'' . $col_name . '\' already exists for course ' . $course->id . '.', 'skip');
             //} else {
             $grade_item = new \grade_item();
             // Create a new item object.
             $grade_item->courseid = $course->id;
             // Course id.
             $grade_item->itemtype = 'manual';
             // Set the category name (no description).
             $grade_item->itemname = $col_name;
             // The item's name.
             $grade_item->iteminfo = $col_desc;
             // Description of the item.
开发者ID:vaughany,项目名称:moodle-block_leap,代码行数:67,代码来源:overnight.php

示例15: tlog

  * Category checking or creation.
  */
 if ($DB->get_record('grade_categories', array('courseid' => $course->id, 'fullname' => CATNAME))) {
     // Category exists, so skip creation.
     tlog('Category \'' . CATNAME . '\' already exists for course ' . $course->id . '.', 'skip');
 } else {
     // Create a category for this course.
     $grade_category = new grade_category();
     // Course id.
     $grade_category->courseid = $course->id;
     // Set the category name (no description).
     $grade_category->fullname = CATNAME;
     // Set the sort order (making this the first category in the gradebook, hopefully).
     $grade_category->sortorder = 1;
     // Save all that...
     if (!($gc = $grade_category->insert())) {
         tlog('Category \'' . CATNAME . '\' could not be inserted for course ' . $course->id . '.', 'EROR');
         exit(1);
     } else {
         tlog('Category \'' . CATNAME . '\' (' . $gc . ') created for course ' . $course->id . '.');
     }
 }
 // We've either checked a category exists or created one, so this *should* always work.
 $cat_id = $DB->get_record('grade_categories', array('courseid' => $course->id, 'fullname' => CATNAME));
 $cat_id = $cat_id->id;
 // One thing we need to do is set 'gradetype' to 0 on that newly created category, which prevents a category total showing
 // and the grades counting towards the total course grade.
 $DB->set_field_select('grade_items', 'gradetype', 0, "courseid = " . $course->id . " AND itemtype = 'category' AND iteminstance = " . $cat_id);
 /**
  * Column checking or creation.
  */
开发者ID:vaughany,项目名称:moodle-block_leap,代码行数:31,代码来源:tracker_cron.php


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