class CourseObjectAccessTiming 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
- 8.2 src/Plugin/course/CourseObjectAccess/CourseObjectAccessTiming.php \Drupal\course\Plugin\course\CourseObjectAccess\CourseObjectAccessTiming
Plugin annotation
@CourseObjectAccess(
id = "timing",
label = @Translation("Timing"),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\course\Plugin\CourseObjectAccessPluginBase implements PluginFormInterface, CourseObjectAccessInterface
- class \Drupal\course\Plugin\course\CourseObjectAccess\CourseObjectAccessTiming
- class \Drupal\course\Plugin\CourseObjectAccessPluginBase implements PluginFormInterface, CourseObjectAccessInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of CourseObjectAccessTiming
File
- src/
Plugin/ course/ CourseObjectAccess/ CourseObjectAccessTiming.php, line 15
Namespace
Drupal\course\Plugin\course\CourseObjectAccessView source
class CourseObjectAccessTiming extends CourseObjectAccessPluginBase {
public function optionsDefinition() {
$defaults = parent::optionsDefinition();
$defaults += array(
'duration' => NULL,
'release' => NULL,
'expiration' => NULL,
'release_hidden' => NULL,
'expiration_hidden' => NULL,
);
return $defaults;
}
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;
}
function see($account) {
if (!$this
->isReleased() && $this
->getOption('release_hidden')) {
return FALSE;
}
if ($this
->isExpired() && $this
->getOption('expiration_hidden')) {
return FALSE;
}
}
function view($account) {
return $this
->take($account);
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$config = $this
->getOptions();
if (Drupal::moduleHandler()
->moduleExists('timeperiod')) {
$form['duration'] = array(
'#title' => t('Duration'),
'#description' => t('Length of time a user can remain in this object before it is closed.'),
'#type' => 'timeperiod_select',
'#units' => array(
'86400' => array(
'max' => 30,
'step size' => 1,
),
'3600' => array(
'max' => 24,
'step size' => 1,
),
'60' => array(
'max' => 60,
'step size' => 1,
),
),
'#default_value' => $config['duration'],
);
}
else {
$form['duration'] = array(
'#title' => t('Duration'),
'#description' => t('Length of time in seconds a user can remain in this object before it is closed.'),
'#type' => 'textfield',
'#size' => 8,
'#default_value' => $config['duration'],
);
}
$form['release'] = array(
'#title' => t('Release date'),
'#description' => t('When this object can be accessed. If this object is required, users will not be able to proceed until after this date.'),
'#type' => 'date',
'#default_value' => $config['release'],
);
$form['expiration'] = array(
'#title' => t('Expiration date'),
'#description' => t('When this object will close. If this object is required, users will not be able to proceed to the next activity after this date.'),
'#type' => 'date',
'#default_value' => $config['expiration'],
);
$form['release_hidden'] = array(
'#title' => t('Hide until release date'),
'#type' => 'checkbox',
'#description' => t('Hide the object until the release date. For example, an evaluation after a live event.'),
'#default_value' => $config['release_hidden'],
);
$form['expiration_hidden'] = array(
'#title' => t('Hide after expiration date'),
'#type' => 'checkbox',
'#description' => t('Hide the object after the expiration. For example, an optional pre-test that expires.'),
'#default_value' => $config['expiration_hidden'],
);
return $form;
}
function isReleased() {
$release_date = strtotime($this
->getOption('release'));
if (\Drupal::time()
->getRequestTime() <= $release_date) {
$release_date_formatted = \Drupal::service('date.formatter')
->format($release_date, 'long');
$this
->getCourseObject()
->setAccessMessage('not-open', t('%title will be available on %release.', array(
'%title' => $this
->getCourseObject()
->getTitle(),
'%release' => $release_date_formatted,
)));
return FALSE;
}
else {
return TRUE;
}
}
function isExpired() {
$expiration_date = strtotime($this
->getOption('expiration'));
if ($this
->getOption('expiration') && \Drupal::time()
->getRequestTime() > $expiration_date) {
$expiration_date_formatted = \Drupal::service('date.formatter')
->format($expiration_date, 'long');
$this
->getCourseObject()
->setAccessMessage('closed', t('%title closed on %expiration.', array(
'%title' => $this
->getCourseObject()
->getTitle(),
'%expiration' => $expiration_date_formatted,
)));
return TRUE;
}
else {
return FALSE;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CourseObjectAccessPluginBase:: |
private | property | ||
CourseObjectAccessPluginBase:: |
private | property | ||
CourseObjectAccessPluginBase:: |
public | function | Alter a property during display/tracking. Does not affect the stored options. This is called in CourseObject::getReadOnlyOptions(). | |
CourseObjectAccessPluginBase:: |
public | function | Evaluate the access conditions. | 1 |
CourseObjectAccessPluginBase:: |
public | function | ||
CourseObjectAccessPluginBase:: |
public | function | Helper method to get possible objects. | 1 |
CourseObjectAccessPluginBase:: |
public | function | ||
CourseObjectAccessPluginBase:: |
public | function | ||
CourseObjectAccessPluginBase:: |
public | function | ||
CourseObjectAccessPluginBase:: |
public | function | ||
CourseObjectAccessPluginBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
CourseObjectAccessPluginBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
CourseObjectAccessTiming:: |
public | function |
Define the form to be used in the object access settings area. Overrides CourseObjectAccessPluginBase:: |
|
CourseObjectAccessTiming:: |
function | |||
CourseObjectAccessTiming:: |
function | |||
CourseObjectAccessTiming:: |
public | function |
Overrides CourseObjectAccessPluginBase:: |
|
CourseObjectAccessTiming:: |
function |
Can the user see the object in the outline? Overrides CourseObjectAccessPluginBase:: |
||
CourseObjectAccessTiming:: |
function |
Can the user take the object? Overrides CourseObjectAccessPluginBase:: |
||
CourseObjectAccessTiming:: |
function |
Can the user view the object but not interact? Overrides CourseObjectAccessPluginBase:: |
||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 98 |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |