コード例 #1
0
<?php

trigger_reg('material.graded', function ($codeOrName, $id, $studentId) {
    global $CFG;
    $code = is_numeric($codeOrName) ? $codeOrName : array_search($codeOrName, $CFG->material);
    if (!is_numeric($code)) {
        throw new Exception('Cannot detect meterial type of "' . $codeOrName . '"', 500);
    }
    $updisciplines = entries_sql('SELECT ud.*,e.groupPeriodId,e.learningMode FROM event e, updiscipline ud, group_period gp, group_history gh
								WHERE e.updisciplineId=ud.updisciplineId AND ud.upId=gp.upId AND gp.groupPeriodId=gh.groupPeriodId AND e.instanceType=:type AND  e.instanceId=:id AND gh.studentId=:studentId', array('type' => $code, 'id' => $id, 'studentId' => $studentId));
    foreach ($updisciplines as $upd) {
        $events = entries_sql('SELECT * FROM event WHERE updisciplineId=:updisciplineId AND groupPeriodId=:groupPeriodId AND learningMode=:learningMode', array('groupPeriodId' => $upd['groupPeriodId'], 'updisciplineId' => $upd['updisciplineId'], 'learningMode' => $upd['learningMode']));
        $result = array_reduce($events, function ($r, $e) {
            $r['sum'] += $e['weight'];
            $r['got'] += $e['weight'] * val(material::i($e['instanceType'])->get_grade($e['instanceId'], $r['studentId']), 'coef', 0);
            return $r;
        }, array('studentId' => $studentId, 'sum' => 0, 'got' => 0));
        if (empty($result['sum'])) {
            continue;
        }
        entry_change('result', array('grade' => $result['got'] / $result['sum'] * 100), array('studentId' => $studentId, 'updisciplineId' => $upd['updisciplineId'], 'learningMode' => $upd['learningMode']));
    }
});
コード例 #2
0
ファイル: main.php プロジェクト: vealexeev/quiz_engine_light
function trigger_exe($name, $args = array())
{
    $callbacks = trigger_reg($name);
    foreach ($callbacks as $callback) {
        call_user_func_array($callback, $args);
    }
}