当前位置: 首页>>代码示例>>PHP>>正文


PHP restore_dbops::restore_get_questions方法代码示例

本文整理汇总了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);
                 }
             }
         }
     }
 }
开发者ID:edurenye,项目名称:sharing_cart,代码行数:52,代码来源:restore_fix_missing_questions.php


注:本文中的restore_dbops::restore_get_questions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。