From ac122465e0c27bc9a4c72fa0df5533c2544c8ba3 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Fri, 3 Feb 2017 16:31:21 +0100 Subject: [PATCH] MDL-57820 mod_feedback: Create function to get analysis for external api --- mod/feedback/item/captcha/lib.php | 13 ++++++++++++ mod/feedback/item/feedback_item_class.php | 24 ++++++++++++++++++++++ mod/feedback/item/info/lib.php | 22 ++++++++++++++++++++ mod/feedback/item/label/lib.php | 13 ++++++++++++ mod/feedback/item/multichoice/lib.php | 22 ++++++++++++++++++++ mod/feedback/item/multichoicerated/lib.php | 22 ++++++++++++++++++++ mod/feedback/item/numeric/lib.php | 20 ++++++++++++++++++ mod/feedback/item/textarea/lib.php | 20 ++++++++++++++++++ mod/feedback/item/textfield/lib.php | 20 ++++++++++++++++++ 9 files changed, 176 insertions(+) diff --git a/mod/feedback/item/captcha/lib.php b/mod/feedback/item/captcha/lib.php index c57663a9ae8..8c44deb2868 100644 --- a/mod/feedback/item/captcha/lib.php +++ b/mod/feedback/item/captcha/lib.php @@ -202,4 +202,17 @@ class feedback_item_captcha extends feedback_item_base { $data[] = $CFG->recaptchapublickey; return json_encode($data); } + + /** + * Return the analysis data ready for external functions. + * + * @param stdClass $item the item (question) information + * @param int $groupid the group id to filter data (optional) + * @param int $courseid the course id (optional) + * @return array an array of data with non scalar types json encoded + * @since Moodle 3.3 + */ + public function get_analysed_for_external($item, $groupid = false, $courseid = false) { + return []; + } } diff --git a/mod/feedback/item/feedback_item_class.php b/mod/feedback/item/feedback_item_class.php index 4bb19724896..9d914b72399 100644 --- a/mod/feedback/item/feedback_item_class.php +++ b/mod/feedback/item/feedback_item_class.php @@ -274,6 +274,17 @@ abstract class feedback_item_base { public function get_data_for_external($item) { return null; } + + /** + * Return the analysis data ready for external functions. + * + * @param stdClass $item the item (question) information + * @param int $groupid the group id to filter data (optional) + * @param int $courseid the course id (optional) + * @return array an array of data with non scalar types json encoded + * @since Moodle 3.3 + */ + abstract public function get_analysed_for_external($item, $groupid = false, $courseid = false); } //a dummy class to realize pagebreaks @@ -347,4 +358,17 @@ class feedback_item_pagebreak extends feedback_item_base { ); return $actions; } + + /** + * Return the analysis data ready for external functions. + * + * @param stdClass $item the item (question) information + * @param int $groupid the group id to filter data (optional) + * @param int $courseid the course id (optional) + * @return array an array of data with non scalar types json encoded + * @since Moodle 3.3 + */ + public function get_analysed_for_external($item, $groupid = false, $courseid = false) { + return; + } } diff --git a/mod/feedback/item/info/lib.php b/mod/feedback/item/info/lib.php index ef041d643ee..f1157ec8968 100644 --- a/mod/feedback/item/info/lib.php +++ b/mod/feedback/item/info/lib.php @@ -297,4 +297,26 @@ class feedback_item_info extends feedback_item_base { // Return the default value (course name, category name or timestamp). return $this->get_current_value($item, $feedback, $feedback->course); } + + /** + * Return the analysis data ready for external functions. + * + * @param stdClass $item the item (question) information + * @param int $groupid the group id to filter data (optional) + * @param int $courseid the course id (optional) + * @return array an array of data with non scalar types json encoded + * @since Moodle 3.3 + */ + public function get_analysed_for_external($item, $groupid = false, $courseid = false) { + + $externaldata = array(); + $data = $this->get_analysed($item, $groupid, $courseid); + + if (is_array($data->data)) { + foreach ($data->data as $d) { + $externaldata[] = json_encode($d); + } + } + return $externaldata; + } } diff --git a/mod/feedback/item/label/lib.php b/mod/feedback/item/label/lib.php index 9fabd5126d0..91e685c37f8 100644 --- a/mod/feedback/item/label/lib.php +++ b/mod/feedback/item/label/lib.php @@ -243,4 +243,17 @@ class feedback_item_label extends feedback_item_base { } public function get_printval($item, $value) { } + + /** + * Return the analysis data ready for external functions. + * + * @param stdClass $item the item (question) information + * @param int $groupid the group id to filter data (optional) + * @param int $courseid the course id (optional) + * @return array an array of data with non scalar types json encoded + * @since Moodle 3.3 + */ + public function get_analysed_for_external($item, $groupid = false, $courseid = false) { + return []; + } } diff --git a/mod/feedback/item/multichoice/lib.php b/mod/feedback/item/multichoice/lib.php index e9205ff5ac8..9dea3fe0207 100644 --- a/mod/feedback/item/multichoice/lib.php +++ b/mod/feedback/item/multichoice/lib.php @@ -473,4 +473,26 @@ class feedback_item_multichoice extends feedback_item_base { } return false; } + + /** + * Return the analysis data ready for external functions. + * + * @param stdClass $item the item (question) information + * @param int $groupid the group id to filter data (optional) + * @param int $courseid the course id (optional) + * @return array an array of data with non scalar types json encoded + * @since Moodle 3.3 + */ + public function get_analysed_for_external($item, $groupid = false, $courseid = false) { + + $externaldata = array(); + $data = $this->get_analysed($item, $groupid, $courseid); + + if (!empty($data[2]) && is_array($data[2])) { + foreach ($data[2] as $d) { + $externaldata[] = json_encode($d); + } + } + return $externaldata; + } } diff --git a/mod/feedback/item/multichoicerated/lib.php b/mod/feedback/item/multichoicerated/lib.php index 8f80a5294a5..8494726e73d 100644 --- a/mod/feedback/item/multichoicerated/lib.php +++ b/mod/feedback/item/multichoicerated/lib.php @@ -469,4 +469,26 @@ class feedback_item_multichoicerated extends feedback_item_base { } return false; } + + /** + * Return the analysis data ready for external functions. + * + * @param stdClass $item the item (question) information + * @param int $groupid the group id to filter data (optional) + * @param int $courseid the course id (optional) + * @return array an array of data with non scalar types json encoded + * @since Moodle 3.3 + */ + public function get_analysed_for_external($item, $groupid = false, $courseid = false) { + + $externaldata = array(); + $data = $this->get_analysed($item, $groupid, $courseid); + + if (!empty($data[2]) && is_array($data[2])) { + foreach ($data[2] as $d) { + $externaldata[] = json_encode($d); + } + } + return $externaldata; + } } diff --git a/mod/feedback/item/numeric/lib.php b/mod/feedback/item/numeric/lib.php index 2cddf274c94..2d3a340e1cf 100644 --- a/mod/feedback/item/numeric/lib.php +++ b/mod/feedback/item/numeric/lib.php @@ -306,4 +306,24 @@ class feedback_item_numeric extends feedback_item_base { } return $data; } + + /** + * Return the analysis data ready for external functions. + * + * @param stdClass $item the item (question) information + * @param int $groupid the group id to filter data (optional) + * @param int $courseid the course id (optional) + * @return array an array of data with non scalar types json encoded + * @since Moodle 3.3 + */ + public function get_analysed_for_external($item, $groupid = false, $courseid = false) { + + $externaldata = array(); + $data = $this->get_analysed($item, $groupid, $courseid); + + if (is_array($data->data)) { + return $data->data; // No need to json, scalar type. + } + return $externaldata; + } } diff --git a/mod/feedback/item/textarea/lib.php b/mod/feedback/item/textarea/lib.php index 6e9f5a901c9..cc3a997fa2a 100644 --- a/mod/feedback/item/textarea/lib.php +++ b/mod/feedback/item/textarea/lib.php @@ -196,4 +196,24 @@ class feedback_item_textarea extends feedback_item_base { public function create_value($data) { return s($data); } + + /** + * Return the analysis data ready for external functions. + * + * @param stdClass $item the item (question) information + * @param int $groupid the group id to filter data (optional) + * @param int $courseid the course id (optional) + * @return array an array of data with non scalar types json encoded + * @since Moodle 3.3 + */ + public function get_analysed_for_external($item, $groupid = false, $courseid = false) { + + $externaldata = array(); + $data = $this->get_analysed($item, $groupid, $courseid); + + if (is_array($data->data)) { + return $data->data; // No need to json, scalar type. + } + return $externaldata; + } } diff --git a/mod/feedback/item/textfield/lib.php b/mod/feedback/item/textfield/lib.php index c491f0b648f..c8260ffc909 100644 --- a/mod/feedback/item/textfield/lib.php +++ b/mod/feedback/item/textfield/lib.php @@ -195,4 +195,24 @@ class feedback_item_textfield extends feedback_item_base { public function create_value($value) { return s($value); } + + /** + * Return the analysis data ready for external functions. + * + * @param stdClass $item the item (question) information + * @param int $groupid the group id to filter data (optional) + * @param int $courseid the course id (optional) + * @return array an array of data with non scalar types json encoded + * @since Moodle 3.3 + */ + public function get_analysed_for_external($item, $groupid = false, $courseid = false) { + + $externaldata = array(); + $data = $this->get_analysed($item, $groupid, $courseid); + + if (is_array($data->data)) { + return $data->data; // No need to json, scalar type. + } + return $externaldata; + } }