function CourseObjectAttendance::access in Course 3.x
Response to "attendance" operations to check attendance window access.
Overrides ContentEntityBase::access
File
- modules/
course_attendance/ src/ Plugin/ course/ CourseObject/ CourseObjectAttendance.php, line 213
Class
- CourseObjectAttendance
- Plugin annotation @CourseObject( id = "attendance", label = "Attendance", )
Namespace
Drupal\course_attendance\Plugin\course\CourseObjectCode
function access($operation, AccountInterface $account = NULL, $return_as_object = FALSE) {
if ($operation == 'attendance') {
$start_date = strtotime($this
->getCourse()
->get('field_course_event_date')->value . ' UTC');
$open = $start_date + $this
->getOption('open');
$close = $start_date + $this
->getOption('close');
if (\Drupal::time()
->getRequestTime() < $open) {
return $return_as_object ? AccessResultForbidden::forbidden('not_open') : FALSE;
}
if (\Drupal::time()
->getRequestTime() > $close) {
return $return_as_object ? AccessResultForbidden::forbidden('closed') : FALSE;
}
}
return parent::access($operation, $account, $return_as_object);
}