| 1 | 
           efrain | 
           1 | 
           <?php
  | 
        
        
            | 
            | 
           2 | 
           // This file is part of Moodle - http://moodle.org/
  | 
        
        
            | 
            | 
           3 | 
           //
  | 
        
        
            | 
            | 
           4 | 
           // Moodle is free software: you can redistribute it and/or modify
  | 
        
        
            | 
            | 
           5 | 
           // it under the terms of the GNU General Public License as published by
  | 
        
        
            | 
            | 
           6 | 
           // the Free Software Foundation, either version 3 of the License, or
  | 
        
        
            | 
            | 
           7 | 
           // (at your option) any later version.
  | 
        
        
            | 
            | 
           8 | 
           //
  | 
        
        
            | 
            | 
           9 | 
           // Moodle is distributed in the hope that it will be useful,
  | 
        
        
            | 
            | 
           10 | 
           // but WITHOUT ANY WARRANTY; without even the implied warranty of
  | 
        
        
            | 
            | 
           11 | 
           // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  | 
        
        
            | 
            | 
           12 | 
           // GNU General Public License for more details.
  | 
        
        
            | 
            | 
           13 | 
           //
  | 
        
        
            | 
            | 
           14 | 
           // You should have received a copy of the GNU General Public License
  | 
        
        
            | 
            | 
           15 | 
           // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  | 
        
        
            | 
            | 
           16 | 
              | 
        
        
            | 
            | 
           17 | 
           /**
  | 
        
        
            | 
            | 
           18 | 
            * Question related functions.
  | 
        
        
            | 
            | 
           19 | 
            *
  | 
        
        
            | 
            | 
           20 | 
            * This file was created just because Fragment API expects callbacks to be defined on lib.php
  | 
        
        
            | 
            | 
           21 | 
            *
  | 
        
        
            | 
            | 
           22 | 
            * Please, do not add new functions to this file.
  | 
        
        
            | 
            | 
           23 | 
            *
  | 
        
        
            | 
            | 
           24 | 
            * @package   core_question
  | 
        
        
            | 
            | 
           25 | 
            * @copyright 2018 Simey Lameze <simey@moodle.com>
  | 
        
        
            | 
            | 
           26 | 
            * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
        
        
            | 
            | 
           27 | 
            */
  | 
        
        
            | 
            | 
           28 | 
              | 
        
        
            | 
            | 
           29 | 
           defined('MOODLE_INTERNAL') || die();
  | 
        
        
            | 
            | 
           30 | 
              | 
        
        
            | 
            | 
           31 | 
           require_once($CFG->dirroot . '/question/editlib.php');
  | 
        
        
            | 
            | 
           32 | 
              | 
        
        
            | 
            | 
           33 | 
           /**
  | 
        
        
            | 
            | 
           34 | 
            * Question data fragment to get the question html via ajax call.
  | 
        
        
            | 
            | 
           35 | 
            *
  | 
        
        
            | 
            | 
           36 | 
            * @param array $args Arguments for rendering the fragment. Expected keys:
  | 
        
        
            | 
            | 
           37 | 
            *  * view - the view class
  | 
        
        
            | 
            | 
           38 | 
            *  * cmid - if in an activity, the course module ID.
  | 
        
        
            | 
            | 
           39 | 
            *  * filterquery - the current filters encoded as a URL parameter.
  | 
        
        
            | 
            | 
           40 | 
            *  * lastchanged - the ID of the last edited question.
  | 
        
        
            | 
            | 
           41 | 
            *  * sortdata - Array of sorted columns.
  | 
        
        
            | 
            | 
           42 | 
            *  * filtercondition - the current filters encoded as an object.
  | 
        
        
            | 
            | 
           43 | 
            *  * extraparams - additional parameters required for a particular view class.
  | 
        
        
            | 
            | 
           44 | 
            *
  | 
        
        
            | 
            | 
           45 | 
            * @return array|string
  | 
        
        
            | 
            | 
           46 | 
            */
  | 
        
        
            | 
            | 
           47 | 
           function core_question_output_fragment_question_data(array $args): string {
  | 
        
        
            | 
            | 
           48 | 
               if (empty($args)) {
  | 
        
        
            | 
            | 
           49 | 
                   return '';
  | 
        
        
            | 
            | 
           50 | 
               }
  | 
        
        
            | 
            | 
           51 | 
               [$params, $extraparams] = \core_question\local\bank\filter_condition_manager::extract_parameters_from_fragment_args($args);
  | 
        
        
            | 
            | 
           52 | 
               [
  | 
        
        
            | 
            | 
           53 | 
                   $thispageurl,
  | 
        
        
            | 
            | 
           54 | 
                   $contexts,
  | 
        
        
            | 
            | 
           55 | 
                   ,
  | 
        
        
            | 
            | 
           56 | 
                   $cm,
  | 
        
        
            | 
            | 
           57 | 
                   ,
  | 
        
        
            | 
            | 
           58 | 
                   $pagevars
  | 
        
        
            | 
            | 
           59 | 
               ] = question_build_edit_resources('questions', '/question/edit.php', $params);
  | 
        
        
            | 
            | 
           60 | 
              | 
        
        
            | 
            | 
           61 | 
               if (is_null($cm)) {
  | 
        
        
            | 
            | 
           62 | 
                   $course = get_course(clean_param($args['courseid'], PARAM_INT));
  | 
        
        
            | 
            | 
           63 | 
               } else {
  | 
        
        
            | 
            | 
           64 | 
                   $course = get_course($cm->course);
  | 
        
        
            | 
            | 
           65 | 
               }
  | 
        
        
            | 
            | 
           66 | 
              | 
        
        
            | 
            | 
           67 | 
               $viewclass = empty($args['view']) ? \core_question\local\bank\view::class : clean_param($args['view'], PARAM_NOTAGS);
  | 
        
        
            | 
            | 
           68 | 
              | 
        
        
            | 
            | 
           69 | 
               if (!empty($args['lastchanged'])) {
  | 
        
        
            | 
            | 
           70 | 
                   $thispageurl->param('lastchanged', clean_param($args['lastchanged'], PARAM_INT));
  | 
        
        
            | 
            | 
           71 | 
               }
  | 
        
        
            | 
            | 
           72 | 
               // This is highly suspicious, but it is the same approach taken in /question/edit.php. See MDL-79281.
  | 
        
        
            | 
            | 
           73 | 
               $thispageurl->param('deleteall', 1);
  | 
        
        
            | 
            | 
           74 | 
               $questionbank = new $viewclass($contexts, $thispageurl, $course, $cm, $pagevars, $extraparams);
  | 
        
        
            | 
            | 
           75 | 
               $questionbank->add_standard_search_conditions();
  | 
        
        
            | 
            | 
           76 | 
               ob_start();
  | 
        
        
            | 
            | 
           77 | 
               $questionbank->display_question_list();
  | 
        
        
            | 
            | 
           78 | 
               return ob_get_clean();
  | 
        
        
            | 
            | 
           79 | 
           }
  |