本文整理匯總了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;
}