MDL-57815 mod_feedback: Add new method to item class to return other data

This commit is contained in:
Juan Leyva
2017-03-16 15:35:05 +01:00
parent b315d721d9
commit d52973ae19
3 changed files with 35 additions and 0 deletions
+14
View File
@@ -188,4 +188,18 @@ class feedback_item_captcha extends feedback_item_base {
unset($actions['update']);
return $actions;
}
public function get_data_for_external($item) {
global $CFG;
if (empty($CFG->recaptchaprivatekey) || empty($CFG->recaptchapublickey)) {
return null;
}
require_once($CFG->libdir . '/recaptchalib.php');
// We return the public key, maybe we want to use the javascript api to get the image.
$data = recaptcha_get_challenge_hash_and_urls(RECAPTCHA_API_SECURE_SERVER, $CFG->recaptchapublickey);
$data[] = $CFG->recaptchapublickey;
return json_encode($data);
}
}
+14
View File
@@ -260,6 +260,20 @@ abstract class feedback_item_base {
return $actions;
}
/**
* Return extra data for external functions.
*
* Some items may have additional configuration data or default values that should be returned for external functions:
* - Info elements: The default value information (course or category name)
* - Captcha: The recaptcha challenge hash key
*
* @param stdClass $item the item object
* @return str the data, may be json_encoded for large structures
*/
public function get_data_for_external($item) {
return null;
}
}
//a dummy class to realize pagebreaks
+7
View File
@@ -290,4 +290,11 @@ class feedback_item_info extends feedback_item_base {
public function can_switch_require() {
return false;
}
public function get_data_for_external($item) {
global $DB;
$feedback = $DB->get_record('feedback', array('id' => $item->feedback), '*', MUST_EXIST);
// Return the default value (course name, category name or timestamp).
return $this->get_current_value($item, $feedback, $feedback->course);
}
}