abstract class CourseObjectNode in Course 6
Same name and namespace in other branches
- 7.2 includes/CourseObjectNode.inc \CourseObjectNode
- 7 includes/CourseObjectNode.inc \CourseObjectNode
A course object that uses a node as a base.
Hierarchy
- class \CourseHandler
- class \CourseObject
- class \CourseObjectNode
- class \CourseObject
Expanded class hierarchy of CourseObjectNode
1 string reference to 'CourseObjectNode'
- course_cron in ./
course.module - Implements hook_cron().
File
- includes/
course_object.core.inc, line 1066
View source
abstract class CourseObjectNode extends CourseObject {
protected $node;
public function __construct($object, $user = NULL, $course = NULL) {
// Pass configuration to parent.
parent::__construct($object, $user, $course);
$this->node = node_load($this
->getInstanceId());
}
public function hasNodePrivacySupport() {
return module_exists('content_access') && module_exists('acl');
}
/**
* Return a list of valid node types.
*
* @return array
* An array keyed by machine name of a node type.
* return array(
* 'my_event' => 'My event content type',
* );
*/
public abstract function getNodeTypes();
/**
* Simple node course object behavior is to just redirect to the node.
*/
public function getTakeType() {
return 'redirect';
}
public function getTakeUrl() {
if ($this
->getInstanceId()) {
return url("node/{$this->node->nid}");
}
}
public function getEditUrl() {
if ($this
->getInstanceId()) {
return url("node/{$this->node->nid}/edit");
}
}
public function create() {
$node = new stdClass();
$node->type = $this
->getOption('node_type');
$node->title = $this
->getTitle();
$node->uid = $this->user->uid;
node_save($node);
$this
->setNode($node);
}
/**
* Set the node and instance ID (node ID) of this CourseObjectNode.
*
* @param mixed $node
* A node or node ID.
*/
public function setNode($node) {
$this->node = $node;
$this
->setInstanceId($this->node->nid);
}
/**
* Destroy the node instance.
*/
public function delete() {
node_delete($this
->getInstanceId());
}
public function optionsDefinition() {
$defaults = parent::optionsDefinition();
$defaults['private'] = 0;
$options = array_intersect_key(node_get_types('names'), $this
->getNodeTypes());
$defaults['node_type'] = key($options);
return $defaults;
}
public function optionsForm(&$form, &$form_state) {
parent::optionsForm($form, $form_state);
$config = $this
->getOptions();
if (!$this
->getInstanceId()) {
$types = drupal_map_assoc($this
->getNodeTypes());
$options = array_intersect_key(node_get_types('names'), $types);
if (count($options) > 1) {
array_unshift($options, '- select -');
}
$form['node_type'] = array(
'#title' => 'Create node',
'#type' => 'select',
'#options' => $options,
'#description' => 'Selecting a node type will automatically create this node and link it to this course object.',
'#default_value' => $config['node_type'],
);
if (count($options) > 1) {
$form['node_type']['#required'] = TRUE;
}
}
$form['node'] = array(
'#type' => 'fieldset',
'#title' => 'Node',
'#description' => 'Settings for node-based objects.',
);
$form['node']['instance'] = array(
'#title' => 'Existing node',
'#autocomplete_path' => 'course/autocomplete/node/' . implode(',', $this
->getNodeTypes()),
'#type' => 'textfield',
'#description' => t('Use an existing node instead of creating a new one.'),
);
$form['node']['private'] = array(
'#title' => t('Private'),
'#description' => $this
->hasNodePrivacySupport() ? t('This content will not be available to users who are not enrolled in this course.') : t('You must enable content_access and acl in order to restrict course content to users who are enrolled in this course.'),
'#type' => 'checkbox',
'#default_value' => $config['private'],
'#disabled' => !$this
->hasNodePrivacySupport(),
);
$nid = $this
->getInstanceId();
if ($nid) {
$node = node_load($nid);
$link = l(t("'%title' [node id %nid]", array(
'%title' => $node->title,
'%nid' => $node->nid,
)), "node/{$node->nid}", array(
'attributes' => array(
'target' => '_blank',
'title' => t('Open in new window'),
),
'html' => TRUE,
));
$form['node']['instance']['#description'] = t('Currently set to !link', array(
'!link' => $link,
));
}
}
/**
* Validate the options form. Check the node type.
*/
public function optionsValidate(&$form, &$form_state) {
if (isset($form_state['values']['node_type']) && empty($form_state['values']['node_type'])) {
form_set_error('node_type', 'Please select a node type.');
}
}
public function optionsSubmit(&$form, &$form_state) {
$nid = $form_state['values']['instance'];
if (!is_numeric($nid)) {
preg_match('/^(?:\\s*|(.*) )?\\[\\s*nid\\s*:\\s*(\\d+)\\s*\\]$/', $nid, $matches);
$nid = $matches[2];
}
if ($nid) {
$form_state['values']['instance'] = $nid;
}
else {
// Unset it, or we'll erase the relationship (since the textfield is
// actually blank).
unset($form_state['values']['instance']);
}
parent::optionsSubmit($form, $form_state);
}
public function getWarnings() {
$warnings = parent::getWarnings();
if ($this
->getOption('private')) {
$settings = variable_get('content_access_settings', array());
if (!$settings['per_node'][$this
->getComponent()]) {
$warnings[] = t('%t is set to Private, but the content type %c does not have access control lists enabled. Users will not be able to acces this content. Please visit !l to set up content access settings.', array(
'%t' => $this
->getTitle(),
'%c' => $this
->getComponent(),
'!l' => l('Access control', "admin/content/node-type/{$this->getComponent()}/access"),
));
}
}
return $warnings;
}
/**
* Grant access to course content before going to it.
*/
function grant() {
if ($this
->hasNodePrivacySupport()) {
if ($this
->getOption('private')) {
$uid = $this->user->uid;
module_load_include('inc', 'content_access', 'content_access.admin');
$acl_id = content_access_get_acl_id($this->node, 'view');
acl_add_user($acl_id, $uid);
acl_node_add_acl($this->node->nid, $acl_id, 1, 0, 0, content_access_get_settings('priority', $this->node->type));
node_save($this->node);
}
}
}
/**
* Duration expired (or something) - CourseObject is telling us so.
*/
function revoke() {
if ($this
->hasNodePrivacySupport()) {
if ($this
->getOption('private')) {
$uid = $this->user->uid;
module_load_include('inc', 'content_access', 'content_access.admin');
$acl_id = content_access_get_acl_id($this->node, 'view');
acl_remove_user($acl_id, $uid);
node_save($this->node);
}
}
}
/**
* On object write, set privacy on this node.
*/
function save() {
parent::save();
if ($this
->hasNodePrivacySupport() && $this
->getOption('private')) {
// Ensure that per-node access is enabled.
$global_settings = content_access_get_settings();
$global_settings['per_node'][$this->node->type] = 1;
content_access_set_settings($global_settings);
// Remove "view" permissions to everyone on this node.
$settings = content_access_get_per_node_settings($this->node);
$settings['view'] = array();
content_access_save_per_node_settings($this->node, $settings);
// Resave node to update access.
node_save($this->node);
}
}
/**
* Freeze data to persist over cloning/exporting.
* @return array
* An array of data to be frozen.
*/
function freeze() {
if ($this->node->nid != $this
->getCourse()
->getNode()->nid) {
// Don't freeze the course, if this course is part of the objects.
$ice = new stdClass();
$ice->node = $this->node;
return $ice;
}
}
/**
* Thaw data frozen from an earlier export/clone.
*
* @param array $data
* Unfrozen data.
*
* @return int
* The new instance ID.
*/
function thaw($ice) {
$this->node = $ice->node;
unset($this->node->nid);
node_save($this->node);
return $this->node->nid;
}
function getCloneAbility() {
return t('%object will be cloned as a node. Results may vary.', array(
'%object' => $this
->getTitle(),
));
}
}
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:: |
private | function | Merge arrays with replace, not append. | |
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. | |
CourseObject:: |
private | property | ||
CourseObject:: |
private | property | ||
CourseObject:: |
protected | property | ||
CourseObject:: |
public | function | Access functionality for course objects. | |
CourseObject:: |
function | Get the object component for this course object. | ||
CourseObject:: |
function | Get the Course that contains this CourseObject. | ||
CourseObject:: |
function | Get the course node ID this CourseObject belongs to. | ||
CourseObject:: |
public | function | Get this course object's fulfillment object. | |
CourseObject:: |
function | Get the instance ID. This could be the external component ID, a Node ID... | ||
CourseObject:: |
public static | function | Return the number of occurances that can be in a course at the same time. For example, the design of the Certificate module can only have 1 set of mappings per node. The same goes for Course Credit. We may also want a course object that can only be… | 2 |
CourseObject:: |
function | Get the module that provides this course object. | ||
CourseObject:: |
public | function |
Get options, with session options having precedence. Overrides CourseHandler:: |
|
CourseObject:: |
public | function |
Get core options summary. Overrides CourseHandler:: |
2 |
CourseObject:: |
function | Let the course object provide its own reports. | 4 | |
CourseObject:: |
function | Let the course object provide its own reports. | 4 | |
CourseObject:: |
public | function | Get the user's status in this course object. | 1 |
CourseObject:: |
function | |||
CourseObject:: |
public | function | Return the URL to the course object router. | |
CourseObject:: |
public | function | Specify whether fulfillment uses asynchronous polling. | 2 |
CourseObject:: |
public | function | ||
CourseObject:: |
function | Is this object graded? | 2 | |
CourseObject:: |
public | function | Is this course object required for course completion? | |
CourseObject:: |
function | Checks the temporary status of a course object. | ||
CourseObject:: |
private | function | ||
CourseObject:: |
public | function | Override navigation links. | 1 |
CourseObject:: |
public | function | Overrides a course outline list item. | 1 |
CourseObject:: |
function | Give the course object a chance do asynchronous polling and set completion on demand. | ||
CourseObject:: |
public | function | Get all course object implementations of getOptionsSummary(). | |
CourseObject:: |
function | Set the object component for this course object. | ||
CourseObject:: |
public | function | Set the Course for this CourseObject. | |
CourseObject:: |
function | Set the internal course object ID. | ||
CourseObject:: |
function | Set this object's instance ID. | ||
CourseObject:: |
function | Set the module that provides this course object. | ||
CourseObject:: |
function | Set the user fulfilling/creating this course object. | ||
CourseObject:: |
public | function | 5 | |
CourseObject:: |
final public | function | Take a course object. | |
CourseObject:: |
function | Remove any records associated with this course object for the user. | 1 | |
CourseObjectNode:: |
protected | property | ||
CourseObjectNode:: |
public | function |
Creates a course object. Overrides CourseObject:: |
7 |
CourseObjectNode:: |
public | function |
Destroy the node instance. Overrides CourseObject:: |
|
CourseObjectNode:: |
function |
Freeze data to persist over cloning/exporting. Overrides CourseObject:: |
||
CourseObjectNode:: |
function |
Returns an translated error message if this object has issues with cloning. Overrides CourseObject:: |
6 | |
CourseObjectNode:: |
public | function |
Get the URL to edit this course object, if any. Overrides CourseObject:: |
|
CourseObjectNode:: |
abstract public | function | Return a list of valid node types. | 8 |
CourseObjectNode:: |
public | function |
Simple node course object behavior is to just redirect to the node. Overrides CourseObject:: |
3 |
CourseObjectNode:: |
public | function |
Get the URL to take this course object, if any. Overrides CourseObject:: |
1 |
CourseObjectNode:: |
public | function |
Return a list of warning strings about this handler. Overrides CourseHandler:: |
2 |
CourseObjectNode:: |
function |
Grant access to course content before going to it. Overrides CourseObject:: |
||
CourseObjectNode:: |
public | function | ||
CourseObjectNode:: |
public | function |
Define configuration elements and their defaults. Overrides CourseObject:: |
3 |
CourseObjectNode:: |
public | function |
Default options form for all course objects. Overrides CourseObject:: |
5 |
CourseObjectNode:: |
public | function |
Save object configs to cache. Overrides CourseObject:: |
2 |
CourseObjectNode:: |
public | function |
Validate the options form. Check the node type. Overrides CourseObject:: |
|
CourseObjectNode:: |
function |
Duration expired (or something) - CourseObject is telling us so. Overrides CourseObject:: |
||
CourseObjectNode:: |
function |
On object write, set privacy on this node. Overrides CourseObject:: |
||
CourseObjectNode:: |
public | function | Set the node and instance ID (node ID) of this CourseObjectNode. | |
CourseObjectNode:: |
function |
Thaw data frozen from an earlier export/clone. Overrides CourseObject:: |
3 | |
CourseObjectNode:: |
public | function |
Construct a course object from a database record. Overrides CourseObject:: |