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


PHP grade_grade::update方法代码示例

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


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

示例1: test_task_timefilter

 public function test_task_timefilter()
 {
     $task = new \local_gradelock\task\lock_grades();
     $grade_grade = new grade_grade();
     $grade_grade->itemid = $this->grade_items[0]->id;
     $grade_grade->userid = 10;
     $grade_grade->rawgrade = 88;
     $grade_grade->rawgrademax = 110;
     $grade_grade->rawgrademin = 18;
     $grade_grade->load_grade_item();
     $grade_grade->insert();
     $grade_grade->grade_item->update_final_grade($this->user[0]->id, 100, 'gradebook', '', FORMAT_MOODLE);
     $grade_grade->update();
     $task->execute();
     $grade_grade = grade_grade::fetch(array('userid' => $this->user[0]->id, 'itemid' => $this->grade_items[0]->id));
     $this->assertFalse($grade_grade->is_locked());
 }
开发者ID:ispedals,项目名称:moodle-local_gradelock,代码行数:17,代码来源:task_test.php

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

示例3: restore_migrate_old_gradebook

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

示例4: foreach

 /**
  * internal function - does the final grade calculation
  */
 function use_formula($userid, $params, $useditems, $oldgrade)
 {
     if (empty($userid)) {
         return true;
     }
     // add missing final grade values
     // not graded (null) is counted as 0 - the spreadsheet way
     foreach ($useditems as $gi) {
         if (!array_key_exists('gi' . $gi, $params)) {
             $params['gi' . $gi] = 0;
         } else {
             $params['gi' . $gi] = (double) $params['gi' . $gi];
         }
     }
     // can not use own final grade during calculation
     unset($params['gi' . $this->id]);
     // insert final grade - will be needed later anyway
     if ($oldgrade) {
         $oldfinalgrade = $oldgrade->finalgrade;
         $grade = new grade_grade($oldgrade, false);
         // fetching from db is not needed
         $grade->grade_item =& $this;
     } else {
         $grade = new grade_grade(array('itemid' => $this->id, 'userid' => $userid), false);
         $grade->grade_item =& $this;
         $grade->insert('system');
         $oldfinalgrade = null;
     }
     // no need to recalculate locked or overridden grades
     if ($grade->is_locked() or $grade->is_overridden()) {
         return true;
     }
     // do the calculation
     $this->formula->set_params($params);
     $result = $this->formula->evaluate();
     if ($result === false) {
         $grade->finalgrade = null;
     } else {
         // normalize
         $result = bounded_number($this->grademin, $result, $this->grademax);
         if ($this->gradetype == GRADE_TYPE_SCALE) {
             $result = round($result + 1.0E-5);
             // round scales upwards
         }
         $grade->finalgrade = $result;
     }
     // update in db if changed
     if (grade_floats_different($grade->finalgrade, $oldfinalgrade)) {
         $grade->update('compute');
     }
     if ($result !== false) {
         //lock grade if needed
     }
     if ($result === false) {
         return false;
     } else {
         return true;
     }
 }
开发者ID:r007,项目名称:PMoodle,代码行数:62,代码来源:grade_item.php

示例5: check_locktime_all

 /**
  * Lock the grade if needed. Make sure this is called only when final grades are valid
  *
  * @param array $items array of all grade item ids
  * @return void
  */
 public static function check_locktime_all($items)
 {
     global $CFG, $DB;
     $now = time();
     // no rounding needed, this is not supposed to be called every 10 seconds
     list($usql, $params) = $DB->get_in_or_equal($items);
     $params[] = $now;
     $rs = $DB->get_recordset_select('grade_grades', "itemid {$usql} AND locked = 0 AND locktime > 0 AND locktime < ?", $params);
     foreach ($rs as $grade) {
         $grade_grade = new grade_grade($grade, false);
         $grade_grade->locked = time();
         $grade_grade->update('locktime');
     }
     $rs->close();
 }
开发者ID:sriysk,项目名称:moodle-integration,代码行数:21,代码来源:grade_grade.php

示例6: use_formula

 /**
  * Internal function that does the final grade calculation
  *
  * @param int $userid The user ID
  * @param array $params An array of grade items of the form {'gi'.$itemid]} => $finalgrade
  * @param array $useditems An array of grade item IDs that this grade item depends on plus its own ID
  * @param grade_grade $oldgrade A grade_grade instance containing the old values from the database
  * @return bool False if an error occurred
  */
 public function use_formula($userid, $params, $useditems, $oldgrade)
 {
     if (empty($userid)) {
         return true;
     }
     // add missing final grade values
     // not graded (null) is counted as 0 - the spreadsheet way
     $allinputsnull = true;
     foreach ($useditems as $gi) {
         if (!array_key_exists('gi' . $gi, $params) || is_null($params['gi' . $gi])) {
             $params['gi' . $gi] = 0;
         } else {
             $params['gi' . $gi] = (double) $params['gi' . $gi];
             if ($gi != $this->id) {
                 $allinputsnull = false;
             }
         }
     }
     // can not use own final grade during calculation
     unset($params['gi' . $this->id]);
     // 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);
     $rawminandmaxchanged = false;
     // insert final grade - will be needed later anyway
     if ($oldgrade) {
         // Only run through this code if the gradebook isn't frozen.
         if ($gradebookcalculationsfreeze && (int) $gradebookcalculationsfreeze <= 20150627) {
             // Do nothing.
         } else {
             // The grade_grade for a calculated item should have the raw grade maximum and minimum set to the
             // grade_item grade maximum and minimum respectively.
             if ($oldgrade->rawgrademax != $this->grademax || $oldgrade->rawgrademin != $this->grademin) {
                 $rawminandmaxchanged = true;
                 $oldgrade->rawgrademax = $this->grademax;
                 $oldgrade->rawgrademin = $this->grademin;
             }
         }
         $oldfinalgrade = $oldgrade->finalgrade;
         $grade = new grade_grade($oldgrade, false);
         // fetching from db is not needed
         $grade->grade_item =& $this;
     } else {
         $grade = new grade_grade(array('itemid' => $this->id, 'userid' => $userid), false);
         $grade->grade_item =& $this;
         $rawminandmaxchanged = false;
         if ($gradebookcalculationsfreeze && (int) $gradebookcalculationsfreeze <= 20150627) {
             // Do nothing.
         } else {
             // The grade_grade for a calculated item should have the raw grade maximum and minimum set to the
             // grade_item grade maximum and minimum respectively.
             $rawminandmaxchanged = true;
             $grade->rawgrademax = $this->grademax;
             $grade->rawgrademin = $this->grademin;
         }
         $grade->insert('system');
         $oldfinalgrade = null;
     }
     // no need to recalculate locked or overridden grades
     if ($grade->is_locked() or $grade->is_overridden()) {
         return true;
     }
     if ($allinputsnull) {
         $grade->finalgrade = null;
         $result = true;
     } else {
         // do the calculation
         $this->formula->set_params($params);
         $result = $this->formula->evaluate();
         if ($result === false) {
             $grade->finalgrade = null;
         } else {
             // normalize
             $grade->finalgrade = $this->bounded_grade($result);
         }
     }
     // Only run through this code if the gradebook isn't frozen.
     if ($gradebookcalculationsfreeze && (int) $gradebookcalculationsfreeze <= 20150627) {
         // Update in db if changed.
         if (grade_floats_different($grade->finalgrade, $oldfinalgrade)) {
             $grade->timemodified = time();
             $success = $grade->update('compute');
             // If successful trigger a user_graded event.
             if ($success) {
                 \core\event\user_graded::create_from_grade($grade)->trigger();
             }
         }
     } else {
         // Update in db if changed.
         if (grade_floats_different($grade->finalgrade, $oldfinalgrade) || $rawminandmaxchanged) {
             $grade->timemodified = time();
//.........这里部分代码省略.........
开发者ID:mongo0se,项目名称:moodle,代码行数:101,代码来源:grade_item.php

示例7: implode

 /**
  * Lock the grade if needed - make sure this is called only when final grades are valid
  * @param array $items array of all grade item ids
  * @return void
  */
 function check_locktime_all($items)
 {
     global $CFG;
     $items_sql = implode(',', $items);
     $now = time();
     // no rounding needed, this is not supposed to be called every 10 seconds
     if ($rs = get_recordset_select('grade_grades', "itemid IN ({$items_sql}) AND locked = 0 AND locktime > 0 AND locktime < {$now}")) {
         while ($grade = rs_fetch_next_record($rs)) {
             $grade_grade = new grade_grade($grade, false);
             $grade_grade->locked = time();
             $grade_grade->update('locktime');
         }
         rs_close($rs);
     }
 }
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:20,代码来源:grade_grade.php

示例8: tlog

             } else {
                 tlog('   ' . strtoupper($target) . ' (' . $score . ') inserted for user ' . $enrollee->userid . ' on course ' . $course->id . '.');
             }
         } else {
             // If the row already exists, UPDATE, but don't ever *update* the TAG.
             if ($target == 'mag' && !$score) {
                 // For MAGs, we don't want to update to a zero or null score as that may overwrite a manually-entered MAG.
                 tlog('   ' . strtoupper($target) . ' of 0 or null (' . $score . ') purposefully not updated for user ' . $enrollee->userid . ' on course ' . $course->id . '.');
                 $logging['not_updated'][] = $enrollee->firstname . ' ' . $enrollee->lastname . ' (' . $enrollee->studentid . ') [' . $enrollee->userid . '] on course ' . $course->id . ': ' . strtoupper($target) . ' of \'' . $score . '\'.';
             } else {
                 if ($target != 'tag') {
                     $grade->id = $gradegrade->id;
                     // We don't want to set this again, but we do want the modified time set.
                     unset($grade->timecreated);
                     $grade->timemodified = time();
                     if (!($gl = $grade->update())) {
                         tlog('   ' . strtoupper($target) . ' update failed for user ' . $enrollee->userid . ' on course ' . $course->id . '.', 'EROR');
                     } else {
                         tlog('   ' . strtoupper($target) . ' (' . $score . ') update for user ' . $enrollee->userid . ' on course ' . $course->id . '.');
                     }
                 } else {
                     tlog('   ' . strtoupper($target) . ' purposefully not updated for user ' . $enrollee->userid . ' on course ' . $course->id . '.', 'skip');
                     $logging['not_updated'][] = $enrollee->firstname . ' ' . $enrollee->lastname . ' (' . $enrollee->studentid . ') [' . $enrollee->userid . '] on course ' . $course->id . ': ' . strtoupper($target) . ' of \'' . $score . '\'.';
                 }
             }
             // END ignore updating the TAG.
         }
         // END insert or update check.
     }
     // END foreach loop.
 }
开发者ID:vaughany,项目名称:moodle-block_leap,代码行数:31,代码来源:tracker_cron.php

示例9: use_formula

 /**
  * Internal function that does the final grade calculation
  *
  * @param int $userid The user ID
  * @param array $params An array of grade items of the form {'gi'.$itemid]} => $finalgrade
  * @param array $useditems An array of grade item IDs that this grade item depends on plus its own ID
  * @param grade_grade $oldgrade A grade_grade instance containing the old values from the database
  * @return bool False if an error occurred
  */
 public function use_formula($userid, $params, $useditems, $oldgrade)
 {
     if (empty($userid)) {
         return true;
     }
     // add missing final grade values
     // not graded (null) is counted as 0 - the spreadsheet way
     $allinputsnull = true;
     foreach ($useditems as $gi) {
         if (!array_key_exists('gi' . $gi, $params) || is_null($params['gi' . $gi])) {
             $params['gi' . $gi] = 0;
         } else {
             $params['gi' . $gi] = (double) $params['gi' . $gi];
             if ($gi != $this->id) {
                 $allinputsnull = false;
             }
         }
     }
     // can not use own final grade during calculation
     unset($params['gi' . $this->id]);
     // insert final grade - will be needed later anyway
     if ($oldgrade) {
         $oldfinalgrade = $oldgrade->finalgrade;
         $grade = new grade_grade($oldgrade, false);
         // fetching from db is not needed
         $grade->grade_item =& $this;
     } else {
         $grade = new grade_grade(array('itemid' => $this->id, 'userid' => $userid), false);
         $grade->grade_item =& $this;
         $grade->insert('system');
         $oldfinalgrade = null;
     }
     // no need to recalculate locked or overridden grades
     if ($grade->is_locked() or $grade->is_overridden()) {
         return true;
     }
     if ($allinputsnull) {
         $grade->finalgrade = null;
         $result = true;
     } else {
         // do the calculation
         $this->formula->set_params($params);
         $result = $this->formula->evaluate();
         if ($result === false) {
             $grade->finalgrade = null;
         } else {
             // normalize
             $grade->finalgrade = $this->bounded_grade($result);
         }
     }
     // update in db if changed
     if (grade_floats_different($grade->finalgrade, $oldfinalgrade)) {
         $grade->timemodified = time();
         $grade->update('compute');
     }
     if ($result !== false) {
         //lock grade if needed
     }
     if ($result === false) {
         return false;
     } else {
         return true;
     }
 }
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:73,代码来源:grade_item.php

示例10: error

                    } else {
                        $gradeval = $grEval->finalgrade;
                    }
                    break;
                }
                //foreach($gradeEvalcomix as $grEval)
            }
            //if($gradeEvalcomix)
        }
        //else
    }
    //else
}
//if($rst = get_record('grade_grades_history', 'userid', $userid, 'itemid', $grade->grade_item->id, 'source', 'evalcomixAdd'))
//Comprobamos que el item actual no es un "resultado"
if ($grade->grade_item->itemnumber == 0) {
    $modulo = $grade->grade_item->itemmodule;
    $instancia = $grade->grade_item->iteminstance;
    $maxgrade = $grade->grade_item->grademax;
    $student = $userid;
    $courseid = $courseid;
    if (!($grade_item = grade_item::fetch(array('iteminstance' => $instancia, 'itemmodule' => $modulo, 'courseid' => $courseid, 'itemnumber' => 0)))) {
        error('Can not find grade_item 2');
    }
    $grade_old = new grade_grade(array('itemid' => $grade_item->id, 'userid' => $student));
    $overridden = $grade_old->overridden;
    $grade_item->update_final_grade($student, $gradeval, 'evalcomixDelete');
    $grade1 = new grade_grade(array('itemid' => $grade_item->id, 'userid' => $student));
    $grade1->overridden = $overridden;
    $grade1->update();
}
开发者ID:srpaedagogus,项目名称:aulavirtual,代码行数:31,代码来源:undone_evx.php

示例11: elseif

                        if ($category->aggregation >= 100) {
                            // grade >100% hack
                            $grademax = $grademax * $maxcoef;
                        }
                    }
                }
                if ($gradeval > $grademax) {
                    $gradeval = $grademax;
                }
                if ($gradeval < $grade_item->grademin) {
                    $gradeval = $grade_item->grademin;
                }
            } elseif ($gradeval == '-' || $gradeval == '') {
                $grade_old = new grade_grade(array('itemid' => $grade_item->id, 'userid' => $student));
                $gradeval = $finalgrade;
                $gradeval *= $multfactor;
                $gradeval += $plusfactor;
                if ($gradeval > 100) {
                    $gradeval = 100;
                }
            }
            if (!$grade_item->scaleid && $grade->grade_item->itemnumber == 0) {
                $overridden = $grade_old->overridden;
                $grade_item->update_final_grade($student, $gradeval, 'evalcomixAdd');
                $grade = new grade_grade(array('itemid' => $grade_item->id, 'userid' => $student));
                $grade->overridden = $overridden;
                $grade->update('EvalcomixUpdate');
            }
        }
    }
}
开发者ID:srpaedagogus,项目名称:aulavirtual,代码行数:31,代码来源:gradeevx.php

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

示例13: object

 /**
  * Updates final grade value for given user, this is a only way to update final
  * grades from gradebook and import because it logs the change in history table
  * and deals with overridden flag. This flag is set to prevent later overriding
  * from raw grades submitted from modules.
  *
  * @param int $userid the graded user
  * @param mixed $finalgrade float value of final grade - false means do not change
  * @param string $howmodified modification source
  * @param string $note optional note
  * @param mixed $feedback teachers feedback as string - false means do not change
  * @param int $feedbackformat
  * @return boolean success
  */
 function update_final_grade($userid, $finalgrade = false, $source = NULL, $feedback = false, $feedbackformat = FORMAT_MOODLE, $usermodified = null)
 {
     global $USER, $CFG;
     $result = true;
     // no grading used or locked
     if ($this->gradetype == GRADE_TYPE_NONE or $this->is_locked()) {
         return false;
     }
     $grade = new grade_grade(array('itemid' => $this->id, 'userid' => $userid));
     $grade->grade_item =& $this;
     // prevent db fetching of this grade_item
     if (empty($usermodified)) {
         $grade->usermodified = $USER->id;
     } else {
         $grade->usermodified = $usermodified;
     }
     if ($grade->is_locked()) {
         // do not update locked grades at all
         return false;
     }
     $locktime = $grade->get_locktime();
     if ($locktime and $locktime < time()) {
         // do not update grades that should be already locked, force regrade instead
         $this->force_regrading();
         return false;
     }
     $oldgrade = new object();
     $oldgrade->finalgrade = $grade->finalgrade;
     $oldgrade->overridden = $grade->overridden;
     $oldgrade->feedback = $grade->feedback;
     $oldgrade->feedbackformat = $grade->feedbackformat;
     // changed grade?
     if ($finalgrade !== false) {
         if ($this->is_overridable_item()) {
             $grade->overridden = time();
         } else {
             $grade->overridden = 0;
         }
         $grade->finalgrade = $this->bounded_grade($finalgrade);
     }
     // do we have comment from teacher?
     if ($feedback !== false) {
         if ($this->is_overridable_item_feedback()) {
             // external items (modules, plugins) may have own feedback
             $grade->overridden = time();
         }
         $grade->feedback = $feedback;
         $grade->feedbackformat = $feedbackformat;
     }
     // HACK: Bob Puffer to allow accurate max score to be inserted into the grade_item record
     $grade->rawgrademax = $this->grademax;
     // END OF HACK
     if (empty($grade->id)) {
         $grade->timecreated = null;
         // hack alert - date submitted - no submission yet
         $grade->timemodified = time();
         // hack alert - date graded
         $result = (bool) $grade->insert($source);
     } else {
         if (grade_floats_different($grade->finalgrade, $oldgrade->finalgrade) or $grade->feedback !== $oldgrade->feedback or $grade->feedbackformat != $oldgrade->feedbackformat or $grade->overridden != $oldgrade->overridden) {
             $grade->timemodified = time();
             // hack alert - date graded
             $result = $grade->update($source);
         } else {
             // no grade change
             return $result;
         }
     }
     if (!$result) {
         // something went wrong - better force final grade recalculation
         $this->force_regrading();
     } else {
         if ($this->is_course_item() and !$this->needsupdate) {
             if (grade_regrade_final_grades($this->courseid, $userid, $this) !== true) {
                 $this->force_regrading();
             }
         } else {
             if (!$this->needsupdate) {
                 $course_item = grade_item_local::fetch_course_item($this->courseid);
                 if (!$course_item->needsupdate) {
                     if (grade_regrade_final_grades_local($this->courseid, $userid, $this) !== true) {
                         $this->force_regrading();
                     }
                 } else {
                     $this->force_regrading();
                 }
//.........这里部分代码省略.........
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:101,代码来源:locallib.php

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

示例15: aggregate_grades

 /**
  * Internal function for grade category grade aggregation
  *
  * @param int    $userid The User ID
  * @param array  $items Grade items
  * @param array  $grade_values Array of grade values
  * @param object $oldgrade Old grade
  * @param array  $excluded Excluded
  * @param array  $grademinoverrides User specific grademin values if different to the grade_item grademin (key is itemid)
  * @param array  $grademaxoverrides User specific grademax values if different to the grade_item grademax (key is itemid)
  */
 private function aggregate_grades($userid, $items, $grade_values, $oldgrade, $excluded, $grademinoverrides, $grademaxoverrides)
 {
     global $CFG, $DB;
     // Remember these so we can set flags on them to describe how they were used in the aggregation.
     $novalue = array();
     $dropped = array();
     $extracredit = array();
     $usedweights = array();
     if (empty($userid)) {
         //ignore first call
         return;
     }
     if ($oldgrade) {
         $oldfinalgrade = $oldgrade->finalgrade;
         $grade = new grade_grade($oldgrade, false);
         $grade->grade_item =& $this->grade_item;
     } else {
         // insert final grade - it will be needed later anyway
         $grade = new grade_grade(array('itemid' => $this->grade_item->id, 'userid' => $userid), false);
         $grade->grade_item =& $this->grade_item;
         $grade->insert('system');
         $oldfinalgrade = null;
     }
     // no need to recalculate locked or overridden grades
     if ($grade->is_locked() or $grade->is_overridden()) {
         return;
     }
     // can not use own final category grade in calculation
     unset($grade_values[$this->grade_item->id]);
     // Make sure a grade_grade exists for every grade_item.
     // We need to do this so we can set the aggregationstatus
     // with a set_field call instead of checking if each one exists and creating/updating.
     if (!empty($items)) {
         list($ggsql, $params) = $DB->get_in_or_equal(array_keys($items), SQL_PARAMS_NAMED, 'g');
         $params['userid'] = $userid;
         $sql = "SELECT itemid\n                      FROM {grade_grades}\n                     WHERE itemid {$ggsql} AND userid = :userid";
         $existingitems = $DB->get_records_sql($sql, $params);
         $notexisting = array_diff(array_keys($items), array_keys($existingitems));
         foreach ($notexisting as $itemid) {
             $gradeitem = $items[$itemid];
             $gradegrade = new grade_grade(array('itemid' => $itemid, 'userid' => $userid, 'rawgrademin' => $gradeitem->grademin, 'rawgrademax' => $gradeitem->grademax), false);
             $gradegrade->grade_item = $gradeitem;
             $gradegrade->insert('system');
         }
     }
     // if no grades calculation possible or grading not allowed clear final grade
     if (empty($grade_values) or empty($items) or $this->grade_item->gradetype != GRADE_TYPE_VALUE and $this->grade_item->gradetype != GRADE_TYPE_SCALE) {
         $grade->finalgrade = null;
         if (!is_null($oldfinalgrade)) {
             $success = $grade->update('aggregation');
             // If successful trigger a user_graded event.
             if ($success) {
                 \core\event\user_graded::create_from_grade($grade)->trigger();
             }
         }
         $dropped = $grade_values;
         $this->set_usedinaggregation($userid, $usedweights, $novalue, $dropped, $extracredit);
         return;
     }
     // Normalize the grades first - all will have value 0...1
     // ungraded items are not used in aggregation.
     foreach ($grade_values as $itemid => $v) {
         if (is_null($v)) {
             // If null, it means no grade.
             if ($this->aggregateonlygraded) {
                 unset($grade_values[$itemid]);
                 // Mark this item as "excluded empty" because it has no grade.
                 $novalue[$itemid] = 0;
                 continue;
             }
         }
         if (in_array($itemid, $excluded)) {
             unset($grade_values[$itemid]);
             $dropped[$itemid] = 0;
             continue;
         }
         // Check for user specific grade min/max overrides.
         $usergrademin = $items[$itemid]->grademin;
         $usergrademax = $items[$itemid]->grademax;
         if (isset($grademinoverrides[$itemid])) {
             $usergrademin = $grademinoverrides[$itemid];
         }
         if (isset($grademaxoverrides[$itemid])) {
             $usergrademax = $grademaxoverrides[$itemid];
         }
         if ($this->aggregation == GRADE_AGGREGATE_SUM) {
             // Assume that the grademin is 0 when standardising the score, to preserve negative grades.
             $grade_values[$itemid] = grade_grade::standardise_score($v, 0, $usergrademax, 0, 1);
         } else {
//.........这里部分代码省略.........
开发者ID:jtibbetts,项目名称:moodle,代码行数:101,代码来源:grade_category.php


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