Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 23... Línea 23...
23
 * @package    mod_quiz
23
 * @package    mod_quiz
24
 * @copyright  1999 onwards Martin Dougiamas {@link http://moodle.com}
24
 * @copyright  1999 onwards Martin Dougiamas {@link http://moodle.com}
25
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 */
26
 */
Línea 27... Línea -...
27
 
-
 
-
 
27
 
28
 
28
use core_question\local\bank\question_bank_helper;
Línea 29... Línea 29...
29
use qbank_managecategories\helper;
29
use qbank_managecategories\helper;
Línea 30... Línea 30...
30
 
30
 
Línea 252... Línea 252...
252
    // Check for group overrides.
252
    // Check for group overrides.
253
    $groupings = groups_get_user_groups($quiz->course, $userid);
253
    $groupings = groups_get_user_groups($quiz->course, $userid);
Línea 254... Línea 254...
254
 
254
 
255
    if (!empty($groupings[0])) {
255
    if (!empty($groupings[0])) {
256
        // Select all overrides that apply to the User's groups.
256
        // Select all overrides that apply to the User's groups.
257
        list($extra, $params) = $DB->get_in_or_equal(array_values($groupings[0]));
257
        [$extra, $params] = $DB->get_in_or_equal(array_values($groupings[0]));
258
        $sql = "SELECT * FROM {quiz_overrides}
258
        $sql = "SELECT * FROM {quiz_overrides}
259
                WHERE groupid $extra AND quiz = ?";
259
                WHERE groupid $extra AND quiz = ?";
260
        $params[] = $quiz->id;
260
        $params[] = $quiz->id;
Línea 522... Línea 522...
522
        case 'all':
522
        case 'all':
523
            $statuscondition = '';
523
            $statuscondition = '';
524
            break;
524
            break;
Línea 525... Línea 525...
525
 
525
 
526
        case 'finished':
526
        case 'finished':
527
            $statuscondition = ' AND state IN (:state1, :state2)';
527
            $statuscondition = ' AND state IN (:state1, :state2, :state3)';
528
            $params['state1'] = quiz_attempt::FINISHED;
528
            $params['state1'] = quiz_attempt::FINISHED;
-
 
529
            $params['state2'] = quiz_attempt::ABANDONED;
529
            $params['state2'] = quiz_attempt::ABANDONED;
530
            $params['state3'] = quiz_attempt::SUBMITTED;
Línea 530... Línea 531...
530
            break;
531
            break;
531
 
532
 
532
        case 'unfinished':
533
        case 'unfinished':
533
            $statuscondition = ' AND state IN (:state1, :state2)';
534
            $statuscondition = ' AND state IN (:state1, :state2)';
534
            $params['state1'] = quiz_attempt::IN_PROGRESS;
535
            $params['state1'] = quiz_attempt::IN_PROGRESS;
535
            $params['state2'] = quiz_attempt::OVERDUE;
536
            $params['state2'] = quiz_attempt::OVERDUE;
Línea 536... Línea 537...
536
            break;
537
            break;
537
    }
538
    }
538
 
539
 
539
    $quizids = (array) $quizids;
540
    $quizids = (array) $quizids;
Línea 540... Línea 541...
540
    list($insql, $inparams) = $DB->get_in_or_equal($quizids, SQL_PARAMS_NAMED);
541
    [$insql, $inparams] = $DB->get_in_or_equal($quizids, SQL_PARAMS_NAMED);
541
    $params += $inparams;
542
    $params += $inparams;
Línea 1413... Línea 1414...
1413
 *
1414
 *
1414
 * @param MoodleQuickForm $mform the course reset form that is being built.
1415
 * @param MoodleQuickForm $mform the course reset form that is being built.
1415
 */
1416
 */
1416
function quiz_reset_course_form_definition($mform) {
1417
function quiz_reset_course_form_definition($mform) {
1417
    $mform->addElement('header', 'quizheader', get_string('modulenameplural', 'quiz'));
1418
    $mform->addElement('header', 'quizheader', get_string('modulenameplural', 'quiz'));
-
 
1419
    $mform->addElement('static', 'quizdelete', get_string('delete'));
1418
    $mform->addElement('advcheckbox', 'reset_quiz_attempts',
1420
    $mform->addElement('advcheckbox', 'reset_quiz_attempts',
1419
            get_string('removeallquizattempts', 'quiz'));
1421
            get_string('removeallquizattempts', 'quiz'));
1420
    $mform->addElement('advcheckbox', 'reset_quiz_user_overrides',
1422
    $mform->addElement('advcheckbox', 'reset_quiz_user_overrides',
1421
            get_string('removealluseroverrides', 'quiz'));
1423
            get_string('removealluseroverrides', 'quiz'));
1422
    $mform->addElement('advcheckbox', 'reset_quiz_group_overrides',
1424
    $mform->addElement('advcheckbox', 'reset_quiz_group_overrides',
Línea 1480... Línea 1482...
1480
 
1482
 
1481
        $DB->delete_records_select('quiz_attempts',
1483
        $DB->delete_records_select('quiz_attempts',
1482
                'quiz IN (SELECT id FROM {quiz} WHERE course = ?)', [$data->courseid]);
1484
                'quiz IN (SELECT id FROM {quiz} WHERE course = ?)', [$data->courseid]);
1483
        $status[] = [
1485
        $status[] = [
1484
            'component' => $componentstr,
1486
            'component' => $componentstr,
1485
            'item' => get_string('attemptsdeleted', 'quiz'),
1487
            'item' => get_string('removeallquizattempts', 'quiz'),
Línea 1486... Línea 1488...
1486
            'error' => false];
1488
            'error' => false];
1487
 
1489
 
1488
        // Remove all grades from gradebook.
1490
        // Remove all grades from gradebook.
1489
        $DB->delete_records_select('quiz_grades',
1491
        $DB->delete_records_select('quiz_grades',
1490
                'quiz IN (SELECT id FROM {quiz} WHERE course = ?)', [$data->courseid]);
1492
                'quiz IN (SELECT id FROM {quiz} WHERE course = ?)', [$data->courseid]);
1491
        if (empty($data->reset_gradebook_grades)) {
1493
        if (empty($data->reset_gradebook_grades)) {
1492
            quiz_reset_gradebook($data->courseid);
1494
            quiz_reset_gradebook($data->courseid);
1493
        }
1495
        }
1494
        $status[] = [
1496
        $status[] = [
1495
            'component' => $componentstr,
1497
            'component' => $componentstr,
1496
            'item' => get_string('gradesdeleted', 'quiz'),
1498
            'item' => get_string('grades'),
Línea 1497... Línea 1499...
1497
            'error' => false];
1499
            'error' => false];
Línea 1503... Línea 1505...
1503
    if (!empty($data->reset_quiz_user_overrides)) {
1505
    if (!empty($data->reset_quiz_user_overrides)) {
1504
        $DB->delete_records_select('quiz_overrides',
1506
        $DB->delete_records_select('quiz_overrides',
1505
                'quiz IN (SELECT id FROM {quiz} WHERE course = ?) AND userid IS NOT NULL', [$data->courseid]);
1507
                'quiz IN (SELECT id FROM {quiz} WHERE course = ?) AND userid IS NOT NULL', [$data->courseid]);
1506
        $status[] = [
1508
        $status[] = [
1507
            'component' => $componentstr,
1509
            'component' => $componentstr,
1508
            'item' => get_string('useroverridesdeleted', 'quiz'),
1510
            'item' => get_string('useroverrides', 'quiz'),
1509
            'error' => false];
1511
            'error' => false];
1510
        $purgeoverrides = true;
1512
        $purgeoverrides = true;
1511
    }
1513
    }
1512
    // Remove group overrides.
1514
    // Remove group overrides.
1513
    if (!empty($data->reset_quiz_group_overrides)) {
1515
    if (!empty($data->reset_quiz_group_overrides)) {
1514
        $DB->delete_records_select('quiz_overrides',
1516
        $DB->delete_records_select('quiz_overrides',
1515
                'quiz IN (SELECT id FROM {quiz} WHERE course = ?) AND groupid IS NOT NULL', [$data->courseid]);
1517
                'quiz IN (SELECT id FROM {quiz} WHERE course = ?) AND groupid IS NOT NULL', [$data->courseid]);
1516
        $status[] = [
1518
        $status[] = [
1517
            'component' => $componentstr,
1519
            'component' => $componentstr,
1518
            'item' => get_string('groupoverridesdeleted', 'quiz'),
1520
            'item' => get_string('groupoverrides', 'quiz'),
1519
            'error' => false];
1521
            'error' => false];
1520
        $purgeoverrides = true;
1522
        $purgeoverrides = true;
1521
    }
1523
    }
Línea 1522... Línea 1524...
1522
 
1524
 
Línea 1578... Línea 1580...
1578
                        '{groups_members} gm ON qa.userid = gm.userid ' .
1580
                        '{groups_members} gm ON qa.userid = gm.userid ' .
1579
                        'WHERE quiz = ? AND preview = 0 AND groupid = ?',
1581
                        'WHERE quiz = ? AND preview = 0 AND groupid = ?',
1580
                        [$quiz->id, $currentgroup]);
1582
                        [$quiz->id, $currentgroup]);
1581
                return get_string('attemptsnumthisgroup', 'quiz', $a);
1583
                return get_string('attemptsnumthisgroup', 'quiz', $a);
1582
            } else if ($groups = groups_get_all_groups($cm->course, $USER->id, $cm->groupingid)) {
1584
            } else if ($groups = groups_get_all_groups($cm->course, $USER->id, $cm->groupingid)) {
1583
                list($usql, $params) = $DB->get_in_or_equal(array_keys($groups));
1585
                [$usql, $params] = $DB->get_in_or_equal(array_keys($groups));
1584
                $a->group = $DB->count_records_sql('SELECT COUNT(DISTINCT qa.id) FROM ' .
1586
                $a->group = $DB->count_records_sql('SELECT COUNT(DISTINCT qa.id) FROM ' .
1585
                        '{quiz_attempts} qa JOIN ' .
1587
                        '{quiz_attempts} qa JOIN ' .
1586
                        '{groups_members} gm ON qa.userid = gm.userid ' .
1588
                        '{groups_members} gm ON qa.userid = gm.userid ' .
1587
                        'WHERE quiz = ? AND preview = 0 AND ' .
1589
                        'WHERE quiz = ? AND preview = 0 AND ' .
1588
                        "groupid $usql", array_merge([$quiz->id], $params));
1590
                        "groupid $usql", array_merge([$quiz->id], $params));
Línea 1870... Línea 1872...
1870
    $updates->questions = (object) ['updated' => false];
1872
    $updates->questions = (object) ['updated' => false];
1871
    $quizobj = quiz_settings::create($cm->instance, $USER->id);
1873
    $quizobj = quiz_settings::create($cm->instance, $USER->id);
1872
    $quizobj->preload_questions();
1874
    $quizobj->preload_questions();
1873
    $questionids = array_keys($quizobj->get_questions(null, false));
1875
    $questionids = array_keys($quizobj->get_questions(null, false));
1874
    if (!empty($questionids)) {
1876
    if (!empty($questionids)) {
1875
        list($questionsql, $params) = $DB->get_in_or_equal($questionids, SQL_PARAMS_NAMED);
1877
        [$questionsql, $params] = $DB->get_in_or_equal($questionids, SQL_PARAMS_NAMED);
1876
        $select = 'id ' . $questionsql . ' AND (timemodified > :time1 OR timecreated > :time2)';
1878
        $select = 'id ' . $questionsql . ' AND (timemodified > :time1 OR timecreated > :time2)';
1877
        $params['time1'] = $from;
1879
        $params['time1'] = $from;
1878
        $params['time2'] = $from;
1880
        $params['time2'] = $from;
1879
        $questions = $DB->get_records_select('question', $select, $params, '', 'id');
1881
        $questions = $DB->get_records_select('question', $select, $params, '', 'id');
1880
        if (!empty($questions)) {
1882
        if (!empty($questions)) {
Línea 1908... Línea 1910...
1908
        if (groups_get_activity_groupmode($cm) == SEPARATEGROUPS) {
1910
        if (groups_get_activity_groupmode($cm) == SEPARATEGROUPS) {
1909
            $groupusers = array_keys(groups_get_activity_shared_group_members($cm));
1911
            $groupusers = array_keys(groups_get_activity_shared_group_members($cm));
1910
            if (empty($groupusers)) {
1912
            if (empty($groupusers)) {
1911
                return $updates;
1913
                return $updates;
1912
            }
1914
            }
1913
            list($insql, $inparams) = $DB->get_in_or_equal($groupusers);
1915
            [$insql, $inparams] = $DB->get_in_or_equal($groupusers);
1914
            $select .= ' AND userid ' . $insql;
1916
            $select .= ' AND userid ' . $insql;
1915
            $params = array_merge($params, $inparams);
1917
            $params = array_merge($params, $inparams);
1916
        }
1918
        }
Línea 1917... Línea 1919...
1917
 
1919
 
Línea 2326... Línea 2328...
2326
    $params = [];
2328
    $params = [];
2327
    $extraparams = [];
2329
    $extraparams = [];
2328
    $querystring = parse_url($args['querystring'], PHP_URL_QUERY);
2330
    $querystring = parse_url($args['querystring'], PHP_URL_QUERY);
2329
    parse_str($querystring, $params);
2331
    parse_str($querystring, $params);
Línea -... Línea 2332...
-
 
2332
 
-
 
2333
    // Load the bank we are looking at rather than always the quiz module itself.
-
 
2334
    $params['cmid'] = clean_param($args['bankcmid'], PARAM_INT);
2330
 
2335
 
2331
    $viewclass = \mod_quiz\question\bank\custom_view::class;
2336
    $viewclass = \mod_quiz\question\bank\custom_view::class;
Línea -... Línea 2337...
-
 
2337
    $extraparams['view'] = $viewclass;
-
 
2338
 
-
 
2339
    // We need the quiz modid to POST back to.
2332
    $extraparams['view'] = $viewclass;
2340
    $extraparams['quizcmid'] = clean_param($args['quizcmid'], PARAM_INT);
2333
 
2341
 
2334
    // Build required parameters.
2342
    // Build required parameters.
Línea 2335... Línea 2343...
2335
    [$contexts, $thispageurl, $cm, $pagevars, $extraparams] =
2343
    [$contexts, $thispageurl, $cm, $pagevars, $extraparams] =
-
 
2344
            build_required_parameters_for_custom_view($params, $extraparams);
2336
            build_required_parameters_for_custom_view($params, $extraparams);
2345
 
-
 
2346
    $course = get_course($cm->course);
Línea 2337... Línea 2347...
2337
 
2347
    if (!has_capability('moodle/question:useall', $contexts->lowest())) {
2338
    $course = get_course($cm->course);
2348
        require_capability('moodle/question:usemine', $contexts->lowest());
Línea 2339... Línea 2349...
2339
    require_capability('mod/quiz:manage', $contexts->lowest());
2349
    }
2340
 
2350
 
2341
    // Custom View.
2351
    // Custom View.
2342
    $questionbank = new $viewclass($contexts, $thispageurl, $course, $cm, $pagevars, $extraparams);
2352
    $questionbank = new $viewclass($contexts, $thispageurl, $course, $cm, $pagevars, $extraparams);
Línea 2343... Línea 2353...
2343
 
2353
 
-
 
2354
    // Output.
-
 
2355
    $renderer = $PAGE->get_renderer('mod_quiz', 'edit');
-
 
2356
    return $renderer->question_bank_contents($questionbank, $pagevars);
-
 
2357
}
-
 
2358
 
-
 
2359
/**
-
 
2360
 * Build and return the output for the question bank and category chooser.
-
 
2361
 *
-
 
2362
 * @param array $args provided by the AJAX request.
-
 
2363
 * @return string html to render to the modal.
-
 
2364
 */
-
 
2365
function mod_quiz_output_fragment_switch_question_bank($args): string {
-
 
2366
    global $USER, $COURSE, $OUTPUT;
-
 
2367
 
-
 
2368
    $quizcmid = clean_param($args['quizcmid'], PARAM_INT);
-
 
2369
 
2344
    // Output.
2370
    $switchbankwidget = new \core_question\output\switch_question_bank($quizcmid, $COURSE->id, $USER->id);
2345
    $renderer = $PAGE->get_renderer('mod_quiz', 'edit');
2371
 
2346
    return $renderer->question_bank_contents($questionbank, $pagevars);
2372
    return $OUTPUT->render($switchbankwidget);
2347
}
2373
}
2348
 
-
 
2349
/**
2374
 
2350
 * Generates the add random question in a fragment output. This allows the
2375
/**
2351
 * form to be rendered in javascript, for example inside a modal.
2376
 * Generates the add random question in a fragment output. This allows the
-
 
2377
 * form to be rendered in javascript, for example inside a modal.
2352
 *
2378
 *
2353
 * The required arguments as keys in the $args array are:
2379
 * The required arguments as keys in the $args array are:
2354
 *      cat {string} The category and category context ids comma separated.
2380
 *      addonpage {int} The page id to add this question to.
2355
 *      addonpage {int} The page id to add this question to.
2381
 *      returnurl {string} URL to return to after form submission.
2356
 *      returnurl {string} URL to return to after form submission.
2382
 *      quizcmid {int} The quiz course module id the questions are being added to.
2357
 *      cmid {int} The course module id the questions are being added to.
2383
 *      bankcmid {int} The question bank course module id the questions are being added from.
-
 
2384
 *
-
 
2385
 * @param array $args The fragment arguments.
-
 
2386
 * @return string The rendered mform fragment.
-
 
2387
 */
-
 
2388
function mod_quiz_output_fragment_add_random_question_form($args) {
-
 
2389
    global $PAGE, $OUTPUT, $DB;
-
 
2390
 
-
 
2391
    $slotid = clean_param($args['slotid'] ?? 0, PARAM_INT);
-
 
2392
    if (empty($slotid)) {
-
 
2393
        $params = $args;
-
 
2394
    } else {
-
 
2395
        // Load the stored filters for the current slot.
-
 
2396
        $setreference = $DB->get_record('question_set_references',
-
 
2397
            ['itemid' => $slotid, 'component' => 'mod_quiz', 'questionarea' => 'slot']);
-
 
2398
        $filterconditions = json_decode($setreference->filtercondition, true);
-
 
2399
        $filterconditions = \core_question\question_reference_manager::convert_legacy_set_reference_filter_condition(
-
 
2400
            $filterconditions,
-
 
2401
        );
-
 
2402
        $params = \core_question\local\bank\filter_condition_manager::filter_invalid_values($filterconditions);
Línea 2358... Línea 2403...
2358
 *
2403
    }
-
 
2404
 
-
 
2405
    if (!empty($args['savedfiltercondition'])) {
Línea 2359... Línea 2406...
2359
 * @param array $args The fragment arguments.
2406
        $filtercondition = json_decode($args['savedfiltercondition'], true);
2360
 * @return string The rendered mform fragment.
2407
        $params['filter'] = $filtercondition['filter'];
2361
 */
2408
    }
Línea 2362... Línea 2409...
2362
function mod_quiz_output_fragment_add_random_question_form($args) {
2409
 
2363
    global $PAGE, $OUTPUT;
2410
    $extraparams = [];
Línea 2364... Línea 2411...
2364
 
2411
    $extraparams['quizcmid'] = clean_param($args['quizcmid'], PARAM_INT);
Línea 2402... Línea 2449...
2402
    $data = [
2449
    $data = [
2403
        'questionbank' => $questionbankoutput,
2450
        'questionbank' => $questionbankoutput,
2404
        'randomoptions' => $randomcount,
2451
        'randomoptions' => $randomcount,
2405
        'questioncategoryoptions' => $catoptions,
2452
        'questioncategoryoptions' => $catoptions,
2406
    ];
2453
    ];
-
 
2454
    if (!empty($slotid)) {
-
 
2455
        $data['slotid'] = $slotid;
-
 
2456
    }
Línea 2407... Línea 2457...
2407
 
2457
 
2408
    $helpicon = new \help_icon('parentcategory', 'question');
2458
    $helpicon = new \help_icon('parentcategory', 'question');
Línea 2409... Línea 2459...
2409
    $data['questioncategoryhelp'] = $helpicon->export_for_template($renderer);
2459
    $data['questioncategoryhelp'] = $helpicon->export_for_template($renderer);
Línea 2475... Línea 2525...
2475
    // Build required parameters.
2525
    // Build required parameters.
2476
    $cmid = clean_param($args['cmid'], PARAM_INT);
2526
    $cmid = clean_param($args['cmid'], PARAM_INT);
2477
    $thispageurl = new \moodle_url('/mod/quiz/edit.php', ['cmid' => $cmid]);
2527
    $thispageurl = new \moodle_url('/mod/quiz/edit.php', ['cmid' => $cmid]);
2478
    $thiscontext = \context_module::instance($cmid);
2528
    $thiscontext = \context_module::instance($cmid);
2479
    $contexts = new \core_question\local\bank\question_edit_contexts($thiscontext);
2529
    $contexts = new \core_question\local\bank\question_edit_contexts($thiscontext);
2480
    $defaultcategory = question_make_default_categories($contexts->all());
2530
    $defaultcategory = question_get_default_category($contexts->lowest()->id, true);
2481
    $params['cat'] = implode(',', [$defaultcategory->id, $defaultcategory->contextid]);
2531
    $params['cat'] = implode(',', [$defaultcategory->id, $defaultcategory->contextid]);
Línea 2482... Línea 2532...
2482
 
2532
 
-
 
2533
    $course = get_course($params['courseid']);
2483
    $course = get_course($params['courseid']);
2534
    // The viewing bank mod id.
2484
    [, $cm] = get_module_from_cmid($cmid);
2535
    [, $cm] = get_module_from_cmid(clean_param($args['cmid'], PARAM_INT));
-
 
2536
    $params['tabname'] = 'questions';
Línea 2485... Línea 2537...
2485
    $params['tabname'] = 'questions';
2537
    $extraparams['quizcmid'] = clean_param($args['quizcmid'], PARAM_INT);
2486
 
2538
 
2487
    // Custom question bank View.
2539
    // Custom question bank View.
Línea 2514... Línea 2566...
2514
            $defaultpagesize);
2566
            $defaultpagesize);
Línea 2515... Línea 2567...
2515
 
2567
 
2516
    // Add cmid so we can retrieve later in extra params.
2568
    // Add cmid so we can retrieve later in extra params.
Línea -... Línea 2569...
-
 
2569
    $extraparams['cmid'] = $cmid;
-
 
2570
 
2517
    $extraparams['cmid'] = $cmid;
2571
    $extraparams['requirebankswitch'] = !empty(question_bank_helper::get_activity_types_with_shareable_questions());
2518
 
2572
 
Línea 2519... Línea 2573...
2519
    return [$contexts, $thispageurl, $cm, $pagevars, $extraparams];
2573
    return [$contexts, $thispageurl, $cm, $pagevars, $extraparams];
2520
}
2574
}