Merge branch 'MDL-57814-master' of git://github.com/jleyva/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2017-03-20 18:00:48 +01:00
commit beff62f6ec
7 changed files with 178 additions and 2 deletions

View File

@ -101,7 +101,7 @@ class mod_feedback_completion extends mod_feedback_structure {
*
* @return stdClass|false record from feedback_completedtmp or false if not found
*/
protected function get_current_completed_tmp() {
public function get_current_completed_tmp() {
global $USER, $DB;
if ($this->completedtmp === null) {
$params = array('feedback' => $this->get_feedback()->id);

View File

@ -29,6 +29,7 @@ defined('MOODLE_INTERNAL') || die;
require_once("$CFG->libdir/externallib.php");
use mod_feedback\external\feedback_summary_exporter;
use mod_feedback\external\feedback_completedtmp_exporter;
/**
* Feedback external functions
@ -300,4 +301,61 @@ class mod_feedback_external extends external_api {
)
);
}
/**
* Describes the parameters for get_current_completed_tmp.
*
* @return external_function_parameters
* @since Moodle 3.3
*/
public static function get_current_completed_tmp_parameters() {
return new external_function_parameters (
array(
'feedbackid' => new external_value(PARAM_INT, 'Feedback instance id'),
)
);
}
/**
* Returns the temporary completion record for the current user.
*
* @param int $feedbackid feedback instance id
* @return array of warnings and status result
* @since Moodle 3.3
* @throws moodle_exception
*/
public static function get_current_completed_tmp($feedbackid) {
global $PAGE;
$params = array('feedbackid' => $feedbackid);
$params = self::validate_parameters(self::get_current_completed_tmp_parameters(), $params);
$warnings = array();
list($feedback, $course, $cm, $context) = self::validate_feedback($params['feedbackid']);
$feedbackcompletion = new mod_feedback_completion($feedback, $cm, $course->id);
if ($completed = $feedbackcompletion->get_current_completed_tmp()) {
$exporter = new feedback_completedtmp_exporter($completed);
return array(
'feedback' => $exporter->export($PAGE->get_renderer('core')),
'warnings' => $warnings,
);
}
throw new moodle_exception('not_started', 'feedback');
}
/**
* Describes the get_current_completed_tmp return value.
*
* @return external_single_structure
* @since Moodle 3.3
*/
public static function get_current_completed_tmp_returns() {
return new external_single_structure(
array(
'feedback' => feedback_completedtmp_exporter::get_read_structure(),
'warnings' => new external_warnings(),
)
);
}
}

View File

@ -0,0 +1,78 @@
<?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/>.
/**
* Class for exporting a feedback temporary completion record.
*
* @package mod_feedback
* @copyright 2017 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_feedback\external;
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
/**
* Class for exporting a feedback temporary completion record.
*
* @copyright 2017 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class feedback_completedtmp_exporter extends exporter {
/**
* Return the list of properties.
*
* @return array list of properties
*/
protected static function define_properties() {
return array(
'id' => array(
'type' => PARAM_INT,
'description' => 'The record id.',
),
'feedback' => array(
'type' => PARAM_INT,
'description' => 'The feedback instance id this records belongs to.',
),
'userid' => array(
'type' => PARAM_INT,
'description' => 'The user who completed the feedback (0 for anonymous).',
),
'guestid' => array(
'type' => PARAM_RAW,
'description' => 'For guests, this is the session key.',
),
'timemodified' => array(
'type' => PARAM_INT,
'description' => 'The last time the feedback was completed.',
),
'random_response' => array(
'type' => PARAM_INT,
'description' => 'The response number (used when shuffling anonymous responses).',
),
'anonymous_response' => array(
'type' => PARAM_INT,
'description' => 'Whether is an anonymous response.',
),
'courseid' => array(
'type' => PARAM_INT,
'description' => 'The course id where the feedback was completed.',
),
);
}
}

View File

@ -53,4 +53,12 @@ $functions = array(
'capabilities' => 'mod/feedback:view',
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE)
),
'mod_feedback_get_current_completed_tmp' => array(
'classname' => 'mod_feedback_external',
'methodname' => 'get_current_completed_tmp',
'description' => 'Returns the temporary completion record for the current user.',
'type' => 'read',
'capabilities' => 'mod/feedback:view',
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE)
),
);

View File

@ -273,4 +273,32 @@ class mod_feedback_external_testcase extends externallib_advanced_testcase {
$this->assertEventContextNotUsed($event);
$this->assertNotEmpty($event->get_name());
}
/**
* Test get_current_completed_tmp.
*/
public function test_get_current_completed_tmp() {
global $DB;
// Force non anonymous.
$DB->set_field('feedback', 'anonymous', 0, array('id' => $this->feedback->id));
// Add a completed_tmp record.
$record = [
'feedback' => $this->feedback->id,
'userid' => $this->student->id,
'guestid' => '',
'timemodified' => time() - DAYSECS,
'random_response' => 0,
'anonymous_response' => 2,
'courseid' => $this->course->id,
];
$record['id'] = $DB->insert_record('feedback_completedtmp', (object) $record);
// Test user with full capabilities.
$this->setUser($this->student);
$result = mod_feedback_external::get_current_completed_tmp($this->feedback->id);
$result = external_api::clean_returnvalue(mod_feedback_external::get_current_completed_tmp_returns(), $result);
$this->assertEquals($record['id'], $result['feedback']['id']);
}
}

View File

@ -1,3 +1,7 @@
=== 3.3 ===
* Method get_current_completed_tmp in mod_feedback_completion class is now public.
=== 3.1 ===
* feedback_get_courses_from_sitecourse_map() now returns course id as 'id' attribute

View File

@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2016120503; // The current module version (Date: YYYYMMDDXX)
$plugin->version = 2016120504; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2016112900; // Requires this Moodle version
$plugin->component = 'mod_feedback'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 0;