MDL-57919 mod_data: Refactor and new method get_configs_for_external

This commit is contained in:
Juan Leyva
2017-03-29 11:38:38 +02:00
parent 6e1523c38b
commit aefe9c5faa
15 changed files with 213 additions and 1 deletions
+15
View File
@@ -266,4 +266,19 @@ class data_field_checkbox extends data_field_base {
return trim($strvalue, "\r\n ");
}
/**
* Return the plugin configs for external functions.
*
* @return array the list of config parameters
* @since Moodle 3.3
*/
public function get_config_for_external() {
// Return all the config parameters.
$configs = [];
for ($i = 1; $i <= 10; $i++) {
$configs["param$i"] = $this->field->{"param$i"};
}
return $configs;
}
}
+14 -1
View File
@@ -167,5 +167,18 @@ class data_field_date extends data_field_base {
return $DB->sql_cast_char2int($fieldname, true);
}
/**
* Return the plugin configs for external functions.
*
* @return array the list of config parameters
* @since Moodle 3.3
*/
public function get_config_for_external() {
// Return all the config parameters.
$configs = [];
for ($i = 1; $i <= 10; $i++) {
$configs["param$i"] = $this->field->{"param$i"};
}
return $configs;
}
}
+14
View File
@@ -222,4 +222,18 @@ class data_field_file extends data_field_base {
return false;
}
/**
* Return the plugin configs for external functions.
*
* @return array the list of config parameters
* @since Moodle 3.3
*/
public function get_config_for_external() {
// Return all the config parameters.
$configs = [];
for ($i = 1; $i <= 10; $i++) {
$configs["param$i"] = $this->field->{"param$i"};
}
return $configs;
}
}
+15
View File
@@ -291,4 +291,19 @@ class data_field_latlong extends data_field_base {
// If we get here then only one field has been filled in.
return get_string('latlongboth', 'data');
}
/**
* Return the plugin configs for external functions.
*
* @return array the list of config parameters
* @since Moodle 3.3
*/
public function get_config_for_external() {
// Return all the config parameters.
$configs = [];
for ($i = 1; $i <= 10; $i++) {
$configs["param$i"] = $this->field->{"param$i"};
}
return $configs;
}
}
+14
View File
@@ -134,4 +134,18 @@ class data_field_menu extends data_field_base {
return strval($value) !== '';
}
/**
* Return the plugin configs for external functions.
*
* @return array the list of config parameters
* @since Moodle 3.3
*/
public function get_config_for_external() {
// Return all the config parameters.
$configs = [];
for ($i = 1; $i <= 10; $i++) {
$configs["param$i"] = $this->field->{"param$i"};
}
return $configs;
}
}
+14
View File
@@ -293,4 +293,18 @@ class data_field_multimenu extends data_field_base {
return trim($strvalue, "\r\n ");
}
/**
* Return the plugin configs for external functions.
*
* @return array the list of config parameters
* @since Moodle 3.3
*/
public function get_config_for_external() {
// Return all the config parameters.
$configs = [];
for ($i = 1; $i <= 10; $i++) {
$configs["param$i"] = $this->field->{"param$i"};
}
return $configs;
}
}
+15
View File
@@ -105,6 +105,21 @@ class data_field_number extends data_field_base {
function notemptyfield($value, $name) {
return strval($value) !== '';
}
/**
* Return the plugin configs for external functions.
*
* @return array the list of config parameters
* @since Moodle 3.3
*/
public function get_config_for_external() {
// Return all the config parameters.
$configs = [];
for ($i = 1; $i <= 10; $i++) {
$configs["param$i"] = $this->field->{"param$i"};
}
return $configs;
}
}
+15
View File
@@ -324,4 +324,19 @@ class data_field_picture extends data_field_base {
}
return false;
}
/**
* Return the plugin configs for external functions.
*
* @return array the list of config parameters
* @since Moodle 3.3
*/
public function get_config_for_external() {
// Return all the config parameters.
$configs = [];
for ($i = 1; $i <= 10; $i++) {
$configs["param$i"] = $this->field->{"param$i"};
}
return $configs;
}
}
@@ -132,5 +132,20 @@ class data_field_radiobutton extends data_field_base {
function notemptyfield($value, $name) {
return strval($value) !== '';
}
/**
* Return the plugin configs for external functions.
*
* @return array the list of config parameters
* @since Moodle 3.3
*/
public function get_config_for_external() {
// Return all the config parameters.
$configs = [];
for ($i = 1; $i <= 10; $i++) {
$configs["param$i"] = $this->field->{"param$i"};
}
return $configs;
}
}
+15
View File
@@ -61,6 +61,21 @@ class data_field_text extends data_field_base {
function notemptyfield($value, $name) {
return strval($value) !== '';
}
/**
* Return the plugin configs for external functions.
*
* @return array the list of config parameters
* @since Moodle 3.3
*/
public function get_config_for_external() {
// Return all the config parameters.
$configs = [];
for ($i = 1; $i <= 10; $i++) {
$configs["param$i"] = $this->field->{"param$i"};
}
return $configs;
}
}
+14
View File
@@ -294,4 +294,18 @@ class data_field_textarea extends data_field_base {
return content_to_text($content->content, $content->content1);
}
/**
* Return the plugin configs for external functions.
*
* @return array the list of config parameters
* @since Moodle 3.3
*/
public function get_config_for_external() {
// Return all the config parameters.
$configs = [];
for ($i = 1; $i <= 10; $i++) {
$configs["param$i"] = $this->field->{"param$i"};
}
return $configs;
}
}
+14
View File
@@ -224,4 +224,18 @@ class data_field_url extends data_field_base {
return $record->content . " " . $record->content1;
}
/**
* Return the plugin configs for external functions.
*
* @return array the list of config parameters
* @since Moodle 3.3
*/
public function get_config_for_external() {
// Return all the config parameters.
$configs = [];
for ($i = 1; $i <= 10; $i++) {
$configs["param$i"] = $this->field->{"param$i"};
}
return $configs;
}
}
+16
View File
@@ -560,6 +560,22 @@ class data_field_base { // Base class for Database Field Types (see field/*/
public static function get_content_value($content) {
return trim($content->content, "\r\n ");
}
/**
* Return the plugin configs for external functions,
* in some cases the configs will need formatting or be returned only if the current user has some capabilities enabled.
*
* @return array the list of config parameters
* @since Moodle 3.3
*/
public function get_config_for_external() {
// Return all the field configs to null (maybe there is a private key for a service or something similar there).
$configs = [];
for ($i = 1; $i <= 10; $i++) {
$configs["param$i"] = null;
}
return $configs;
}
}
+19
View File
@@ -1058,3 +1058,22 @@ function data_can_view_record($data, $record, $currentgroup, $canmanageentries)
}
return false;
}
/**
* Return all the field instances for a given database.
*
* @param stdClass $data database object
* @return array field instances
* @since Moodle 3.3
*/
function data_get_field_instances($data) {
global $DB;
$instances = [];
if ($fields = $DB->get_records('data_fields', array('dataid' => $data->id), 'id')) {
foreach ($fields as $field) {
$instances[] = data_get_field($field, $data);
}
}
return $instances;
}
+4
View File
@@ -6,6 +6,10 @@ information provided here is intended especially for developers.
* External function get_databases_by_courses now return more fields for users with mod/data:viewentry capability enabled:
maxentries, rssarticles, singletemplate, listtemplate, listtemplateheader, listtemplatefooter, addtemplate,
rsstemplate, rsstitletemplate, csstemplate, jstemplate, asearchtemplate, approval, defaultsort, defaultsortdir, manageapproved.
* Data field classes extending data_field_base should implement the get_config_for_external method.
This method is used for returning the field settings for external functions.
You should check the user capabilities of the current user before returning any field setting value.
This is intended to protect field settings like private keys for external systems.
=== 3.2 ===