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,136 @@
<?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/>.
/**
* Calendar action event class.
*
* @package core_calendar
* @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_calendar\local\event\entities;
defined('MOODLE_INTERNAL') || die();
use core_calendar\local\event\factories\action_factory_interface;
/**
* Class representing an actionable event.
*
* An actionable event can be thought of as an embellished event. That is,
* it does everything a regular event does, but has some extra information
* attached to it. For example, the URL a user needs to visit to complete
* an action, the number of actionable items, etc.
*
* @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class action_event implements action_event_interface {
/**
* @var event_interface $event The event to delegate to.
*/
protected $event;
/**
* @var action_interface $action The action associated with this event.
*/
protected $action;
/**
* @var proxy_interface $category Category for this event.
*/
protected $category;
/**
* Constructor.
*
* @param event_interface $event The event to delegate to.
* @param action_interface $action The action associated with this event.
*/
public function __construct(event_interface $event, action_interface $action) {
$this->event = $event;
$this->action = $action;
}
public function get_id() {
return $this->event->get_id();
}
public function get_name() {
return $this->event->get_name();
}
public function get_description() {
return $this->event->get_description();
}
public function get_location() {
return $this->event->get_location();
}
public function get_category() {
return $this->event->get_category();
}
public function get_course() {
return $this->event->get_course();
}
public function get_course_module() {
return $this->event->get_course_module();
}
public function get_group() {
return $this->event->get_group();
}
public function get_user() {
return $this->event->get_user();
}
public function get_type() {
return $this->event->get_type();
}
public function get_times() {
return $this->event->get_times();
}
public function get_repeats() {
return $this->event->get_repeats();
}
public function get_subscription() {
return $this->event->get_subscription();
}
public function is_visible() {
return $this->event->is_visible();
}
public function get_action() {
return $this->action;
}
/**
* Event component
* @return string
*/
public function get_component() {
return $this->event->get_component();
}
}
@@ -0,0 +1,42 @@
<?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/>.
/**
* Calendar action event interface.
*
* @package core_calendar
* @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_calendar\local\event\entities;
defined('MOODLE_INTERNAL') || die();
/**
* Interface for an action event class.
*
* @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
interface action_event_interface extends event_interface {
/**
* Get the action event's action.
*
* @return action_interface
*/
public function get_action();
}
@@ -0,0 +1,63 @@
<?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/>.
/**
* Action interface.
*
* @package core_calendar
* @copyright 2017 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_calendar\local\event\entities;
defined('MOODLE_INTERNAL') || die();
/**
* Interface for a action class.
*
* @copyright 2017 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
interface action_interface {
/**
* Get the name of the action.
*
* @return string
*/
public function get_name();
/**
* Get the URL of the action.
*
* @return \moodle_url
*/
public function get_url();
/**
* Get the number of items that need actioning.
*
* @return int
*/
public function get_item_count();
/**
* Get the actions actionability.
*
* @return bool
*/
public function is_actionable();
}
@@ -0,0 +1,231 @@
<?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/>.
/**
* Calendar event class.
*
* @package core_calendar
* @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_calendar\local\event\entities;
defined('MOODLE_INTERNAL') || die();
use core_calendar\local\event\proxies\proxy_interface;
use core_calendar\local\event\value_objects\description_interface;
use core_calendar\local\event\value_objects\times_interface;
/**
* Class representing a calendar event.
*
* @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class event implements event_interface {
/**
* @var int $id The event's id in the database.
*/
protected $id;
/**
* @var string $name The name of this event.
*/
protected $name;
/**
* @var description_interface $description Description for this event.
*/
protected $description;
/**
* @var string $location Location of this event.
*/
protected $location;
/**
* @var proxy_interface $category Category for this event.
*/
protected $category;
/**
* @var proxy_interface $course Course for this event.
*/
protected $course;
/**
* @var proxy_interface $group Group for this event.
*/
protected $group;
/**
* @var proxy_interface $user User for this event.
*/
protected $user;
/**
* @var event_collection_interface $repeats Collection of repeat events.
*/
protected $repeats;
/**
* @var proxy_interface $coursemodule The course module that created this event.
*/
protected $coursemodule;
/**
* @var string type The type of this event.
*/
protected $type;
/**
* @var times_interface $times The times for this event.
*/
protected $times;
/**
* @var bool $visible The visibility of this event.
*/
protected $visible;
/**
* @var string $component
*/
protected $component;
/**
* @var proxy_interface $subscription Subscription for this event.
*/
protected $subscription;
/**
* Constructor.
*
* @param int $id The event's ID in the database.
* @param string $name The event's name.
* @param description_interface $description The event's description.
* @param proxy_interface|null $category The category associated with the event.
* @param proxy_interface|null $course The course associated with the event.
* @param proxy_interface|null $group The group associated with the event.
* @param proxy_interface|null $user The user associated with the event.
* @param event_collection_interface|null $repeats Collection of repeat events.
* @param proxy_interface|null $coursemodule The course module that created the event.
* @param string $type The event's type.
* @param times_interface $times The times associated with the event.
* @param bool $visible The event's visibility. True for visible, false for invisible.
* @param proxy_interface|null $subscription The event's subscription.
* @param string $location The event's location.
* @param string $component The event's component.
*/
public function __construct(
$id,
$name,
description_interface $description,
?proxy_interface $category,
?proxy_interface $course,
?proxy_interface $group,
?proxy_interface $user,
?event_collection_interface $repeats,
?proxy_interface $coursemodule,
$type,
times_interface $times,
$visible,
proxy_interface $subscription = null,
$location = null,
$component = null
) {
$this->id = $id;
$this->name = $name;
$this->description = $description;
$this->location = $location;
$this->category = $category;
$this->course = $course;
$this->group = $group;
$this->user = $user;
$this->repeats = $repeats;
$this->coursemodule = $coursemodule;
$this->type = $type;
$this->times = $times;
$this->visible = $visible;
$this->subscription = $subscription;
$this->component = $component;
}
public function get_id() {
return $this->id;
}
public function get_name() {
return $this->name;
}
public function get_description() {
return $this->description;
}
public function get_location() {
return $this->location;
}
public function get_category() {
return $this->category;
}
public function get_course() {
return $this->course;
}
public function get_course_module() {
return $this->coursemodule;
}
public function get_group() {
return $this->group;
}
public function get_user() {
return $this->user;
}
public function get_type() {
return $this->type;
}
public function get_times() {
return $this->times;
}
public function get_repeats() {
return $this->repeats;
}
public function get_subscription() {
return $this->subscription;
}
public function is_visible() {
return $this->visible;
}
/**
* Resolved event component (frankenstyle name of activity module or the component)
* @return string|null
*/
public function get_component() {
return $this->get_course_module() ? 'mod_' . $this->get_course_module()->get('modname') : $this->component;
}
}
@@ -0,0 +1,49 @@
<?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/>.
/**
* Interface for an event collection class.
*
* @package core_calendar
* @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_calendar\local\event\entities;
defined('MOODLE_INTERNAL') || die();
/**
* Interface for an event collection class.
*
* @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
interface event_collection_interface extends \IteratorAggregate {
/**
* Get the event collection's ID.
*
* @return int
*/
public function get_id();
/**
* Get the total number of repeats in the collection.
*
* @return int
*/
public function get_num();
}
@@ -0,0 +1,142 @@
<?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/>.
/**
* Calendar event interface.
*
* @package core_calendar
* @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_calendar\local\event\entities;
use core_calendar\local\event\proxies\proxy_interface;
defined('MOODLE_INTERNAL') || die();
/**
* Interface for an event class.
*
* @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
interface event_interface {
/**
* Get the event's ID.
*
* @return integer
*/
public function get_id();
/**
* Get the event's name.
*
* @return string
*/
public function get_name();
/**
* Get the event's description.
*
* @return description_interface
*/
public function get_description();
/**
* Get the event's location.
*
* @return location_interface
*/
public function get_location();
/**
* Get the category object associated with the event.
*
* @return proxy_interface
*/
public function get_category();
/**
* Get the course object associated with the event.
*
* @return proxy_interface
*/
public function get_course();
/**
* Get the course module object that created the event.
*
* @return proxy_interface
*/
public function get_course_module();
/**
* Get the group object associated with the event.
*
* @return proxy_interface
*/
public function get_group();
/**
* Get the user object associated with the event.
*
* @return proxy_interface
*/
public function get_user();
/**
* Get the event's type.
*
* @return string
*/
public function get_type();
/**
* Get the times associated with the event.
*
* @return times_interface
*/
public function get_times();
/**
* Get repeats of this event or null if the event has no
* repeats.
*
* @return event_collection_interface|null
*/
public function get_repeats();
/**
* Get the event's subscription.
*
* @return proxy_interface
*/
public function get_subscription();
/**
* Get the event's visibility.
*
* @return bool true if the event is visible, false otherwise
*/
public function is_visible();
/**
* Resolved event component (frankenstyle name of activity module or the component)
* @return string|null
*/
public function get_component();
}
@@ -0,0 +1,151 @@
<?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/>.
/**
* Event collection class.
*
* @package core_calendar
* @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_calendar\local\event\entities;
defined('MOODLE_INTERNAL') || die();
use core_calendar\local\event\factories\event_factory_interface;
/**
* Class representing a collection of repeat events.
*
* @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class repeat_event_collection implements event_collection_interface {
/**
* @var int DB_QUERY_LIMIT How many records to pull from the DB at once.
*/
const DB_QUERY_LIMIT = 100;
/**
* @var int $parentid The ID of the event which the events in this collection are repeats of.
*/
protected $parentid;
/**
* @var \stdClass $parentrecord The parent event record from the database.
*/
protected $parentrecord;
/**
* @var event_factory_interface $factory Event factory.
*/
protected $factory;
/**
* @var int $num Total number of events that could be retrieved by this collection.
*/
protected $num;
/**
* Constructor.
*
* @param stdClass $dbrow The event dbrow that is being repeated.
* @param event_factory_interface $factory Event factory.
*/
public function __construct($dbrow, event_factory_interface $factory) {
$eventid = $dbrow->id;
$repeatid = $dbrow->repeatid;
if (empty($repeatid)) {
$this->parentrecord = $dbrow;
$this->parentid = $eventid;
} else {
$this->parentid = $repeatid;
}
if ($eventid === $repeatid) {
// This means the record we've been given is the parent
// record.
$this->parentrecord = $dbrow;
}
$this->factory = $factory;
}
public function get_id() {
return $this->parentid;
}
public function get_num() {
global $DB;
// Subtract one because the original event has repeatid = its own id.
return $this->num = max(
isset($this->num) ? $this->num : ($DB->count_records('event', ['repeatid' => $this->parentid]) - 1),
0
);
}
public function getIterator(): \Traversable {
$parentrecord = $this->get_parent_record();
foreach ($this->load_event_records() as $eventrecords) {
foreach ($eventrecords as $eventrecord) {
// In the case of the repeat event having unset information, fallback on the parent.
yield $this->factory->create_instance((object)array_merge((array)$parentrecord, (array)$eventrecord));
}
}
}
/**
* Return the parent DB record.
*
* @return \stdClass
*/
protected function get_parent_record() {
global $DB;
if (!isset($this->parentrecord)) {
$this->parentrecord = $DB->get_record('event', ['id' => $this->parentid]);
}
return $this->parentrecord;
}
/**
* Generate more event records.
*
* @param int $start Start offset.
* @return \stdClass[]
*/
protected function load_event_records($start = 0) {
global $DB;
while ($records = $DB->get_records_select(
'event',
'id <> :parentid AND repeatid = :repeatid',
[
'parentid' => $this->parentid,
'repeatid' => $this->parentid,
],
'id ASC',
'*',
$start,
self::DB_QUERY_LIMIT
)) {
yield $records;
$start += self::DB_QUERY_LIMIT;
}
}
}