function CourseObjectAccessTiming::take in Course 3.x
Same name and namespace in other branches
- 8.3 src/Plugin/course/CourseObjectAccess/CourseObjectAccessTiming.php \Drupal\course\Plugin\course\CourseObjectAccess\CourseObjectAccessTiming::take()
- 8.2 src/Plugin/course/CourseObjectAccess/CourseObjectAccessTiming.php \Drupal\course\Plugin\course\CourseObjectAccess\CourseObjectAccessTiming::take()
Can the user take the object?
Parameters
type $account:
Return value
boolean
Overrides CourseObjectAccessPluginBase::take
1 call to CourseObjectAccessTiming::take()
- CourseObjectAccessTiming::view in src/
Plugin/ course/ CourseObjectAccess/ CourseObjectAccessTiming.php - Can the user view the object but not interact?
File
- src/
Plugin/ course/ CourseObjectAccess/ CourseObjectAccessTiming.php, line 31
Class
- CourseObjectAccessTiming
- Plugin annotation @CourseObjectAccess( id = "timing", label = @Translation("Timing"), )
Namespace
Drupal\course\Plugin\course\CourseObjectAccessCode
function take($account) {
$time = \Drupal::time()
->getRequestTime();
if ($this
->getOption('duration')) {
if ($this
->getCourseObject()
->getFulfillment($account)
->getOption('date_started')) {
$duration_end = $this
->getCourseObject()
->getFulfillment($account)
->getOption('date_started') + $this
->getOption('duration');
if ($time > $duration_end) {
$duration_end_h = \Drupal::service('date.formatter')
->format($duration_end, 'long');
$this
->getCourseObject()
->setAccessMessage('duration-expired', t('Your enrollment in this activity expired on %date.', array(
'%date' => $duration_end_h,
)));
return FALSE;
}
}
}
$released = $this
->isReleased();
$expired = $this
->isExpired();
return $released && !$expired;
}