class CourseObjectAccessTiming in Course 6
Same name and namespace in other branches
- 7.2 plugins/course_object_access/timing.inc \CourseObjectAccessTiming
- 7 plugins/course_object_access/timing.inc \CourseObjectAccessTiming
Hierarchy
- class \CourseHandler
- class \CourseObjectAccess
- class \CourseObjectAccessTiming
- class \CourseObjectAccess
Expanded class hierarchy of CourseObjectAccessTiming
1 string reference to 'CourseObjectAccessTiming'
- timing.inc in plugins/
course/ access/ timing.inc
File
- plugins/
course/ access/ timing.inc, line 11
View source
class CourseObjectAccessTiming extends CourseObjectAccess {
public function optionsDefinition() {
$defaults = parent::optionsDefinition();
$defaults += array(
'duration' => NULL,
'release' => NULL,
'expiration' => NULL,
'release_hidden' => NULL,
'expiration_hidden' => NULL,
);
return $defaults;
}
function take() {
$time = time();
if ($this
->getOption('duration')) {
if ($this
->getCourseObject()
->getFulfillment()
->getOption('date_started')) {
$duration_end = $this
->getCourseObject()
->getFulfillment()
->getOption('date_started') + $this
->getOption('duration');
if ($time > $duration_end) {
$duration_end_h = date('Y-m-d H:i:s', $duration_end);
$this
->getCourseObject()
->setAccessMessage('duration-expired', 'Your enrollment in this activity expired on ' . $duration_end_h);
return FALSE;
}
}
}
$released = $this
->isReleased();
$expired = $this
->isExpired();
return $released && !$expired;
}
function see() {
if (!$this
->isReleased() && $this
->getOption('release_hidden')) {
return FALSE;
}
if ($this
->isExpired() && $this
->getOption('expiration_hidden')) {
return FALSE;
}
}
function view() {
return $this
->take();
}
function optionsValidate(&$form, &$values) {
if (module_exists('duration_element')) {
$values['duration'] = $values['duration']
->to_single_metric('seconds');
}
}
function optionsForm() {
$form = array();
$config = $this
->getOptions();
if (module_exists('duration_element')) {
$duration = duration_create();
$duration
->set_seconds($config['duration']);
$duration
->normalize();
$form['duration'] = array(
'#title' => t('Duration'),
'#description' => 'Length of time a user can remain in this object before it is closed.',
'#type' => 'duration_combo',
'#largest_metric' => 'days',
'#smallest_metric' => 'minutes',
'#default_value' => $duration,
);
}
else {
$form['duration'] = array(
'#title' => t('Duration'),
'#description' => '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_popup',
'#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_popup',
'#default_value' => $config['expiration'],
);
$form['release_hidden'] = array(
'#title' => 'Hide until release date',
'#type' => 'checkbox',
'#default_value' => $config['release_hidden'],
);
$form['expiration_hidden'] = array(
'#title' => 'Hide after expiration date',
'#type' => 'checkbox',
'#description' => 'Hide the object after the expiration. For example, an optional pre-test that expires.',
'#default_value' => $config['expiration_hidden'],
);
return $form;
}
function isReleased() {
if (time() <= strtotime($this
->getOption('release'))) {
$this
->getCourseObject()
->setAccessMessage('not-open', t('This activity will be available on @release.', array(
'@release' => $this
->getOption('release'),
)));
return FALSE;
}
else {
return TRUE;
}
}
function isExpired() {
if ($this
->getOption('expiration') && time() > strtotime($this
->getOption('expiration'))) {
$this
->getCourseObject()
->setAccessMessage('closed', t('This activity closed on @expiration.', array(
'@expiration' => $this
->getOption('expiration'),
)));
return TRUE;
}
else {
return FALSE;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CourseHandler:: |
private | property | ||
CourseHandler:: |
protected | property | ||
CourseHandler:: |
public | property | ||
CourseHandler:: |
public | property | ||
CourseHandler:: |
public | property | ||
CourseHandler:: |
public | property | ||
CourseHandler:: |
final public | function | Merge an array of options onto the existing options. | |
CourseHandler:: |
public | function | Get an array of access messages. | |
CourseHandler:: |
protected | function | Return an array of database fields. This determines what fields should be serialized instead of stored. | |
CourseHandler:: |
function | |||
CourseHandler:: |
final public | function | Get an option stored in this CourseObject. | |
CourseHandler:: |
public | function | Get an object's configuration. | 1 |
CourseHandler:: |
public | function | Stub. Get the summary of an object's options. | 1 |
CourseHandler:: |
public | function | Return a list of warning strings about this handler. | 1 |
CourseHandler:: |
private | function | Merge arrays with replace, not append. | |
CourseHandler:: |
public | function | Save data somewhere. | 1 |
CourseHandler:: |
public | function | 2 | |
CourseHandler:: |
public | function | Set an access message to be displayed along with the course object when it is in the outline. For example, "This activity will open on XYZ" or "Please complete Step 1 to take this activity." | |
CourseHandler:: |
final public | function | Set an option for this handler. | |
CourseHandler:: |
final public | function | Set this entire handler's options. | |
CourseObjectAccess:: |
private | property | ||
CourseObjectAccess:: |
public | function | ||
CourseObjectAccess:: |
public | function | ||
CourseObjectAccess:: |
function |
Overrides CourseHandler:: |
||
CourseObjectAccessTiming:: |
function | |||
CourseObjectAccessTiming:: |
function | |||
CourseObjectAccessTiming:: |
public | function |
Handlers need to declare their defaults if they have a configuration form. Overrides CourseHandler:: |
|
CourseObjectAccessTiming:: |
function |
Handlers can declare a form. Overrides CourseHandler:: |
||
CourseObjectAccessTiming:: |
function |
Validate? Overrides CourseHandler:: |
||
CourseObjectAccessTiming:: |
function |
Overrides CourseObjectAccess:: |
||
CourseObjectAccessTiming:: |
function |
Overrides CourseObjectAccess:: |
||
CourseObjectAccessTiming:: |
function |
Overrides CourseObjectAccess:: |