Exemplo n.º 1
0
/**
 * Category is about to be deleted,
 * 1/ All question categories and their questions are deleted for this course category.
 * 2/ All questions are moved to new category
 *
 * @param object|coursecat $category course category object
 * @param object|coursecat $newcategory empty means everything deleted, otherwise id of
 *      category where content moved
 * @param boolean $feedback to specify if the process must output a summary of its work
 * @return boolean
 */
function question_delete_course_category($category, $newcategory, $feedback = true)
{
    global $DB, $OUTPUT;
    $context = context_coursecat::instance($category->id);
    if (empty($newcategory)) {
        $feedbackdata = question_delete_context($context->id, $feedback);
        // Output feedback if requested.
        if ($feedback && $feedbackdata) {
            $table = new html_table();
            $table->head = array(get_string('questioncategory', 'question'), get_string('action'));
            $table->data = $feedbackdata;
            echo html_writer::table($table);
        }
    } else {
        // Move question categories to the new context.
        if (!($newcontext = context_coursecat::instance($newcategory->id))) {
            return false;
        }
        // Update the contextid for any tag instances for questions in the old context.
        core_tag_tag::move_context('core_question', 'question', $context, $newcontext);
        $DB->set_field('question_categories', 'contextid', $newcontext->id, array('contextid' => $context->id));
        if ($feedback) {
            $a = new stdClass();
            $a->oldplace = $context->get_context_name();
            $a->newplace = $newcontext->get_context_name();
            echo $OUTPUT->notification(get_string('movedquestionsandcategories', 'question', $a), 'notifysuccess');
        }
    }
    return true;
}