class CourseObjectBook in Course 7
Same name and namespace in other branches
- 6 modules/course_book/course_book.classes.inc \CourseObjectBook
- 7.2 modules/course_book/course_book.classes.inc \CourseObjectBook
Hierarchy
- class \Entity implements EntityInterface
- class \CourseHandler
- class \CourseObject
- class \CourseObjectNode
- class \CourseObjectBook
- class \CourseObjectNode
- class \CourseObject
- class \CourseHandler
Expanded class hierarchy of CourseObjectBook
1 string reference to 'CourseObjectBook'
- course_book_course_handlers in modules/
course_book/ course_book.module - Implements hook_course_handlers().
File
- modules/
course_book/ course_book.classes.inc, line 3
View source
class CourseObjectBook extends CourseObjectNode {
/**
* Course node context handler callback.
*/
public static function getNodeInstances($node) {
if (!empty($node->book['bid'])) {
return array(
$node->book['bid'],
);
}
}
function getNodeTypes() {
if (user_access('administer book outlines')) {
return array_keys(node_type_get_names());
}
else {
return variable_get('book_allowed_types', array(
'book',
));
}
}
/**
* Make the book.
*/
public function create($node = NULL) {
$node = new stdClass();
$node->type = $this
->getOption('node_type');
$node->book['bid'] = 'new';
$node->book['mlid'] = NULL;
parent::create($node);
}
function optionsDefinition() {
$defaults = parent::optionsDefinition();
$defaults['node_type'] = variable_get('course_book_default_node_type', 'book');
$defaults['book_tracking'] = 'all';
$defaults['outline_list_item_type'] = 'active_tree';
return $defaults;
}
function optionsForm(&$form, &$form_state) {
$config = $this
->getOptions();
parent::optionsForm($form, $form_state);
$form['book_tracking'] = array(
'#title' => t('Completion criteria'),
'#type' => 'select',
'#options' => array(
'one' => t('View any page'),
'all' => t('View all pages'),
),
'#default_value' => $config['book_tracking'],
);
// Add a book-specific configuration for course outline list item type, only
// if the standard course list outline handler is selected.
if ($this
->getCourse()
->getNode()->course['outline'] == 'course') {
$form['outline_list_item_type'] = array(
'#title' => t('Course outline list item type'),
'#type' => 'select',
'#options' => array(
'all_pages' => t('All book pages as an expanded, nested list'),
'active_tree' => t('Only the active book menu tree items, with a count indicator'),
'count' => t('A count indicator only'),
),
'#default_value' => $config['outline_list_item_type'],
);
}
if (!module_exists('node_access_book')) {
$form['node']['private']['#description'] .= '<br/><span style="color: #d00">If using "private", you should install <a href="http://drupal.org/project/node_access_book">Node access book</a> to ensure that book sub-pages obey the content access on the book parent.';
}
}
/**
* Grade (track) the book based on the fulfillment data.
*/
function grade() {
if (course_book_count($this->node->nid) == 0) {
// Book has no pages. Complete object.
$this
->getFulfillment()
->setComplete(1)
->save();
return;
}
if ($this
->getOption('book_tracking') == 'all') {
// Possibly a bug here. book_toc doesn't return inaccessible book pages.
$mlids = array_keys(book_toc($this->node->nid, 99));
$fulfillment = $this
->getFulfillment()
->getOption('book_fulfillment');
$viewed = $fulfillment ? array_keys(array_filter($fulfillment)) : array();
if (!array_diff($mlids, $viewed)) {
$this
->getFulfillment()
->setComplete(1)
->save();
}
}
elseif ($this
->getOption('book_tracking') == 'one') {
$this
->getFulfillment()
->setComplete(1)
->save();
}
}
/**
* Overrides navigation links.
*/
public function overrideNavigation() {
$links = parent::overrideNavigation();
$node = node_load(arg(1));
if (isset($node->book)) {
$book_link = $node->book;
if ($prev = book_prev($book_link)) {
$links['prev'] = l(t('Previous'), $prev['href']);
}
if ($next = book_next($book_link)) {
$links['next'] = l(t('Next'), $next['href']);
}
}
return $links;
}
/**
* Overrides a course outline list item.
*/
public function overrideOutlineListItem(&$item) {
// Check that course list outline handler is selected.
if ($this
->getCourse()
->getNode()->course['outline'] == 'course') {
$type = $this
->getOption('outline_list_item_type');
// Override the list item by reference.
course_book_override_outline_list_item($item, $this, $type);
}
}
public function getCloneAbility() {
return t('%title will only clone the first page.', array(
'%title' => $this
->getTitle(),
));
}
/**
* Override of CourseObjectNode::save()
*
* We have to remove the stock "view" content access permissions on Books, if
* node_access_book is enabled. Otherwise, users outside of the course can
* still access child book pages of a private book parent.
*/
public function save() {
// Take care of the parent book page.
parent::save();
if ($this
->hasNodePrivacySupport() && $this
->getOption('private') && module_exists('node_access_book')) {
// Remove "view" permissions on all the child pages.
$flat = array();
$tree = menu_tree_all_data($this->node->book['menu_name']);
_book_flatten_menu($tree, $flat);
foreach ($flat as $item) {
$nid = str_replace('node/', '', $item['link_path']);
$node = node_load($nid);
$settings = content_access_get_per_node_settings($node);
$settings['view'] = array();
content_access_save_per_node_settings($node, $settings);
// Resave node to update access.
node_access_acquire_grants($node);
}
}
}
/**
* Override of CourseObjectNode::freeze().
*
* Do not freeze the parent book ID.
*
* course_book_node_insert() stumbles if this is set and we are cloning a
* book.
*/
public function freeze() {
$ice = parent::freeze();
unset($ice->node->book['bid']);
return $ice;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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:: |
public | function | Get an handler option's value. | |
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:: |
public | function | Set an option for this handler. | |
CourseHandler:: |
final public | function | Set this entire handler's options. | |
CourseObject:: |
protected | property | ||
CourseObject:: |
function |
Builds a structured array representing the entity's content. Overrides Entity:: |
||
CourseObject:: |
function | Get the object component for this course object. | ||
CourseObject:: |
function | Get the object component title 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 the user's fulfillment for this course 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, except weight, having precedence. Overrides CourseHandler:: |
|
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. | 2 |
CourseObject:: |
public | function | Return the URL to the course object router. | |
CourseObject:: |
public | function | ||
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:: |
public | function | If this course object is required, can be it skipped? | |
CourseObject:: |
function | Checks the temporary status of a course object. | ||
CourseObject:: |
private | function | ||
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:: |
public | function | Mark this object for deletion. | |
CourseObject:: |
function | Set the internal course object ID. | ||
CourseObject:: |
function | Set the module that provides this course object. | ||
CourseObject:: |
public | function | ||
CourseObject:: |
public | function | 6 | |
CourseObject:: |
final public | function | Take a course object. | |
CourseObject:: |
function | Remove any records associated with this course object for the user. | 2 | |
CourseObject:: |
public | function |
Generate URI from course object. Overrides Entity:: |
|
CourseObjectBook:: |
public | function |
Make the book. Overrides CourseObjectNode:: |
|
CourseObjectBook:: |
public | function |
Override of CourseObjectNode::freeze(). Overrides CourseObjectNode:: |
|
CourseObjectBook:: |
public | function |
Returns an translated error message if this object has issues with cloning. Overrides CourseObjectNode:: |
|
CourseObjectBook:: |
public static | function |
Course node context handler callback. Overrides CourseObjectNode:: |
|
CourseObjectBook:: |
function |
Return a list of valid node types. Overrides CourseObjectNode:: |
||
CourseObjectBook:: |
function | Grade (track) the book based on the fulfillment data. | ||
CourseObjectBook:: |
function |
Define configuration elements and their defaults. Overrides CourseObjectNode:: |
||
CourseObjectBook:: |
function |
Default options form for all course objects. Overrides CourseObjectNode:: |
||
CourseObjectBook:: |
public | function |
Overrides navigation links. Overrides CourseObject:: |
|
CourseObjectBook:: |
public | function |
Overrides a course outline list item. Overrides CourseObject:: |
|
CourseObjectBook:: |
public | function |
Override of CourseObjectNode::save() Overrides CourseObjectNode:: |
|
CourseObjectNode:: |
protected | property | ||
CourseObjectNode:: |
function |
Deny access to objects without content. Overrides CourseObject:: |
||
CourseObjectNode:: |
public static | function |
Course context handler callback. Overrides CourseObject:: |
|
CourseObjectNode:: |
public | function |
Destroy the node instance. Overrides CourseObject:: |
|
CourseObjectNode:: |
public | function |
Get the URL to edit this course object, if any. Overrides CourseObject:: |
|
CourseObjectNode:: |
function | |||
CourseObjectNode:: |
function |
Get core options summary. Overrides CourseObject:: |
2 | |
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:: |
function |
Get the object title, or return this object's node's title if the option
is set. Overrides CourseObject:: |
||
CourseObjectNode:: |
public | function |
Get the URL to view this course object, if any. Overrides CourseObject:: |
|
CourseObjectNode:: |
function |
Show a warning if this object has an instance, but the node does not exist. Overrides CourseHandler:: |
2 | |
CourseObjectNode:: |
function |
Grant access to course content before going to it. Overrides CourseObject:: |
||
CourseObjectNode:: |
public | function | ||
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 |
When setting our instance ID, also set the 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 |
Overrides CourseHandler:: |
|
Entity:: |
protected | property | 1 | |
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
public | function |
Returns the bundle of the entity. Overrides EntityInterface:: |
|
Entity:: |
protected | function | Defines the entity label if the 'entity_class_label' callback is used. | 1 |
Entity:: |
protected | function | Override this in order to implement a custom default URI and specify 'entity_class_uri' as 'uri callback' hook_entity_info(). | |
Entity:: |
public | function |
Returns the info of the type of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the type of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Exports the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Gets the raw, translated value of a property or field. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Checks if the entity has a certain exportable status. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the entity identifier, i.e. the entities name or numeric id. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the internal, numeric identifier. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Checks whether the entity is the default revision. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the label of the entity. Overrides EntityInterface:: |
|
Entity:: |
protected | function | Set up the object instance on construction or unserializiation. | |
Entity:: |
public | function |
Generate an array for rendering the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the EntityMetadataWrapper of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function | Magic method to only serialize what's necessary. | |
Entity:: |
public | function | Magic method to invoke setUp() on unserialization. |