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


PHP grade_item::update方法代码示例

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


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

示例1: process_grade_item

 protected function process_grade_item($data)
 {
     global $DB;
     $data = (object) $data;
     $oldid = $data->id;
     // We'll need these later
     $oldparentid = $data->categoryid;
     $courseid = $this->get_courseid();
     // make sure top course category exists, all grade items will be associated
     // to it. Later, if restoring the whole gradebook, categories will be introduced
     $coursecat = grade_category::fetch_course_category($courseid);
     $coursecatid = $coursecat->id;
     // Get the categoryid to be used
     $idnumber = null;
     if (!empty($data->idnumber)) {
         // Don't get any idnumber from course module. Keep them as they are in grade_item->idnumber
         // Reason: it's not clear what happens with outcomes->idnumber or activities with multiple items (workshop)
         // so the best is to keep the ones already in the gradebook
         // Potential problem: duplicates if same items are restored more than once. :-(
         // This needs to be fixed in some way (outcomes & activities with multiple items)
         // $data->idnumber     = get_coursemodule_from_instance($data->itemmodule, $data->iteminstance)->idnumber;
         // In any case, verify always for uniqueness
         $sql = "SELECT cm.id\n                      FROM {course_modules} cm\n                     WHERE cm.course = :courseid AND\n                           cm.idnumber = :idnumber AND\n                           cm.id <> :cmid";
         $params = array('courseid' => $courseid, 'idnumber' => $data->idnumber, 'cmid' => $this->task->get_moduleid());
         if (!$DB->record_exists_sql($sql, $params) && !$DB->record_exists('grade_items', array('courseid' => $courseid, 'idnumber' => $data->idnumber))) {
             $idnumber = $data->idnumber;
         }
     }
     unset($data->id);
     $data->categoryid = $coursecatid;
     $data->courseid = $this->get_courseid();
     $data->iteminstance = $this->task->get_activityid();
     $data->idnumber = $idnumber;
     $data->scaleid = $this->get_mappingid('scale', $data->scaleid);
     $data->outcomeid = $this->get_mappingid('outcome', $data->outcomeid);
     $data->timecreated = $this->apply_date_offset($data->timecreated);
     $data->timemodified = $this->apply_date_offset($data->timemodified);
     $gradeitem = new grade_item($data, false);
     $gradeitem->insert('restore');
     //sortorder is automatically assigned when inserting. Re-instate the previous sortorder
     $gradeitem->sortorder = $data->sortorder;
     $gradeitem->update('restore');
     // Set mapping, saving the original category id into parentitemid
     // gradebook restore (final task) will need it to reorganise items
     $this->set_mapping('grade_item', $oldid, $gradeitem->id, false, null, $oldparentid);
 }
开发者ID:Jinelle,项目名称:moodle,代码行数:46,代码来源:restore_stepslib.php

示例2: grade_cron

/**
 * Grading cron job
 */
function grade_cron()
{
    global $CFG;
    $now = time();
    $sql = "SELECT i.*\n              FROM {$CFG->prefix}grade_items i\n             WHERE i.locked = 0 AND i.locktime > 0 AND i.locktime < {$now} AND EXISTS (\n                SELECT 'x' FROM {$CFG->prefix}grade_items c WHERE c.itemtype='course' AND c.needsupdate=0 AND c.courseid=i.courseid)";
    // go through all courses that have proper final grades and lock them if needed
    if ($rs = get_recordset_sql($sql)) {
        if ($rs->RecordCount() > 0) {
            while ($item = rs_fetch_next_record($rs)) {
                $grade_item = new grade_item($item, false);
                $grade_item->locked = $now;
                $grade_item->update('locktime');
            }
        }
        rs_close($rs);
    }
    $grade_inst = new grade_grade();
    $fields = 'g.' . implode(',g.', $grade_inst->required_fields);
    $sql = "SELECT {$fields}\n              FROM {$CFG->prefix}grade_grades g, {$CFG->prefix}grade_items i\n             WHERE g.locked = 0 AND g.locktime > 0 AND g.locktime < {$now} AND g.itemid=i.id AND EXISTS (\n                SELECT 'x' FROM {$CFG->prefix}grade_items c WHERE c.itemtype='course' AND c.needsupdate=0 AND c.courseid=i.courseid)";
    // go through all courses that have proper final grades and lock them if needed
    if ($rs = get_recordset_sql($sql)) {
        if ($rs->RecordCount() > 0) {
            while ($grade = rs_fetch_next_record($rs)) {
                $grade_grade = new grade_grade($grade, false);
                $grade_grade->locked = $now;
                $grade_grade->update('locktime');
            }
        }
        rs_close($rs);
    }
}
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:34,代码来源:gradelib.php

示例3: auto_update_max

 /**
  * Some aggregation types may automatically update max grade
  *
  * @param array $items sub items
  */
 private function auto_update_max($items)
 {
     if ($this->aggregation != GRADE_AGGREGATE_SUM) {
         // not needed at all
         return;
     }
     if (!$items) {
         if ($this->grade_item->grademax != 0 or $this->grade_item->gradetype != GRADE_TYPE_VALUE) {
             $this->grade_item->grademax = 0;
             $this->grade_item->grademin = 0;
             $this->grade_item->gradetype = GRADE_TYPE_VALUE;
             $this->grade_item->update('aggregation');
         }
         return;
     }
     //find max grade possible
     $maxes = array();
     foreach ($items as $item) {
         if ($item->aggregationcoef > 0) {
             // extra credit from this activity - does not affect total
             continue;
         }
         if ($item->gradetype == GRADE_TYPE_VALUE) {
             $maxes[$item->id] = $item->grademax;
         } else {
             if ($item->gradetype == GRADE_TYPE_SCALE) {
                 $maxes[$item->id] = $item->grademax;
                 // 0 = nograde, 1 = first scale item, 2 = second scale item
             }
         }
     }
     // apply droplow and keephigh
     $this->apply_limit_rules($maxes, $items);
     $max = array_sum($maxes);
     // update db if anything changed
     if ($this->grade_item->grademax != $max or $this->grade_item->grademin != 0 or $this->grade_item->gradetype != GRADE_TYPE_VALUE) {
         $this->grade_item->grademax = $max;
         $this->grade_item->grademin = 0;
         $this->grade_item->gradetype = GRADE_TYPE_VALUE;
         $this->grade_item->update('aggregation');
     }
 }
开发者ID:covex-nn,项目名称:moodle,代码行数:47,代码来源:grade_category.php

示例4: grade_cron

/**
 * Grading cron job. Performs background clean up on the gradebook
 */
function grade_cron()
{
    global $CFG, $DB;
    $now = time();
    $sql = "SELECT i.*\n              FROM {grade_items} i\n             WHERE i.locked = 0 AND i.locktime > 0 AND i.locktime < ? AND EXISTS (\n                SELECT 'x' FROM {grade_items} c WHERE c.itemtype='course' AND c.needsupdate=0 AND c.courseid=i.courseid)";
    // go through all courses that have proper final grades and lock them if needed
    $rs = $DB->get_recordset_sql($sql, array($now));
    foreach ($rs as $item) {
        $grade_item = new grade_item($item, false);
        $grade_item->locked = $now;
        $grade_item->update('locktime');
    }
    $rs->close();
    $grade_inst = new grade_grade();
    $fields = 'g.' . implode(',g.', $grade_inst->required_fields);
    $sql = "SELECT {$fields}\n              FROM {grade_grades} g, {grade_items} i\n             WHERE g.locked = 0 AND g.locktime > 0 AND g.locktime < ? AND g.itemid=i.id AND EXISTS (\n                SELECT 'x' FROM {grade_items} c WHERE c.itemtype='course' AND c.needsupdate=0 AND c.courseid=i.courseid)";
    // go through all courses that have proper final grades and lock them if needed
    $rs = $DB->get_recordset_sql($sql, array($now));
    foreach ($rs as $grade) {
        $grade_grade = new grade_grade($grade, false);
        $grade_grade->locked = $now;
        $grade_grade->update('locktime');
    }
    $rs->close();
    //TODO: do not run this cleanup every cron invocation
    // cleanup history tables
    if (!empty($CFG->gradehistorylifetime)) {
        // value in days
        $histlifetime = $now - $CFG->gradehistorylifetime * 3600 * 24;
        $tables = array('grade_outcomes_history', 'grade_categories_history', 'grade_items_history', 'grade_grades_history', 'scale_history');
        foreach ($tables as $table) {
            if ($DB->delete_records_select($table, "timemodified < ?", array($histlifetime))) {
                mtrace("    Deleted old grade history records from '{$table}'");
            }
        }
    }
}
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:40,代码来源:gradelib.php

示例5: sub_test_grade_item_depends_on

 protected function sub_test_grade_item_depends_on()
 {
     global $CFG;
     $origenableoutcomes = $CFG->enableoutcomes;
     $CFG->enableoutcomes = 0;
     $grade_item = new grade_item($this->grade_items[1], false);
     // Calculated grade dependency.
     $deps = $grade_item->depends_on();
     sort($deps, SORT_NUMERIC);
     // For comparison.
     $this->assertEquals(array($this->grade_items[0]->id), $deps);
     // Simulate depends on returns none when locked.
     $grade_item->locked = time();
     $grade_item->update();
     $deps = $grade_item->depends_on();
     sort($deps, SORT_NUMERIC);
     // For comparison.
     $this->assertEquals(array(), $deps);
     // Category dependency.
     $grade_item = new grade_item($this->grade_items[3], false);
     $deps = $grade_item->depends_on();
     sort($deps, SORT_NUMERIC);
     // For comparison.
     $res = array($this->grade_items[4]->id, $this->grade_items[5]->id);
     $this->assertEquals($res, $deps);
     $CFG->enableoutcomes = 1;
     $origgradeincludescalesinaggregation = $CFG->grade_includescalesinaggregation;
     $CFG->grade_includescalesinaggregation = 1;
     // Item in category with aggregate sub categories + $CFG->grade_includescalesinaggregation = 1.
     $grade_item = new grade_item($this->grade_items[12], false);
     $deps = $grade_item->depends_on();
     sort($deps, SORT_NUMERIC);
     $res = array($this->grade_items[15]->id, $this->grade_items[16]->id);
     $this->assertEquals($res, $deps);
     // Item in category with aggregate sub categories + $CFG->grade_includescalesinaggregation = 0.
     $CFG->grade_includescalesinaggregation = 0;
     $grade_item = new grade_item($this->grade_items[12], false);
     $deps = $grade_item->depends_on();
     sort($deps, SORT_NUMERIC);
     $res = array($this->grade_items[15]->id);
     $this->assertEquals($res, $deps);
     $CFG->grade_includescalesinaggregation = 1;
     // Outcome item in category with with aggregate sub categories.
     $CFG->enableoutcomes = 0;
     $grade_item = new grade_item($this->grade_items[12], false);
     $deps = $grade_item->depends_on();
     sort($deps, SORT_NUMERIC);
     $res = array($this->grade_items[15]->id, $this->grade_items[16]->id, $this->grade_items[17]->id);
     $this->assertEquals($res, $deps);
     $CFG->enableoutcomes = $origenableoutcomes;
     $CFG->grade_includescalesinaggregation = $origgradeincludescalesinaggregation;
 }
开发者ID:covex-nn,项目名称:moodle,代码行数:52,代码来源:grade_item_test.php

示例6: process_grade_item

 protected function process_grade_item($data)
 {
     global $DB;
     $data = (object) $data;
     $oldid = $data->id;
     // We'll need these later
     $oldparentid = $data->categoryid;
     $courseid = $this->get_courseid();
     $idnumber = null;
     if (!empty($data->idnumber)) {
         // Don't get any idnumber from course module. Keep them as they are in grade_item->idnumber
         // Reason: it's not clear what happens with outcomes->idnumber or activities with multiple items (workshop)
         // so the best is to keep the ones already in the gradebook
         // Potential problem: duplicates if same items are restored more than once. :-(
         // This needs to be fixed in some way (outcomes & activities with multiple items)
         // $data->idnumber     = get_coursemodule_from_instance($data->itemmodule, $data->iteminstance)->idnumber;
         // In any case, verify always for uniqueness
         $sql = "SELECT cm.id\n                      FROM {course_modules} cm\n                     WHERE cm.course = :courseid AND\n                           cm.idnumber = :idnumber AND\n                           cm.id <> :cmid";
         $params = array('courseid' => $courseid, 'idnumber' => $data->idnumber, 'cmid' => $this->task->get_moduleid());
         if (!$DB->record_exists_sql($sql, $params) && !$DB->record_exists('grade_items', array('courseid' => $courseid, 'idnumber' => $data->idnumber))) {
             $idnumber = $data->idnumber;
         }
     }
     if (!empty($data->categoryid)) {
         // If the grade category id of the grade item being restored belongs to this course
         // then it is a fair assumption that this is the correct grade category for the activity
         // and we should leave it in place, if not then unset it.
         // TODO MDL-34790 Gradebook does not import if target course has gradebook categories.
         $conditions = array('id' => $data->categoryid, 'courseid' => $courseid);
         if (!$this->task->is_samesite() || !$DB->record_exists('grade_categories', $conditions)) {
             unset($data->categoryid);
         }
     }
     unset($data->id);
     $data->courseid = $this->get_courseid();
     $data->iteminstance = $this->task->get_activityid();
     $data->idnumber = $idnumber;
     $data->scaleid = $this->get_mappingid('scale', $data->scaleid);
     $data->outcomeid = $this->get_mappingid('outcome', $data->outcomeid);
     $data->timecreated = $this->apply_date_offset($data->timecreated);
     $data->timemodified = $this->apply_date_offset($data->timemodified);
     $gradeitem = new grade_item($data, false);
     $gradeitem->insert('restore');
     //sortorder is automatically assigned when inserting. Re-instate the previous sortorder
     $gradeitem->sortorder = $data->sortorder;
     $gradeitem->update('restore');
     // Set mapping, saving the original category id into parentitemid
     // gradebook restore (final task) will need it to reorganise items
     $this->set_mapping('grade_item', $oldid, $gradeitem->id, false, null, $oldparentid);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:50,代码来源:restore_stepslib.php

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

示例8: sub_test_grade_item_depends_on

 protected function sub_test_grade_item_depends_on()
 {
     $grade_item = new grade_item($this->grade_items[1], false);
     // calculated grade dependency
     $deps = $grade_item->depends_on();
     sort($deps, SORT_NUMERIC);
     // for comparison
     $this->assertEquals(array($this->grade_items[0]->id), $deps);
     // simulate depends on returns none when locked
     $grade_item->locked = time();
     $grade_item->update();
     $deps = $grade_item->depends_on();
     sort($deps, SORT_NUMERIC);
     // for comparison
     $this->assertEquals(array(), $deps);
     // category dependency
     $grade_item = new grade_item($this->grade_items[3], false);
     $deps = $grade_item->depends_on();
     sort($deps, SORT_NUMERIC);
     // for comparison
     $res = array($this->grade_items[4]->id, $this->grade_items[5]->id);
     $this->assertEquals($res, $deps);
 }
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:23,代码来源:grade_item_test.php

示例9: auto_update_max

 /**
  * Some aggregation types may need to update their max grade.
  *
  * This must be executed after updating the weights as it relies on them.
  *
  * @return void
  */
 private function auto_update_max()
 {
     global $DB;
     if ($this->aggregation != GRADE_AGGREGATE_SUM) {
         // not needed at all
         return;
     }
     // Find grade items of immediate children (category or grade items) and force site settings.
     $this->load_grade_item();
     $depends_on = $this->grade_item->depends_on();
     $items = false;
     if (!empty($depends_on)) {
         list($usql, $params) = $DB->get_in_or_equal($depends_on);
         $sql = "SELECT *\n                      FROM {grade_items}\n                     WHERE id {$usql}";
         $items = $DB->get_records_sql($sql, $params);
     }
     if (!$items) {
         if ($this->grade_item->grademax != 0 or $this->grade_item->gradetype != GRADE_TYPE_VALUE) {
             $this->grade_item->grademax = 0;
             $this->grade_item->grademin = 0;
             $this->grade_item->gradetype = GRADE_TYPE_VALUE;
             $this->grade_item->update('aggregation');
         }
         return;
     }
     //find max grade possible
     $maxes = array();
     foreach ($items as $item) {
         if ($item->aggregationcoef > 0) {
             // extra credit from this activity - does not affect total
             continue;
         } else {
             if ($item->aggregationcoef2 <= 0) {
                 // Items with a weight of 0 do not affect the total.
                 continue;
             }
         }
         if ($item->gradetype == GRADE_TYPE_VALUE) {
             $maxes[$item->id] = $item->grademax;
         } else {
             if ($item->gradetype == GRADE_TYPE_SCALE) {
                 $maxes[$item->id] = $item->grademax;
                 // 0 = nograde, 1 = first scale item, 2 = second scale item
             }
         }
     }
     if ($this->can_apply_limit_rules()) {
         // Apply droplow and keephigh.
         $this->apply_limit_rules($maxes, $items);
     }
     $max = array_sum($maxes);
     // update db if anything changed
     if ($this->grade_item->grademax != $max or $this->grade_item->grademin != 0 or $this->grade_item->gradetype != GRADE_TYPE_VALUE) {
         $this->grade_item->grademax = $max;
         $this->grade_item->grademin = 0;
         $this->grade_item->gradetype = GRADE_TYPE_VALUE;
         $this->grade_item->update('aggregation');
     }
 }
开发者ID:jtibbetts,项目名称:moodle,代码行数:66,代码来源:grade_category.php

示例10: auto_update_max

 /**
  * Some aggregation types may need to update their max grade.
  *
  * This must be executed after updating the weights as it relies on them.
  *
  * @return void
  */
 private function auto_update_max()
 {
     global $DB;
     if ($this->aggregation != GRADE_AGGREGATE_SUM) {
         // not needed at all
         return;
     }
     // Find grade items of immediate children (category or grade items) and force site settings.
     $this->load_grade_item();
     $depends_on = $this->grade_item->depends_on();
     // Check to see if the gradebook is frozen. This allows grades to not be altered at all until a user verifies that they
     // wish to update the grades.
     $gradebookcalculationsfreeze = get_config('core', 'gradebook_calculations_freeze_' . $this->courseid);
     // Only run if the gradebook isn't frozen.
     if ($gradebookcalculationsfreeze && (int) $gradebookcalculationsfreeze <= 20150627) {
         // Do nothing.
     } else {
         // Don't automatically update the max for calculated items.
         if ($this->grade_item->is_calculated()) {
             return;
         }
     }
     $items = false;
     if (!empty($depends_on)) {
         list($usql, $params) = $DB->get_in_or_equal($depends_on);
         $sql = "SELECT *\n                      FROM {grade_items}\n                     WHERE id {$usql}";
         $items = $DB->get_records_sql($sql, $params);
     }
     if (!$items) {
         if ($this->grade_item->grademax != 0 or $this->grade_item->gradetype != GRADE_TYPE_VALUE) {
             $this->grade_item->grademax = 0;
             $this->grade_item->grademin = 0;
             $this->grade_item->gradetype = GRADE_TYPE_VALUE;
             $this->grade_item->update('aggregation');
         }
         return;
     }
     //find max grade possible
     $maxes = array();
     foreach ($items as $item) {
         if ($item->aggregationcoef > 0) {
             // extra credit from this activity - does not affect total
             continue;
         } else {
             if ($item->aggregationcoef2 <= 0) {
                 // Items with a weight of 0 do not affect the total.
                 continue;
             }
         }
         if ($item->gradetype == GRADE_TYPE_VALUE) {
             $maxes[$item->id] = $item->grademax;
         } else {
             if ($item->gradetype == GRADE_TYPE_SCALE) {
                 $maxes[$item->id] = $item->grademax;
                 // 0 = nograde, 1 = first scale item, 2 = second scale item
             }
         }
     }
     if ($this->can_apply_limit_rules()) {
         // Apply droplow and keephigh.
         $this->apply_limit_rules($maxes, $items);
     }
     $max = array_sum($maxes);
     // update db if anything changed
     if ($this->grade_item->grademax != $max or $this->grade_item->grademin != 0 or $this->grade_item->gradetype != GRADE_TYPE_VALUE) {
         $this->grade_item->grademax = $max;
         $this->grade_item->grademin = 0;
         $this->grade_item->gradetype = GRADE_TYPE_VALUE;
         $this->grade_item->update('aggregation');
     }
 }
开发者ID:Gavinthisisit,项目名称:Moodle,代码行数:78,代码来源:grade_category.php

示例11: sub_test_grade_item_depends_on

 protected function sub_test_grade_item_depends_on()
 {
     global $CFG;
     $origenableoutcomes = $CFG->enableoutcomes;
     $CFG->enableoutcomes = 0;
     $grade_item = new grade_item($this->grade_items[1], false);
     // Calculated grade dependency.
     $deps = $grade_item->depends_on();
     sort($deps, SORT_NUMERIC);
     // For comparison.
     $this->assertEquals(array($this->grade_items[0]->id), $deps);
     // Simulate depends on returns none when locked.
     $grade_item->locked = time();
     $grade_item->update();
     $deps = $grade_item->depends_on();
     sort($deps, SORT_NUMERIC);
     // For comparison.
     $this->assertEquals(array(), $deps);
     // Category dependency.
     $grade_item = new grade_item($this->grade_items[3], false);
     $deps = $grade_item->depends_on();
     sort($deps, SORT_NUMERIC);
     // For comparison.
     $res = array($this->grade_items[4]->id, $this->grade_items[5]->id);
     $this->assertEquals($res, $deps);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:26,代码来源:grade_item_test.php

示例12: save_grade_item

 private static function save_grade_item($grade_item)
 {
     if (!$grade_item) {
         throw new InvalidArgumentException("grade_item must be set");
     }
     if (!$grade_item->courseid) {
         throw new InvalidArgumentException("grade_item->courseid must be set");
     }
     if (!$grade_item->categoryid) {
         throw new InvalidArgumentException("grade_item->categoryid must be set");
     }
     if (!$grade_item->name) {
         throw new InvalidArgumentException("grade_item->name must be set");
     }
     if (!isset($grade_item->item_number)) {
         $grade_item->item_number = 0;
     }
     // check for an existing item and update or create
     $grade_item_tosave = grade_item::fetch(array('courseid' => $grade_item->courseid, 'itemmodule' => self::GRADE_ITEM_MODULE, 'itemname' => $grade_item->name));
     if (!$grade_item_tosave) {
         // create new one
         $grade_item_tosave = new grade_item();
         $grade_item_tosave->itemmodule = self::GRADE_ITEM_MODULE;
         $grade_item_tosave->courseid = $grade_item->courseid;
         $grade_item_tosave->categoryid = $grade_item->categoryid;
         $grade_item_tosave->iteminfo = $grade_item->typename;
         //$grade_item_tosave->iteminfo = $grade_item->name.' '.$grade_item->type.' '.self::GRADE_CATEGORY_NAME;
         $grade_item_tosave->itemnumber = $grade_item->item_number;
         //$grade_item_tosave->idnumber = $grade_item->name;
         $grade_item_tosave->itemname = $grade_item->name;
         $grade_item_tosave->itemtype = self::GRADE_ITEM_TYPE;
         //$grade_item_tosave->itemmodule = self::GRADE_ITEM_MODULE;
         if (isset($grade_item->points_possible) && $grade_item->points_possible > 0) {
             $grade_item_tosave->grademax = $grade_item->points_possible;
         }
         $grade_item_tosave->insert(self::GRADE_LOCATION_STR);
     } else {
         // update
         if (isset($grade_item->points_possible) && $grade_item->points_possible > 0) {
             $grade_item_tosave->grademax = $grade_item->points_possible;
         }
         $grade_item_tosave->categoryid = $grade_item->categoryid;
         $grade_item_tosave->iteminfo = $grade_item->typename;
         $grade_item_tosave->update(self::GRADE_LOCATION_STR);
     }
     $grade_item_id = $grade_item_tosave->id;
     $grade_item_pp = $grade_item_tosave->grademax;
     // now save the related scores
     if (isset($grade_item->scores) && !empty($grade_item->scores)) {
         // get the existing scores
         $current_scores = array();
         $existing_grades = grade_grade::fetch_all(array('itemid' => $grade_item_id));
         if ($existing_grades) {
             foreach ($existing_grades as $grade) {
                 $current_scores[$grade->userid] = $grade;
             }
         }
         // run through the scores in the gradeitem and try to save them
         $errors_count = 0;
         $processed_scores = array();
         foreach ($grade_item->scores as $score) {
             $user = self::get_users($score->user_id);
             if (!$user) {
                 $score->error = self::USER_DOES_NOT_EXIST_ERROR;
                 $processed_scores[] = $score;
                 $errors_count++;
                 continue;
             }
             $user_id = $user->id;
             // null/blank scores are not allowed
             if (!isset($score->score)) {
                 $score->error = 'NO_SCORE_ERROR';
                 $processed_scores[] = $score;
                 $errors_count++;
                 continue;
             }
             if (!is_numeric($score->score)) {
                 $score->error = 'SCORE_INVALID';
                 $processed_scores[] = $score;
                 $errors_count++;
                 continue;
             }
             $score->score = floatval($score->score);
             // Student Score should not be greater than the total points possible
             if ($score->score > $grade_item_pp) {
                 $score->error = self::POINTS_POSSIBLE_UPDATE_ERRORS;
                 $processed_scores[] = $score;
                 $errors_count++;
                 continue;
             }
             try {
                 $grade_tosave = null;
                 if (isset($current_scores[$user_id])) {
                     // existing score
                     $grade_tosave = $current_scores[$user_id];
                     // check against existing score
                     if ($score->score < $grade_tosave->rawgrade) {
                         $score->error = self::SCORE_UPDATE_ERRORS;
                         $processed_scores[] = $score;
                         $errors_count++;
//.........这里部分代码省略.........
开发者ID:dirkcgrunwald,项目名称:iclicker-moodle2-integrate,代码行数:101,代码来源:iclicker_service.php

示例13: execute

 /**
  * This is the function which runs when cron calls.
  */
 public function execute()
 {
     global $CFG, $DB;
     echo "BEGIN >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n";
     /**
      * A script, to be run overnight, to pull L3VA scores from Leap and generate
      * the MAG, for each student on specifically-tagged courses, and add it into
      * our live Moodle.
      *
      * @copyright 2014-2015 Paul Vaughan
      * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
      */
     // Script start time.
     $time_start = microtime(true);
     // Null or an int (course's id): run the script only for this course. For testing or one-offs.
     // TODO: Consider changing $thiscourse as an array, not an integer.
     $thiscourse = null;
     // null or e.g. 1234
     // TODO: can we use *all* the details in version.php? It would make a lot more sense.
     $version = '1.0.20';
     //$build      = '20150128';
     $build = get_config('block_leap', 'version');
     // Debugging.
     define('DEBUG', true);
     // Debugging.
     define('TRUNCATE_LOG', true);
     // Truncate the log table.
     if (TRUNCATE_LOG) {
         echo 'Truncating block_leap_log...';
         $DB->delete_records('block_leap_log', null);
         echo " done.\n";
     }
     overnight::tlog('GradeTracker script, v' . $version . ', ' . $build . '.', 'hiya');
     overnight::tlog('Started at ' . date('c', $time_start) . '.', ' go ');
     if ($thiscourse) {
         overnight::tlog('IMPORTANT! Processing only course \'' . $thiscourse . '\'.', 'warn');
     }
     overnight::tlog('', '----');
     // Before almost anything has the chance to fail, reset the fail delay setting back to 0.
     if (DEBUG) {
         if (!($reset = $DB->set_field('task_scheduled', 'faildelay', 0, array('component' => 'block_leap', 'classname' => '\\block_leap\\task\\overnight')))) {
             overnight::tlog('Scheduled task "fail delay" could not be reset.', 'warn');
         } else {
             overnight::tlog('Scheduled task "fail delay" reset to 0.', 'dbug');
         }
     }
     $leap_url = get_config('block_leap', 'leap_url');
     $auth_token = get_config('block_leap', 'auth_token');
     define('LEAP_API_URL', $leap_url . '/people/%s/views/courses.json?token=' . $auth_token);
     //overnight::tlog( 'Leap API URL: ' . LEAP_API_URL, 'dbug' );
     // Number of decimal places in the processed targets (and elsewhere).
     define('DECIMALS', 3);
     // Search term to use when searching for courses to process.
     define('IDNUMBERLIKE', 'leapcore_%');
     //define( 'IDNUMBERLIKE', 'leapcore_test' );
     // Category details for the above columns to go into.
     define('CATNAME', get_string('gradebook:category_title', 'block_leap'));
     // Include some details.
     require dirname(__FILE__) . '/../../details.php';
     // Logging array for the end-of-script summary.
     $logging = array('courses' => array(), 'students_processed' => array(), 'students_unique' => array(), 'no_l3va' => array(), 'not_updated' => array(), 'grade_types' => array('btec' => 0, 'a level' => 0, 'gcse' => 0, 'refer and pass' => 0, 'noscale' => 0, 'develop, pass' => 0), 'poor_grades' => array(), 'num' => array('courses' => 0, 'students_processed' => 0, 'students_unique' => 0, 'no_l3va' => 0, 'not_updated' => 0, 'grade_types' => 0, 'grade_types_in_use' => 0, 'poor_grades' => 0));
     // Small array to store the GCSE English and maths grades from the JSON.
     $gcse = array('english' => null, 'maths' => null);
     // Just for internal use, defines the grade type (int) and what it is (string).
     $gradetypes = array(0 => 'None', 1 => 'Value', 2 => 'Scale', 3 => 'Text');
     // Define the wanted column names (will appear in this order in the Gradebook, initially).
     // These column names are an integral part of this plugin and should not be changed.
     $column_names = array(get_string('gradebook:tag', 'block_leap') => get_string('gradebook:tag_desc', 'block_leap'));
     // Make an array keyed to the column names to store the grades in.
     $targets = array();
     foreach ($column_names as $name => $desc) {
         $targets[strtolower($name)] = '';
     }
     /**
      * The next section looks through all courses for those with a properly configured Leap block
      * and adds it (and the tracking configuration) to the $courses array.
      */
     overnight::tlog('', '----');
     $courses = $DB->get_records('course', null, null, 'id,shortname,fullname');
     $allcourses = array();
     foreach ($courses as $course) {
         if ($course->id != 1) {
             $coursecontext = \context_course::instance($course->id);
             if (!($blockrecord = $DB->get_record('block_instances', array('blockname' => 'leap', 'parentcontextid' => $coursecontext->id)))) {
                 if (DEBUG) {
                     overnight::tlog('No Leap block found for course "' . $course->id . '" (' . $course->shortname . ')', 'dbug');
                 }
                 continue;
             }
             if (!($blockinstance = block_instance('leap', $blockrecord))) {
                 if (DEBUG) {
                     overnight::tlog('No Leap block instance found for course "' . $course->id . '" (' . $course->shortname . ')', 'dbug');
                 }
                 continue;
             }
             if (isset($blockinstance->config->trackertype) && !empty($blockinstance->config->trackertype)) {
                 $course->trackertype = $blockinstance->config->trackertype;
//.........这里部分代码省略.........
开发者ID:vaughany,项目名称:moodle-block_leap,代码行数:101,代码来源:overnight.php

示例14: update_grade_item_category

 /**
  * Adds the grade item to the category specified by fullname.
  * If the category does not it is first created. This may create a performance hit
  * as the service call locks the database table until it completes adding the category.
  * Adding the category is delegated to an ad-hoc task.
  * If desired the code can be adjusted to queue the task for cron instead of executing
  * it here. This can consist of a mode switch by a config setting and when in background
  * mode, calling \core\task\manager::queue_adhoc_task($addcat) to queue the task.
  *
  * @param \grade_item $gitem
  * @param string $catnam
  * @return void.
  */
 protected static function update_grade_item_category($gitem, $catname)
 {
     $courseid = $gitem->courseid;
     // Fetch the grade category item that matches the target grade category by fullname.
     // There could be more than one grade category with the same name, so fetch all and
     // sort by id so that we always use the oldest one.
     $fetchparams = array('fullname' => $catname, 'courseid' => $courseid);
     if ($categories = \grade_category::fetch_all($fetchparams)) {
         // Categories found.
         if (count($categories) > 1) {
             // Sort by key which is the category id,
             // to put the oldest first.
             ksort($categories);
         }
         // Take the first.
         $category = reset($categories);
         if ($gitem->categoryid != $category->id) {
             // Item needs update.
             $gitem->categoryid = $category->id;
             $gitem->update();
         }
     } else {
         // Category not found so we task it.
         $addcat = new \block_mhaairs\task\add_grade_category_task();
         // We don't set blocking by set_blocking(true).
         // We add custom data.
         $addcat->set_custom_data(array('catname' => $catname, 'courseid' => $courseid, 'itemid' => $gitem->id));
         // We execute the task.
         // This will throw an exception if fails to create the category.
         $addcat->execute();
     }
 }
开发者ID:itamart,项目名称:moodle-block_mhaairs,代码行数:45,代码来源:externallib.php


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