Skip to content

Commit

Permalink
MDL-58386 calendar: Fixed CI issues
Browse files Browse the repository at this point in the history
Part of MDL-55611 epic.
  • Loading branch information
junpataleta authored and danpoltawski committed Apr 4, 2017
1 parent 966cbed commit 20592f5
Show file tree
Hide file tree
Showing 34 changed files with 222 additions and 175 deletions.
1 change: 1 addition & 0 deletions calendar/classes/action_factory.php
Expand Up @@ -36,6 +36,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class action_factory implements action_factory_interface {

public function create_instance($name, \moodle_url $url, $itemcount, $actionable) {
return new action ($name, $url, $itemcount, $actionable);
}
Expand Down
3 changes: 2 additions & 1 deletion calendar/classes/external/event_action_exporter.php
Expand Up @@ -43,7 +43,8 @@ class event_action_exporter extends exporter {
/**
* Constructor.
*
* @param action_interface $action
* @param action_interface $action The action object.
* @param array $related Related data.
*/
public function __construct(action_interface $action, $related = []) {
$data = new \stdClass();
Expand Down
1 change: 1 addition & 0 deletions calendar/classes/external/event_exporter.php
Expand Up @@ -50,6 +50,7 @@ class event_exporter extends exporter {
* Constructor.
*
* @param event_interface $event
* @param array $related The related data.
*/
public function __construct(event_interface $event, $related = []) {
$this->event = $event;
Expand Down
1 change: 1 addition & 0 deletions calendar/classes/external/event_icon_exporter.php
Expand Up @@ -42,6 +42,7 @@ class event_icon_exporter extends exporter {
* Constructor.
*
* @param event_interface $event
* @param array $related The related data.
*/
public function __construct(event_interface $event, $related = []) {
$coursemodule = $event->get_course_module();
Expand Down
Expand Up @@ -15,8 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Contains event class for displaying a list of calendar events grouped
* by course id.
* Contains event class for displaying a list of calendar events grouped by course id.
*
* @package core_calendar
* @copyright 2017 Ryan Wyllie <ryan@moodle.com>
Expand Down Expand Up @@ -52,7 +51,7 @@ class events_grouped_by_course_exporter extends exporter {
/**
* Constructor.
*
* @param array $events An array of event_interface objects
* @param array $eventsbycourse An array of event_interface objects
* @param array $related An array of related objects
*/
public function __construct(array $eventsbycourse, $related = []) {
Expand Down
18 changes: 9 additions & 9 deletions calendar/classes/external/events_related_objects_cache.php
Expand Up @@ -15,8 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Contains event class for providing the related objects when exporting
* a list of calendar events.
* Contains event class for providing the related objects when exporting a list of calendar events.
*
* @package core_calendar
* @copyright 2017 Ryan Wyllie <ryan@moodle.com>
Expand All @@ -27,11 +26,12 @@

defined('MOODLE_INTERNAL') || die();

use context;
use \core_calendar\local\interfaces\event_interface;
use stdClass;

/**
* Class to providing the related objects when exporting
* a list of calendar events.
* Class to providing the related objects when exporting a list of calendar events.
*
* This class is only meant for use with exporters. It attempts to bulk load
* the related objects for a list of events and cache them to avoid having
Expand Down Expand Up @@ -66,7 +66,7 @@ class events_related_objects_cache {
/**
* Constructor.
*
* @param array $event Array of event_interface events
* @param array $events Array of event_interface events
* @param array $courses Array of courses to populate the cache with
*/
public function __construct(array $events, array $courses = null) {
Expand All @@ -84,7 +84,7 @@ public function __construct(array $events, array $courses = null) {
/**
* Get the related course object for a given event.
*
* @param event_interface $event.
* @param event_interface $event The event object.
* @return stdClass|null
*/
public function get_course(event_interface $event) {
Expand All @@ -103,7 +103,7 @@ public function get_course(event_interface $event) {
/**
* Get the related context for a given event.
*
* @param event_interface $event.
* @param event_interface $event The event object.
* @return context|null
*/
public function get_context(event_interface $event) {
Expand Down Expand Up @@ -132,7 +132,7 @@ public function get_context(event_interface $event) {
/**
* Get the related group object for a given event.
*
* @param event_interface $event.
* @param event_interface $event The event object.
* @return stdClass|null
*/
public function get_group(event_interface $event) {
Expand All @@ -151,7 +151,7 @@ public function get_group(event_interface $event) {
/**
* Get the related course module for a given event.
*
* @param event_interface $event.
* @param event_interface $event The event object.
* @return stdClass|null
*/
public function get_course_module(event_interface $event) {
Expand Down
3 changes: 1 addition & 2 deletions calendar/classes/external/events_same_course_exporter.php
Expand Up @@ -15,8 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Contains event class for displaying a list of calendar events for
* a single course.
* Contains event class for displaying a list of calendar events for a single course.
*
* @package core_calendar
* @copyright 2017 Ryan Wyllie <ryan@moodle.com>
Expand Down
32 changes: 16 additions & 16 deletions calendar/classes/local/api.php
Expand Up @@ -39,22 +39,20 @@ class api {
/**
* Get all events restricted by various parameters, taking in to account user and group overrides.
*
* @param int|null $timestartfrom Events with timestart from this value (inclusive).
* @param int|null $timestartto Events with timestart until this value (inclusive).
* @param int|null $timesortfrom Events with timesort from this value (inclusive).
* @param int|null $timesortto Events with timesort until this value (inclusive).
* @param int|null $timestartaftereventid Restrict the events in the timestart range to ones
after this ID.
* @param int $timesortaftereventid Restrict the events in the timesort range to ones
after this ID.
* @param int $limitnum Return at most this number of events.
* @param int $type Return only events of this type.
* @param array|null $usersfilter Return only events for these users.
* @param array|null $groupsfilter Return only events for these groups.
* @param array|null $coursesfilter Return only events for these courses.
* @param bool $withduration If true return only events starting within specified
* timestart otherwise return in progress events as well.
* @param bool $ignorehidden If true don't return hidden events.
* @param int|null $timestartfrom Events with timestart from this value (inclusive).
* @param int|null $timestartto Events with timestart until this value (inclusive).
* @param int|null $timesortfrom Events with timesort from this value (inclusive).
* @param int|null $timesortto Events with timesort until this value (inclusive).
* @param int|null $timestartaftereventid Restrict the events in the timestart range to ones after this ID.
* @param int|null $timesortaftereventid Restrict the events in the timesort range to ones after this ID.
* @param int $limitnum Return at most this number of events.
* @param int|null $type Return only events of this type.
* @param array|null $usersfilter Return only events for these users.
* @param array|null $groupsfilter Return only events for these groups.
* @param array|null $coursesfilter Return only events for these courses.
* @param bool $withduration If true return only events starting within specified
* timestart otherwise return in progress events as well.
* @param bool $ignorehidden If true don't return hidden events.
* @return \core_calendar\local\interfaces\event_interface[] Array of event_interfaces.
*/
public static function get_events(
Expand Down Expand Up @@ -113,6 +111,7 @@ public static function get_events(
* @param int|null $aftereventid Only return events after this one
* @param int $limitnum Limit results to this amount (between 1 and 50)
* @return array A list of action_event_interface objects
* @throws \moodle_exception
*/
public static function get_action_events_by_timesort(
$timesortfrom = null,
Expand Down Expand Up @@ -150,6 +149,7 @@ public static function get_action_events_by_timesort(
* @param int|null $aftereventid Only return events after this one
* @param int $limitnum Limit results to this amount (between 1 and 50)
* @return array A list of action_event_interface objects
* @throws limit_invalid_parameter_exception
*/
public static function get_action_events_by_course(
$course,
Expand Down
4 changes: 2 additions & 2 deletions calendar/classes/local/event/core_container.php
Expand Up @@ -82,12 +82,12 @@ class core_container {
protected static $callbacks = array();

/**
* @var stdClass[] An array of cached courses to use with the event factory.
* @var \stdClass[] An array of cached courses to use with the event factory.
*/
protected static $coursecache = array();

/**
* @var stdClass[] An array of cached modules to use with the event factory.
* @var \stdClass[] An array of cached modules to use with the event factory.
*/
protected static $modulecache = array();

Expand Down
46 changes: 40 additions & 6 deletions calendar/classes/local/event/data_access/event_vault.php
Expand Up @@ -24,15 +24,18 @@

namespace core_calendar\local\event\data_access;

defined('MOODLE_INTERNAL') || die();

use core_calendar\local\event\exceptions\limit_invalid_parameter_exception;
use core_calendar\local\event\exceptions\timesort_invalid_parameter_exception;
use core_calendar\local\interfaces\action_event_interface;
use core_calendar\local\interfaces\event_factory_interface;
use core_calendar\local\interfaces\event_interface;
use core_calendar\local\interfaces\event_vault_interface;
use core_calendar\local\interfaces\raw_event_retrieval_strategy_interface;

/**
* Event vault class.
*
* This class will handle interacting with the database layer to retrieve
* the records. This is required to house the complex logic required for
* pagination because it's not a one-to-one mapping between database records
Expand Down Expand Up @@ -60,6 +63,7 @@ class event_vault implements event_vault_interface {
* Create an event vault.
*
* @param event_factory_interface $factory An event factory
* @param raw_event_retrieval_strategy_interface $retrievalstrategy
*/
public function __construct(
event_factory_interface $factory,
Expand Down Expand Up @@ -245,6 +249,16 @@ function ($event) use ($course) {
);
}

/**
* Generates SQL subquery and parameters for 'from' pagination.
*
* @param string $field
* @param int $timefrom
* @param int|null $lastseentime
* @param int|null $lastseenid
* @param bool $withduration
* @return array
*/
protected function timefield_pagination_from(
$field,
$timefrom,
Expand Down Expand Up @@ -279,6 +293,15 @@ protected function timefield_pagination_from(
return ['where' => [$where], 'params' => $params];
}

/**
* Generates SQL subquery and parameters for 'to' pagination.
*
* @param string $field
* @param int $timeto
* @param int|null $lastseentime
* @param int|null $lastseenid
* @return array|bool
*/
protected function timefield_pagination_to(
$field,
$timeto,
Expand Down Expand Up @@ -313,17 +336,28 @@ protected function timefield_pagination_to(
* Create an event from a database record.
*
* @param \stdClass $record The database record
* @return event_interface|false
* @return event_interface|null
*/
protected function transform_from_database_record(\stdClass $record) {
if ($record->courseid == 0 && $record->instance && $record->modulename) {
list($course, $cm) = get_course_and_cm_from_instance($record->instance, $record->modulename);
$record->courseid = $course->id;
}
if ($record->courseid == 0 && $record->instance && $record->modulename) {
list($course, $cm) = get_course_and_cm_from_instance($record->instance, $record->modulename);
$record->courseid = $course->id;
}

return $this->factory->create_instance($record);
}

/**
* Fetches records from DB.
*
* @param int $userid
* @param string $whereconditions
* @param array $whereparams
* @param string $ordersql
* @param int $offset
* @param int $limitnum
* @return array
*/
protected function get_from_db(
$userid,
$whereconditions,
Expand Down
Expand Up @@ -39,7 +39,7 @@
*/
class repeat_event_collection implements event_collection_interface {
/**
* @var DB_QUERY_LIMIT How many records to pull from the DB at once.
* @var int DB_QUERY_LIMIT How many records to pull from the DB at once.
*/
const DB_QUERY_LIMIT = 100;

Expand Down
Expand Up @@ -38,10 +38,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class action_event_factory implements action_event_factory_interface {
public function create_instance(
event_interface $event,
action_interface $action
) {

public function create_instance(event_interface $event, action_interface $action) {
return new action_event($event, $action);
}
}
Expand Up @@ -92,6 +92,7 @@ protected abstract function expose_event(event_interface $event);
* @param callable $visibilitycallbackapplier Function to apply component visibility callbacks.
* @param callable $bailoutcheck Function to test if we can return null early.
* @param array $coursecachereference Cache to use with get_course_cached.
* @param array $modulecachereference Cache to use with get_module_cached.
*/
public function __construct(
callable $actioncallbackapplier,
Expand Down
1 change: 1 addition & 0 deletions calendar/classes/local/event/factories/event_factory.php
Expand Up @@ -37,6 +37,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class event_factory extends event_abstract_factory {

protected function apply_component_action(event_interface $event) {
$callbackapplier = $this->actioncallbackapplier;
$callbackresult = $callbackapplier($event);
Expand Down
10 changes: 9 additions & 1 deletion calendar/classes/local/event/proxies/module_std_proxy.php
Expand Up @@ -27,7 +27,6 @@
defined('MOODLE_INTERNAL') || die();

use core_calendar\local\interfaces\proxy_interface;
use core_calendar\local\event\exceptions\member_does_not_exist_exception;

/**
* Course module stdClass proxy.
Expand All @@ -42,6 +41,15 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class module_std_proxy extends std_proxy implements proxy_interface {

/**
* module_std_proxy constructor.
*
* @param int $modulename The module name.
* @param callable $instance The module instance.
* @param callable $callback Callback to load the class.
* @param \stdClass $base Class containing base values.
*/
public function __construct($modulename, $instance, callable $callback, \stdClass $base = null) {
$this->modulename = $modulename;
$this->instance = $instance;
Expand Down
Expand Up @@ -37,6 +37,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class raw_event_retrieval_strategy implements raw_event_retrieval_strategy_interface {

public function get_raw_events(
array $usersfilter = null,
array $groupsfilter = null,
Expand All @@ -49,7 +50,7 @@ public function get_raw_events(
$ignorehidden = true
) {
return $this->get_raw_events_legacy_implementation(
!is_null($usersfilter) ? $usersfilter : true, //true means no filter in old implementation
!is_null($usersfilter) ? $usersfilter : true, // True means no filter in old implementation.
!is_null($groupsfilter) ? $groupsfilter : true,
!is_null($coursesfilter) ? $coursesfilter : true,
$whereconditions,
Expand All @@ -67,10 +68,14 @@ public function get_raw_events(
* @param array|int|boolean $users array of users, user id or boolean for all/no user events
* @param array|int|boolean $groups array of groups, group id or boolean for all/no group events
* @param array|int|boolean $courses array of courses, course id or boolean for all/no course events
* @param boolean $withduration whether only events starting within time range selected
* or events in progress/already started selected as well
* @param string $whereconditions The conditions in the WHERE clause.
* @param array $whereparams The parameters for the WHERE clause.
* @param string $ordersql The ORDER BY clause.
* @param int $offset Offset.
* @param int $limitnum Limit.
* @param boolean $ignorehidden whether to select only visible events or all events
* @return array $events of selected events or an empty array if there aren't any (or there was an error) */
* @return array $events of selected events or an empty array if there aren't any (or there was an error)
*/
protected function get_raw_events_legacy_implementation(
$users,
$groups,
Expand Down

0 comments on commit 20592f5

Please sign in to comment.