MDL-57919 mod_data: Refactor and new method get_configs_for_external
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 ===
|
||||
|
||||
|
||||
Reference in New Issue
Block a user