當前位置: 首頁>>代碼示例>>PHP>>正文


PHP restore_dbops::restore_get_question_categories方法代碼示例

本文整理匯總了PHP中restore_dbops::restore_get_question_categories方法的典型用法代碼示例。如果您正苦於以下問題:PHP restore_dbops::restore_get_question_categories方法的具體用法?PHP restore_dbops::restore_get_question_categories怎麽用?PHP restore_dbops::restore_get_question_categories使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在restore_dbops的用法示例。


在下文中一共展示了restore_dbops::restore_get_question_categories方法的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_question_categories方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。