/** * This function helps move a question cateogry to a new context by moving all * the files belonging to all the questions to the new context. * Also moves subcategories. * @param integer $categoryid the id of the category being moved. * @param integer $oldcontextid the old context id. * @param integer $newcontextid the new context id. */ function question_move_category_to_context($categoryid, $oldcontextid, $newcontextid) { global $DB; $questionids = $DB->get_records_menu('question', array('category' => $categoryid), '', 'id,qtype'); foreach ($questionids as $questionid => $qtype) { question_bank::get_qtype($qtype)->move_files($questionid, $oldcontextid, $newcontextid); // Purge this question from the cache. question_bank::notify_question_edited($questionid); } core_tag_tag::change_items_context('core_question', 'question', array_keys($questionids), $newcontextid); $subcatids = $DB->get_records_menu('question_categories', array('parent' => $categoryid), '', 'id,1'); foreach ($subcatids as $subcatid => $notused) { $DB->set_field('question_categories', 'contextid', $newcontextid, array('id' => $subcatid)); question_move_category_to_context($subcatid, $oldcontextid, $newcontextid); } }