當前位置: 首頁>>代碼示例>>PHP>>正文


PHP grade_grade::load_optional_fields方法代碼示例

本文整理匯總了PHP中grade_grade::load_optional_fields方法的典型用法代碼示例。如果您正苦於以下問題:PHP grade_grade::load_optional_fields方法的具體用法?PHP grade_grade::load_optional_fields怎麽用?PHP grade_grade::load_optional_fields使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在grade_grade的用法示例。


在下文中一共展示了grade_grade::load_optional_fields方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: grade_update


//.........這裏部分代碼省略.........
        return GRADE_UPDATE_OK;
    }
    /// Finally start processing of grades
    if (is_object($grades)) {
        $grades = array($grades->userid => $grades);
    } else {
        if (array_key_exists('userid', $grades)) {
            $grades = array($grades['userid'] => $grades);
        }
    }
    /// normalize and verify grade array
    foreach ($grades as $k => $g) {
        if (!is_array($g)) {
            $g = (array) $g;
            $grades[$k] = $g;
        }
        if (empty($g['userid']) or $k != $g['userid']) {
            debugging('Incorrect grade array index, must be user id! Grade ignored.');
            unset($grades[$k]);
        }
    }
    if (empty($grades)) {
        return GRADE_UPDATE_FAILED;
    }
    $count = count($grades);
    if ($count > 0 and $count < 200) {
        list($uids, $params) = $DB->get_in_or_equal(array_keys($grades), SQL_PARAMS_NAMED, $start = 'uid');
        $params['gid'] = $grade_item->id;
        $sql = "SELECT * FROM {grade_grades} WHERE itemid = :gid AND userid {$uids}";
    } else {
        $sql = "SELECT * FROM {grade_grades} WHERE itemid = :gid";
        $params = array('gid' => $grade_item->id);
    }
    $rs = $DB->get_recordset_sql($sql, $params);
    $failed = false;
    while (count($grades) > 0) {
        $grade_grade = null;
        $grade = null;
        foreach ($rs as $gd) {
            $userid = $gd->userid;
            if (!isset($grades[$userid])) {
                // this grade not requested, continue
                continue;
            }
            // existing grade requested
            $grade = $grades[$userid];
            $grade_grade = new grade_grade($gd, false);
            unset($grades[$userid]);
            break;
        }
        if (is_null($grade_grade)) {
            if (count($grades) == 0) {
                // no more grades to process
                break;
            }
            $grade = reset($grades);
            $userid = $grade['userid'];
            $grade_grade = new grade_grade(array('itemid' => $grade_item->id, 'userid' => $userid), false);
            $grade_grade->load_optional_fields();
            // add feedback and info too
            unset($grades[$userid]);
        }
        $rawgrade = false;
        $feedback = false;
        $feedbackformat = FORMAT_MOODLE;
        $usermodified = $USER->id;
        $datesubmitted = null;
        $dategraded = null;
        if (array_key_exists('rawgrade', $grade)) {
            $rawgrade = $grade['rawgrade'];
        }
        if (array_key_exists('feedback', $grade)) {
            $feedback = $grade['feedback'];
        }
        if (array_key_exists('feedbackformat', $grade)) {
            $feedbackformat = $grade['feedbackformat'];
        }
        if (array_key_exists('usermodified', $grade)) {
            $usermodified = $grade['usermodified'];
        }
        if (array_key_exists('datesubmitted', $grade)) {
            $datesubmitted = $grade['datesubmitted'];
        }
        if (array_key_exists('dategraded', $grade)) {
            $dategraded = $grade['dategraded'];
        }
        // update or insert the grade
        if (!$grade_item->update_raw_grade($userid, $rawgrade, $source, $feedback, $feedbackformat, $usermodified, $dategraded, $datesubmitted, $grade_grade)) {
            $failed = true;
        }
    }
    if ($rs) {
        $rs->close();
    }
    if (!$failed) {
        return GRADE_UPDATE_OK;
    } else {
        return GRADE_UPDATE_FAILED;
    }
}
開發者ID:saurabh947,項目名稱:MoodleLearning,代碼行數:101,代碼來源:gradelib.php


注:本文中的grade_grade::load_optional_fields方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。