ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilCalendarScheduleFilterTimings Class Reference

Calendar schedule filter for individual timings. More...

+ Inheritance diagram for ilCalendarScheduleFilterTimings:
+ Collaboration diagram for ilCalendarScheduleFilterTimings:

Public Member Functions

 __construct ($a_usr_id)
 ilCalendarScheduleFilterTimings constructor. More...
 
 getLogger ()
 Get logger. More...
 
 filterCategories (array $a_cats)
 Filter categories All categories are show no filtering (support for individual folder appointments) More...
 
 modifyEvent (ilCalendarEntry $a_event)
 modify event => return false for not presenting event More...
 
 addCustomEvents (ilDate $start, ilDate $end, array $a_categories)
 Add custom events: relative timings, modified timings. More...
 

Data Fields

const CAL_TIMING_START = 1
 
const CAL_TIMING_END = 2
 

Protected Member Functions

 findCalendarEntriesForItem ($category_id, $item_ref_id)
 
 isCourseCategory ($a_category_id)
 
 enabledCourseTimings ($a_course_ref)
 Check if timings enabled for ref_id. More...
 

Private Attributes

 $user_id = 0
 
 $logger
 

Detailed Description

Calendar schedule filter for individual timings.

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e

Definition at line 11 of file class.ilCalendarScheduleFilterTimings.php.

Constructor & Destructor Documentation

◆ __construct()

ilCalendarScheduleFilterTimings::__construct (   $a_usr_id)

ilCalendarScheduleFilterTimings constructor.

Parameters
inta_usr_id

Definition at line 31 of file class.ilCalendarScheduleFilterTimings.php.

References ilLoggerFactory\getLogger().

32  {
33  $this->user_id = $a_usr_id;
34  $this->logger = ilLoggerFactory::getLogger('crs');
35  }
static getLogger($a_component_id)
Get component logger.
+ Here is the call graph for this function:

Member Function Documentation

◆ addCustomEvents()

ilCalendarScheduleFilterTimings::addCustomEvents ( ilDate  $start,
ilDate  $end,
array  $a_categories 
)

Add custom events: relative timings, modified timings.

Parameters
ilDate$start
ilDate$end
array$a_categories

Implements ilCalendarScheduleFilter.

Definition at line 139 of file class.ilCalendarScheduleFilterTimings.php.

References $end, $start, ilObject\_getAllReferences(), ilDateTime\_within(), ilObjCourse\CAL_COURSE_TIMING_END, ilObjCourse\CAL_COURSE_TIMING_START, enabledCourseTimings(), findCalendarEntriesForItem(), getLogger(), ilLoggerFactory\getLogger(), ilObjectActivation\getTimingsItems(), IL_CAL_DATE, ilCourseConstants\IL_CRS_VIEW_TIMING_ABSOLUTE, isCourseCategory(), ilObjCourse\lookupTimingMode(), and ilObjectActivation\TIMINGS_PRESETTING.

140  {
141  // @fixme
142  // @todo categories can appear more than once
143  $a_categories = array_unique($a_categories);
144 
145 
146  $all_events = [];
147  foreach ($a_categories as $cat_id) {
148  $category = $this->isCourseCategory($cat_id);
149  if (!$category) {
150  continue;
151  }
152  $course_obj_id = $category->getObjId();
153  $ref_ids = ilObject::_getAllReferences($course_obj_id);
154  $course_ref_id = end($ref_ids);
155  $course_timing_mode = ilObjCourse::lookupTimingMode($course_obj_id);
156  if (!$this->enabledCourseTimings($course_ref_id)) {
157  ilLoggerFactory::getLogger('cal')->debug('Timings disabled for course: ');
158  continue;
159  }
160  $active = ilObjectActivation::getTimingsItems($course_ref_id);
161  foreach ($active as $null => $item) {
162  if ($item['timing_type'] != ilObjectActivation::TIMINGS_PRESETTING) {
163  $this->getLogger()->debug('timings not active for: ' . $item['ref_id']);
164  continue;
165  }
166  if (
167  !$item['changeable'] &&
169  ) {
170  $this->getLogger('cal')->debug('Not creating new event since item is unchangeable and absolute');
171  continue;
172  }
173 
174  $user_data = new ilTimingUser($item['ref_id'], $this->user_id);
175  if (!$user_data->isScheduled()) {
176  $this->getLogger()->debug('No scheduled timings for user');
177  continue;
178  }
179  if (
180  ilDateTime::_within($user_data->getStart(), $start, $end) or
181  ilDateTime::_within($user_data->getEnd(), $start, $end)
182  ) {
183  $entries = $this->findCalendarEntriesForItem($category->getCategoryID(), $item['ref_id']);
184 
185  $this->logger->dump($item);
186  $this->logger->debug('Number of found entries is: ' . count($entries));
187 
188  foreach ($entries as $entry) {
189  if ($entry->getContextId() == ilObjCourse::CAL_COURSE_TIMING_START) {
190  $entry->setStart(new ilDate($user_data->getStart()->get(IL_CAL_DATE), IL_CAL_DATE));
191  $entry->setEnd(new ilDate($user_data->getStart()->get(IL_CAL_DATE), IL_CAL_DATE));
192  }
193  if ($entry->getContextId() == ilObjCourse::CAL_COURSE_TIMING_END) {
194  $entry->setStart(new ilDate($user_data->getEnd()->get(IL_CAL_DATE), IL_CAL_DATE));
195  $entry->setEnd(new ilDate($user_data->getEnd()->get(IL_CAL_DATE), IL_CAL_DATE));
196  }
197  $all_events[] = $entry;
198  }
199  }
200  }
201  }
202  return $all_events;
203  }
enabledCourseTimings($a_course_ref)
Check if timings enabled for ref_id.
static getTimingsItems($a_container_ref_id)
Get (sub) item data for timings view (no session material, no side blocks)
TableGUI class for timings administration.
static lookupTimingMode($a_obj_id)
static _getAllReferences($a_id)
get all reference ids of object
$start
Definition: bench.php:8
Class for single dates.
const CAL_COURSE_TIMING_END
const IL_CAL_DATE
const CAL_COURSE_TIMING_START
static getLogger($a_component_id)
Get component logger.
static _within(ilDateTime $dt, ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
Check whether an date is within a date duration given by start and end.
+ Here is the call graph for this function:

◆ enabledCourseTimings()

ilCalendarScheduleFilterTimings::enabledCourseTimings (   $a_course_ref)
protected

Check if timings enabled for ref_id.

Parameters
int$a_course_ref
Returns
bool

Definition at line 255 of file class.ilCalendarScheduleFilterTimings.php.

References ilObject\_lookupObjId(), ilObjCourse\_lookupViewMode(), getLogger(), and ilContainer\VIEW_TIMING.

Referenced by addCustomEvents(), and modifyEvent().

256  {
258  $this->getLogger()->debug('Parent course has other view mode than timings. course ref_id = ' . $a_course_ref);
259  return false;
260  }
261  return true;
262  }
static _lookupViewMode($a_id)
lookup view mode of container
static _lookupObjId($a_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ filterCategories()

ilCalendarScheduleFilterTimings::filterCategories ( array  $a_cats)

Filter categories All categories are show no filtering (support for individual folder appointments)

Parameters
int[]$a_cats

Implements ilCalendarScheduleFilter.

Definition at line 51 of file class.ilCalendarScheduleFilterTimings.php.

52  {
53  return $a_cats;
54  }

◆ findCalendarEntriesForItem()

ilCalendarScheduleFilterTimings::findCalendarEntriesForItem (   $category_id,
  $item_ref_id 
)
protected
Parameters
$category_id
$item_ref_id
Returns
ilCalendarEntry[]

Definition at line 210 of file class.ilCalendarScheduleFilterTimings.php.

References ilCalendarCategoryAssignments\_getAssignedAppointments(), ilObjCourse\CAL_COURSE_TIMING_END, and ilObjCourse\CAL_COURSE_TIMING_START.

Referenced by addCustomEvents().

211  {
213  $entries = [];
214  foreach ($app_ids as $app_id) {
215  $entry = new ilCalendarEntry($app_id);
216 
217  if (
218  (
219  $entry->getContextId() == ilObjCourse::CAL_COURSE_TIMING_START ||
220  $entry->getContextId() == ilObjCourse::CAL_COURSE_TIMING_END
221  ) &&
222  $entry->getContextInfo() == $item_ref_id
223  ) {
224  $entries[] = $entry;
225  }
226  }
227  return $entries;
228  }
Model for a calendar entry.
const CAL_COURSE_TIMING_END
static _getAssignedAppointments($a_cat_id)
Get assigned apointments.
const CAL_COURSE_TIMING_START
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLogger()

ilCalendarScheduleFilterTimings::getLogger ( )

Get logger.

Returns

Definition at line 41 of file class.ilCalendarScheduleFilterTimings.php.

References $logger.

Referenced by addCustomEvents(), enabledCourseTimings(), isCourseCategory(), and modifyEvent().

+ Here is the caller graph for this function:

◆ isCourseCategory()

ilCalendarScheduleFilterTimings::isCourseCategory (   $a_category_id)
protected
Parameters
int$a_category_id
Returns
bool|ilCalendarCategory

Definition at line 235 of file class.ilCalendarScheduleFilterTimings.php.

References ilCalendarCategory\getInstanceByCategoryId(), getLogger(), and ilCalendarCategory\TYPE_OBJ.

Referenced by addCustomEvents(), and modifyEvent().

236  {
237  $category = ilCalendarCategory::getInstanceByCategoryId($a_category_id);
238 
239  if ($category->getType() != ilCalendarCategory::TYPE_OBJ) {
240  $this->getLogger()->debug('No object calendar => not modifying event.');
241  return false;
242  }
243  if ($category->getObjType() != 'crs') {
244  $this->getLogger()->debug('Category object type is != crs => not modifying event');
245  return false;
246  }
247  return $category;
248  }
static getInstanceByCategoryId($a_cat_id)
Get instance by category id.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ modifyEvent()

ilCalendarScheduleFilterTimings::modifyEvent ( ilCalendarEntry  $a_event)

modify event => return false for not presenting event

Parameters
\ilCalendarEntry$a_event
Returns
bool|ilCalendarEntry

Implements ilCalendarScheduleFilter.

Definition at line 61 of file class.ilCalendarScheduleFilterTimings.php.

References ilObject\_getAllReferences(), ilCalendarCategoryAssignments\_lookupCategory(), ilObject\_lookupObjId(), ilObject\_lookupTitle(), ilObjCourse\CAL_COURSE_TIMING_END, ilObjCourse\CAL_COURSE_TIMING_START, enabledCourseTimings(), ilCalendarEntry\getContextId(), ilCalendarEntry\getContextInfo(), ilCalendarEntry\getEntryId(), ilObjectActivation\getItem(), getLogger(), ilCalendarEntry\getPresentationTitle(), ilCalendarEntry\getTitle(), ilCourseConstants\IL_CRS_VIEW_TIMING_RELATIVE, ilCalendarEntry\isAutoGenerated(), isCourseCategory(), ilObjCourse\lookupTimingMode(), ilCalendarEntry\setTitle(), and ilObjectActivation\TIMINGS_PRESETTING.

62  {
63  $this->getLogger()->debug('Modifying events for timings');
64  if (!$a_event->isAutoGenerated()) {
65  $this->getLogger()->debug($a_event->getTitle() . ' is not autogenerated => no modification');
66  return $a_event;
67  }
68 
69  if (
72  ) {
73  $this->getLogger()->debug('Non Timing event: unmodified');
74  return $a_event;
75  }
76 
77  // check course calendar
79  $category = $this->isCourseCategory($cat_id);
80  if (!$category) {
81  // no course category
82  return $a_event;
83  }
84 
85  // check absolute timings
86  // category object type is folder
87  $obj_id = $category->getObjId();
88  $ref_ids = ilObject::_getAllReferences($obj_id);
89  $ref_id = end($ref_ids);
91  // relative timings => always modify event
92  $this->getLogger()->debug('Filtering event since mode is relative timing: ' . $a_event->getPresentationTitle(true));
93  return false;
94  }
95 
96  // timings enabled?
97  if (!$this->enabledCourseTimings($ref_id)) {
98  return false;
99  }
100 
101  // check context info
102  if (!$a_event->getContextInfo()) {
103  $this->getLogger()->warning('Missing context info');
104  return false;
105  }
106 
107  $item_ref_id = (int) $a_event->getContextInfo();
108  $timing_item = ilObjectActivation::getItem($item_ref_id);
109  if ($timing_item['timing_type'] != ilObjectActivation::TIMINGS_PRESETTING) {
110  $this->getLogger()->debug('Delete event with disabled timing settings');
111  return false;
112  }
113 
114  if ($timing_item['changeable']) {
115  // check if scheduled
116  $user_data = new ilTimingUser($item_ref_id, $this->user_id);
117  if ($user_data->isScheduled()) {
118  $this->getLogger()->debug('Filtering event since item is scheduled by user: ' . $a_event->getPresentationTitle(true));
119  return false;
120  }
121  }
122 
123  // valid event => refresh title
124  $this->getLogger()->debug('Valid timings event. Update title');
125  $a_event->setTitle(
127  );
128  return $a_event;
129  }
static _lookupCategory($a_cal_id)
Lookup category id.
getPresentationTitle($a_shorten=true)
get title for presentation.
setTitle($a_title)
set title
enabledCourseTimings($a_course_ref)
Check if timings enabled for ref_id.
TableGUI class for timings administration.
static getItem($a_ref_id)
Get item data.
getEntryId()
get entry id
static _lookupTitle($a_id)
lookup object title
static lookupTimingMode($a_obj_id)
static _getAllReferences($a_id)
get all reference ids of object
static _lookupObjId($a_id)
isAutoGenerated()
is auto generated
const CAL_COURSE_TIMING_END
getContextId()
get context id
const CAL_COURSE_TIMING_START
+ Here is the call graph for this function:

Field Documentation

◆ $logger

ilCalendarScheduleFilterTimings::$logger
private

Definition at line 25 of file class.ilCalendarScheduleFilterTimings.php.

Referenced by getLogger().

◆ $user_id

ilCalendarScheduleFilterTimings::$user_id = 0
private

Definition at line 19 of file class.ilCalendarScheduleFilterTimings.php.

◆ CAL_TIMING_END

const ilCalendarScheduleFilterTimings::CAL_TIMING_END = 2

Definition at line 14 of file class.ilCalendarScheduleFilterTimings.php.

◆ CAL_TIMING_START

const ilCalendarScheduleFilterTimings::CAL_TIMING_START = 1

Definition at line 13 of file class.ilCalendarScheduleFilterTimings.php.


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