本文整理汇总了PHP中restore_dbops::restore_get_questions方法的典型用法代码示例。如果您正苦于以下问题:PHP restore_dbops::restore_get_questions方法的具体用法?PHP restore_dbops::restore_get_questions怎么用?PHP restore_dbops::restore_get_questions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类restore_dbops
的用法示例。
在下文中一共展示了restore_dbops::restore_get_questions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: define_execution
/**
* Checks if mapped questions are exact valid, or marks them to be created
*
* @global $DB
* @throws moodle_exception
*/
protected function define_execution()
{
global $DB;
$restoreid = $this->get_restoreid();
$courseid = $this->get_courseid();
$userid = $this->task->get_userid();
$workaround_qtypes = explode(',', get_config('block_sharing_cart', 'workaround_qtypes'));
// @see /backup/util/dbops/restore_dbops.class.php#prechek_precheck_qbanks_by_level
$contexts = restore_dbops::restore_get_question_banks($restoreid);
foreach ($contexts as $contextid => $contextlevel) {
$categories = restore_dbops::restore_get_question_categories($restoreid, $contextid);
$canadd = false;
if ($targetcontext = restore_dbops::restore_find_best_target_context($categories, $courseid, $contextlevel)) {
$canadd = has_capability('moodle/question:add', $targetcontext, $userid);
}
foreach ($categories as $category) {
$questions = restore_dbops::restore_get_questions($restoreid, $category->id);
foreach ($questions as $question) {
if (!in_array($question->qtype, $workaround_qtypes)) {
continue;
}
$mapping = restore_dbops::get_backup_ids_record($restoreid, 'question', $question->id);
if ($mapping && $mapping->newitemid && !self::is_question_valid($question->qtype, $mapping->newitemid)) {
if (!$canadd) {
throw new moodle_exception('questioncannotberestored', 'backup', '', $question);
}
$catmapping = restore_dbops::get_backup_ids_record($restoreid, 'question_category', $category->id);
$matchquestions = $DB->get_records('question', array('category' => $catmapping->newitemid, 'qtype' => $question->qtype, 'stamp' => $question->stamp, 'version' => $question->version));
$newitemid = 0;
// to be created if no valid duplicate exists
foreach ($matchquestions as $q) {
if ($q->id == $mapping->newitemid) {
continue;
}
if (self::is_question_valid($question->qtype, $q->id)) {
$newitemid = $q->id;
// updates mapping if a valid one found
break;
}
}
$this->update_mapping($mapping, $newitemid);
}
}
}
}
}