[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/resource/classes/ -> external.php (source)

   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   * Resource external API
  19   *
  20   * @package    mod_resource
  21   * @category   external
  22   * @copyright  2015 Juan Leyva <juan@moodle.com>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   * @since      Moodle 3.0
  25   */
  26  
  27  defined('MOODLE_INTERNAL') || die;
  28  
  29  require_once("$CFG->libdir/externallib.php");
  30  
  31  /**
  32   * Resource external functions
  33   *
  34   * @package    mod_resource
  35   * @category   external
  36   * @copyright  2015 Juan Leyva <juan@moodle.com>
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   * @since      Moodle 3.0
  39   */
  40  class mod_resource_external extends external_api {
  41  
  42      /**
  43       * Returns description of method parameters
  44       *
  45       * @return external_function_parameters
  46       * @since Moodle 3.0
  47       */
  48      public static function view_resource_parameters() {
  49          return new external_function_parameters(
  50              array(
  51                  'resourceid' => new external_value(PARAM_INT, 'resource instance id')
  52              )
  53          );
  54      }
  55  
  56      /**
  57       * Simulate the resource/view.php web interface page: trigger events, completion, etc...
  58       *
  59       * @param int $resourceid the resource instance id
  60       * @return array of warnings and status result
  61       * @since Moodle 3.0
  62       * @throws moodle_exception
  63       */
  64      public static function view_resource($resourceid) {
  65          global $DB, $CFG;
  66          require_once($CFG->dirroot . "/mod/resource/lib.php");
  67  
  68          $params = self::validate_parameters(self::view_resource_parameters(),
  69                                              array(
  70                                                  'resourceid' => $resourceid
  71                                              ));
  72          $warnings = array();
  73  
  74          // Request and permission validation.
  75          $resource = $DB->get_record('resource', array('id' => $params['resourceid']), '*', MUST_EXIST);
  76          list($course, $cm) = get_course_and_cm_from_instance($resource, 'resource');
  77  
  78          $context = context_module::instance($cm->id);
  79          self::validate_context($context);
  80  
  81          require_capability('mod/resource:view', $context);
  82  
  83          // Call the resource/lib API.
  84          resource_view($resource, $course, $cm, $context);
  85  
  86          $result = array();
  87          $result['status'] = true;
  88          $result['warnings'] = $warnings;
  89          return $result;
  90      }
  91  
  92      /**
  93       * Returns description of method result value
  94       *
  95       * @return external_description
  96       * @since Moodle 3.0
  97       */
  98      public static function view_resource_returns() {
  99          return new external_single_structure(
 100              array(
 101                  'status' => new external_value(PARAM_BOOL, 'status: true if success'),
 102                  'warnings' => new external_warnings()
 103              )
 104          );
 105      }
 106  
 107  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1