Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   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   * Provides the class {@link workshopform_accumulative\privacy\provider}
  19   *
  20   * @package     workshopform_accumulative
  21   * @category    privacy
  22   * @copyright   2018 David Mudrák <david@moodle.com>
  23   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  namespace workshopform_accumulative\privacy;
  27  
  28  use core_privacy\local\request\writer;
  29  
  30  defined('MOODLE_INTERNAL') || die();
  31  
  32  /**
  33   * Privacy API implementation for the Accumulative grading strategy.
  34   *
  35   * @copyright 2018 David Mudrák <david@moodle.com>
  36   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class provider implements \core_privacy\local\metadata\null_provider, \mod_workshop\privacy\workshopform_provider {
  39  
  40      /**
  41       * Explain that this plugin stores no personal data.
  42       *
  43       * @return string
  44       */
  45      public static function get_reason() : string {
  46          return 'privacy:metadata';
  47      }
  48  
  49      /**
  50       * Return details of the filled assessment form.
  51       *
  52       * @param stdClass $user User we are exporting data for
  53       * @param context $context The workshop activity context
  54       * @param array $subcontext Subcontext within the context to export to
  55       * @param int $assessmentid ID of the assessment
  56       */
  57      public static function export_assessment_form(\stdClass $user, \context $context, array $subcontext, int $assessmentid) {
  58          global $DB;
  59  
  60          if ($context->contextlevel != CONTEXT_MODULE) {
  61              throw new \coding_exception('Unexpected context provided');
  62          }
  63  
  64          $sql = "SELECT dim.id, dim.description, dim.descriptionformat, dim.grade AS dimgrade, dim.weight,
  65                         wg.grade, wg.peercomment, wg.peercommentformat
  66                    FROM {course_modules} cm
  67                    JOIN {context} ctx ON ctx.contextlevel = :contextlevel AND ctx.instanceid = cm.id
  68                    JOIN {workshop} w ON cm.instance = w.id
  69                    JOIN {workshopform_accumulative} dim ON dim.workshopid = w.id
  70               LEFT JOIN {workshop_grades} wg ON wg.strategy = :strategy
  71                         AND wg.dimensionid = dim.id AND wg.assessmentid = :assessmentid
  72                   WHERE ctx.id = :contextid
  73                ORDER BY dim.sort";
  74  
  75          $params = [
  76              'strategy' => 'accumulative',
  77              'contextlevel' => CONTEXT_MODULE,
  78              'contextid' => $context->id,
  79              'assessmentid' => $assessmentid,
  80          ];
  81  
  82          $writer = \core_privacy\local\request\writer::with_context($context);
  83          $data = [];
  84          $hasdata = false;
  85          $dimensionids = [];
  86  
  87          foreach ($DB->get_records_sql($sql, $params) as $record) {
  88              if ($record->grade !== null) {
  89                  $hasdata = true;
  90              }
  91              $record->description = $writer->rewrite_pluginfile_urls($subcontext, 'workshopform_accumulative',
  92                  'description', $record->id, $record->description);
  93              $dimensionids[] = $record->id;
  94              unset($record->id);
  95              $data[] = $record;
  96          }
  97  
  98          if ($hasdata) {
  99              $writer->export_data($subcontext, (object) ['aspects' => $data]);
 100              foreach ($dimensionids as $dimensionid) {
 101                  $writer->export_area_files($subcontext, 'workshopform_accumulative', 'description', $dimensionid);
 102              }
 103          }
 104      }
 105  }