本文整理汇总了PHP中moodle_transaction::rollback方法的典型用法代码示例。如果您正苦于以下问题:PHP moodle_transaction::rollback方法的具体用法?PHP moodle_transaction::rollback怎么用?PHP moodle_transaction::rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类moodle_transaction
的用法示例。
在下文中一共展示了moodle_transaction::rollback方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: persist_grades
/**
* Persist the passed in grades (keyed by userid) to the database
*
* @param array $grades
* @param \moodle_transaction $transaction
*
* @return bool
*/
protected function persist_grades($grades, \moodle_transaction $transaction)
{
global $DB;
foreach ($grades as $userid => $grade) {
if ($usergrade = $DB->get_record('activequiz_grades', array('userid' => $userid, 'activequizid' => $this->rtq->getRTQ()->id))) {
// we're updating
$usergrade->grade = $grade;
$usergrade->timemodified = time();
if (!$DB->update_record('activequiz_grades', $usergrade)) {
$transaction->rollback(new \Exception('Can\'t update user grades'));
}
} else {
// we're adding
$usergrade = new \stdClass();
$usergrade->activequizid = $this->rtq->getRTQ()->id;
$usergrade->userid = $userid;
$usergrade->grade = $grade;
$usergrade->timemodified = time();
if (!$DB->insert_record('activequiz_grades', $usergrade)) {
$transaction->rollback(new \Exception('Can\'t insert user grades'));
}
}
}
return true;
}