Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
core_calendar\local\event\data_access\event_vault Class Reference

Event vault class. More...

Inheritance diagram for core_calendar\local\event\data_access\event_vault:
core_calendar\local\event\data_access\event_vault_interface

Public Member Functions

 __construct (event_factory_interface $factory, raw_event_retrieval_strategy_interface $retrievalstrategy)
 Create an event vault. More...
 
 get_action_events_by_course (stdClass $user, stdClass $course, $timesortfrom=null, $timesortto=null, event_interface $afterevent=null, $limitnum=20)
 Retrieve an array of events for the given user filtered by the course and time constraints. More...
 
 get_action_events_by_timesort (stdClass $user, $timesortfrom=null, $timesortto=null, event_interface $afterevent=null, $limitnum=20, $limittononsuspendedevents=false)
 Retrieve an array of events for the given user and time constraints. More...
 
 get_event_by_id ($id)
 Retrieve an event for the given id. More...
 
 get_events ( $timestartfrom=null, $timestartto=null, $timesortfrom=null, $timesortto=null, event_interface $timestartafterevent=null, event_interface $timesortafterevent=null, $limitnum=20, $type=null, array $usersfilter=null, array $groupsfilter=null, array $coursesfilter=null, array $categoriesfilter=null, $withduration=true, $ignorehidden=true, callable $filter=null)
 Get all events restricted by various parameters, taking in to account user and group overrides. More...
 

Protected Member Functions

 get_from_db ( $userid, $whereconditions, $whereparams, $ordersql, $offset, $limitnum)
 Fetches records from DB. More...
 
 timefield_pagination_from ( $field, $timefrom, $lastseentime=null, $lastseenid=null, $withduration=true)
 Generates SQL subquery and parameters for 'from' pagination. More...
 
 timefield_pagination_to ( $field, $timeto, $lastseentime=null, $lastseenid=null)
 Generates SQL subquery and parameters for 'to' pagination. More...
 
 transform_from_database_record (\stdClass $record)
 Create an event from a database record. More...
 

Protected Attributes

event_factory_interface $factory
 $factory Factory for creating events.
 
raw_event_retrieval_strategy_interface $retrievalstrategy
 $retrievalstrategy Strategy for getting events from the DB.
 

Detailed Description

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 and users.

This is a repository. It's called a vault to reduce confusion because Moodle has already taken the name repository. Vault is cooler anyway.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

core_calendar\local\event\data_access\event_vault::__construct ( event_factory_interface  $factory,
raw_event_retrieval_strategy_interface  $retrievalstrategy 
)

Create an event vault.

Parameters
event_factory_interface$factoryAn event factory
raw_event_retrieval_strategy_interface$retrievalstrategy

Member Function Documentation

◆ get_action_events_by_course()

core_calendar\local\event\data_access\event_vault::get_action_events_by_course ( stdClass  $user,
stdClass  $course,
  $timesortfrom = null,
  $timesortto = null,
event_interface  $afterevent = null,
  $limitnum = 20 
)

Retrieve an array of events for the given user filtered by the course and time constraints.

If using this function for pagination then you can provide the last event that you've seen ($afterevent) and it will be used to appropriately offset the result set so that you don't receive the same events again.

Parameters
stdClass$userThe user for whom the events belong
stdClass$courseThe course to filter by
int$timesortfromEvents with timesort from this value (inclusive)
int$timesorttoEvents with timesort until this value (inclusive)
event_interface$aftereventOnly return events after this one
int$limitnumReturn at most this number of events
Return values
action_event_interface

Implements core_calendar\local\event\data_access\event_vault_interface.

◆ get_action_events_by_timesort()

core_calendar\local\event\data_access\event_vault::get_action_events_by_timesort ( stdClass  $user,
  $timesortfrom = null,
  $timesortto = null,
event_interface  $afterevent = null,
  $limitnum = 20,
  $limittononsuspendedevents = false 
)

Retrieve an array of events for the given user and time constraints.

If using this function for pagination then you can provide the last event that you've seen ($afterevent) and it will be used to appropriately offset the result set so that you don't receive the same events again.

Parameters
stdClass$userThe user for whom the events belong
int$timesortfromEvents with timesort from this value (inclusive)
int$timesorttoEvents with timesort until this value (inclusive)
event_interface$aftereventOnly return events after this one
int$limitnumReturn at most this number of events
bool$lmittononsuspendedeventsLimit course events to courses the user is active in (not suspended).
Return values
event_interface

Implements core_calendar\local\event\data_access\event_vault_interface.

◆ get_event_by_id()

core_calendar\local\event\data_access\event_vault::get_event_by_id (   $id)

Retrieve an event for the given id.

Parameters
int$idThe event id
Return values
event_interface|false

Implements core_calendar\local\event\data_access\event_vault_interface.

◆ get_events()

core_calendar\local\event\data_access\event_vault::get_events (   $timestartfrom = null,
  $timestartto = null,
  $timesortfrom = null,
  $timesortto = null,
event_interface  $timestartafterevent = null,
event_interface  $timesortafterevent = null,
  $limitnum = 20,
  $type = null,
array  $usersfilter = null,
array  $groupsfilter = null,
array  $coursesfilter = null,
array  $categoriesfilter = null,
  $withduration = true,
  $ignorehidden = true,
callable  $filter = null 
)

Get all events restricted by various parameters, taking in to account user and group overrides.

Parameters
int | null$timestartfromEvents with timestart from this value (inclusive).
int | null$timestarttoEvents with timestart until this value (inclusive).
int | null$timesortfromEvents with timesort from this value (inclusive).
int | null$timesorttoEvents with timesort until this value (inclusive).
event_interface | null$timestartaftereventRestrict the events in the timestart range to ones after this one.
event_interface | null$timesortaftereventRestrict the events in the timesort range to ones after this one.
int$limitnumReturn at most this number of events.
int | null$typeReturn only events of this type.
array | null$usersfilterReturn only events for these users.
array | null$groupsfilterReturn only events for these groups.
array | null$coursesfilterReturn only events for these courses.
bool$withdurationIf true return only events starting within specified timestart otherwise return in progress events as well.
bool$ignorehiddenIf true don't return hidden events.
callable | null$filterAdditional logic to filter out unwanted events. Must return true to keep the event, false to discard it.
Return values
event_interface[]Array of event_interfaces.

Implements core_calendar\local\event\data_access\event_vault_interface.

◆ get_from_db()

core_calendar\local\event\data_access\event_vault::get_from_db (   $userid,
  $whereconditions,
  $whereparams,
  $ordersql,
  $offset,
  $limitnum 
)
protected

Fetches records from DB.

Parameters
int$userid
string$whereconditions
array$whereparams
string$ordersql
int$offset
int$limitnum
Return values
array

◆ timefield_pagination_from()

core_calendar\local\event\data_access\event_vault::timefield_pagination_from (   $field,
  $timefrom,
  $lastseentime = null,
  $lastseenid = null,
  $withduration = true 
)
protected

Generates SQL subquery and parameters for 'from' pagination.

Parameters
string$field
int$timefrom
int | null$lastseentime
int | null$lastseenid
bool$withduration
Return values
array

◆ timefield_pagination_to()

core_calendar\local\event\data_access\event_vault::timefield_pagination_to (   $field,
  $timeto,
  $lastseentime = null,
  $lastseenid = null 
)
protected

Generates SQL subquery and parameters for 'to' pagination.

Parameters
string$field
int$timeto
int | null$lastseentime
int | null$lastseenid
Return values
array|bool

◆ transform_from_database_record()

core_calendar\local\event\data_access\event_vault::transform_from_database_record ( \stdClass  $record)
protected

Create an event from a database record.

Parameters
stdClass$recordThe database record
Return values
event_interface|null

The documentation for this class was generated from the following file: