MDL-57599 core_calendar: Add action event class
This patch adds a "regular" calendar event class, and a simple extension of it which we are calling an action event. Part of MDL-55611 epic.
This commit is contained in:
committed by
Damyon Wiese
parent
f7ce6eab7e
commit
e46efe3a72
@@ -0,0 +1,117 @@
|
||||
<?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 <[email protected]>
|
||||
* @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\interfaces\action_event_interface;
|
||||
use core_calendar\local\interfaces\action_interface;
|
||||
use core_calendar\local\interfaces\event_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 <[email protected]>
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* 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_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_id() {
|
||||
return $this->event->get_subscription_id();
|
||||
}
|
||||
|
||||
public function is_visible() {
|
||||
return $this->event->is_visible();
|
||||
}
|
||||
|
||||
public function get_action() {
|
||||
return $this->action;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
<?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 <[email protected]>
|
||||
* @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\interfaces\event_collection_interface;
|
||||
use core_calendar\local\interfaces\event_interface;
|
||||
use core_calendar\local\interfaces\proxy_interface;
|
||||
use core_calendar\local\interfaces\description_interface;
|
||||
use core_calendar\local\interfaces\times_interface;
|
||||
|
||||
/**
|
||||
* Class representing a calendar event.
|
||||
*
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @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 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 int $subscriptionid The event's subscription ID.
|
||||
*/
|
||||
protected $subscriptionid;
|
||||
|
||||
/**
|
||||
* 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 $course The course associated with the event.
|
||||
* @param proxy_interface $group The group associated with the event.
|
||||
* @param proxy_interface $user The user associated with the event.
|
||||
* @param event_collection_interface $repeats Collection of repeat events.
|
||||
* @param proxy_interface $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 int $subscriptionid The event's subscription ID.
|
||||
*/
|
||||
public function __construct(
|
||||
$id,
|
||||
$name,
|
||||
description_interface $description,
|
||||
proxy_interface $course = null,
|
||||
proxy_interface $group = null,
|
||||
proxy_interface $user = null,
|
||||
event_collection_interface $repeats,
|
||||
proxy_interface $coursemodule = null,
|
||||
$type,
|
||||
times_interface $times,
|
||||
$visible,
|
||||
$subscriptionid
|
||||
) {
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
$this->description = $description;
|
||||
$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->subscriptionid = $subscriptionid;
|
||||
}
|
||||
|
||||
public function get_id() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function get_name() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function get_description() {
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
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_id() {
|
||||
return $this->subscriptionid;
|
||||
}
|
||||
|
||||
public function is_visible() {
|
||||
return $this->visible;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
<?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 <[email protected]>
|
||||
* @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\interfaces\event_collection_interface;
|
||||
use core_calendar\local\interfaces\event_factory_interface;
|
||||
use core_calendar\local\interfaces\event_interface;
|
||||
use core_calendar\local\event\exceptions\no_repeat_parent_exception;
|
||||
|
||||
/**
|
||||
* Class representing a collection of repeat events.
|
||||
*
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class repeat_event_collection implements event_collection_interface {
|
||||
/**
|
||||
* @var 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 int $parentid ID of the parent event.
|
||||
* @param event_factory_interface $factory Event factory.
|
||||
* @throws no_repeat_parent_exception If the parent record can't be loaded.
|
||||
*/
|
||||
public function __construct($parentid, event_factory_interface $factory) {
|
||||
$this->parentid = $parentid;
|
||||
$this->factory = $factory;
|
||||
|
||||
if (!$this->get_parent_record()) {
|
||||
throw new no_repeat_parent_exception(sprintf('No record found for id %d', $parentid));
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
$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(
|
||||
$eventrecord->id,
|
||||
!empty($eventrecord->name) ? $eventrecord->name : $parentrecord->name,
|
||||
!empty($eventrecord->description) ? $eventrecord->description : $parentrecord->description,
|
||||
!empty($eventrecord->format) ? $eventrecord->format : $parentrecord->format,
|
||||
!empty($eventrecord->courseid) ? $eventrecord->courseid : $parentrecord->courseid,
|
||||
!empty($eventrecord->groupid) ? $eventrecord->groupid : $parentrecord->groupid,
|
||||
!empty($eventrecord->userid) ? $eventrecord->userid : $parentrecord->userid,
|
||||
!empty($eventrecord->repeatid) ? $eventrecord->repeatid : $parentrecord->repeatid,
|
||||
!empty($eventrecord->modulename) ? $eventrecord->modulename : $parentrecord->modulename,
|
||||
!empty($eventrecord->instance) ? $eventrecord->instance : $parentrecord->instance,
|
||||
!empty($eventrecord->eventtype) ? $eventrecord->eventtype : $parentrecord->eventtype,
|
||||
!empty($eventrecord->timestart) ? $eventrecord->timestart : $parentrecord->timestart,
|
||||
!empty($eventrecord->timeduration) ? $eventrecord->timeduration : $parentrecord->timeduration,
|
||||
!empty($eventrecord->timemodified) ? $eventrecord->timemodified : $parentrecord->timemodified,
|
||||
!empty($eventrecord->timesort) ? $eventrecord->timesort : $parentrecord->timesort,
|
||||
!empty($eventrecord->visible) ? $eventrecord->visible : $parentrecord->visible,
|
||||
!empty($eventrecord->subscriptionid) ? $eventrecord->subscriptionid : $parentrecord->subscriptionid
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the parent DB record.
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
protected function get_parent_record() {
|
||||
global $DB;
|
||||
|
||||
if (isset($this->parentrecord)) {
|
||||
return $this->parentrecord;
|
||||
}
|
||||
|
||||
return $DB->get_record('event', ['id' => $this->parentid]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate more event records.
|
||||
*
|
||||
* @param int $start Start offset.
|
||||
* @return \stdClass[]
|
||||
*/
|
||||
protected function load_event_records($start = 1) {
|
||||
global $DB;
|
||||
while ($records = $DB->get_records(
|
||||
'event',
|
||||
['repeatid' => $this->parentid],
|
||||
'',
|
||||
'*',
|
||||
$start,
|
||||
self::DB_QUERY_LIMIT
|
||||
)) {
|
||||
yield $records;
|
||||
$start += self::DB_QUERY_LIMIT;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Member does not exist exception.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Ryan Wyllie <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_calendar\local\event\exceptions;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Member does not exist exception.
|
||||
*
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class member_does_not_exist_exception extends \moodle_exception {
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* No repeat parent exception.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Ryan Wyllie <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_calendar\local\event\exceptions;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* No repeat parent exception.
|
||||
*
|
||||
* @copyright 2017 Ryan Wyllie <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class no_repeat_parent_exception extends \moodle_exception {
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* std_proxy class.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_calendar\local\event\proxies;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core_calendar\local\interfaces\proxy_interface;
|
||||
use core_calendar\local\event\exceptions\member_does_not_exist_exception;
|
||||
|
||||
/**
|
||||
* stdClass proxy.
|
||||
*
|
||||
* This class is intended to proxy things like user, group, etc 'classes'
|
||||
* It will only run the callback to load the object from the DB when necessary.
|
||||
*
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class std_proxy implements proxy_interface {
|
||||
/**
|
||||
* @var int $id The ID of the database record.
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @var \stdClass $class The class we are proxying.
|
||||
*/
|
||||
protected $class;
|
||||
|
||||
/**
|
||||
* @var callable $callback Callback to run which will load the class to proxy.
|
||||
*/
|
||||
protected $callback;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param int $id The ID of the record in the database.
|
||||
* @param callable $callback Callback to load the class.
|
||||
*/
|
||||
public function __construct($id, callable $callback) {
|
||||
$this->id = $id;
|
||||
$this->callback = $callback;
|
||||
}
|
||||
|
||||
public function get($member) {
|
||||
if (!property_exists($this->get_proxied_instance(), $member)) {
|
||||
throw new member_does_not_exist_exception(sprintf('Member %s does not exist', $member));
|
||||
}
|
||||
return $this->get_proxied_instance()->{$member};
|
||||
}
|
||||
|
||||
public function set($member, $value) {
|
||||
if (!property_exists($this->get_proxied_instance(), $member)) {
|
||||
throw new member_does_not_exist_exception(sprintf('Member %s does not exist', $member));
|
||||
}
|
||||
|
||||
$this->get_proxied_instance()->{$member} = $value;
|
||||
}
|
||||
|
||||
public function get_proxied_instance() {
|
||||
if ($this->class) {
|
||||
return $this->class;
|
||||
} else {
|
||||
$callback = $this->callback;
|
||||
return $callback($this->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?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 representing an action a user should take.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Ryan Wyllie <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_calendar\local\event\value_objects;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core_calendar\local\interfaces\action_interface;
|
||||
|
||||
/**
|
||||
* Class representing an action a user should take
|
||||
*
|
||||
* @copyright 2017 Ryan Wyllie <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class action implements action_interface {
|
||||
/**
|
||||
* @var string $name The action's name.
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @var \moodle_url $url The action's URL.
|
||||
*/
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* @var int $itemcount How many items there are to action.
|
||||
*/
|
||||
protected $itemcount;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $name The action's name.
|
||||
* @param \moodle_url $url The action's URL.
|
||||
* @param int $itemcount How many items there are to action.
|
||||
*/
|
||||
public function __construct(
|
||||
$name,
|
||||
\moodle_url $url,
|
||||
$itemcount = null
|
||||
) {
|
||||
$this->name = $name;
|
||||
$this->url = $url;
|
||||
$this->itemcount = $itemcount;
|
||||
}
|
||||
|
||||
public function get_name() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function get_url() {
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
public function get_item_count() {
|
||||
return $this->itemcount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Description value object.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_calendar\local\event\value_objects;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core_calendar\local\interfaces\description_interface;
|
||||
|
||||
/**
|
||||
* Class representing a description value object.
|
||||
*
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class event_description implements description_interface {
|
||||
/**
|
||||
* @var string $value The description's text.
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* @var int $format The description's format.
|
||||
*/
|
||||
protected $format;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*
|
||||
* @param stirng $value The description's value.
|
||||
* @param int $format The description's format.
|
||||
*/
|
||||
public function __construct($value, $format) {
|
||||
$this->value = $value;
|
||||
$this->format = $format;
|
||||
}
|
||||
|
||||
public function get_value() {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function get_format() {
|
||||
return $this->format;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?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 times class.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_calendar\local\event\value_objects;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core_calendar\local\interfaces\times_interface;
|
||||
|
||||
/**
|
||||
* Class representing event times.
|
||||
*
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class event_times implements times_interface {
|
||||
/**
|
||||
* @var \DateTimeImmutable $start Event start time.
|
||||
*/
|
||||
protected $start;
|
||||
|
||||
/**
|
||||
* @var \DateTimeImmutable $end Event end time.
|
||||
*/
|
||||
protected $end;
|
||||
|
||||
/**
|
||||
* @var \DateTimeImmutable $sort Time used to sort events.
|
||||
*/
|
||||
protected $sort;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \DateTimeImmutable $start Event start time.
|
||||
* @param \DateTimeImmutable $end Event end time.
|
||||
* @param \DateTimeImmutable $sort Date used to sort events.
|
||||
* @param \DateTimeImmutable $modified Time event was last updated.
|
||||
*/
|
||||
public function __construct(
|
||||
\DateTimeImmutable $start,
|
||||
\DateTimeImmutable $end,
|
||||
\DateTimeImmutable $sort,
|
||||
\DateTimeImmutable $modified
|
||||
) {
|
||||
$this->start = $start;
|
||||
$this->end = $end;
|
||||
$this->sort = $sort;
|
||||
$this->modified = $modified;
|
||||
}
|
||||
|
||||
public function get_start_time() {
|
||||
return $this->start;
|
||||
}
|
||||
|
||||
public function get_end_time() {
|
||||
return $this->end;
|
||||
}
|
||||
|
||||
public function get_duration() {
|
||||
return $this->end->diff($this->start);
|
||||
}
|
||||
|
||||
public function get_modified_time() {
|
||||
return $this->modified;
|
||||
}
|
||||
|
||||
public function get_sort_time() {
|
||||
return $this->sort;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?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 <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_calendar\local\interfaces;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core_calendar\local\interfaces\event_interface;
|
||||
|
||||
/**
|
||||
* Interface for an action event class.
|
||||
*
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @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 \core_calendar\local\event\value_objects\action_interface
|
||||
*/
|
||||
public function get_action();
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?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 <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_calendar\local\interfaces;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Interface for a action class.
|
||||
*
|
||||
* @copyright 2017 Ryan Wyllie <[email protected]>
|
||||
* @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();
|
||||
}
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Description value object interface.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_calendar\local\interfaces;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Interface for a description value object.
|
||||
*
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
interface description_interface {
|
||||
/**
|
||||
* Get the description's text.
|
||||
*
|
||||
* @return string The description's text.
|
||||
*/
|
||||
public function get_value();
|
||||
|
||||
/**
|
||||
* Get the description's format.
|
||||
*
|
||||
* @return int The description's format.
|
||||
*/
|
||||
public function get_format();
|
||||
}
|
||||
@@ -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 <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_calendar\local\interfaces;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Interface for an event collection class.
|
||||
*
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @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,76 @@
|
||||
<?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 factory interface.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_calendar\local\interfaces;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Interface for an event factory class.
|
||||
*
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
interface event_factory_interface {
|
||||
/**
|
||||
* Creates an instance of an event.
|
||||
*
|
||||
* @param int $id The event's ID from the database.
|
||||
* @param string $name The event's name.
|
||||
* @param string $descriptionvalue The event's description value.
|
||||
* @param string $descriptionformat The event's description format.
|
||||
* @param int $courseid The course ID associated with the event.
|
||||
* @param int $groupid The group ID associated with the event.
|
||||
* @param int $userid The user ID associated with the event.
|
||||
* @param int $repeatid ID of an event this event is a repeat of.
|
||||
* @param string $modulename The name of the module that created this event.
|
||||
* @param int $moduleinstance The instance ID of the module that created this event.
|
||||
* @param string $type The type of the event.
|
||||
* @param int $timestart Timestamp for when the event starts.
|
||||
* @param int $timeduration The duration of the event in seconds.
|
||||
* @param int $timemodified Timestamp of when the event was last modified.
|
||||
* @param int $timesort Timestamp by which to sort events.
|
||||
* @param bool $visible The event's visibility. True for visible, false for invisible.
|
||||
* @param int $subscriptionid The subscription ID of the event.
|
||||
*/
|
||||
public function create_instance(
|
||||
$id,
|
||||
$name,
|
||||
$descriptionvalue,
|
||||
$descriptionformat,
|
||||
$courseid,
|
||||
$groupid,
|
||||
$userid,
|
||||
$repeatid,
|
||||
$modulename,
|
||||
$moduleinstance,
|
||||
$type,
|
||||
$timestart,
|
||||
$timeduration,
|
||||
$timemodified,
|
||||
$timesort,
|
||||
$visible,
|
||||
$subscriptionid
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?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 <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_calendar\local\interfaces;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Interface for an event class.
|
||||
*
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @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 \core_calendar\local\event\value_objects\description_interface
|
||||
*/
|
||||
public function get_description();
|
||||
|
||||
/**
|
||||
* Get the course object associated with the event.
|
||||
*
|
||||
* @return \core_calendar\local\event\proxies\proxy_interface
|
||||
*/
|
||||
public function get_course();
|
||||
|
||||
/**
|
||||
* Get the course module object that created the event.
|
||||
*
|
||||
* @return \core_calendar\local\event\proxies\proxy_interface
|
||||
*/
|
||||
public function get_course_module();
|
||||
|
||||
/**
|
||||
* Get the group object associated with the event.
|
||||
*
|
||||
* @return \core_calendar\local\event\value_objects\proxy_interface
|
||||
*/
|
||||
public function get_group();
|
||||
|
||||
/**
|
||||
* Get the user object associated with the event.
|
||||
*
|
||||
* @return \core_calendar\local\event\proxies\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 \core_calendar\local\event\value_objects\times_interface
|
||||
*/
|
||||
public function get_times();
|
||||
|
||||
/**
|
||||
* Get repeats of this event.
|
||||
*
|
||||
* @return \core_calendar\local\event\entities\event_collection_interface
|
||||
*/
|
||||
public function get_repeats();
|
||||
|
||||
/**
|
||||
* Get the event's subscritpion ID.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_subscription_id();
|
||||
|
||||
/**
|
||||
* Get the event's visibility.
|
||||
*
|
||||
* @return bool true if the event is visible, false otherwise
|
||||
*/
|
||||
public function is_visible();
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Proxy interface.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_calendar\local\interfaces;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Interface for a proxy class.
|
||||
*
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
interface proxy_interface {
|
||||
/**
|
||||
* Retrieve a member of the proxied class.
|
||||
*
|
||||
* @param string $member The name of the member to retrieve
|
||||
* @throws \core_calendar\local\event\exceptions\member_does_not_exist_exception If the proxied class does not have the requested member.
|
||||
* @return mixed The member.
|
||||
*/
|
||||
public function get($member);
|
||||
|
||||
/**
|
||||
* Set a member of the proxied class.
|
||||
*
|
||||
* @param string $member The name of the member to set
|
||||
* @param mixed $value The value to set the member to
|
||||
* @throws \core_calendar\local\event\exceptions\member_does_not_exist_exception If the proxied class does not have the requested member.
|
||||
* @return void
|
||||
*/
|
||||
public function set($member, $value);
|
||||
|
||||
/**
|
||||
* Get the full instance of the proxied class.
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function get_proxied_instance();
|
||||
}
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Times interface.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_calendar\local\interfaces;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Interface for various times.
|
||||
*
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
interface times_interface {
|
||||
/**
|
||||
* Get the start time.
|
||||
*
|
||||
* @return \DateTimeImmutable
|
||||
*/
|
||||
public function get_start_time();
|
||||
|
||||
/**
|
||||
* Get the end time.
|
||||
*
|
||||
* @return \DateTimeImmutable
|
||||
*/
|
||||
public function get_end_time();
|
||||
|
||||
/**
|
||||
* Get the duration (the time between start and end).
|
||||
*
|
||||
* @return \DateInterval
|
||||
*/
|
||||
public function get_duration();
|
||||
|
||||
/**
|
||||
* Get the sort time.
|
||||
*
|
||||
* @return \DateTimeImmutable
|
||||
*/
|
||||
public function get_sort_time();
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
<?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 event tests.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core_calendar\local\event\entities\action_event;
|
||||
use core_calendar\local\event\value_objects\action;
|
||||
use core_calendar\local\event\value_objects\event_description;
|
||||
use core_calendar\local\event\value_objects\event_times;
|
||||
use core_calendar\local\interfaces\event_collection_interface;
|
||||
use core_calendar\local\interfaces\event_interface;
|
||||
|
||||
/**
|
||||
* Action event testcase.
|
||||
*
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_action_event_testcase extends advanced_testcase {
|
||||
/**
|
||||
* Test event class getters.
|
||||
*
|
||||
* @dataProvider getters_testcases()
|
||||
* @param array $constructorparams Associative array of constructor parameters.
|
||||
*/
|
||||
public function test_getters($constructorparams) {
|
||||
$event = new action_event(
|
||||
$constructorparams['event'],
|
||||
$constructorparams['action']
|
||||
);
|
||||
|
||||
foreach ($constructorparams as $name => $value) {
|
||||
if ($name !== 'event') {
|
||||
$this->assertEquals($event->{'get_' . $name}(), $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for getters test.
|
||||
*/
|
||||
public function getters_testcases() {
|
||||
return [
|
||||
'Dataset 1' => [
|
||||
'constructorparams' => [
|
||||
'event' => new core_calendar_action_event_test_event(),
|
||||
'action' => new action(
|
||||
'action 1',
|
||||
new moodle_url('http://example.com'),
|
||||
2
|
||||
)
|
||||
]
|
||||
],
|
||||
'Dataset 2' => [
|
||||
'constructorparams' => [
|
||||
'event' => new core_calendar_action_event_test_event(),
|
||||
'action' => new action(
|
||||
'action 2',
|
||||
new moodle_url('http://example.com'),
|
||||
5
|
||||
)
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test event.
|
||||
*
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_action_event_test_event implements event_interface {
|
||||
public function get_id() {
|
||||
return 1729;
|
||||
}
|
||||
|
||||
public function get_name() {
|
||||
return 'Jeff';
|
||||
}
|
||||
|
||||
public function get_description() {
|
||||
return new event_description('asdf', 1);
|
||||
}
|
||||
|
||||
public function get_course() {
|
||||
return new \stdClass();
|
||||
}
|
||||
|
||||
public function get_course_module() {
|
||||
return new \stdClass();
|
||||
}
|
||||
|
||||
public function get_group() {
|
||||
return new \stdClass();
|
||||
}
|
||||
|
||||
public function get_user() {
|
||||
return new \stdClass();
|
||||
}
|
||||
|
||||
public function get_type() {
|
||||
return 'asdf';
|
||||
}
|
||||
|
||||
public function get_times() {
|
||||
return new event_times(
|
||||
(new \DateTimeImmutable())->setTimestamp('-2461276800'),
|
||||
(new \DateTimeImmutable())->setTimestamp('115776000'),
|
||||
(new \DateTimeImmutable())->setTimestamp('115776000'),
|
||||
(new \DateTimeImmutable())->setTimestamp(time())
|
||||
);
|
||||
}
|
||||
|
||||
public function get_repeats() {
|
||||
return new core_calendar_action_event_test_event_collection();
|
||||
}
|
||||
|
||||
public function get_subscription_id() {
|
||||
return 1729;
|
||||
}
|
||||
|
||||
public function is_visible() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test event collection.
|
||||
*
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_action_event_test_event_collection implements event_collection_interface {
|
||||
protected $events;
|
||||
|
||||
public function __construct() {
|
||||
$this->events = [
|
||||
'not really an event hahaha',
|
||||
'also not really. gottem.'
|
||||
];
|
||||
}
|
||||
|
||||
public function get_id() {
|
||||
return 1729;
|
||||
}
|
||||
|
||||
public function get_num() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function getIterator() {
|
||||
foreach ($this->events as $event) {
|
||||
yield $event;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Action tests.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core_calendar\local\event\value_objects\action;
|
||||
|
||||
/**
|
||||
* Action testcase.
|
||||
*
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_action_testcase extends advanced_testcase {
|
||||
/**
|
||||
* Test action class getters.
|
||||
*
|
||||
* @dataProvider getters_testcases()
|
||||
* @param array $constructorparams Associative array of constructor parameters.
|
||||
*/
|
||||
public function test_getters($constructorparams) {
|
||||
$action = new action(
|
||||
$constructorparams['name'],
|
||||
$constructorparams['url'],
|
||||
$constructorparams['item_count']
|
||||
);
|
||||
|
||||
foreach ($constructorparams as $name => $value) {
|
||||
$this->assertEquals($action->{'get_' . $name}(), $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for getters test.
|
||||
*/
|
||||
public function getters_testcases() {
|
||||
return [
|
||||
'Dataset 1' => [
|
||||
'constructorparams' => [
|
||||
'name' => 'Hello',
|
||||
'url' => new moodle_url('http://example.com'),
|
||||
'item_count' => 1
|
||||
]
|
||||
],
|
||||
'Dataset 2' => [
|
||||
'constructorparams' => [
|
||||
'name' => 'Goodbye',
|
||||
'url' => new moodle_url('http://example.com'),
|
||||
'item_count' => 2
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Event description tests.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core_calendar\local\event\value_objects\event_description;
|
||||
|
||||
/**
|
||||
* Action testcase.
|
||||
*
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_event_description_testcase extends advanced_testcase {
|
||||
/**
|
||||
* Test event description class getters.
|
||||
*
|
||||
* @dataProvider getters_testcases()
|
||||
* @param array $constructorparams Associative array of constructor parameters.
|
||||
*/
|
||||
public function test_getters($constructorparams) {
|
||||
$eventdescription = new event_description(
|
||||
$constructorparams['value'],
|
||||
$constructorparams['format']
|
||||
);
|
||||
foreach ($constructorparams as $name => $value) {
|
||||
$this->assertEquals($eventdescription->{'get_' . $name}(), $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for getters test.
|
||||
*/
|
||||
public function getters_testcases() {
|
||||
return [
|
||||
'Dataset 1' => [
|
||||
'constructorparams' => [
|
||||
'value' => 'Hello',
|
||||
'format' => 1
|
||||
]
|
||||
],
|
||||
'Dataset 2' => [
|
||||
'constructorparams' => [
|
||||
'value' => 'Goodbye',
|
||||
'format' => 2
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
<?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 tests.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core_calendar\local\event\entities\event;
|
||||
use core_calendar\local\event\proxies\std_proxy;
|
||||
use core_calendar\local\event\value_objects\event_description;
|
||||
use core_calendar\local\event\value_objects\event_times;
|
||||
use core_calendar\local\interfaces\event_collection_interface;
|
||||
|
||||
/**
|
||||
* Event testcase.
|
||||
*
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_event_testcase extends advanced_testcase {
|
||||
/**
|
||||
* Test event class getters.
|
||||
*
|
||||
* @dataProvider getters_testcases()
|
||||
* @param array $constructorparams Associative array of constructor parameters.
|
||||
*/
|
||||
public function test_getters($constructorparams) {
|
||||
$event = new event(
|
||||
$constructorparams['id'],
|
||||
$constructorparams['name'],
|
||||
$constructorparams['description'],
|
||||
$constructorparams['course'],
|
||||
$constructorparams['group'],
|
||||
$constructorparams['user'],
|
||||
$constructorparams['repeats'],
|
||||
$constructorparams['course_module'],
|
||||
$constructorparams['type'],
|
||||
$constructorparams['times'],
|
||||
$constructorparams['visible'],
|
||||
$constructorparams['subscription_id']
|
||||
);
|
||||
|
||||
foreach ($constructorparams as $name => $value) {
|
||||
if ($name !== 'visible') {
|
||||
$this->assertEquals($event->{'get_' . $name}(), $value);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEquals($event->is_visible(), $constructorparams['visible']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for getters test.
|
||||
*/
|
||||
public function getters_testcases() {
|
||||
$lamecallable = function($id) {
|
||||
return (object)['id' => $id];
|
||||
};
|
||||
|
||||
return [
|
||||
'Dataset 1' => [
|
||||
'constructorparams' => [
|
||||
'id' => 1,
|
||||
'name' => 'Test event 1',
|
||||
'description' => new event_description('asdf', 1),
|
||||
'course' => new std_proxy(1, $lamecallable),
|
||||
'group' => new std_proxy(1, $lamecallable),
|
||||
'user' => new std_proxy(1, $lamecallable),
|
||||
'repeats' => new core_calendar_event_test_event_collection(),
|
||||
'course_module' => new std_proxy(1, $lamecallable),
|
||||
'type' => 'dunno what this actually is meant to be',
|
||||
'times' => new event_times(
|
||||
(new \DateTimeImmutable())->setTimestamp('-2461276800'),
|
||||
(new \DateTimeImmutable())->setTimestamp('115776000'),
|
||||
(new \DateTimeImmutable())->setTimestamp('115776000'),
|
||||
(new \DateTimeImmutable())->setTimestamp(time())
|
||||
),
|
||||
'visible' => true,
|
||||
'subscription_id' => 3
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test event class.
|
||||
*
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_event_test_event_collection implements event_collection_interface {
|
||||
/**
|
||||
* @var array $events Array of events.
|
||||
*/
|
||||
protected $events;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->events = [
|
||||
'not really an event hahaha',
|
||||
'also not really. gottem.'
|
||||
];
|
||||
}
|
||||
|
||||
public function get_id() {
|
||||
return 1729;
|
||||
}
|
||||
|
||||
public function get_num() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function getIterator() {
|
||||
foreach ($this->events as $event) {
|
||||
yield $event;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Event times tests.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core_calendar\local\event\value_objects\event_times;
|
||||
|
||||
/**
|
||||
* Event times testcase.
|
||||
*
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_event_times_testcase extends advanced_testcase {
|
||||
/**
|
||||
* Test event times class getters.
|
||||
*
|
||||
* @dataProvider getters_testcases()
|
||||
* @param array $constructorparams Associative array of constructor parameters.
|
||||
*/
|
||||
public function test_getters($constructorparams) {
|
||||
$eventtimes = new event_times(
|
||||
$constructorparams['start_time'],
|
||||
$constructorparams['end_time'],
|
||||
$constructorparams['sort_time'],
|
||||
$constructorparams['modified_time']
|
||||
);
|
||||
|
||||
foreach ($constructorparams as $name => $value) {
|
||||
$this->assertEquals($eventtimes->{'get_' . $name}(), $value);
|
||||
}
|
||||
|
||||
$this->assertEquals($eventtimes->get_duration(), $constructorparams['end_time']->diff($constructorparams['start_time']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for getters test.
|
||||
*/
|
||||
public function getters_testcases() {
|
||||
return [
|
||||
'Dataset 1' => [
|
||||
'constructorparams' => [
|
||||
'start_time' => (new \DateTimeImmutable())->setTimestamp('-2461276800'),
|
||||
'end_time' => (new \DateTimeImmutable())->setTimestamp('115776000'),
|
||||
'sort_time' => (new \DateTimeImmutable())->setTimestamp('115776000'),
|
||||
'modified_time' => (new \DateTimeImmutable())->setTimestamp(time())
|
||||
]
|
||||
],
|
||||
'Dataset 2' => [
|
||||
'constructorparams' => [
|
||||
'start_time' => (new \DateTimeImmutable())->setTimestamp('123456'),
|
||||
'end_time' => (new \DateTimeImmutable())->setTimestamp('12345678'),
|
||||
'sort_time' => (new \DateTimeImmutable())->setTimestamp('1111'),
|
||||
'modified_time' => (new \DateTimeImmutable())->setTimestamp(time())
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Repeat event collection tests.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Ryan Wyllie <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core_calendar\local\event\entities\event;
|
||||
use core_calendar\local\event\entities\repeat_event_collection;
|
||||
use core_calendar\local\event\proxies\std_proxy;
|
||||
use core_calendar\local\event\value_objects\event_description;
|
||||
use core_calendar\local\event\value_objects\event_times;
|
||||
use core_calendar\local\interfaces\event_factory_interface;
|
||||
|
||||
/**
|
||||
* Repeat event collection tests.
|
||||
*
|
||||
* @copyright 2017 Ryan Wyllie <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_repeat_event_collection_testcase extends advanced_testcase {
|
||||
/**
|
||||
* Test that creating a repeat collection for a parent that doesn't
|
||||
* exist throws an exception.
|
||||
*
|
||||
* @expectedException \core_calendar\local\event\exceptions\no_repeat_parent_exception
|
||||
*/
|
||||
public function test_no_parent_collection() {
|
||||
$this->resetAfterTest(true);
|
||||
$parentid = 123122131;
|
||||
$factory = new core_calendar_repeat_event_collection_event_test_factory();
|
||||
$collection = new repeat_event_collection($parentid, $factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that an empty collection is valid.
|
||||
*/
|
||||
public function test_empty_collection() {
|
||||
$this->resetAfterTest(true);
|
||||
$this->setAdminUser();
|
||||
|
||||
$event = $this->create_event([
|
||||
// This causes the code to set the repeat id on this record
|
||||
// but not create any repeat event records.
|
||||
'repeat' => 1,
|
||||
'repeats' => 0
|
||||
]);
|
||||
$parentid = $event->id;
|
||||
$factory = new core_calendar_repeat_event_collection_event_test_factory();
|
||||
|
||||
// Event collection with no repeats.
|
||||
$collection = new repeat_event_collection($parentid, $factory);
|
||||
|
||||
$this->assertEquals($parentid, $collection->get_id());
|
||||
$this->assertEquals(0, $collection->get_num());
|
||||
$this->assertNull($collection->getIterator()->next());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a collection with values behaves correctly.
|
||||
*/
|
||||
public function test_values_collection() {
|
||||
$this->resetAfterTest(true);
|
||||
$this->setAdminUser();
|
||||
|
||||
$factory = new core_calendar_repeat_event_collection_event_test_factory();
|
||||
$event = $this->create_event([
|
||||
// This causes the code to set the repeat id on this record
|
||||
// but not create any repeat event records.
|
||||
'repeat' => 1,
|
||||
'repeats' => 0
|
||||
]);
|
||||
$parentid = $event->id;
|
||||
$repeats = [];
|
||||
|
||||
for ($i = 1; $i < 4; $i++) {
|
||||
$record = $this->create_event([
|
||||
'name' => sprintf('repeat %d', $i),
|
||||
'repeatid' => $parentid
|
||||
]);
|
||||
|
||||
// Index by name so that we don't have to rely on sorting
|
||||
// when doing the comparison later.
|
||||
$repeats[$record->name] = $record;
|
||||
}
|
||||
|
||||
// Event collection with no repeats.
|
||||
$collection = new repeat_event_collection($parentid, $factory);
|
||||
|
||||
$this->assertEquals($parentid, $collection->get_id());
|
||||
$this->assertEquals(count($repeats), $collection->get_num());
|
||||
|
||||
foreach ($collection as $index => $event) {
|
||||
$name = $event->get_name();
|
||||
$this->assertEquals($repeats[$name]->name, $name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to create calendar events using the old code.
|
||||
*
|
||||
* @param array $properties A list of calendar event properties to set
|
||||
* @return event
|
||||
*/
|
||||
protected function create_event($properties = []) {
|
||||
$record = new \stdClass();
|
||||
$record->name = 'event name';
|
||||
$record->eventtype = 'global';
|
||||
$record->repeat = 0;
|
||||
$record->repeats = 0;
|
||||
$record->timestart = time();
|
||||
$record->timeduration = 0;
|
||||
$record->timesort = 0;
|
||||
$record->type = 1;
|
||||
$record->courseid = 0;
|
||||
|
||||
foreach ($properties as $name => $value) {
|
||||
$record->$name = $value;
|
||||
}
|
||||
|
||||
$event = new \core_calendar\event($record);
|
||||
return $event->create($record, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test event factory.
|
||||
*
|
||||
* @copyright 2017 Ryan Wyllie <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_repeat_event_collection_event_test_factory implements event_factory_interface {
|
||||
public function create_instance(
|
||||
$id,
|
||||
$name,
|
||||
$descriptionvalue,
|
||||
$descriptionformat,
|
||||
$courseid,
|
||||
$groupid,
|
||||
$userid,
|
||||
$repeatid,
|
||||
$modulename,
|
||||
$moduleinstance,
|
||||
$type,
|
||||
$timestart,
|
||||
$timeduration,
|
||||
$timemodified,
|
||||
$timesort,
|
||||
$visible,
|
||||
$subscriptionid
|
||||
) {
|
||||
$identity = function($id) {
|
||||
return $id;
|
||||
};
|
||||
return new event(
|
||||
$id,
|
||||
$name,
|
||||
new event_description($descriptionvalue, $descriptionformat),
|
||||
new std_proxy($courseid, $identity),
|
||||
new std_proxy($groupid, $identity),
|
||||
new std_proxy($userid, $identity),
|
||||
new repeat_event_collection($id, $this),
|
||||
new std_proxy($moduleinstance, $identity),
|
||||
$type,
|
||||
new event_times(
|
||||
(new \DateTimeImmutable())->setTimestamp($timestart),
|
||||
(new \DateTimeImmutable())->setTimestamp($timestart + $timeduration),
|
||||
(new \DateTimeImmutable())->setTimestamp($timesort ? $timesort : $timestart),
|
||||
(new \DateTimeImmutable())->setTimestamp($timemodified)
|
||||
),
|
||||
!empty($visible),
|
||||
$subscriptionid
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* std_proxy tests.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core_calendar\local\event\proxies\std_proxy;
|
||||
|
||||
/**
|
||||
* std_proxy testcase.
|
||||
*
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_std_proxy_testcase extends advanced_testcase {
|
||||
/**
|
||||
* @var \stdClass[] $objects Array of objects to proxy.
|
||||
*/
|
||||
public static $objects;
|
||||
|
||||
public static function setUpBeforeClass() {
|
||||
self::$objects = [
|
||||
1 => (object) [
|
||||
'member1' => 'Hello',
|
||||
'member2' => 1729,
|
||||
'member3' => 'Something else'
|
||||
],
|
||||
5 => (object) [
|
||||
'member1' => 'Hej',
|
||||
'member2' => 87539319,
|
||||
'member3' => 'nagot annat'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test proxying.
|
||||
*
|
||||
* @dataProvider test_proxy_testcases()
|
||||
* @param int $id Object ID.
|
||||
* @param string $member Object member to retrieve.
|
||||
* @param mixed $expected Expected value of member.
|
||||
*/
|
||||
public function test_proxy($id, $member, $expected) {
|
||||
$proxy = new std_proxy($id, function($id) {
|
||||
return self::$objects[$id];
|
||||
});
|
||||
|
||||
$this->assertEquals($proxy->get($member), $expected);
|
||||
|
||||
// Test changing the value.
|
||||
$proxy->set($member, 'something else');
|
||||
$this->assertEquals($proxy->get($member), 'something else');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getting a non existant member.
|
||||
*
|
||||
* @dataProvider test_get_set_testcases()
|
||||
* @expectedException \core_calendar\local\event\exceptions\member_does_not_exist_exception
|
||||
*/
|
||||
public function test_get_invalid_member($id) {
|
||||
$proxy = new std_proxy($id, function($id) {
|
||||
return self::$objects[$id];
|
||||
});
|
||||
|
||||
$proxy->get('thisdoesnotexist');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test setting a non existant member.
|
||||
*
|
||||
* @dataProvider test_get_set_testcases()
|
||||
* @expectedException \core_calendar\local\event\exceptions\member_does_not_exist_exception
|
||||
*/
|
||||
public function test_set_invalid_member($id) {
|
||||
$proxy = new std_proxy($id, function($id) {
|
||||
return self::$objects[$id];
|
||||
});
|
||||
|
||||
$proxy->set('thisdoesnotexist', 'should break');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get proxied instance.
|
||||
*
|
||||
* @dataProvider test_get_set_testcases()
|
||||
* @param int $id Object ID.
|
||||
*/
|
||||
public function test_get_proxied_instance($id) {
|
||||
$proxy = new std_proxy($id, function($id) {
|
||||
return self::$objects[$id];
|
||||
});
|
||||
|
||||
$this->assertEquals($proxy->get_proxied_instance(), self::$objects[$id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for proxying test.
|
||||
*/
|
||||
public function test_proxy_testcases() {
|
||||
return [
|
||||
'Object 1 member 1' => [
|
||||
1,
|
||||
'member1',
|
||||
'Hello'
|
||||
],
|
||||
'Object 1 member 2' => [
|
||||
1,
|
||||
'member2',
|
||||
1729
|
||||
],
|
||||
'Object 1 member 3' => [
|
||||
1,
|
||||
'member3',
|
||||
'Something else'
|
||||
],
|
||||
'Object 2 member 1' => [
|
||||
5,
|
||||
'member1',
|
||||
'Hej'
|
||||
],
|
||||
'Object 2 member 2' => [
|
||||
5,
|
||||
'member2',
|
||||
87539319
|
||||
],
|
||||
'Object 3 member 3' => [
|
||||
5,
|
||||
'member3',
|
||||
'nagot annat'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for getting and setting tests.
|
||||
*/
|
||||
public function test_get_set_testcases() {
|
||||
return [
|
||||
'Object 1' => [1],
|
||||
'Object 2' => [5]
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user