first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,72 @@
<?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/>.
/**
* Privacy Subsystem implementation for datafield_checkbox.
*
* @package datafield_checkbox
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace datafield_checkbox\privacy;
use core_privacy\local\request\writer;
use mod_data\privacy\datafield_provider;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for datafield_checkbox implementing null_provider.
*
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider,
datafield_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
/**
* Exports data about one record in {data_content} table.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
* @param \stdClass $defaultvalue pre-populated default value that most of plugins will use
*/
public static function export_data_content($context, $recordobj, $fieldobj, $contentobj, $defaultvalue) {
$defaultvalue->field['options'] = preg_split('/\s*\n\s*/', trim($fieldobj->param1), -1, PREG_SPLIT_NO_EMPTY);
$defaultvalue->content = explode('##', $defaultvalue->content);
writer::with_context($context)->export_data([$recordobj->id, $contentobj->id], $defaultvalue);
}
/**
* Allows plugins to delete locally stored data.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
*/
public static function delete_data_content($context, $recordobj, $fieldobj, $contentobj) {
}
}
+306
View File
@@ -0,0 +1,306 @@
<?php
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999-onwards Moodle Pty Ltd http://moodle.com //
// //
// This program 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 2 of the License, or //
// (at your option) any later version. //
// //
// This program 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: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
class data_field_checkbox extends data_field_base {
var $type = 'checkbox';
/**
* priority for globalsearch indexing
*
* @var int
*/
protected static $priority = self::LOW_PRIORITY;
public function supports_preview(): bool {
return true;
}
public function get_data_content_preview(int $recordid): stdClass {
$options = explode("\n", $this->field->param1);
$options = array_map('trim', $options);
$selected = $options[$recordid % count($options)];
return (object)[
'id' => 0,
'fieldid' => $this->field->id,
'recordid' => $recordid,
'content' => $selected,
'content1' => null,
'content2' => null,
'content3' => null,
'content4' => null,
];
}
function display_add_field($recordid = 0, $formdata = null) {
global $DB, $OUTPUT;
if ($formdata) {
$fieldname = 'field_' . $this->field->id;
$content = $formdata->$fieldname ?? [];
} else if ($recordid) {
$content = $DB->get_field('data_content', 'content', ['fieldid' => $this->field->id, 'recordid' => $recordid]);
$content = explode('##', $content ?? '');
} else {
$content = [];
}
$str = '<div title="' . s($this->field->description) . '">';
$str .= '<fieldset><legend><span class="accesshide">'.s($this->field->name);
if ($this->field->required) {
$str .= '$nbsp;' . get_string('requiredelement', 'form');
$str .= '</span></legend>';
$image = $OUTPUT->pix_icon('req', get_string('requiredelement', 'form'));
$str .= html_writer::div($image, 'inline-req');
} else {
$str .= '</span></legend>';
}
$i = 0;
foreach (explode("\n", $this->field->param1) as $checkbox) {
$checkbox = trim($checkbox);
if ($checkbox === '') {
continue; // skip empty lines
}
$str .= '<input type="hidden" name="field_' . $this->field->id . '[]" value="" />';
$str .= '<input type="checkbox" id="field_'.$this->field->id.'_'.$i.'" name="field_' . $this->field->id . '[]" ';
$str .= 'value="' . s($checkbox) . '" class="mod-data-input mr-1" ';
if (array_search($checkbox, $content) !== false) {
$str .= 'checked />';
} else {
$str .= '/>';
}
$str .= '<label for="field_'.$this->field->id.'_'.$i.'">'.$checkbox.'</label><br />';
$i++;
}
$str .= '</fieldset>';
$str .= '</div>';
return $str;
}
function display_search_field($value='') {
global $CFG, $DB;
if (is_array($value)) {
$content = $value['checked'];
$allrequired = $value['allrequired'] ? true : false;
} else {
$content = array();
$allrequired = false;
}
$str = '';
$found = false;
$marginclass = ['class' => 'mr-1'];
foreach (explode("\n",$this->field->param1) as $checkbox) {
$checkbox = trim($checkbox);
if (in_array($checkbox, $content)) {
$str .= html_writer::checkbox('f_'.$this->field->id.'[]', s($checkbox), true, $checkbox, $marginclass);
} else {
$str .= html_writer::checkbox('f_'.$this->field->id.'[]', s($checkbox), false, $checkbox, $marginclass);
}
$str .= html_writer::empty_tag('br');
$found = true;
}
if (!$found) {
return '';
}
$requiredstr = get_string('selectedrequired', 'data');
$str .= html_writer::checkbox('f_'.$this->field->id.'_allreq', null, $allrequired, $requiredstr, $marginclass);
return $str;
}
public function parse_search_field($defaults = null) {
$paramselected = 'f_'.$this->field->id;
$paramallrequired = 'f_'.$this->field->id.'_allreq';
if (empty($defaults[$paramselected])) { // One empty means the other ones are empty too.
$defaults = array($paramselected => array(), $paramallrequired => 0);
}
$selected = optional_param_array($paramselected, $defaults[$paramselected], PARAM_NOTAGS);
$allrequired = optional_param($paramallrequired, $defaults[$paramallrequired], PARAM_BOOL);
if (empty($selected)) {
// no searching
return '';
}
return array('checked'=>$selected, 'allrequired'=>$allrequired);
}
function generate_sql($tablealias, $value) {
global $DB;
static $i=0;
$i++;
$name = "df_checkbox_{$i}_";
$params = array();
$varcharcontent = $DB->sql_compare_text("{$tablealias}.content", 255);
$allrequired = $value['allrequired'];
$selected = $value['checked'];
if ($selected) {
$conditions = array();
$j=0;
foreach ($selected as $sel) {
$j++;
$xname = $name.$j;
$likesel = str_replace('%', '\%', $sel);
$likeselsel = str_replace('_', '\_', $likesel);
$conditions[] = "({$tablealias}.fieldid = {$this->field->id} AND ({$varcharcontent} = :{$xname}a
OR {$tablealias}.content LIKE :{$xname}b
OR {$tablealias}.content LIKE :{$xname}c
OR {$tablealias}.content LIKE :{$xname}d))";
$params[$xname.'a'] = $sel;
$params[$xname.'b'] = "$likesel##%";
$params[$xname.'c'] = "%##$likesel";
$params[$xname.'d'] = "%##$likesel##%";
}
if ($allrequired) {
return array(" (".implode(" AND ", $conditions).") ", $params);
} else {
return array(" (".implode(" OR ", $conditions).") ", $params);
}
} else {
return array(" ", array());
}
}
function update_content($recordid, $value, $name='') {
global $DB;
$content = new stdClass();
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
$content->content = $this->format_data_field_checkbox_content($value);
if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$content->id = $oldcontent->id;
return $DB->update_record('data_content', $content);
} else {
return $DB->insert_record('data_content', $content);
}
}
function display_browse_field($recordid, $template) {
$content = $this->get_data_content($recordid);
if (!$content || empty($content->content)) {
return '';
}
$options = explode("\n", $this->field->param1);
$options = array_map('trim', $options);
$contentarray = explode('##', $content->content);
$str = '';
foreach ($contentarray as $line) {
if (!in_array($line, $options)) {
// Hmm, looks like somebody edited the field definition.
continue;
}
$str .= $line . "<br />\n";
}
return $str;
}
function format_data_field_checkbox_content($content) {
if (!is_array($content)) {
return NULL;
}
$options = explode("\n", $this->field->param1);
$options = array_map('trim', $options);
$vals = array();
foreach ($content as $key=>$val) {
if ($key === 'xxx') {
continue;
}
if (!in_array($val, $options)) {
continue;
}
$vals[] = $val;
}
if (empty($vals)) {
return NULL;
}
return implode('##', $vals);
}
/**
* Check whether any boxes in the checkbox where checked.
*
* @param mixed $value The submitted values
* @param mixed $name
* @return bool
*/
function notemptyfield($value, $name) {
$found = false;
foreach ($value as $checkboxitem) {
if (strval($checkboxitem) !== '') {
$found = true;
break;
}
}
return $found;
}
/**
* Returns the presentable string value for a field content.
*
* The returned string should be plain text.
*
* @param stdClass $content
* @return string
*/
public static function get_content_value($content) {
$arr = explode('##', $content->content);
$strvalue = '';
foreach ($arr as $a) {
$strvalue .= $a . ' ';
}
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;
}
}
@@ -0,0 +1,29 @@
<?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/>.
/**
* Strings for component 'datafield_checkbox', language 'en', branch 'master'
*
* @package datafield
* @subpackage checkbox
* @copyright 2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'Checkboxes';
$string['fieldtypelabel'] = 'Checkboxes';
$string['privacy:metadata'] = 'The Checkboxes field component doesn\'t store any personal data; it uses tables defined in mod_data.';
@@ -0,0 +1,54 @@
{{!
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/>.
}}
{{!
@template datafield_checkbox/checkbox
The purpose of this template is to enable the user to define a checkbox field.
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* name string The field's name.
* description string The field's description.
* required bool The field's requiredness.
* param1 string The field's options.
Example context (json):
{
"name": "A name",
"description": "A description",
"required": true,
"param1": "One\nTwo\nThree"
}
}}
<fieldset>
{{> mod_data/fields/basicfields }}
{{> mod_data/fields/requiredfield }}
<div class="form-group row fitem">
<div class="col-md-3 col-form-label d-flex pb-0 pr-md-0">
<label for="param1">{{#str}}fieldoptions, data{{/str}}</label>
</div>
<div class="col-md-9 form-inline align-items-start felement">
<textarea class="optionstextarea form-control" name="param1" id="param1" cols="80" rows="10">{{param1}}</textarea>
</div>
</div>
</fieldset>
+28
View File
@@ -0,0 +1,28 @@
<?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/>.
/**
* @package datafield
* @subpackage checkbox
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'datafield_checkbox'; // Full name of the plugin (used for diagnostics)
@@ -0,0 +1,72 @@
<?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/>.
/**
* Privacy Subsystem implementation for datafield_date.
*
* @package datafield_date
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace datafield_date\privacy;
use core_privacy\local\request\transform;
use core_privacy\local\request\writer;
use mod_data\privacy\datafield_provider;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for datafield_date implementing null_provider.
*
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider,
datafield_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
/**
* Exports data about one record in {data_content} table.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
* @param \stdClass $defaultvalue pre-populated default value that most of plugins will use
*/
public static function export_data_content($context, $recordobj, $fieldobj, $contentobj, $defaultvalue) {
$defaultvalue->content = transform::date($defaultvalue->content);
writer::with_context($context)->export_data([$recordobj->id, $contentobj->id], $defaultvalue);
}
/**
* Allows plugins to delete locally stored data.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
*/
public static function delete_data_content($context, $recordobj, $fieldobj, $contentobj) {
}
}
+235
View File
@@ -0,0 +1,235 @@
<?php
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999-onwards Moodle Pty Ltd http://moodle.com //
// //
// This program 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 2 of the License, or //
// (at your option) any later version. //
// //
// This program 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: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
//2/19/07: Advanced search of the date field is currently disabled because it does not track
// pre 1970 dates and does not handle blank entrys. Advanced search functionality for this field
// type can be enabled once these issues are addressed in the core API.
class data_field_date extends data_field_base {
var $type = 'date';
var $day = 0;
var $month = 0;
var $year = 0;
public function supports_preview(): bool {
return true;
}
public function get_data_content_preview(int $recordid): stdClass {
return (object)[
'id' => 0,
'fieldid' => $this->field->id,
'recordid' => $recordid,
'content' => (string) time(),
'content1' => null,
'content2' => null,
'content3' => null,
'content4' => null,
];
}
function display_add_field($recordid = 0, $formdata = null) {
global $DB, $OUTPUT;
if ($formdata) {
$fieldname = 'field_' . $this->field->id . '_day';
$day = $formdata->$fieldname;
$fieldname = 'field_' . $this->field->id . '_month';
$month = $formdata->$fieldname;
$fieldname = 'field_' . $this->field->id . '_year';
$year = $formdata->$fieldname;
$calendartype = \core_calendar\type_factory::get_calendar_instance();
$gregoriandate = $calendartype->convert_to_gregorian($year, $month, $day);
$content = make_timestamp(
$gregoriandate['year'],
$gregoriandate['month'],
$gregoriandate['day'],
$gregoriandate['hour'],
$gregoriandate['minute'],
0,
0,
false);
} else if ($recordid) {
$content = (int)$DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid));
} else {
$content = time();
}
$str = '<div title="'.s($this->field->description).'" class="mod-data-input d-flex flex-wrap align-items-center">';
$dayselector = html_writer::select_time(
type: 'days',
name: "field_{$this->field->id}_day",
currenttime: $content,
timezone: 0,
);
$monthselector = html_writer::select_time(
type: 'months',
name: "field_{$this->field->id}_month",
currenttime: $content,
timezone: 0,
);
$yearselector = html_writer::select_time(
type: 'years',
name: "field_{$this->field->id}_year",
currenttime: $content,
timezone: 0,
);
$str .= $dayselector . $monthselector . $yearselector;
$str .= '</div>';
return $str;
}
// Enable the following three functions once core API issues have been addressed.
/**
* Display the search field in advanced search page
* @param mixed $value
* @return string
* @throws coding_exception
*/
public function display_search_field($value = null) {
$currenttime = time();
$selectors = html_writer::select_time('days', 'f_' . $this->field->id . '_d', $value['timestamp'] ?? $currenttime)
. html_writer::select_time('months', 'f_' . $this->field->id . '_m', $value['timestamp'] ?? $currenttime)
. html_writer::select_time('years', 'f_' . $this->field->id . '_y', $value['timestamp'] ?? $currenttime);
$datecheck = html_writer::checkbox('f_' . $this->field->id . '_z', 1, $value['usedate'] ?? 0);
$str = '<div class="d-flex flex-wrap">' . $selectors . ' ' . $datecheck . ' ' . get_string('usedate', 'data') . '</div>';
return $str;
}
function generate_sql($tablealias, $value) {
global $DB;
static $i=0;
$i++;
$name = "df_date_$i";
$varcharcontent = $DB->sql_compare_text("{$tablealias}.content");
return array(" ({$tablealias}.fieldid = {$this->field->id} AND $varcharcontent = :$name) ", array($name => $value['timestamp']));
}
public function parse_search_field($defaults = null) {
$paramday = 'f_'.$this->field->id.'_d';
$parammonth = 'f_'.$this->field->id.'_m';
$paramyear = 'f_'.$this->field->id.'_y';
$paramusedate = 'f_'.$this->field->id.'_z';
if (empty($defaults[$paramday])) { // One empty means the other ones are empty too.
$defaults = array($paramday => 0, $parammonth => 0, $paramyear => 0, $paramusedate => 0);
}
$day = optional_param($paramday, $defaults[$paramday], PARAM_INT);
$month = optional_param($parammonth, $defaults[$parammonth], PARAM_INT);
$year = optional_param($paramyear, $defaults[$paramyear], PARAM_INT);
$usedate = optional_param($paramusedate, $defaults[$paramusedate], PARAM_INT);
$data = array();
if (!empty($day) && !empty($month) && !empty($year) && $usedate == 1) {
$calendartype = \core_calendar\type_factory::get_calendar_instance();
$gregoriandate = $calendartype->convert_to_gregorian($year, $month, $day);
$data['timestamp'] = make_timestamp(
$gregoriandate['year'],
$gregoriandate['month'],
$gregoriandate['day'],
$gregoriandate['hour'],
$gregoriandate['minute'],
0,
0,
false);
$data['usedate'] = 1;
return $data;
} else {
return 0;
}
}
function update_content($recordid, $value, $name='') {
global $DB;
$names = explode('_',$name);
$name = $names[2]; // day month or year
$this->$name = $value;
if ($this->day and $this->month and $this->year) { // All of them have been collected now
$content = new stdClass();
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
$calendartype = \core_calendar\type_factory::get_calendar_instance();
$gregoriandate = $calendartype->convert_to_gregorian($this->year, $this->month, $this->day);
$content->content = make_timestamp(
$gregoriandate['year'],
$gregoriandate['month'],
$gregoriandate['day'],
$gregoriandate['hour'],
$gregoriandate['minute'],
0,
0,
false);
if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$content->id = $oldcontent->id;
return $DB->update_record('data_content', $content);
} else {
return $DB->insert_record('data_content', $content);
}
}
}
function display_browse_field($recordid, $template) {
$content = $this->get_data_content($recordid);
if (!$content || empty($content->content)) {
return '';
}
return userdate($content->content, get_string('strftimedate'), 0);
}
function get_sort_sql($fieldname) {
global $DB;
return $DB->sql_cast_char2real($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;
}
}
@@ -0,0 +1,29 @@
<?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/>.
/**
* Strings for component 'datafield_date', language 'en', branch 'master'
*
* @package datafield
* @subpackage date
* @copyright 2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'Date';
$string['fieldtypelabel'] = 'Date';
$string['privacy:metadata'] = 'The Date field component doesn\'t store any personal data; it uses tables defined in mod_data.';
@@ -0,0 +1,41 @@
{{!
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/>.
}}
{{!
@template datafield_date/date
The purpose of this template is to enable the user to define a date field.
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* name string The field's name.
* description string The field's description.
Example context (json):
{
"name": "A name",
"description": "A description"
}
}}
<fieldset>
{{> mod_data/fields/basicfields }}
</fieldset>
+28
View File
@@ -0,0 +1,28 @@
<?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/>.
/**
* @package datafield
* @subpackage date
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'datafield_date'; // Full name of the plugin (used for diagnostics)
@@ -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/>.
/**
* Privacy Subsystem implementation for datafield_file.
*
* @package datafield_file
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace datafield_file\privacy;
use mod_data\privacy\datafield_provider;
use core_privacy\local\request\writer;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for datafield_file implementing null_provider.
*
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider,
datafield_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
/**
* Exports data about one record in {data_content} table.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
* @param \stdClass $defaultvalue pre-populated default value that most of plugins will use
*/
public static function export_data_content($context, $recordobj, $fieldobj, $contentobj, $defaultvalue) {
if ($fieldobj->param3) {
$defaultvalue->field['maxbytes'] = $fieldobj->param3;
}
// Change file name to file path.
$defaultvalue->file = writer::with_context($context)
->rewrite_pluginfile_urls([$recordobj->id, $contentobj->id], 'mod_data', 'content', $contentobj->id,
'@@PLUGINFILE@@/' . $defaultvalue->content);
unset($defaultvalue->content);
writer::with_context($context)->export_data([$recordobj->id, $contentobj->id], $defaultvalue);
}
/**
* Allows plugins to delete locally stored data.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
*/
public static function delete_data_content($context, $recordobj, $fieldobj, $contentobj) {
}
}
+338
View File
@@ -0,0 +1,338 @@
<?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 file field for database activity
*
* @package datafield_file
* @copyright 2005 Martin Dougiamas
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class data_field_file extends data_field_base {
var $type = 'file';
public function supports_preview(): bool {
return true;
}
public function get_data_content_preview(int $recordid): stdClass {
return (object)[
'id' => 0,
'fieldid' => $this->field->id,
'recordid' => $recordid,
'content' => 'samplefile.csv',
'content1' => 'samplefile.csv',
'content2' => null,
'content3' => null,
'content4' => null,
];
}
function display_add_field($recordid = 0, $formdata = null) {
global $CFG, $DB, $OUTPUT, $PAGE;
// Necessary for the constants used in args.
require_once($CFG->dirroot . '/repository/lib.php');
$itemid = null;
// editing an existing database entry
if ($formdata) {
$fieldname = 'field_' . $this->field->id . '_file';
$itemid = clean_param($formdata->$fieldname, PARAM_INT);
} else if ($recordid) {
if (!$content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid))) {
// Quickly make one now!
$content = new stdClass();
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
$id = $DB->insert_record('data_content', $content);
$content = $DB->get_record('data_content', array('id' => $id));
}
file_prepare_draft_area($itemid, $this->context->id, 'mod_data', 'content', $content->id);
} else {
$itemid = file_get_unused_draft_itemid();
}
// database entry label
$html = '<div title="' . s($this->field->description) . '">';
$html .= '<fieldset><legend><span class="accesshide">'.s($this->field->name);
if ($this->field->required) {
$html .= '&nbsp;' . get_string('requiredelement', 'form') . '</span></legend>';
$image = $OUTPUT->pix_icon('req', get_string('requiredelement', 'form'));
$html .= html_writer::div($image, 'inline-req');
} else {
$html .= '</span></legend>';
}
// itemid element
$html .= '<input type="hidden" name="field_'.$this->field->id.'_file" value="'.s($itemid).'" />';
$options = new stdClass();
$options->maxbytes = $this->field->param3;
$options->maxfiles = 1; // Limit to one file for the moment, this may be changed if requested as a feature in the future.
$options->itemid = $itemid;
$options->accepted_types = '*';
$options->return_types = FILE_INTERNAL | FILE_CONTROLLED_LINK;
$options->context = $PAGE->context;
$fm = new form_filemanager($options);
// Print out file manager.
$output = $PAGE->get_renderer('core', 'files');
$html .= '<div class="mod-data-input">';
$html .= $output->render($fm);
$html .= '</div>';
$html .= '</fieldset>';
$html .= '</div>';
return $html;
}
function display_search_field($value = '') {
return '<label class="accesshide" for="f_' . $this->field->id . '">' . s($this->field->name) . '</label>' .
'<input type="text" size="16" id="f_'.$this->field->id.'" name="f_'.$this->field->id.'" ' .
'value="'.s($value).'" class="form-control"/>';
}
function generate_sql($tablealias, $value) {
global $DB;
static $i=0;
$i++;
$name = "df_file_$i";
return array(" ({$tablealias}.fieldid = {$this->field->id} AND ".$DB->sql_like("{$tablealias}.content", ":$name", false).") ", array($name=>"%$value%"));
}
public function parse_search_field($defaults = null) {
$param = 'f_'.$this->field->id;
if (empty($defaults[$param])) {
$defaults = array($param => '');
}
return optional_param($param, $defaults[$param], PARAM_NOTAGS);
}
function get_file($recordid, $content=null) {
global $DB;
if (empty($content)) {
if (!$content = $this->get_data_content($recordid)) {
return null;
}
}
$fs = get_file_storage();
if (!$file = $fs->get_file($this->context->id, 'mod_data', 'content', $content->id, '/', $content->content)) {
return null;
}
return $file;
}
function display_browse_field($recordid, $template) {
global $OUTPUT;
$content = $this->get_data_content($recordid);
if (!$content || empty($content->content)) {
return '';
}
$file = null;
$url = '';
$name = !empty($content->content1) ? $content->content1 : $content->content;
if ($this->preview) {
$file = (object)[
'filename' => $content->content,
'mimetype' => 'text/csv',
];
$name = $content->content;
} else {
$file = $this->get_file($recordid, $content);
if (!$file) {
return '';
}
$fileurl = moodle_url::make_pluginfile_url(
$file->get_contextid(),
$file->get_component(),
$file->get_filearea(),
$file->get_itemid(),
$file->get_filepath(),
$file->get_filename()
);
$url = $fileurl->out();
}
$icon = $OUTPUT->pix_icon(
file_file_icon($file),
get_mimetype_description($file),
'moodle',
['width' => 16, 'height' => 16]
);
return $icon . '&nbsp;<a class="data-field-link" href="'.$url.'" >' . s($name) . '</a>';
}
// content: "a##b" where a is the file name, b is the display name
function update_content($recordid, $value, $name='') {
global $CFG, $DB, $USER;
$fs = get_file_storage();
// Should always be available since it is set by display_add_field before initializing the draft area.
$content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid));
if (!$content) {
$content = (object)array('fieldid' => $this->field->id, 'recordid' => $recordid);
$content->id = $DB->insert_record('data_content', $content);
}
file_save_draft_area_files($value, $this->context->id, 'mod_data', 'content', $content->id);
$usercontext = context_user::instance($USER->id);
$files = $fs->get_area_files($this->context->id, 'mod_data', 'content', $content->id, 'itemid, filepath, filename', false);
// We expect no or just one file (maxfiles = 1 option is set for the form_filemanager).
if (count($files) == 0) {
$content->content = null;
} else {
$content->content = array_values($files)[0]->get_filename();
if (count($files) > 1) {
// This should not happen with a consistent database. Inform admins/developers about the inconsistency.
debugging('more then one file found in mod_data instance {$this->data->id} file field (field id: {$this->field->id}) area during update data record {$recordid} (content id: {$content->id})', DEBUG_NORMAL);
}
}
$DB->update_record('data_content', $content);
}
/**
* Here we export the text value of a file field which is the filename of the exported file.
*
* @param stdClass $record the record which is being exported
* @return string the value which will be stored in the exported file for this field
*/
public function export_text_value(stdClass $record): string {
return !empty($record->content) ? $record->content : '';
}
/**
* Specifies that this field type supports the export of files.
*
* @return bool true which means that file export is being supported by this field type
*/
public function file_export_supported(): bool {
return true;
}
/**
* Specifies that this field type supports the import of files.
*
* @return bool true which means that file import is being supported by this field type
*/
public function file_import_supported(): bool {
return true;
}
/**
* Provides the necessary code for importing a file when importing the content of a mod_data instance.
*
* @param int $contentid the id of the mod_data content record
* @param string $filecontent the content of the file to import as string
* @param string $filename the filename the imported file should get
* @return void
*/
public function import_file_value(int $contentid, string $filecontent, string $filename): void {
$filerecord = [
'contextid' => $this->context->id,
'component' => 'mod_data',
'filearea' => 'content',
'itemid' => $contentid,
'filepath' => '/',
'filename' => $filename,
];
$fs = get_file_storage();
$fs->create_file_from_string($filerecord, $filecontent);
}
/**
* Exports the file content for file export.
*
* @param stdClass $record the data content record the file belongs to
* @return null|string The file content of the stored file or null if no file should be exported for this record
*/
public function export_file_value(stdClass $record): null|string {
$file = $this->get_file($record->id);
return $file ? $file->get_content() : null;
}
function file_ok($path) {
return true;
}
/**
* Custom notempty function
*
* @param string $value
* @param string $name
* @return bool
*/
function notemptyfield($value, $name) {
global $USER;
$names = explode('_', $name);
if ($names[2] == 'file') {
$usercontext = context_user::instance($USER->id);
$fs = get_file_storage();
$files = $fs->get_area_files($usercontext->id, 'user', 'draft', $value);
return count($files) >= 2;
}
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;
}
public function get_field_params(): array {
global $DB, $CFG;
$data = parent::get_field_params();
$course = $DB->get_record('course', ['id' => $this->data->course]);
$filesizes = get_max_upload_sizes($CFG->maxbytes, $course->maxbytes, 0, $this->field->param3);
foreach ($filesizes as $value => $name) {
if (!((isset($this->field->param3) && $value == $this->field->param3))) {
$data['filesizes'][] = ['name' => $name, 'value' => $value, 'selected' => 0];
} else {
$data['filesizes'][] = ['name' => $name, 'value' => $value, 'selected' => 1];
}
}
return $data;
}
}
@@ -0,0 +1,29 @@
<?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/>.
/**
* Strings for component 'datafield_file', language 'en', branch 'master'
*
* @package datafield
* @subpackage file
* @copyright 2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'File';
$string['fieldtypelabel'] = 'File';
$string['privacy:metadata'] = 'The File field component doesn\'t store any personal data; it uses tables defined in mod_data.';
@@ -0,0 +1,58 @@
{{!
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/>.
}}
{{!
@template datafield_file/file
The purpose of this template is to enable the user to define a file field.
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* name string The field's name.
* description string The field's description.
* required bool The field's requiredness.
* filesizes array The field's file sizes.
Example context (json):
{
"name": "A name",
"description": "A description",
"required": true,
"filesizes": [ { "name": "Site upload limit (64MB)", "value": "0", "selected": true },
{ "name": "64MB", "value": "67108864", "selected": false } ]
}
}}
<fieldset>
{{> mod_data/fields/basicfields }}
{{> mod_data/fields/requiredfield }}
<div class="form-group row fitem">
<div class="col-md-3"><label for="param3" class="mb-0">
{{#str}}maxsize, data{{/str}}</label></div>
<div class="col-md-9 form-inline align-items-start felement">
<select id="param3" class="select custom-select form-control" name="param3">
{{#filesizes}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/filesizes}}
</select>
</div>
</div>
</fieldset>
+28
View File
@@ -0,0 +1,28 @@
<?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/>.
/**
* @package datafield
* @subpackage file
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'datafield_file'; // Full name of the plugin (used for diagnostics)
@@ -0,0 +1,82 @@
<?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/>.
/**
* Privacy Subsystem implementation for datafield_latlong.
*
* @package datafield_latlong
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace datafield_latlong\privacy;
use core_privacy\local\request\writer;
use mod_data\privacy\datafield_provider;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for datafield_latlong implementing null_provider.
*
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider,
datafield_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
/**
* Exports data about one record in {data_content} table.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
* @param \stdClass $defaultvalue pre-populated default value that most of plugins will use
*/
public static function export_data_content($context, $recordobj, $fieldobj, $contentobj, $defaultvalue) {
$defaultvalue->field['services'] = explode(',', $fieldobj->param1);
if ($fieldobj->param2 > 0) {
$defaultvalue->field['label'] = 'Content of field '.$fieldobj->param2;
} else if ($fieldobj->param2 == -2) {
$defaultvalue->field['label'] = 'lattitude/longitude';
} else {
$defaultvalue->field['label'] = 'item #';
}
$defaultvalue->lattitude = $contentobj->content;
$defaultvalue->longitude = $contentobj->content1;
unset($defaultvalue->content);
unset($defaultvalue->content1);
writer::with_context($context)->export_data([$recordobj->id, $contentobj->id], $defaultvalue);
}
/**
* Allows plugins to delete locally stored data.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
*/
public static function delete_data_content($context, $recordobj, $fieldobj, $contentobj) {
}
}
+397
View File
@@ -0,0 +1,397 @@
<?php
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999-onwards Moodle Pty Ltd http://moodle.com //
// //
// This program 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 2 of the License, or //
// (at your option) any later version. //
// //
// This program 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: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
class data_field_latlong extends data_field_base {
var $type = 'latlong';
// This is an array of URL schemes for linking out to services, using the float values of lat and long.
// In each scheme, the special markers @lat@ and @long@ will be replaced by the float values.
// The config options for the field store each service name that should be displayed, in a comma-separated
// field. Therefore please DO NOT include commas in the service names if you are adding extra services.
// Parameter data used:
// "param1" is a comma-separated list of the linkout service names that are enabled for this instance
// "param2" indicates the label that will be used in generating Google Earth KML files: -1 for item #, -2 for lat/long, positive number for the (text) field to use.
var $linkoutservices = array(
"Google Maps" => "http://maps.google.com/maps?q=@lat@,+@long@&iwloc=A&hl=en",
"Google Earth" => "@wwwroot@/mod/data/field/latlong/kml.php?d=@dataid@&fieldid=@fieldid@&rid=@recordid@",
"Geabios" => "http://www.geabios.com/html/services/maps/PublicMap.htm?lat=@lat@&lon=@long@&fov=0.3&title=Moodle%20data%20item",
"OpenStreetMap" => "http://www.openstreetmap.org/index.html?lat=@lat@&lon=@long@&zoom=11",
"Multimap" => "http://www.multimap.com/map/browse.cgi?scale=200000&lon=@long@&lat=@lat@&icon=x"
);
// Other map sources listed at http://kvaleberg.com/extensions/mapsources/index.php?params=51_30.4167_N_0_7.65_W_region:earth
public function supports_preview(): bool {
return true;
}
public function get_data_content_preview(int $recordid): stdClass {
return (object)[
'id' => 0,
'fieldid' => $this->field->id,
'recordid' => $recordid,
'content' => 41.391205,
'content1' => 2.163873,
'content2' => null,
'content3' => null,
'content4' => null,
];
}
function display_add_field($recordid = 0, $formdata = null) {
global $CFG, $DB, $OUTPUT;
$lat = '';
$long = '';
if ($formdata) {
$fieldname = 'field_' . $this->field->id . '_0';
$lat = $formdata->$fieldname;
$fieldname = 'field_' . $this->field->id . '_1';
$long = $formdata->$fieldname;
} else if ($recordid) {
if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$lat = $content->content;
$long = $content->content1;
}
}
$str = '<div title="'.s($this->field->description).'">';
$str .= '<fieldset><legend><span class="accesshide">'.s($this->field->name).'</span></legend>';
$str .= '<table class="d-flex flex-wrap align-items-center"><tr><td align="right">';
$classes = 'mod-data-input form-control-static';
$str .= '<label for="field_'.$this->field->id.'_0" class="' . $classes . '">' . get_string('latitude', 'data');
if ($this->field->required) {
$str .= $OUTPUT->pix_icon('req', get_string('requiredelement', 'form'));
}
$classes = 'form-control mx-1';
$str .= '</label></td><td>';
$str .= '<input class="' . $classes . '" type="text" name="field_'.$this->field->id.'_0" ';
$str .= ' id="field_'.$this->field->id.'_0" value="';
$str .= s($lat).'" size="10" />°N</td></tr>';
$classes = 'mod-data-input form-control-static';
$str .= '<tr><td align="right"><label for="field_'.$this->field->id.'_1" class="' . $classes . '">';
$str .= get_string('longitude', 'data');
if ($this->field->required) {
$str .= $OUTPUT->pix_icon('req', get_string('requiredelement', 'form'));
}
$classes = 'form-control mx-1';
$str .= '</label></td><td><input class="' . $classes . '" type="text" ';
$str .= 'name="field_'.$this->field->id.'_1" id="field_'.$this->field->id.'_1" value="';
$str .= s($long).'" size="10" />°E</td>';
$str .= '</tr>';
$str .= '</table>';
$str .= '</fieldset>';
$str .= '</div>';
return $str;
}
function display_search_field($value = '') {
global $CFG, $DB;
$varcharlat = $DB->sql_compare_text('content');
$varcharlong= $DB->sql_compare_text('content1');
$latlongsrs = $DB->get_recordset_sql(
"SELECT DISTINCT $varcharlat AS la, $varcharlong AS lo
FROM {data_content}
WHERE fieldid = ?
ORDER BY $varcharlat, $varcharlong", array($this->field->id));
$options = array();
foreach ($latlongsrs as $latlong) {
$latitude = format_float($latlong->la, 4);
$longitude = format_float($latlong->lo, 4);
if ($latitude && $longitude) {
$options[$latlong->la . ',' . $latlong->lo] = $latitude . ' ' . $longitude;
}
}
$latlongsrs->close();
$classes = array('class' => 'accesshide');
$return = html_writer::label(get_string('latlong', 'data'), 'menuf_'.$this->field->id, false, $classes);
$classes = array('class' => 'custom-select');
$return .= html_writer::select($options, 'f_'.$this->field->id, $value, array('' => get_string('menuchoose', 'data')),
$classes);
return $return;
}
public function parse_search_field($defaults = null) {
$param = 'f_'.$this->field->id;
if (empty($defaults[$param])) {
$defaults = array($param => '');
}
return optional_param($param, $defaults[$param], PARAM_NOTAGS);
}
function generate_sql($tablealias, $value) {
global $DB;
static $i=0;
$i++;
$name1 = "df_latlong1_$i";
$name2 = "df_latlong2_$i";
$varcharlat = $DB->sql_compare_text("{$tablealias}.content");
$varcharlong= $DB->sql_compare_text("{$tablealias}.content1");
$latlong[0] = '';
$latlong[1] = '';
$latlong = explode (',', $value, 2);
return array(" ({$tablealias}.fieldid = {$this->field->id} AND $varcharlat = :$name1 AND $varcharlong = :$name2) ",
array($name1=>$latlong[0], $name2=>$latlong[1]));
}
function display_browse_field($recordid, $template) {
global $CFG;
$content = $this->get_data_content($recordid);
if (!$content) {
return '';
}
$lat = $content->content;
if (strlen($lat ?? '') < 1) {
return '';
}
$long = $content->content1;
if (strlen($long ?? '') < 1) {
return '';
}
// We use format_float to display in the regional format.
if ($lat < 0) {
$compasslat = format_float(-$lat, 4) . '°S';
} else {
$compasslat = format_float($lat, 4) . '°N';
}
if ($long < 0) {
$compasslong = format_float(-$long, 4) . '°W';
} else {
$compasslong = format_float($long, 4) . '°E';
}
// Now let's create the jump-to-services link.
$servicesshown = explode(',', $this->field->param1);
// These are the different things that can be magically inserted into URL schemes.
$urlreplacements = array(
'@lat@' => $lat,
'@long@' => $long,
'@wwwroot@' => $CFG->wwwroot,
'@contentid@' => $content->id,
'@dataid@' => $this->data->id,
'@courseid@' => $this->data->course,
'@fieldid@' => $content->fieldid,
'@recordid@' => $content->recordid,
);
if (count($servicesshown) == 1 && $servicesshown[0]) {
$str = " <a class=\"data-field-link\" href='"
. str_replace(
array_keys($urlreplacements),
array_values($urlreplacements),
$this->linkoutservices[$servicesshown[0]]
) . "' title='$servicesshown[0]'>$compasslat $compasslong</a>";
} else if (count($servicesshown) > 1) {
$str = '<form id="latlongfieldbrowse" class="data-field-html">';
$str .= "$compasslat, $compasslong\n";
$str .= "<label class='accesshide' for='jumpto'>". get_string('jumpto') ."</label>";
$str .= '<select id="jumpto" name="jumpto" class="custom-select">';
foreach ($servicesshown as $servicename) {
// Add a link to a service.
$str .= "\n <option value='"
. str_replace(
array_keys($urlreplacements),
array_values($urlreplacements),
$this->linkoutservices[$servicename]
) . "'>".htmlspecialchars($servicename, ENT_COMPAT)."</option>";
}
// NB! If you are editing this, make sure you don't break the javascript reference "previousSibling"
// which allows the "Go" button to refer to the drop-down selector.
$str .= '\n</select><input type="button" class="btn ml-1 btn-secondary" value="' . get_string('go');
$str .= '" onclick="if(previousSibling.value){self.location=previousSibling.value}"/>';
$str .= '</form>';
} else {
$str = "$compasslat, $compasslong";
}
return $str;
}
function update_content_import($recordid, $value, $name='') {
$values = explode(" ", $value, 2);
foreach ($values as $index => $value) {
$this->update_content($recordid, $value, $name . '_' . $index);
}
}
function update_content($recordid, $value, $name='') {
global $DB;
$content = new stdClass();
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
// When updating these values (which might be region formatted) we should format
// the float to allow for a consistent float format in the database.
$value = unformat_float($value);
$value = trim($value ?? '');
if (strlen($value) > 0) {
$value = floatval($value);
} else {
$value = null;
}
$names = explode('_', $name);
switch ($names[2]) {
case 0:
// update lat
$content->content = $value;
break;
case 1:
// update long
$content->content1 = $value;
break;
default:
break;
}
if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$content->id = $oldcontent->id;
return $DB->update_record('data_content', $content);
} else {
return $DB->insert_record('data_content', $content);
}
}
function get_sort_sql($fieldname) {
global $DB;
return $DB->sql_cast_char2real($fieldname, true);
}
function export_text_value($record) {
// The content here is from the database and does not require location formating.
return sprintf('%01.4f', $record->content) . ' ' . sprintf('%01.4f', $record->content1);
}
/**
* Check if a field from an add form is empty
*
* @param mixed $value
* @param mixed $name
* @return bool
*/
function notemptyfield($value, $name) {
return isset($value) && !($value == '');
}
/**
* Validate values for this field.
* Both the Latitude and the Longitude fields need to be filled in.
*
* @param array $values The entered values for the lat. and long.
* @return string|bool Error message or false.
*/
public function field_validation($values) {
$valuecount = 0;
// The lat long class has two values that need to be checked.
foreach ($values as $value) {
if (isset($value->value) && !($value->value == '')) {
$valuecount++;
}
}
// If we have nothing filled in or both filled in then everything is okay.
if ($valuecount == 0 || $valuecount == 2) {
return false;
}
// 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;
}
public function get_field_params(): array {
global $DB;
$data = parent::get_field_params();
$data['dataid'] = $this->data->id;
if (isset($this->field->param1)) {
$data["param1"] = $this->field->param1;
if (isset($this->linkoutservices)) {
$serviceschosen = explode(',', htmlspecialchars($this->field->param1));
foreach ($this->linkoutservices as $servicename => $serviceurl) {
$servicename = htmlspecialchars($servicename);
$data['latlonglinkservices'][] = [
'name' => $servicename,
'selected' => in_array($servicename, $serviceschosen),
];
unset($serviceschosen[$servicename]);
}
$data['latlonglinkservicessize'] = count($this->linkoutservices);
}
}
$data["otherfields"][] = [
'value' => -1,
'name' => get_string('entry', 'data') . " #",
'selected' => $this->field->param2 == -1,
];
$data['otherfields'][] = [
'value' => -2,
'name' => get_string('latitude', 'data') . "/" . get_string('longitude', 'data'),
'selected' => $this->field->param2 == -2,
];
// Fetch all "suitable" other fields that exist for this database.
$textfields = $DB->get_records('data_fields', ['dataid' => $this->data->id, 'type' => 'text']);
if (count($textfields) > 0) {
$data['otherfieldsoptgroups']['label'] = get_string('latlongotherfields', 'data') . ":";
foreach ($textfields as $textfield) {
$data['otherfieldsoptgroups']['options'][] = [
'value' => $textfield->id,
'name' => $textfield->name,
'selected' => $this->field->param2 == $textfield->id,
];
}
}
if (isset($data['otherfieldsoptgroups'])) {
$data['otherfields'][] = $data['otherfieldsoptgroups'];
}
if (isset($this->field->id)) {
$data['fieldid'] = $this->field->id;
}
return $data;
}
}
+176
View File
@@ -0,0 +1,176 @@
<?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/>.
// A lot of this initial stuff is copied from mod/data/view.php
require_once('../../../../config.php');
require_once('../../lib.php');
// Optional params: row id "rid" - if set then export just one, otherwise export all
$d = required_param('d', PARAM_INT); // database id
$fieldid = required_param('fieldid', PARAM_INT); // field id
$rid = optional_param('rid', 0, PARAM_INT); //record id
$url = new moodle_url('/mod/data/field/latlong/kml.php', array('d'=>$d, 'fieldid'=>$fieldid));
if ($rid !== 0) {
$url->param('rid', $rid);
}
$PAGE->set_url($url);
if ($rid) {
if (! $record = $DB->get_record('data_records', array('id'=>$rid))) {
throw new \moodle_exception('invalidrecord', 'data');
}
if (! $data = $DB->get_record('data', array('id'=>$record->dataid))) {
throw new \moodle_exception('invalidid', 'data');
}
if (! $course = $DB->get_record('course', array('id'=>$data->course))) {
throw new \moodle_exception('coursemisconf');
}
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
throw new \moodle_exception('invalidcoursemodule');
}
if (! $field = $DB->get_record('data_fields', array('id'=>$fieldid))) {
throw new \moodle_exception('invalidfieldid', 'data');
}
if (! $field->type == 'latlong') { // Make sure we're looking at a latlong data type!
throw new \moodle_exception('invalidfieldtype', 'data');
}
if (! $content = $DB->get_record('data_content', array('fieldid'=>$fieldid, 'recordid'=>$rid))) {
throw new \moodle_exception('nofieldcontent', 'data');
}
} else { // We must have $d
if (! $data = $DB->get_record('data', array('id'=>$d))) {
throw new \moodle_exception('invalidid', 'data');
}
if (! $course = $DB->get_record('course', array('id'=>$data->course))) {
throw new \moodle_exception('coursemisconf');
}
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
throw new \moodle_exception('invalidcoursemodule');
}
if (! $field = $DB->get_record('data_fields', array('id'=>$fieldid))) {
throw new \moodle_exception('invalidfieldid', 'data');
}
if (! $field->type == 'latlong') { // Make sure we're looking at a latlong data type!
throw new \moodle_exception('invalidfieldtype', 'data');
}
$record = NULL;
}
require_course_login($course, true, $cm);
$context = context_module::instance($cm->id);
// If we have an empty Database then redirect because this page is useless without data.
if (has_capability('mod/data:managetemplates', $context)) {
if (!$DB->record_exists('data_fields', array('dataid'=>$data->id))) { // Brand new database!
redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id); // Redirect to field entry
}
}
//header('Content-type: text/plain'); // This is handy for debug purposes to look at the KML in the browser
header('Content-type: application/vnd.google-earth.kml+xml kml');
header('Content-Disposition: attachment; filename="moodleearth-'.$d.'-'.$rid.'-'.$fieldid.'.kml"');
echo data_latlong_kml_top();
if($rid) { // List one single item
$pm = new stdClass();
$pm->name = data_latlong_kml_get_item_name($content, $field);
$pm->description = "&lt;a href='$CFG->wwwroot/mod/data/view.php?d=$d&amp;rid=$rid'&gt;Item #$rid&lt;/a&gt; in Moodle data activity";
$pm->long = $content->content1;
$pm->lat = $content->content;
echo data_latlong_kml_placemark($pm);
} else { // List all items in turn
$contents = $DB->get_records('data_content', array('fieldid'=>$fieldid));
echo '<Document>';
foreach($contents as $content) {
$pm->name = data_latlong_kml_get_item_name($content, $field);
$pm->description = "&lt;a href='$CFG->wwwroot/mod/data/view.php?d=$d&amp;rid=$content->recordid'&gt;Item #$content->recordid&lt;/a&gt; in Moodle data activity";
$pm->long = $content->content1;
$pm->lat = $content->content;
echo data_latlong_kml_placemark($pm);
}
echo '</Document>';
}
echo data_latlong_kml_bottom();
function data_latlong_kml_top() {
return '<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
';
}
function data_latlong_kml_placemark($pm) {
return '<Placemark>
<description>'.$pm->description.'</description>
<name>'.$pm->name.'</name>
<LookAt>
<longitude>'.$pm->long.'</longitude>
<latitude>'.$pm->lat.'</latitude>
<range>30500.8880792294568</range>
<tilt>46.72425699662645</tilt>
<heading>0.0</heading>
</LookAt>
<visibility>0</visibility>
<Point>
<extrude>1</extrude>
<altitudeMode>relativeToGround</altitudeMode>
<coordinates>'.$pm->long.','.$pm->lat.',50</coordinates>
</Point>
</Placemark>
';
}
function data_latlong_kml_bottom() {
return '</kml>';
}
function data_latlong_kml_get_item_name($content, $field) {
global $DB;
// $field->param2 contains the user-specified labelling method
$name = '';
if($field->param2 > 0) {
$name = htmlspecialchars($DB->get_field('data_content', 'content', array('fieldid'=>$field->param2, 'recordid'=>$content->recordid)), ENT_COMPAT);
}elseif($field->param2 == -2) {
$name = $content->content . ', ' . $content->content1;
}
if($name=='') { // Done this way so that "item #" is the default that catches any problems
$name = get_string('entry', 'data') . " #$content->recordid";
}
return $name;
}
@@ -0,0 +1,29 @@
<?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/>.
/**
* Strings for component 'datafield_latlong', language 'en', branch 'master'
*
* @package datafield
* @subpackage latlong
* @copyright 2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'Coordinates';
$string['fieldtypelabel'] = 'Coordinates';
$string['privacy:metadata'] = 'The Coordinates field component doesn\'t store any personal data; it uses tables defined in mod_data.';
@@ -0,0 +1,105 @@
{{!
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/>.
}}
{{!
@template datafield_latlong/latlong
The purpose of this template is to enable the user to define a latlong field.
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* name string The field's name.
* description string The field's description.
* required bool The field's requiredness.
* latlonglinkservices array The field's Link out services.
* otherfields array The field's Other fields.
* otherfieldsoptgroups array The field's Other fields optgroups.
* dataid int The field's dataid.
* fieldid int The field's fieldid.
Example context (json):
{
"name": "A name",
"description": "A description",
"required": true,
"latlonglinkservices": [ { "name": "Google Maps", "selected": true },
{ "name": "Google Earth", "selected": false } ],
"latlonglinkservicessize": 2,
"otherfields": [ { "name": "Entry #", "value": "-1", "selected": false },
{ "name": "Latitude/Longitude", "value": "-2", "selected": false } ],
"otherfieldsoptgroups": [
{
"label": "Other fields:",
"options": [
{ "name": "Field A", "value": "6", "selected": false },
{ "name": "Field B", "value": "7", "selected": true }
]
}
],
"dataid": 6,
"fieldid": 0
}
}}
<fieldset>
{{> mod_data/fields/basicfields }}
{{> mod_data/fields/requiredfield }}
<div class="form-group row fitem">
<div class="col-md-3">
<label for="param1">{{#str}}latlonglinkservicesdisplayed, data{{/str}}</label>
</div>
<div class="col-md-9 form-inline align-items-start felement">
<select class="linkservicesdisplayed form-control" name="param1[]" id="param1" multiple="multiple" size="{{latlonglinkservicessize}}">
{{#latlonglinkservices}}
<option {{#selected}}selected{{/selected}}>{{name}}</option>
{{/latlonglinkservices}}
</select>
</div>
</div>
<div class="form-group row fitem">
<div class="col-md-3">
<label for="param2" class="mb-0">{{#str}}latlongkmllabelling, data{{/str}}</label>
</div>
<div class="col-md-9 form-inline align-items-start felement">
<select class="kmllabelling select custom-select form-control" name="param2" id="param2">
{{#otherfields}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/otherfields}}
{{#otherfieldsoptgroups}}
<optgroup label="{{label}}">
{{#otherfieldsoptgroups}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/otherfieldsoptgroups}}
</optgroup>
{{/otherfieldsoptgroups}}
</select>
</div>
</div>
{{#fieldid}}
<div class="form-group row fitem">
<div class="col-md-3">
</div>
<div class="col-md-9 form-inline align-items-start felement">
<a href='./field/latlong/kml.php?d={{dataid}}&fieldid={{fieldid}}'>{{#str}}latlongdownloadallhint, data{{/str}}</a>
</div>
</div>
{{/fieldid}}
</fieldset>
+28
View File
@@ -0,0 +1,28 @@
<?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/>.
/**
* @package datafield
* @subpackage latlong
* @copyright 2006 Dan Stowell
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'datafield_latlong'; // Full name of the plugin (used for diagnostics)
@@ -0,0 +1,71 @@
<?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/>.
/**
* Privacy Subsystem implementation for datafield_menu.
*
* @package datafield_menu
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace datafield_menu\privacy;
use core_privacy\local\request\writer;
use mod_data\privacy\datafield_provider;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for datafield_menu implementing null_provider.
*
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider,
datafield_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
/**
* Exports data about one record in {data_content} table.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
* @param \stdClass $defaultvalue pre-populated default value that most of plugins will use
*/
public static function export_data_content($context, $recordobj, $fieldobj, $contentobj, $defaultvalue) {
$defaultvalue->field['options'] = preg_split('/\s*\n\s*/', trim($fieldobj->param1), -1, PREG_SPLIT_NO_EMPTY);
writer::with_context($context)->export_data([$recordobj->id, $contentobj->id], $defaultvalue);
}
/**
* Allows plugins to delete locally stored data.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
*/
public static function delete_data_content($context, $recordobj, $fieldobj, $contentobj) {
}
}
+176
View File
@@ -0,0 +1,176 @@
<?php
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999-onwards Moodle Pty Ltd http://moodle.com //
// //
// This program 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 2 of the License, or //
// (at your option) any later version. //
// //
// This program 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: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
class data_field_menu extends data_field_base {
var $type = 'menu';
/**
* priority for globalsearch indexing
*
* @var int
*/
protected static $priority = self::HIGH_PRIORITY;
public function supports_preview(): bool {
return true;
}
public function get_data_content_preview(int $recordid): stdClass {
$options = explode("\n", $this->field->param1);
$options = array_map('trim', $options);
$selected = $options[$recordid % count($options)];
return (object)[
'id' => 0,
'fieldid' => $this->field->id,
'recordid' => $recordid,
'content' => $selected,
'content1' => null,
'content2' => null,
'content3' => null,
'content4' => null,
];
}
function display_add_field($recordid = 0, $formdata = null) {
global $DB, $OUTPUT;
if ($formdata) {
$fieldname = 'field_' . $this->field->id;
$content = $formdata->$fieldname;
} else if ($recordid) {
$content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid));
$content = trim($content);
} else {
$content = '';
}
$str = '<div title="' . s($this->field->description) . '">';
$options = array();
$rawoptions = explode("\n",$this->field->param1);
foreach ($rawoptions as $option) {
$option = trim($option);
if (strlen($option) > 0) {
$options[$option] = $option;
}
}
$str .= '<label for="' . 'field_' . $this->field->id . '">';
$str .= html_writer::span($this->field->name, 'accesshide');
if ($this->field->required) {
$image = $OUTPUT->pix_icon('req', get_string('requiredelement', 'form'));
$str .= html_writer::div($image, 'inline-req');
}
$str .= '</label>';
$str .= html_writer::select($options, 'field_'.$this->field->id, $content, array('' => get_string('menuchoose', 'data')),
array('id' => 'field_'.$this->field->id, 'class' => 'mod-data-input custom-select'));
$str .= '</div>';
return $str;
}
function display_search_field($content = '') {
global $CFG, $DB;
$varcharcontent = $DB->sql_compare_text('content', 255);
$sql = "SELECT DISTINCT $varcharcontent AS content
FROM {data_content}
WHERE fieldid=? AND content IS NOT NULL";
$usedoptions = array();
if ($used = $DB->get_records_sql($sql, array($this->field->id))) {
foreach ($used as $data) {
$value = $data->content;
if ($value === '') {
continue;
}
$usedoptions[$value] = $value;
}
}
$options = array();
foreach (explode("\n",$this->field->param1) as $option) {
$option = trim($option);
if (!isset($usedoptions[$option])) {
continue;
}
$options[$option] = $option;
}
if (!$options) {
// oh, nothing to search for
return '';
}
$return = html_writer::label(get_string('fieldtypelabel', "datafield_" . $this->type),
'menuf_' . $this->field->id, false, array('class' => 'accesshide'));
$return .= html_writer::select($options, 'f_'.$this->field->id, $content, array('' => get_string('menuchoose', 'data')),
array('class' => 'custom-select'));
return $return;
}
public function parse_search_field($defaults = null) {
$param = 'f_'.$this->field->id;
if (empty($defaults[$param])) {
$defaults = array($param => '');
}
return optional_param($param, $defaults[$param], PARAM_NOTAGS);
}
function generate_sql($tablealias, $value) {
global $DB;
static $i=0;
$i++;
$name = "df_menu_$i";
$varcharcontent = $DB->sql_compare_text("{$tablealias}.content", 255);
return array(" ({$tablealias}.fieldid = {$this->field->id} AND $varcharcontent = :$name) ", array($name=>$value));
}
/**
* Check if a field from an add form is empty
*
* @param mixed $value
* @param mixed $name
* @return bool
*/
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;
}
}
@@ -0,0 +1,29 @@
<?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/>.
/**
* Strings for component 'datafield_menu', language 'en', branch 'master'
*
* @package datafield
* @subpackage menu
* @copyright 2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'Dropdown list';
$string['fieldtypelabel'] = 'Dropdown list';
$string['privacy:metadata'] = 'The Dropdown list field component doesn\'t store any personal data; it uses tables defined in mod_data.';
@@ -0,0 +1,54 @@
{{!
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/>.
}}
{{!
@template datafield_menu/menu
The purpose of this template is to enable the user to define a menu field.
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* name string The field's name.
* description string The field's description.
* required bool The field's requiredness.
* param1 string The field's options.
Example context (json):
{
"name": "A name",
"description": "A description",
"required": true,
"param1": "One\nTwo\nThree"
}
}}
<fieldset>
{{> mod_data/fields/basicfields }}
{{> mod_data/fields/requiredfield }}
<div class="form-group row fitem">
<div class="col-md-3 col-form-label d-flex pb-0 pr-md-0">
<label for="param1">{{#str}}fieldoptions, data{{/str}}</label>
</div>
<div class="col-md-9 form-inline align-items-start felement">
<textarea class="optionstextarea form-control" name="param1" id="param1" cols="80" rows="10">{{param1}}</textarea>
</div>
</div>
</fieldset>
+28
View File
@@ -0,0 +1,28 @@
<?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/>.
/**
* @package datafield
* @subpackage menu
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'datafield_menu'; // Full name of the plugin (used for diagnostics)
@@ -0,0 +1,75 @@
<?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/>.
/**
* Privacy Subsystem implementation for datafield_multimenu.
*
* @package datafield_multimenu
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace datafield_multimenu\privacy;
use core_privacy\local\request\writer;
use mod_data\privacy\datafield_provider;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for datafield_multimenu implementing null_provider.
*
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider,
datafield_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
/**
* Exports data about one record in {data_content} table.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
* @param \stdClass $defaultvalue pre-populated default value that most of plugins will use
*/
public static function export_data_content($context, $recordobj, $fieldobj, $contentobj, $defaultvalue) {
$defaultvalue->field['options'] = preg_split('/\s*\n\s*/', trim($fieldobj->param1), -1, PREG_SPLIT_NO_EMPTY);
for ($i = 1; $i <= 10; $i++) {
unset($defaultvalue->field['param' . $i]);
}
$defaultvalue->content = explode('##', $defaultvalue->content);
writer::with_context($context)->export_data([$recordobj->id, $contentobj->id], $defaultvalue);
}
/**
* Allows plugins to delete locally stored data.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
*/
public static function delete_data_content($context, $recordobj, $fieldobj, $contentobj) {
}
}
+338
View File
@@ -0,0 +1,338 @@
<?php
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999-onwards Moodle Pty Ltd http://moodle.com //
// //
// This program 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 2 of the License, or //
// (at your option) any later version. //
// //
// This program 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: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
class data_field_multimenu extends data_field_base {
var $type = 'multimenu';
/**
* priority for globalsearch indexing
*
* @var int
* */
protected static $priority = self::LOW_PRIORITY;
public function supports_preview(): bool {
return true;
}
public function get_data_content_preview(int $recordid): stdClass {
$options = explode("\n", $this->field->param1);
$options = array_map('trim', $options);
$selected = $options[$recordid % count($options)];
$selected .= '##' . $options[($recordid + 1) % count($options)];
return (object)[
'id' => 0,
'fieldid' => $this->field->id,
'recordid' => $recordid,
'content' => $selected,
'content1' => null,
'content2' => null,
'content3' => null,
'content4' => null,
];
}
function display_add_field($recordid = 0, $formdata = null) {
global $DB, $OUTPUT;
if ($formdata) {
$fieldname = 'field_' . $this->field->id;
if (isset($formdata->$fieldname)) {
$content = $formdata->$fieldname;
} else {
$content = array();
}
} else if ($recordid) {
$contentfield = $DB->get_field('data_content', 'content', ['fieldid' => $this->field->id, 'recordid' => $recordid]);
$content = explode('##', $contentfield ?? '');
} else {
$content = array();
}
$str = '<div title="'.s($this->field->description).'">';
$str .= '<input name="field_' . $this->field->id . '[xxx]" type="hidden" value="xxx"/>'; // hidden field - needed for empty selection
$str .= '<label for="field_' . $this->field->id . '">';
$str .= '<legend><span class="accesshide">' . s($this->field->name);
if ($this->field->required) {
$str .= '&nbsp;' . get_string('requiredelement', 'form') . '</span></legend>';
$str .= '<div class="inline-req">';
$str .= $OUTPUT->pix_icon('req', get_string('requiredelement', 'form'));
$str .= '</div>';
} else {
$str .= '</span></legend>';
}
$str .= '</label>';
$str .= '<select name="field_' . $this->field->id . '[]" id="field_' . $this->field->id . '"';
$str .= ' multiple="multiple" class="mod-data-input form-control">';
foreach (explode("\n", $this->field->param1) as $option) {
$option = trim($option);
$str .= '<option value="' . s($option) . '"';
if (in_array($option, $content)) {
// Selected by user.
$str .= ' selected = "selected"';
}
$str .= '>';
$str .= $option . '</option>';
}
$str .= '</select>';
$str .= '</div>';
return $str;
}
function display_search_field($value = '') {
global $CFG, $DB;
if (is_array($value)){
$content = $value['selected'];
$allrequired = $value['allrequired'] ? true : false;
} else {
$content = array();
$allrequired = false;
}
static $c = 0;
$str = '<label class="accesshide" for="f_' . $this->field->id . '">' . s($this->field->name) . '</label>';
$str .= '<select id="f_'.$this->field->id.'" name="f_'.$this->field->id.'[]" multiple="multiple" class="form-control">';
// display only used options
$varcharcontent = $DB->sql_compare_text('content', 255);
$sql = "SELECT DISTINCT $varcharcontent AS content
FROM {data_content}
WHERE fieldid=? AND content IS NOT NULL";
$usedoptions = array();
if ($used = $DB->get_records_sql($sql, array($this->field->id))) {
foreach ($used as $data) {
$valuestr = $data->content;
if ($valuestr === '') {
continue;
}
$values = explode('##', $valuestr);
foreach ($values as $value) {
$usedoptions[$value] = $value;
}
}
}
$found = false;
foreach (explode("\n",$this->field->param1) as $option) {
$option = trim($option);
if (!isset($usedoptions[$option])) {
continue;
}
$found = true;
$str .= '<option value="' . s($option) . '"';
if (in_array($option, $content)) {
// Selected by user.
$str .= ' selected = "selected"';
}
$str .= '>' . $option . '</option>';
}
if (!$found) {
// oh, nothing to search for
return '';
}
$str .= '</select>';
$str .= html_writer::checkbox('f_'.$this->field->id.'_allreq', null, $allrequired,
get_string('selectedrequired', 'data'), array('class' => 'mr-1'));
return $str;
}
public function parse_search_field($defaults = null) {
$paramselected = 'f_'.$this->field->id;
$paramallrequired = 'f_'.$this->field->id.'_allreq';
if (empty($defaults[$paramselected])) { // One empty means the other ones are empty too.
$defaults = array($paramselected => array(), $paramallrequired => 0);
}
$selected = optional_param_array($paramselected, $defaults[$paramselected], PARAM_NOTAGS);
$allrequired = optional_param($paramallrequired, $defaults[$paramallrequired], PARAM_BOOL);
if (empty($selected)) {
// no searching
return '';
}
return array('selected'=>$selected, 'allrequired'=>$allrequired);
}
function generate_sql($tablealias, $value) {
global $DB;
static $i=0;
$i++;
$name = "df_multimenu_{$i}_";
$params = array();
$varcharcontent = $DB->sql_compare_text("{$tablealias}.content", 255);
$allrequired = $value['allrequired'];
$selected = $value['selected'];
if ($selected) {
$conditions = array();
$j=0;
foreach ($selected as $sel) {
$j++;
$xname = $name.$j;
$likesel = str_replace('%', '\%', $sel);
$likeselsel = str_replace('_', '\_', $likesel);
$conditions[] = "({$tablealias}.fieldid = {$this->field->id} AND ({$varcharcontent} = :{$xname}a
OR {$tablealias}.content LIKE :{$xname}b
OR {$tablealias}.content LIKE :{$xname}c
OR {$tablealias}.content LIKE :{$xname}d))";
$params[$xname.'a'] = $sel;
$params[$xname.'b'] = "$likesel##%";
$params[$xname.'c'] = "%##$likesel";
$params[$xname.'d'] = "%##$likesel##%";
}
if ($allrequired) {
return array(" (".implode(" AND ", $conditions).") ", $params);
} else {
return array(" (".implode(" OR ", $conditions).") ", $params);
}
} else {
return array(" ", array());
}
}
function update_content($recordid, $value, $name='') {
global $DB;
$content = new stdClass();
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
$content->content = $this->format_data_field_multimenu_content($value);
if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$content->id = $oldcontent->id;
return $DB->update_record('data_content', $content);
} else {
return $DB->insert_record('data_content', $content);
}
}
function format_data_field_multimenu_content($content) {
if (!is_array($content)) {
return NULL;
}
$options = explode("\n", $this->field->param1);
$options = array_map('trim', $options);
$vals = array();
foreach ($content as $key=>$val) {
if ($key === 'xxx') {
continue;
}
if (!in_array($val, $options)) {
continue;
}
$vals[] = $val;
}
if (empty($vals)) {
return NULL;
}
return implode('##', $vals);
}
function display_browse_field($recordid, $template) {
$content = $this->get_data_content($recordid);
if (!$content || empty($content->content)) {
return '';
}
$options = explode("\n", $this->field->param1);
$options = array_map('trim', $options);
$contentarray = explode('##', $content->content);
$str = '';
foreach ($contentarray as $line) {
if (!in_array($line, $options)) {
// Hmm, looks like somebody edited the field definition.
continue;
}
$str .= $line . "<br />\n";
}
return $str;
}
/**
* Check if a field from an add form is empty
*
* @param mixed $value
* @param mixed $name
* @return bool
*/
function notemptyfield($value, $name) {
unset($value['xxx']);
return !empty($value);
}
/**
* Returns the presentable string value for a field content.
*
* The returned string should be plain text.
*
* @param stdClass $content
* @return string
*/
public static function get_content_value($content) {
$arr = explode('##', $content->content);
$strvalue = '';
foreach ($arr as $a) {
$strvalue .= $a . ' ';
}
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;
}
}
@@ -0,0 +1,29 @@
<?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/>.
/**
* Strings for component 'datafield_multimenu', language 'en', branch 'master'
*
* @package datafield
* @subpackage multimenu
* @copyright 2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'Multi-select list';
$string['fieldtypelabel'] = 'Multi-select list';
$string['privacy:metadata'] = 'The Multi-select list field component doesn\'t store any personal data, it uses tables defined in mod_data';
@@ -0,0 +1,54 @@
{{!
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/>.
}}
{{!
@template datafield_multimenu/multimenu
The purpose of this template is to enable the user to define a multimenu field.
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* name string The field's name.
* description string The field's description.
* required bool The field's requiredness.
* param1 string The field's options.
Example context (json):
{
"name": "A name",
"description": "A description",
"required": true,
"param1": "One\nTwo\nThree"
}
}}
<fieldset>
{{> mod_data/fields/basicfields }}
{{> mod_data/fields/requiredfield }}
<div class="form-group row fitem">
<div class="col-md-3 col-form-label d-flex pb-0 pr-md-0">
<label for="param1">{{#str}}fieldoptions, data{{/str}}</label>
</div>
<div class="col-md-9 form-inline align-items-start felement">
<textarea class="optionstextarea form-control" name="param1" id="param1" cols="80" rows="10">{{param1}}</textarea>
</div>
</div>
</fieldset>
+28
View File
@@ -0,0 +1,28 @@
<?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/>.
/**
* @package datafield
* @subpackage multimenu
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'datafield_multimenu'; // Full name of the plugin (used for diagnostics)
@@ -0,0 +1,73 @@
<?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/>.
/**
* Privacy Subsystem implementation for datafield_number.
*
* @package datafield_number
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace datafield_number\privacy;
use core_privacy\local\request\writer;
use mod_data\privacy\datafield_provider;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for datafield_number implementing null_provider.
*
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider,
datafield_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
/**
* Exports data about one record in {data_content} table.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
* @param \stdClass $defaultvalue pre-populated default value that most of plugins will use
*/
public static function export_data_content($context, $recordobj, $fieldobj, $contentobj, $defaultvalue) {
if (preg_match("/^\d+$/", trim($fieldobj->param1))) {
$defaultvalue->field['decimals'] = trim($fieldobj->param1);
}
writer::with_context($context)->export_data([$recordobj->id, $contentobj->id], $defaultvalue);
}
/**
* Allows plugins to delete locally stored data.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
*/
public static function delete_data_content($context, $recordobj, $fieldobj, $contentobj) {
}
}
+138
View File
@@ -0,0 +1,138 @@
<?php
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999-onwards Moodle Pty Ltd http://moodle.com //
// //
// This program 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 2 of the License, or //
// (at your option) any later version. //
// //
// This program 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: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
class data_field_number extends data_field_base {
var $type = 'number';
public function supports_preview(): bool {
return true;
}
public function get_data_content_preview(int $recordid): stdClass {
return (object)[
'id' => 0,
'fieldid' => $this->field->id,
'recordid' => $recordid,
'content' => 1233 + $recordid,
'content1' => null,
'content2' => null,
'content3' => null,
'content4' => null,
];
}
function update_content($recordid, $value, $name='') {
global $DB;
$content = new stdClass();
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
$value = trim($value);
if (strlen($value) > 0) {
$content->content = floatval($value);
} else {
$content->content = null;
}
if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$content->id = $oldcontent->id;
return $DB->update_record('data_content', $content);
} else {
return $DB->insert_record('data_content', $content);
}
}
function display_browse_field($recordid, $template) {
$content = $this->get_data_content($recordid);
if (!$content || $content->content === '') {
return '';
}
$number = $content->content;
$decimals = trim($this->field->param1 ?? '');
// Only apply number formatting if param1 contains an integer number >= 0.
if (preg_match("/^\d+$/", $decimals)) {
$decimals = $decimals * 1;
// Removes leading zeros (eg. '007' -> '7'; '00' -> '0').
$str = format_float($number, $decimals, true);
} else {
$str = $number;
}
return $str;
}
function display_search_field($value = '') {
return '<label class="accesshide" for="f_'.$this->field->id.'">' . get_string('fieldname', 'data') . '</label>' .
'<input type="text" size="16" id="f_'.$this->field->id.'" name="f_'.$this->field->id.'" ' .
'value="'.s($value).'" class="form-control d-inline"/>';
}
public function parse_search_field($defaults = null) {
$param = 'f_'.$this->field->id;
if (empty($defaults[$param])) {
$defaults = array($param => '');
}
return optional_param($param, $defaults[$param], PARAM_NOTAGS);
}
// need to cast?
function generate_sql($tablealias, $value) {
global $DB;
static $i=0;
$i++;
$name = "df_number_$i";
$varcharcontent = $DB->sql_compare_text("{$tablealias}.content");
return array(" ({$tablealias}.fieldid = {$this->field->id} AND $varcharcontent = :$name) ", array($name=>$value));
}
function get_sort_sql($fieldname) {
global $DB;
return $DB->sql_cast_char2real($fieldname, true);
}
/**
* Check if a field from an add form is empty
*
* @param mixed $value
* @param mixed $name
* @return bool
*/
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;
}
}
@@ -0,0 +1,29 @@
<?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/>.
/**
* Strings for component 'datafield_number', language 'en', branch 'master'
*
* @package datafield
* @subpackage number
* @copyright 2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'Number';
$string['fieldtypelabel'] = 'Number';
$string['privacy:metadata'] = 'The Number field component doesn\'t store any personal data; it uses tables defined in mod_data.';
@@ -0,0 +1,44 @@
{{!
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/>.
}}
{{!
@template datafield_number/number
The purpose of this template is to enable the user to define a number field.
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* name string The field's name.
* description string The field's description.
* required bool The field's requiredness.
Example context (json):
{
"name": "A name",
"description": "A description",
"required": true
}
}}
<fieldset>
{{> mod_data/fields/basicfields }}
{{> mod_data/fields/requiredfield }}
</fieldset>
+28
View File
@@ -0,0 +1,28 @@
<?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/>.
/**
* @package datafield
* @subpackage number
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'datafield_number'; // Full name of the plugin (used for diagnostics)
@@ -0,0 +1,89 @@
<?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/>.
/**
* Privacy Subsystem implementation for datafield_picture.
*
* @package datafield_picture
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace datafield_picture\privacy;
use core_privacy\local\request\writer;
use mod_data\privacy\datafield_provider;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for datafield_picture implementing null_provider.
*
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider,
datafield_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
/**
* Exports data about one record in {data_content} table.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
* @param \stdClass $defaultvalue pre-populated default value that most of plugins will use
*/
public static function export_data_content($context, $recordobj, $fieldobj, $contentobj, $defaultvalue) {
if ($fieldobj->param1) {
$defaultvalue->field['width'] = $fieldobj->param1;
}
if ($fieldobj->param2) {
$defaultvalue->field['height'] = $fieldobj->param2;
}
if ($fieldobj->param3) {
$defaultvalue->field['maxbytes'] = $fieldobj->param3;
}
// Change file name to file path.
$defaultvalue->file = writer::with_context($context)
->rewrite_pluginfile_urls([$recordobj->id, $contentobj->id], 'mod_data', 'content', $contentobj->id,
'@@PLUGINFILE@@/' . $defaultvalue->content);
if (isset($defaultvalue->content1)) {
$defaultvalue->alttext = $defaultvalue->content1;
}
unset($defaultvalue->content);
unset($defaultvalue->content1);
writer::with_context($context)->export_data([$recordobj->id, $contentobj->id], $defaultvalue);
}
/**
* Allows plugins to delete locally stored data.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
*/
public static function delete_data_content($context, $recordobj, $fieldobj, $contentobj) {
}
}
+473
View File
@@ -0,0 +1,473 @@
<?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 picture field for database activity
*
* @package datafield_picture
* @copyright 2005 Martin Dougiamas
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class data_field_picture extends data_field_base {
var $type = 'picture';
var $previewwidth = 50;
var $previewheight = 50;
public function supports_preview(): bool {
return true;
}
public function get_data_content_preview(int $recordid): stdClass {
return (object)[
'id' => 0,
'fieldid' => $this->field->id,
'recordid' => $recordid,
'content' => 'datafield_picture/preview',
'content1' => get_string('sample', 'datafield_picture'),
'content2' => null,
'content3' => null,
'content4' => null,
];
}
function display_add_field($recordid = 0, $formdata = null) {
global $CFG, $DB, $OUTPUT, $USER, $PAGE;
// Necessary for the constants used in args.
require_once($CFG->dirroot . '/repository/lib.php');
$file = false;
$content = false;
$alttext = '';
$itemid = null;
$fs = get_file_storage();
if ($formdata) {
$fieldname = 'field_' . $this->field->id . '_file';
$itemid = clean_param($formdata->$fieldname, PARAM_INT);
$fieldname = 'field_' . $this->field->id . '_alttext';
if (isset($formdata->$fieldname)) {
$alttext = $formdata->$fieldname;
}
} else if ($recordid) {
if (!$content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid))) {
// Quickly make one now!
$content = new stdClass();
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
$id = $DB->insert_record('data_content', $content);
$content = $DB->get_record('data_content', array('id' => $id));
}
file_prepare_draft_area($itemid, $this->context->id, 'mod_data', 'content', $content->id);
if (!empty($content->content)) {
if ($file = $fs->get_file($this->context->id, 'mod_data', 'content', $content->id, '/', $content->content)) {
$usercontext = context_user::instance($USER->id);
if ($thumbfile = $fs->get_file($usercontext->id, 'user', 'draft', $itemid, '/', 'thumb_'.$content->content)) {
$thumbfile->delete();
}
}
}
$alttext = $content->content1;
} else {
$itemid = file_get_unused_draft_itemid();
}
$str = '<div title="' . s($this->field->description) . '">';
$str .= '<fieldset><legend><span class="accesshide">'.s($this->field->name);
if ($this->field->required) {
$str .= '&nbsp;' . get_string('requiredelement', 'form') . '</span></legend>';
$image = $OUTPUT->pix_icon('req', get_string('requiredelement', 'form'));
$str .= html_writer::div($image, 'inline-req');
} else {
$str .= '</span></legend>';
}
$str .= '<noscript>';
if ($file) {
$src = file_encode_url($CFG->wwwroot.'/pluginfile.php/', $this->context->id.'/mod_data/content/'.$content->id.'/'.$file->get_filename());
$str .= '<img width="'.s($this->previewwidth).'" height="'.s($this->previewheight).'" src="'.$src.'" alt="" />';
}
$str .= '</noscript>';
$options = new stdClass();
$options->maxbytes = $this->field->param3;
$options->maxfiles = 1; // Only one picture permitted.
$options->itemid = $itemid;
$options->accepted_types = array('web_image');
$options->return_types = FILE_INTERNAL;
$options->context = $PAGE->context;
if (!empty($file)) {
$options->filename = $file->get_filename();
$options->filepath = '/';
}
$fm = new form_filemanager($options);
// Print out file manager.
$output = $PAGE->get_renderer('core', 'files');
$str .= '<div class="mod-data-input">';
$str .= $output->render($fm);
$str .= '<div class="mdl-left">';
$str .= '<input type="hidden" name="field_' . $this->field->id . '_file" value="' . s($itemid) . '" />';
$str .= '<label for="field_' . $this->field->id . '_alttext">' .
get_string('alttext', 'data') .
'</label>&nbsp;<input type="text" class="form-control" name="field_' .
$this->field->id . '_alttext" id="field_' . $this->field->id . '_alttext" value="' . s($alttext) . '" />';
$str .= '</div>';
$str .= '</div>';
$str .= '</fieldset>';
$str .= '</div>';
return $str;
}
/**
* Validate the image field type parameters.
*
* This will check for valid numeric values in the width and height fields.
*
* @param stdClass $fieldinput the field input data
* @return array array of error messages if width or height parameters are not numeric
* @throws coding_exception
*/
public function validate(stdClass $fieldinput): array {
$errors = [];
// These are the params we have to check if they are numeric, because they represent width and height of the image
// in single and list view.
$widthandheightparams = ['param1', 'param2', 'param4', 'param5'];
foreach ($widthandheightparams as $param) {
if (!empty($fieldinput->$param) && !is_numeric($fieldinput->$param)) {
$errors[$param] = get_string('error_invalid' . $param, 'datafield_picture');
}
}
return $errors;
}
// TODO delete this function and instead subclass data_field_file - see MDL-16493
function get_file($recordid, $content=null) {
global $DB;
if (empty($content)) {
if (!$content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
return null;
}
}
$fs = get_file_storage();
if (!$file = $fs->get_file($this->context->id, 'mod_data', 'content', $content->id, '/', $content->content)) {
return null;
}
return $file;
}
function display_search_field($value = '') {
return '<label class="accesshide" for="f_' . $this->field->id . '">' . get_string('fieldname', 'data') . '</label>' .
'<input type="text" size="16" id="f_' . $this->field->id . '" name="f_' . $this->field->id . '" ' .
'value="' . s($value) . '" class="form-control"/>';
}
public function parse_search_field($defaults = null) {
$param = 'f_'.$this->field->id;
if (empty($defaults[$param])) {
$defaults = array($param => '');
}
return optional_param($param, $defaults[$param], PARAM_NOTAGS);
}
function generate_sql($tablealias, $value) {
global $DB;
static $i=0;
$i++;
$name = "df_picture_$i";
return array(" ({$tablealias}.fieldid = {$this->field->id} AND ".$DB->sql_like("{$tablealias}.content", ":$name", false).") ", array($name=>"%$value%"));
}
function display_browse_field($recordid, $template) {
global $OUTPUT;
$content = $this->get_data_content($recordid);
if (!$content || empty($content->content)) {
return '';
}
$alt = $content->content1;
$title = $alt;
$width = $this->field->param1 ? ' width="' . s($this->field->param1) . '" ' : ' ';
$height = $this->field->param2 ? ' height="' . s($this->field->param2) . '" ' : ' ';
if ($this->preview) {
$imgurl = $OUTPUT->image_url('sample', 'datafield_picture');
return '<img ' . $width . $height . ' src="' . $imgurl . '" alt="' . s($alt) . '" class="list_picture"/>';
}
if ($template == 'listtemplate') {
$filename = 'thumb_' . $content->content;
// Thumbnails are already converted to the correct width and height.
$width = '';
$height = '';
$url = new moodle_url('/mod/data/view.php', ['d' => $this->field->dataid, 'rid' => $recordid]);
} else {
$filename = $content->content;
$url = null;
}
$imgurl = moodle_url::make_pluginfile_url($this->context->id, 'mod_data', 'content', $content->id, '/', $filename);
if (!$url) {
$url = $imgurl;
}
$img = '<img ' . $width . $height . ' src="' . $imgurl->out() . '" alt="' . s($alt) .
'" title="' . s($title) . '" class="list_picture"/>';
return '<a class="data-field-link" href="' . $url->out() . '">' . $img . '</a>';
}
function update_field() {
global $DB, $OUTPUT;
// Get the old field data so that we can check whether the thumbnail dimensions have changed
$oldfield = $DB->get_record('data_fields', array('id'=>$this->field->id));
$DB->update_record('data_fields', $this->field);
// Have the thumbnail dimensions changed?
if ($oldfield && ($oldfield->param4 != $this->field->param4 || $oldfield->param5 != $this->field->param5)) {
// Check through all existing records and update the thumbnail
if ($contents = $DB->get_records('data_content', array('fieldid'=>$this->field->id))) {
$fs = get_file_storage();
if (count($contents) > 20) {
echo $OUTPUT->notification(get_string('resizingimages', 'data'), 'notifysuccess');
echo "\n\n";
// To make sure that ob_flush() has the desired effect
ob_flush();
}
foreach ($contents as $content) {
if (!$file = $fs->get_file($this->context->id, 'mod_data', 'content', $content->id, '/', $content->content)) {
continue;
}
if ($thumbfile = $fs->get_file($this->context->id, 'mod_data', 'content', $content->id, '/', 'thumb_'.$content->content)) {
$thumbfile->delete();
}
core_php_time_limit::raise(300);
// Might be slow!
$this->update_thumbnail($content, $file);
}
}
}
return true;
}
function update_content($recordid, $value, $name='') {
global $CFG, $DB, $USER;
// Should always be available since it is set by display_add_field before initializing the draft area.
$content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid));
if (!$content) {
$content = (object)array('fieldid' => $this->field->id, 'recordid' => $recordid);
$content->id = $DB->insert_record('data_content', $content);
}
$names = explode('_', $name);
switch ($names[2]) {
case 'file':
$fs = get_file_storage();
file_save_draft_area_files($value, $this->context->id, 'mod_data', 'content', $content->id);
$usercontext = context_user::instance($USER->id);
$files = $fs->get_area_files(
$this->context->id,
'mod_data', 'content',
$content->id,
'itemid, filepath, filename',
false);
// We expect no or just one file (maxfiles = 1 option is set for the form_filemanager).
if (count($files) == 0) {
$content->content = null;
} else {
$file = array_values($files)[0];
if (count($files) > 1) {
// This should not happen with a consistent database. Inform admins/developers about the inconsistency.
debugging('more then one file found in mod_data instance {$this->data->id} picture field (field id: {$this->field->id}) area during update data record {$recordid} (content id: {$content->id})', DEBUG_NORMAL);
}
if ($file->get_imageinfo() === false) {
$url = new moodle_url('/mod/data/edit.php', array('d' => $this->field->dataid));
redirect($url, get_string('invalidfiletype', 'error', $file->get_filename()));
}
$content->content = $file->get_filename();
$this->update_thumbnail($content, $file);
}
$DB->update_record('data_content', $content);
break;
case 'alttext':
// only changing alt tag
$content->content1 = clean_param($value, PARAM_NOTAGS);
$DB->update_record('data_content', $content);
break;
default:
break;
}
}
function update_thumbnail($content, $file) {
// (Re)generate thumbnail image according to the dimensions specified in the field settings.
// If thumbnail width and height are BOTH not specified then no thumbnail is generated, and
// additionally an attempted delete of the existing thumbnail takes place.
$fs = get_file_storage();
$filerecord = [
'contextid' => $file->get_contextid(), 'component' => $file->get_component(), 'filearea' => $file->get_filearea(),
'itemid' => $file->get_itemid(), 'filepath' => $file->get_filepath(),
'filename' => 'thumb_' . $file->get_filename(), 'userid' => $file->get_userid()
];
try {
// This may fail for various reasons.
$newwidth = isset($this->field->param4) ? (int) $this->field->param4 : null;
$newheight = isset($this->field->param5) ? (int) $this->field->param5 : null;
$fs->convert_image($filerecord, $file, $newwidth, $newheight, true);
return true;
} catch (Exception $e) {
debugging($e->getMessage());
return false;
}
}
/**
* Here we export the text value of a picture field which is the filename of the exported picture.
*
* @param stdClass $record the record which is being exported
* @return string the value which will be stored in the exported file for this field
*/
public function export_text_value(stdClass $record): string {
return !empty($record->content) ? $record->content : '';
}
/**
* Specifies that this field type supports the export of files.
*
* @return bool true which means that file export is being supported by this field type
*/
public function file_export_supported(): bool {
return true;
}
/**
* Exports the file content for file export.
*
* @param stdClass $record the data content record the file belongs to
* @return null|string The file content of the stored file or null if no file should be exported for this record
*/
public function export_file_value(stdClass $record): null|string {
$file = $this->get_file($record->id);
return $file ? $file->get_content() : null;
}
/**
* Specifies that this field type supports the import of files.
*
* @return bool true which means that file import is being supported by this field type
*/
public function file_import_supported(): bool {
return true;
}
/**
* Provides the necessary code for importing a file when importing the content of a mod_data instance.
*
* @param int $contentid the id of the mod_data content record
* @param string $filecontent the content of the file to import as string
* @param string $filename the filename the imported file should get
* @return void
*/
public function import_file_value(int $contentid, string $filecontent, string $filename): void {
$filerecord = [
'contextid' => $this->context->id,
'component' => 'mod_data',
'filearea' => 'content',
'itemid' => $contentid,
'filepath' => '/',
'filename' => $filename,
];
$fs = get_file_storage();
$file = $fs->create_file_from_string($filerecord, $filecontent);
$this->update_thumbnail(null, $file);
}
function file_ok($path) {
return true;
}
/**
* Custom notempty function
*
* @param string $value
* @param string $name
* @return bool
*/
function notemptyfield($value, $name) {
global $USER;
$names = explode('_', $name);
if ($names[2] == 'file') {
$usercontext = context_user::instance($USER->id);
$fs = get_file_storage();
$files = $fs->get_area_files($usercontext->id, 'user', 'draft', $value);
return count($files) >= 2;
}
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;
}
public function get_field_params(): array {
global $DB, $CFG;
$data = parent::get_field_params();
$course = $DB->get_record('course', ['id' => $this->data->course]);
$filesizes = get_max_upload_sizes($CFG->maxbytes, $course->maxbytes, 0, $this->field->param3);
foreach ($filesizes as $value => $name) {
if (!((isset($this->field->param3) && $value == $this->field->param3))) {
$data['options'][] = ['name' => $name, 'value' => $value, 'selected' => 0];
} else {
$data['options'][] = ['name' => $name, 'value' => $value, 'selected' => 1];
}
}
return $data;
}
}
@@ -0,0 +1,34 @@
<?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/>.
/**
* Strings for component 'datafield_picture', language 'en', branch 'master'
*
* @package datafield
* @subpackage picture
* @copyright 2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'Image';
$string['fieldtypelabel'] = 'Image';
$string['error_invalidparam1'] = 'Width in single view needs to be a numeric value.';
$string['error_invalidparam2'] = 'Height in single view needs to be a numeric value.';
$string['error_invalidparam4'] = 'Width in list view needs to be a numeric value.';
$string['error_invalidparam5'] = 'Height in list view needs to be a numeric value.';
$string['privacy:metadata'] = 'The Image field component doesn\'t store any personal data; it uses tables defined in mod_data.';
$string['sample'] = 'Image description placeholder';
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

+42
View File
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
id="svg8"
version="1.1"
viewBox="0 0 105.83334 71.4375"
height="71.4375mm"
width="105.83334mm" preserveAspectRatio="xMinYMid meet">
<defs
id="defs2" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
transform="translate(276.67856,-129.93452)"
id="layer1">
<rect
y="129.93452"
x="-276.67856"
height="71.4375"
width="105.83334"
id="rect864"
style="opacity:1;vector-effect:none;fill:#e9eef1;fill-opacity:1;stroke:none;stroke-width:3.30729175;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:markers fill stroke" />
<path
id="rect826"
d="m -239.31599,150.5547 c -1.81012,0 -3.32227,1.50707 -3.32227,3.31918 v 23.55955 c 0,1.8121 1.51215,3.3184 3.32227,3.3184 h 31.10818 c 1.81012,0 3.32228,-1.5063 3.32228,-3.3184 v -23.55955 c 0,-1.81211 -1.51216,-3.31918 -3.32228,-3.31918 z m -0.004,2.43655 h 31.1149 c 0.46886,0 0.8462,0.3776 0.8462,0.84646 v 23.63112 c 0,0.46886 -0.37734,0.84646 -0.8462,0.84646 h -31.1149 c -0.46886,0 -0.8462,-0.3776 -0.8462,-0.84646 v -23.63112 c 0,-0.46886 0.37734,-0.84646 0.8462,-0.84646 z m 5.40122,2.67271 a 3.7417735,3.7417735 0 0 0 -3.74163,3.74189 3.7417735,3.7417735 0 0 0 3.74163,3.74163 3.7417735,3.7417735 0 0 0 3.74189,-3.74163 3.7417735,3.7417735 0 0 0 -3.74189,-3.74189 z m 15.8024,3.17526 -10.0273,10.02703 -3.24063,-3.24063 -6.27636,6.27636 v 3.7406 h 27.79598 v -8.55141 z"
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#babec1;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3.30072331;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:markers fill stroke;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.2 KiB

@@ -0,0 +1,97 @@
{{!
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/>.
}}
{{!
@template datafield_picture/picture
The purpose of this template is to enable the user to define a picture field.
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* name string The field's name.
* description string The field's description.
* required bool The field's requiredness.
* param1 int The fields width in single view value.
* param2 int The fields height in single view value.
* param3 int The file's maximum size.
* param4 int The fields width in list view value.
* param5 int The fields height in list view value.
* filesizes array The field's file sizes.
Example context (json):
{
"name": "A name",
"description": "A description",
"required": true,
"param1": 100,
"param2": 200,
"param3": 67108864,
"param4": 300,
"param5": 400,
"options": [ { "name": "Site upload limit (64MB)", "value": "0", "selected": true },
{ "name": "64MB", "value": "67108864", "selected": false } ]
}
}}
<fieldset>
{{> mod_data/fields/basicfields }}
{{> mod_data/fields/requiredfield }}
<div class="form-group row fitem">
<div class="col-md-3">
<label for="param1">{{#str}}fieldwidthsingleview, data{{/str}}</label>
</div>
<div class="col-md-9 form-inline align-items-start felement">
<input class="picturefieldsize form-control" type="text" name="param1" id="param1" value="{{param1}}">
</div>
</div>
<div class="form-group row fitem">
<div class="col-md-3"><label for="param2">{{#str}}fieldheightsingleview, data{{/str}}</label>
</div>
<div class="col-md-9 form-inline align-items-start felement">
<input class="picturefieldsize form-control" type="text" name="param2" id="param2" value="{{param2}}">
</div>
</div>
<div class="form-group row fitem">
<div class="col-md-3"><label for="param4">{{#str}}fieldwidthlistview, data{{/str}}</label>
</div>
<div class="col-md-9 form-inline align-items-start felement">
<input class="picturefieldsize form-control" type="text" name="param4" id="param4" value="{{param4}}">
</div>
</div>
<div class="form-group row fitem">
<div class="col-md-3"><label for="param5">{{#str}}fieldheightlistview, data{{/str}}</label>
</div>
<div class="col-md-9 form-inline align-items-start felement">
<input class="picturefieldsize form-control" type="text" name="param5" id="param5" value="{{param5}}">
</div>
</div>
<div class="form-group row fitem">
<div class="col-md-3"><label for="param3" class="mb-0">
{{#str}}maxsize, data{{/str}}</label></div>
<div class="col-md-9 form-inline align-items-start felement">
<select id="param3" class="select custom-select form-control" name="param3">
{{#options}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/options}}
</select>
</div>
</div>
</fieldset>
+28
View File
@@ -0,0 +1,28 @@
<?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/>.
/**
* @package datafield
* @subpackage picture
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'datafield_picture'; // Full name of the plugin (used for diagnostics)
@@ -0,0 +1,71 @@
<?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/>.
/**
* Privacy Subsystem implementation for datafield_radiobutton.
*
* @package datafield_radiobutton
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace datafield_radiobutton\privacy;
use core_privacy\local\request\writer;
use mod_data\privacy\datafield_provider;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for datafield_radiobutton implementing null_provider.
*
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider,
datafield_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
/**
* Exports data about one record in {data_content} table.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
* @param \stdClass $defaultvalue pre-populated default value that most of plugins will use
*/
public static function export_data_content($context, $recordobj, $fieldobj, $contentobj, $defaultvalue) {
$defaultvalue->field['options'] = preg_split('/\s*\n\s*/', trim($fieldobj->param1), -1, PREG_SPLIT_NO_EMPTY);
writer::with_context($context)->export_data([$recordobj->id, $contentobj->id], $defaultvalue);
}
/**
* Allows plugins to delete locally stored data.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
*/
public static function delete_data_content($context, $recordobj, $fieldobj, $contentobj) {
}
}
+176
View File
@@ -0,0 +1,176 @@
<?php
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999-onwards Moodle Pty Ltd http://moodle.com //
// //
// This program 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 2 of the License, or //
// (at your option) any later version. //
// //
// This program 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: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
class data_field_radiobutton extends data_field_base {
var $type = 'radiobutton';
/**
* priority for globalsearch indexing
*
* @var int
*/
protected static $priority = self::HIGH_PRIORITY;
public function supports_preview(): bool {
return true;
}
public function get_data_content_preview(int $recordid): stdClass {
$options = explode("\n", $this->field->param1);
$options = array_map('trim', $options);
$selected = $options[$recordid % count($options)];
return (object)[
'id' => 0,
'fieldid' => $this->field->id,
'recordid' => $recordid,
'content' => $selected,
'content1' => null,
'content2' => null,
'content3' => null,
'content4' => null,
];
}
function display_add_field($recordid = 0, $formdata = null) {
global $CFG, $DB, $OUTPUT;
if ($formdata) {
$fieldname = 'field_' . $this->field->id;
if (isset($formdata->$fieldname)) {
$content = $formdata->$fieldname;
} else {
$content = '';
}
} else if ($recordid) {
$contentfield = $DB->get_field('data_content', 'content', ['fieldid' => $this->field->id, 'recordid' => $recordid]);
$content = trim($contentfield ?? '');
} else {
$content = '';
}
$str = '<div title="' . s($this->field->description) . '">';
$str .= '<fieldset><legend><span class="accesshide">' . s($this->field->name);
if ($this->field->required) {
$str .= '&nbsp;' . get_string('requiredelement', 'form') . '</span></legend>';
$image = $OUTPUT->pix_icon('req', get_string('requiredelement', 'form'));
$str .= html_writer::div($image, 'inline-req');
} else {
$str .= '</span></legend>';
}
$i = 0;
$requiredstr = '';
$options = explode("\n", $this->field->param1);
foreach ($options as $radio) {
$radio = trim($radio);
if ($radio === '') {
continue; // skip empty lines
}
$str .= '<input type="radio" id="field_'.$this->field->id.'_'.$i.'" name="field_' . $this->field->id . '" ';
$str .= 'value="' . s($radio) . '" class="mod-data-input mr-1" ';
if ($content == $radio) {
// Selected by user.
$str .= 'checked />';
} else {
$str .= '/>';
}
$str .= '<label for="field_'.$this->field->id.'_'.$i.'">'.$radio.'</label><br />';
$i++;
}
$str .= '</fieldset>';
$str .= '</div>';
return $str;
}
function display_search_field($value = '') {
global $CFG, $DB;
$varcharcontent = $DB->sql_compare_text('content', 255);
$used = $DB->get_records_sql(
"SELECT DISTINCT $varcharcontent AS content
FROM {data_content}
WHERE fieldid=?
ORDER BY $varcharcontent", array($this->field->id));
$options = array();
if(!empty($used)) {
foreach ($used as $rec) {
$options[$rec->content] = $rec->content; //Build following indicies from the sql.
}
}
$return = html_writer::label(get_string('fieldtypelabel', "datafield_" . $this->type),
'menuf_' . $this->field->id, false, array('class' => 'accesshide'));
$return .= html_writer::select($options, 'f_'.$this->field->id, $value,
array('' => 'choosedots'), array('class' => 'custom-select'));
return $return;
}
public function parse_search_field($defaults = null) {
$param = 'f_'.$this->field->id;
if (empty($defaults[$param])) {
$defaults = array($param => '');
}
return optional_param($param, $defaults[$param], PARAM_NOTAGS);
}
function generate_sql($tablealias, $value) {
global $DB;
static $i=0;
$i++;
$name = "df_radiobutton_$i";
$varcharcontent = $DB->sql_compare_text("{$tablealias}.content", 255);
return array(" ({$tablealias}.fieldid = {$this->field->id} AND $varcharcontent = :$name) ", array($name=>$value));
}
/**
* Check if a field from an add form is empty
*
* @param mixed $value
* @param mixed $name
* @return bool
*/
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;
}
}
@@ -0,0 +1,30 @@
<?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/>.
/**
* Strings for component 'datafield_radiobutton', language 'en', branch 'master'
*
* @package datafield
* @subpackage radiobutton
* @copyright 2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'Radio buttons';
$string['fieldtypelabel'] = 'Radio buttons';
$string['privacy:metadata'] = 'The Radio buttons field component doesn\'t store any personal data; it uses tables defined in mod_data.';
@@ -0,0 +1,54 @@
{{!
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/>.
}}
{{!
@template datafield_radiobutton/radiobutton
The purpose of this template is to enable the user to define a radiobutton field.
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* name string The field's name.
* description string The field's description.
* required bool The field's requiredness.
* param1 string The field's options.
Example context (json):
{
"name": "A name",
"description": "A description",
"required": true,
"param1": "One\nTwo\nThree"
}
}}
<fieldset>
{{> mod_data/fields/basicfields }}
{{> mod_data/fields/requiredfield }}
<div class="form-group row fitem">
<div class="col-md-3 col-form-label d-flex pb-0 pr-md-0">
<label for="param1">{{#str}}fieldoptions, data{{/str}}</label>
</div>
<div class="col-md-9 form-inline align-items-start felement">
<textarea class="optionstextarea form-control" name="param1" id="param1" cols="80" rows="10">{{param1}}</textarea>
</div>
</div>
</fieldset>
+28
View File
@@ -0,0 +1,28 @@
<?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/>.
/**
* @package datafield
* @subpackage radiobutton
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'datafield_radiobutton'; // Full name of the plugin (used for diagnostics)
@@ -0,0 +1,70 @@
<?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/>.
/**
* Privacy Subsystem implementation for datafield_text.
*
* @package datafield_text
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace datafield_text\privacy;
use core_privacy\local\request\writer;
use mod_data\privacy\datafield_provider;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for datafield_text implementing null_provider.
*
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider,
datafield_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
/**
* Exports data about one record in {data_content} table.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
* @param \stdClass $defaultvalue pre-populated default value that most of plugins will use
*/
public static function export_data_content($context, $recordobj, $fieldobj, $contentobj, $defaultvalue) {
writer::with_context($context)->export_data([$recordobj->id, $contentobj->id], $defaultvalue);
}
/**
* Allows plugins to delete locally stored data.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
*/
public static function delete_data_content($context, $recordobj, $fieldobj, $contentobj) {
}
}
+100
View File
@@ -0,0 +1,100 @@
<?php
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999-onwards Moodle Pty Ltd http://moodle.com //
// //
// This program 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 2 of the License, or //
// (at your option) any later version. //
// //
// This program 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: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
class data_field_text extends data_field_base {
var $type = 'text';
/**
* priority for globalsearch indexing
*
* @var int
*/
protected static $priority = self::MAX_PRIORITY;
public function supports_preview(): bool {
return true;
}
public function get_data_content_preview(int $recordid): stdClass {
return (object)[
'id' => 0,
'fieldid' => $this->field->id,
'recordid' => $recordid,
'content' => get_string('sample', 'datafield_text'),
'content1' => null,
'content2' => null,
'content3' => null,
'content4' => null,
];
}
function display_search_field($value = '') {
return '<label class="accesshide" for="f_' . $this->field->id . '">' . s($this->field->name) . '</label>' .
'<input type="text" class="form-control" size="16" id="f_' . $this->field->id . '" ' .
'name="f_' . $this->field->id . '" value="' . s($value) . '" />';
}
public function parse_search_field($defaults = null) {
$param = 'f_'.$this->field->id;
if (empty($defaults[$param])) {
$defaults = array($param => '');
}
return optional_param($param, $defaults[$param], PARAM_NOTAGS);
}
function generate_sql($tablealias, $value) {
global $DB;
static $i=0;
$i++;
$name = "df_text_$i";
return array(" ({$tablealias}.fieldid = {$this->field->id} AND ".$DB->sql_like("{$tablealias}.content", ":$name", false).") ", array($name=>"%$value%"));
}
/**
* Check if a field from an add form is empty
*
* @param mixed $value
* @param mixed $name
* @return bool
*/
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;
}
}
@@ -0,0 +1,30 @@
<?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/>.
/**
* Strings for component 'datafield_text', language 'en', branch 'master'
*
* @package datafield
* @subpackage text
* @copyright 2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'Short text';
$string['fieldtypelabel'] = 'Short text';
$string['privacy:metadata'] = 'The Short text field component doesn\'t store any personal data; it uses tables defined in mod_data.';
$string['sample'] = 'This is a short text';
@@ -0,0 +1,46 @@
{{!
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/>.
}}
{{!
@template datafield_text/autolink
The purpose of this template is to enable the user to define the 'auto link' field.
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* name string The field's name.
* description string The field's description.
Example context (json):
{
"param1": false
}
}}
<div class="form-group row fitem">
<div class="col-md-3 d-flex pb-0 pr-md-0">
<label for="param1" class="mb-0">{{#str}}fieldallowautolink, data{{/str}}</label>
</div>
<div class="col-md-9 form-inline align-items-start felement">
<input class="form-check-input" type="checkbox" name="param1" id="param1"
{{#param1}}checked="checked"{{/param1}}
value="1">
</div>
</div>
@@ -0,0 +1,47 @@
{{!
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/>.
}}
{{!
@template datafield_text/text
The purpose of this template is to enable the user to define a text field.
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* name string The field's name.
* description string The field's description.
* required bool The field's requiredness.
* param1 string The field's auto link value.
Example context (json):
{
"name": "A name",
"description": "A description",
"required": true,
"param1": 1
}
}}
<fieldset>
{{> mod_data/fields/basicfields }}
{{> mod_data/fields/requiredfield }}
{{> datafield_text/autolink }}
</fieldset>
+28
View File
@@ -0,0 +1,28 @@
<?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/>.
/**
* @package datafield
* @subpackage text
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'datafield_text'; // Full name of the plugin (used for diagnostics)
@@ -0,0 +1,85 @@
<?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/>.
/**
* Privacy Subsystem implementation for datafield_textarea.
*
* @package datafield_textarea
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace datafield_textarea\privacy;
use core_privacy\local\request\transform;
use core_privacy\local\request\writer;
use mod_data\privacy\datafield_provider;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for datafield_textarea implementing null_provider.
*
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider,
datafield_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
/**
* Exports data about one record in {data_content} table.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
* @param \stdClass $defaultvalue pre-populated default value that most of plugins will use
*/
public static function export_data_content($context, $recordobj, $fieldobj, $contentobj, $defaultvalue) {
$subcontext = [$recordobj->id, $contentobj->id];
$defaultvalue->content = writer::with_context($context)
->rewrite_pluginfile_urls($subcontext, 'mod_data', 'content', $contentobj->id,
$defaultvalue->content);
$defaultvalue->contentformat = $defaultvalue->content1;
unset($defaultvalue->content1);
$defaultvalue->field['autolink'] = transform::yesno($fieldobj->param1);
$defaultvalue->field['rows'] = $fieldobj->param3;
$defaultvalue->field['cols'] = $fieldobj->param2;
if ($fieldobj->param5) {
$defaultvalue->field['maxbytes'] = $fieldobj->param5;
}
writer::with_context($context)->export_data($subcontext, $defaultvalue);
}
/**
* Allows plugins to delete locally stored data.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
*/
public static function delete_data_content($context, $recordobj, $fieldobj, $contentobj) {
}
}
+351
View File
@@ -0,0 +1,351 @@
<?php
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999-onwards Moodle Pty Ltd http://moodle.com //
// //
// This program 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 2 of the License, or //
// (at your option) any later version. // // //
// This program 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: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot.'/lib/filelib.php');
require_once($CFG->dirroot.'/repository/lib.php');
class data_field_textarea extends data_field_base {
var $type = 'textarea';
/**
* priority for globalsearch indexing
*
* @var int
*/
protected static $priority = self::LOW_PRIORITY;
public function supports_preview(): bool {
return true;
}
public function get_data_content_preview(int $recordid): stdClass {
return (object)[
'id' => 0,
'fieldid' => $this->field->id,
'recordid' => $recordid,
'content' => get_string('sample', 'datafield_textarea'),
'content1' => 1,
'content2' => null,
'content3' => null,
'content4' => null,
];
}
/**
* Returns options for embedded files
*
* @return array
*/
private function get_options() {
if (!isset($this->field->param5)) {
$this->field->param5 = 0;
}
$options = array();
$options['trusttext'] = false;
$options['forcehttps'] = false;
$options['subdirs'] = false;
$options['maxfiles'] = -1;
$options['context'] = $this->context;
$options['maxbytes'] = $this->field->param5;
$options['changeformat'] = 0;
$options['noclean'] = false;
return $options;
}
function display_add_field($recordid = 0, $formdata = null) {
global $CFG, $DB, $OUTPUT, $PAGE;
$text = '';
$format = 0;
$str = '<div title="' . s($this->field->description) . '" class="d-inline-flex">';
$str .= '<label for="field_' . $this->field->id . '">';
$str .= html_writer::span($this->field->name, 'accesshide');
if ($this->field->required) {
$image = $OUTPUT->pix_icon('req', get_string('requiredelement', 'form'));
$str .= html_writer::div($image, 'inline-req');
}
$str .= '</label>';
editors_head_setup();
$options = $this->get_options();
$itemid = $this->field->id;
$field = 'field_'.$itemid;
if ($formdata) {
$fieldname = 'field_' . $this->field->id . '_content1';
if (isset($formdata->$fieldname)) {
$format = $formdata->$fieldname;
} else {
$format = file_get_unused_draft_itemid();
}
$fieldname = 'field_' . $this->field->id . '_itemid';
if (isset($formdata->$fieldname)) {
$draftitemid = clean_param($formdata->$fieldname, PARAM_INT);
} else {
$draftitemid = file_get_unused_draft_itemid();
}
$fieldname = 'field_' . $this->field->id;
if (isset($formdata->$fieldname)) {
$text = $formdata->$fieldname;
}
} else if ($recordid &&
$content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid))) {
$format = $content->content1;
$text = clean_text($content->content, $format);
$text = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_data', 'content', $content->id, $options, $text);
} else {
$draftitemid = file_get_unused_draft_itemid();
$format = editors_get_preferred_format();
}
// get filepicker info
//
$fpoptions = array();
if ($options['maxfiles'] != 0 ) {
$args = new stdClass();
// need these three to filter repositories list
$args->accepted_types = array('web_image');
$args->return_types = (FILE_INTERNAL | FILE_EXTERNAL);
$args->context = $this->context;
$args->env = 'filepicker';
// advimage plugin
$image_options = initialise_filepicker($args);
$image_options->context = $this->context;
$image_options->client_id = uniqid();
$image_options->maxbytes = $options['maxbytes'];
$image_options->env = 'editor';
$image_options->itemid = $draftitemid;
// moodlemedia plugin
$args->accepted_types = array('video', 'audio');
$media_options = initialise_filepicker($args);
$media_options->context = $this->context;
$media_options->client_id = uniqid();
$media_options->maxbytes = $options['maxbytes'];
$media_options->env = 'editor';
$media_options->itemid = $draftitemid;
// advlink plugin
$args->accepted_types = '*';
$link_options = initialise_filepicker($args);
$link_options->context = $this->context;
$link_options->client_id = uniqid();
$link_options->maxbytes = $options['maxbytes'];
$link_options->env = 'editor';
$link_options->itemid = $draftitemid;
// H5P plugin.
$args->accepted_types = ['h5p'];
$h5poptions = initialise_filepicker($args);
$h5poptions->context = $this->context;
$h5poptions->client_id = uniqid();
$h5poptions->maxbytes = $options['maxbytes'];
$h5poptions->env = 'editor';
$h5poptions->itemid = $draftitemid;
$fpoptions['image'] = $image_options;
$fpoptions['media'] = $media_options;
$fpoptions['link'] = $link_options;
$fpoptions['h5p'] = $h5poptions;
}
$editor = editors_get_preferred_editor($format);
$strformats = format_text_menu();
$formats = $editor->get_supported_formats();
foreach ($formats as $fid) {
$formats[$fid] = $strformats[$fid];
}
$editor->set_text($text);
$editor->use_editor($field, $options, $fpoptions);
$str .= '<input type="hidden" name="'.$field.'_itemid" value="'.s($draftitemid).'" />';
$str .= '<div class="mod-data-input">';
$str .= '<div><textarea id="'.$field.'" name="'.$field.'" rows="'.$this->field->param3.'" class="form-control" ' .
'data-fieldtype="editor" ' .
'cols="'.$this->field->param2.'" spellcheck="true">'.s($text).'</textarea></div>';
$str .= '<div><label class="accesshide" for="' . $field . '_content1">' . get_string('format') . '</label>';
$str .= '<select id="' . $field . '_content1" name="'.$field.'_content1">';
foreach ($formats as $key=>$desc) {
$selected = ($format == $key) ? 'selected="selected"' : '';
$str .= '<option value="'.s($key).'" '.$selected.'>'.$desc.'</option>';
}
$str .= '</select>';
$str .= '</div>';
$str .= '</div>';
$str .= '</div>';
return $str;
}
function display_search_field($value = '') {
return '<label class="accesshide" for="f_' . $this->field->id . '">' . s($this->field->name) . '</label>' .
'<input type="text" size="16" id="f_' . $this->field->id . '" name="f_' . $this->field->id . '" ' .
'value="' . s($value) . '" class="form-control"/>';
}
public function parse_search_field($defaults = null) {
$param = 'f_'.$this->field->id;
if (empty($defaults[$param])) {
$defaults = array($param => '');
}
return optional_param($param, $defaults[$param], PARAM_NOTAGS);
}
function generate_sql($tablealias, $value) {
global $DB;
static $i=0;
$i++;
$name = "df_textarea_$i";
return array(" ({$tablealias}.fieldid = {$this->field->id} AND ".$DB->sql_like("{$tablealias}.content", ":$name", false).") ", array($name=>"%$value%"));
}
function print_after_form() {
}
function update_content($recordid, $value, $name='') {
global $DB;
$content = new stdClass();
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
$names = explode('_', $name);
if (!empty($names[2])) {
if ($names[2] == 'itemid') {
// the value will be retrieved by file_get_submitted_draft_itemid, do not need to save in DB
return true;
} else {
$content->{$names[2]} = clean_param($value, PARAM_NOTAGS); // content[1-4]
}
} else {
$content->content = clean_param($value, PARAM_CLEAN);
}
if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$content->id = $oldcontent->id;
} else {
$content->id = $DB->insert_record('data_content', $content);
if (!$content->id) {
return false;
}
}
if (!empty($content->content)) {
$draftitemid = file_get_submitted_draft_itemid('field_'. $this->field->id. '_itemid');
$options = $this->get_options();
$content->content = file_save_draft_area_files($draftitemid, $this->context->id, 'mod_data', 'content', $content->id, $options, $content->content);
}
$rv = $DB->update_record('data_content', $content);
return $rv;
}
/**
* Display the content of the field in browse mode
*
* @param int $recordid
* @param object $template
* @return bool|string
*/
function display_browse_field($recordid, $template) {
$content = $this->get_data_content($recordid);
if (!$content || !isset($content->content)) {
return '';
}
$options = new stdClass();
if ($this->field->param1 == '1') { // We are autolinking this field, so disable linking within us.
$options->filter = false;
}
$options->para = false;
$str = file_rewrite_pluginfile_urls(
$content->content,
'pluginfile.php',
$this->context->id,
'mod_data',
'content',
$content->id,
$this->get_options()
);
$str = format_text($str, $content->content1, $options);
return '<div class="data-field-html">' . $str . '</div>';
}
/**
* Whether this module support files
*
* @param string $relativepath
* @return bool
*/
function file_ok($relativepath) {
return true;
}
/**
* Only look at the first item (second is format)
*
* @param string $value
* @param string $name
* @return bool
*/
function notemptyfield($value, $name) {
$names = explode('_', $name);
// Clean first.
if (count($names) == 2) {
// Don't assume that this is coming from a text editor with tags.
return strval($value) !== '';
}
return false;
}
/**
* Returns the presentable string value for a field content.
*
* The returned string should be plain text.
*
* @param stdClass $content
* @return string
*/
public static function get_content_value($content) {
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;
}
}
@@ -0,0 +1,32 @@
<?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/>.
/**
* Strings for component 'datafield_textarea', language 'en', branch 'master'
*
* @package datafield
* @subpackage textarea
* @copyright 2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['maxbytes'] = 'Maximum embedded file size (bytes)';
$string['maxbytes_desc'] = 'If set to zero will be unlimited by default';
$string['pluginname'] = 'Text area';
$string['fieldtypelabel'] = 'Text area';
$string['privacy:metadata'] = 'The Text area field component doesn\'t store any personal data; it uses tables defined in mod_data.';
$string['sample'] = '<p>This is a text area. It lets users enter long form text which spans over multiple lines.</p><p>You can choose the size of your text areas in rows and columns.</p><p>The text in a text area can be formatted, for example in <strong>bold</strong>, and also include <a href="#">links</a> or images.</p>';
@@ -0,0 +1,75 @@
{{!
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/>.
}}
{{!
@template datafield_textarea/textarea
The purpose of this template is to enable the user to define a textarea field.
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* name string The field's name.
* description string The field's description.
* required bool The field's requiredness.
* param2 int The field's width in columns.
* param3 int The field's height in rows.
* param5 int The field's attached files maxsize.
Example context (json):
{
"name": "A name",
"description": "A description",
"required": true,
"param2": 60,
"param3": 35,
"param5": 4096
}
}}
<fieldset>
{{> mod_data/fields/basicfields }}
{{> mod_data/fields/requiredfield }}
<div class="form-group row fitem">
<div class="col-md-3">
<label for="param2">{{#str}}fieldwidth, data{{/str}}</label>
</div>
<div class="col-md-9 form-inline align-items-start felement">
<input class="textareafieldsize form-control mr-1" type="text" name="param2" id="param2" value="{{#param2}}{{param2}}{{/param2}}{{^param2}}60{{/param2}}">
{{#str}}columns, data{{/str}}</div>
</div>
<div class="form-group row fitem">
<div class="col-md-3">
<label for="param3">{{#str}}fieldheight, data{{/str}}</label>
</div>
<div class="col-md-9 form-inline align-items-start felement">
<input class="textareafieldsize form-control mr-1" type="text" name="param3" id="param3" value="{{#param3}}{{param3}}{{/param3}}{{^param3}}35{{/param3}}">
{{#str}}rows, data{{/str}}</div>
</div>
<div class="form-group row fitem">
<div class="col-md-3">
<label for="param5">{{#str}}maxbytes, datafield_textarea{{/str}}</label>
</div>
<div class="col-md-9 form-inline align-items-start felement">
<input class="c1 form-control mr-1" type="text" name="param5" id="param5" value="{{#param5}}{{param5}}{{/param5}}{{^param5}}0{{/param5}}">
{{#str}}maxbytes_desc, datafield_textarea{{/str}}</div>
</div>
<input type="hidden" name="param4" id="param4" value="1"/>
</fieldset>
+28
View File
@@ -0,0 +1,28 @@
<?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/>.
/**
* @package datafield
* @subpackage textarea
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'datafield_textarea'; // Full name of the plugin (used for diagnostics)
@@ -0,0 +1,80 @@
<?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/>.
/**
* Privacy Subsystem implementation for datafield_url.
*
* @package datafield_url
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace datafield_url\privacy;
use core_privacy\local\request\transform;
use core_privacy\local\request\writer;
use mod_data\privacy\datafield_provider;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for datafield_url implementing null_provider.
*
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider,
datafield_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
/**
* Exports data about one record in {data_content} table.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
* @param \stdClass $defaultvalue pre-populated default value that most of plugins will use
*/
public static function export_data_content($context, $recordobj, $fieldobj, $contentobj, $defaultvalue) {
$defaultvalue->field['autolink'] = transform::yesno($fieldobj->param1);
if (!empty($fieldobj->param2)) {
$defaultvalue->field['forcetext'] = $fieldobj->param2;
}
$defaultvalue->field['blanktarget'] = transform::yesno($fieldobj->param3);
$defaultvalue->url = $contentobj->content;
$defaultvalue->text = $contentobj->content1;
unset($defaultvalue->content);
unset($defaultvalue->content1);
writer::with_context($context)->export_data([$recordobj->id, $contentobj->id], $defaultvalue);
}
/**
* Allows plugins to delete locally stored data.
*
* @param \context_module $context
* @param \stdClass $recordobj record from DB table {data_records}
* @param \stdClass $fieldobj record from DB table {data_fields}
* @param \stdClass $contentobj record from DB table {data_content}
*/
public static function delete_data_content($context, $recordobj, $fieldobj, $contentobj) {
}
}
+263
View File
@@ -0,0 +1,263 @@
<?php
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999-onwards Moodle Pty Ltd http://moodle.com //
// //
// This program 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 2 of the License, or //
// (at your option) any later version. //
// //
// This program 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: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
class data_field_url extends data_field_base {
var $type = 'url';
/**
* priority for globalsearch indexing
*
* @var int
*/
protected static $priority = self::MIN_PRIORITY;
public function supports_preview(): bool {
return true;
}
public function get_data_content_preview(int $recordid): stdClass {
return (object)[
'id' => 0,
'fieldid' => $this->field->id,
'recordid' => $recordid,
'content' => 'https://example.com',
'content1' => null,
'content2' => null,
'content3' => null,
'content4' => null,
];
}
function display_add_field($recordid = 0, $formdata = null) {
global $CFG, $DB, $OUTPUT, $PAGE;
require_once($CFG->dirroot. '/repository/lib.php'); // necessary for the constants used in args
$args = new stdClass();
$args->accepted_types = '*';
$args->return_types = FILE_EXTERNAL;
$args->context = $this->context;
$args->env = 'url';
$fp = new file_picker($args);
$options = $fp->options;
$fieldid = 'field_url_'.$options->client_id;
$straddlink = get_string('choosealink', 'repository');
$url = '';
$text = '';
if ($formdata) {
$fieldname = 'field_' . $this->field->id . '_0';
$url = $formdata->$fieldname;
$fieldname = 'field_' . $this->field->id . '_1';
if (isset($formdata->$fieldname)) {
$text = $formdata->$fieldname;
}
} else if ($recordid) {
if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$url = $content->content;
$text = $content->content1;
}
}
$autolinkable = !empty($this->field->param1) && empty($this->field->param2);
$str = '<div title="' . s($this->field->description) . '" class="d-flex flex-wrap align-items-center">';
$label = '<label for="' . $fieldid . '"><span class="accesshide">' . $this->field->name . '</span>';
if ($this->field->required) {
$image = $OUTPUT->pix_icon('req', get_string('requiredelement', 'form'));
if ($autolinkable) {
$label .= html_writer::div(get_string('requiredelement', 'form'), 'accesshide');
} else {
$label .= html_writer::div($image, 'inline-req');
}
}
$label .= '</label>';
if ($autolinkable) {
$str .= '<table><tr><td align="right">';
$str .= '<span class="mod-data-input">' . get_string('url', 'data') . ':</span>';
if (!empty($image)) {
$str .= $image;
}
$str .= '</td><td>';
$str .= $label;
$str .= '<input type="text" name="field_' . $this->field->id . '_0" id="' . $fieldid . '" value="' . s($url) . '" ' .
'size="40" class="form-control d-inline"/>';
$str .= '<button class="btn btn-secondary ml-1" id="filepicker-button-' . $options->client_id . '" ' .
'style="display:none">' . $straddlink . '</button></td></tr>';
$str .= '<tr><td align="right"><span class="mod-data-input">' . get_string('text', 'data') . ':</span></td><td>';
$str .= '<input type="text" name="field_' . $this->field->id . '_1" id="field_' . $this->field->id . '_1" ' .
'value="' . s($text) . '" size="40" class="form-control d-inline"/></td></tr>';
$str .= '</table>';
} else {
// Just the URL field
$str .= $label;
$str .= '<input type="text" name="field_'.$this->field->id.'_0" id="'.$fieldid.'" value="'.s($url).'"';
$str .= ' size="40" class="mod-data-input form-control d-inline" />';
if (count($options->repositories) > 0) {
$str .= '<button id="filepicker-button-' . $options->client_id . '" class="visibleifjs btn btn-secondary ml-1">' .
$straddlink . '</button>';
}
}
// print out file picker
//$str .= $OUTPUT->render($fp);
$module = array('name'=>'data_urlpicker', 'fullpath'=>'/mod/data/data.js', 'requires'=>array('core_filepicker'));
$PAGE->requires->js_init_call('M.data_urlpicker.init', array($options), true, $module);
$str .= '</div>';
return $str;
}
function display_search_field($value = '') {
return '<label class="accesshide" for="f_' . $this->field->id . '">' . get_string('fieldname', 'data') . '</label>' .
'<input type="text" size="16" id="f_' . $this->field->id . '" '.
' name="f_' . $this->field->id . '" value="' . s($value) . '" class="form-control d-inline"/>';
}
public function parse_search_field($defaults = null) {
$param = 'f_'.$this->field->id;
if (empty($defaults[$param])) {
$defaults = array($param => '');
}
return optional_param($param, $defaults[$param], PARAM_NOTAGS);
}
function generate_sql($tablealias, $value) {
global $DB;
static $i=0;
$i++;
$name = "df_url_$i";
return array(" ({$tablealias}.fieldid = {$this->field->id} AND ".$DB->sql_like("{$tablealias}.content", ":$name", false).") ", array($name=>"%$value%"));
}
function display_browse_field($recordid, $template) {
$content = $this->get_data_content($recordid);
if (!$content) {
return '';
}
$url = empty($content->content) ? '' : $content->content;
$text = empty($content->content1) ? '' : $content->content1;
if (empty($url) || ($url == 'http://')) {
return '';
}
if (!empty($this->field->param2)) {
// Param2 forces the text to something.
$text = $this->field->param2;
}
if ($this->field->param1) {
// Param1 defines whether we want to autolink the url.
$attributes = ['class' => 'data-field-link'];
if ($this->field->param3) {
// Param3 defines whether this URL should open in a new window.
$attributes['target'] = '_blank';
$attributes['rel'] = 'noreferrer';
}
if (empty($text)) {
$text = $url;
}
$str = html_writer::link($url, $text, $attributes);
} else {
$str = $url;
}
return $str;
}
function update_content_import($recordid, $value, $name='') {
$values = explode(" ", $value, 2);
foreach ($values as $index => $value) {
$this->update_content($recordid, $value, $name . '_' . $index);
}
}
function update_content($recordid, $value, $name='') {
global $DB;
$content = new stdClass();
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
$names = explode('_', $name);
switch ($names[2]) {
case 0:
// update link
$content->content = clean_param($value, PARAM_URL);
break;
case 1:
// add text
$content->content1 = clean_param($value, PARAM_NOTAGS);
break;
default:
break;
}
if (!empty($content->content) && (strpos($content->content, '://') === false)
&& (strpos($content->content, '/') !== 0)) {
$content->content = 'http://' . $content->content;
}
if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$content->id = $oldcontent->id;
return $DB->update_record('data_content', $content);
} else {
return $DB->insert_record('data_content', $content);
}
}
function notemptyfield($value, $name) {
$names = explode('_',$name);
$value = clean_param($value, PARAM_URL);
//clean first
if ($names[2] == '0') {
return ($value!='http://' && !empty($value));
}
return false;
}
function export_text_value($record) {
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;
}
}
@@ -0,0 +1,30 @@
<?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/>.
/**
* Strings for component 'datafield_url', language 'en', branch 'master'
*
* @package datafield
* @subpackage url
* @copyright 2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'URL';
$string['openlinkinnewwindow'] = 'Open link in new window';
$string['fieldtypelabel'] = 'URL';
$string['privacy:metadata'] = 'The URL field component doesn\'t store any personal data; it uses tables defined in mod_data.';
+76
View File
@@ -0,0 +1,76 @@
{{!
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/>.
}}
{{!
@template datafield_url/url
The purpose of this template is to enable the user to define a URL field.
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* name string The field's name.
* description string The field's description.
* required bool The field's requiredness.
* param1 string The field's auto link value.
* param3 string The field's open link in new window value.
* param2 string The field's forced link name.
Example context (json):
{
"name": "A name",
"description": "A description",
"required": true,
"param1": 1,
"param3": 1,
"param2": "Link"
}
}}
<fieldset>
{{> mod_data/fields/basicfields }}
<div class="form-group row fitem">
<div class="col-md-3 d-flex pb-0 pr-md-0">
<label for="required" class="mb-0">{{#str}}autolinkurl, data{{/str}}</label>
</div>
<div class="col-md-9 form-inline align-items-start felement">
<input class="requiredfield form-check-input" type="checkbox" name="param1" id="param1" {{#param1}}
checked="checked" {{/param1}}>
</div>
</div>
{{> mod_data/fields/requiredfield }}
<div class="form-group row fitem">
<div class="col-md-3 d-flex pb-0 pr-md-0">
<label for="param3">{{#str}}openlinkinnewwindow, datafield_url{{/str}}</label>
</div>
<div class="col-md-9 form-inline align-items-start felement">
<input class="requiredfield form-check-input" type="checkbox" name="param3" id="param3" {{#param3}}
checked="checked" {{/param3}}>
</div>
</div>
<div class="form-group row fitem">
<div class="col-md-3 col-form-label">
<label for="forcelinkname">{{#str}}forcelinkname, data{{/str}}</label>
</div>
<div class="col-md-9 form-inline align-items-start felement">
<input class="forcelinkname form-control" type="text" name="param2" id="forcelinkname" value="{{param2}}">
</div>
</div>
</fieldset>
+28
View File
@@ -0,0 +1,28 @@
<?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/>.
/**
* @package datafield
* @subpackage url
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'datafield_url'; // Full name of the plugin (used for diagnostics)