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_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)