You are here

class CourseObjectBook in Course 6

Same name and namespace in other branches
  1. 7.2 modules/course_book/course_book.classes.inc \CourseObjectBook
  2. 7 modules/course_book/course_book.classes.inc \CourseObjectBook

Hierarchy

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 {
  function getNodeTypes() {
    return array(
      'book',
    );
  }

  /**
   * Make the book.
   */
  public function create() {
    $node = new stdClass();
    $node->type = $this
      ->getComponent();
    $node->title = $this
      ->getTitle();
    $node->uid = $this->user->uid;
    $node->book['bid'] = 'new';
    node_save($node);
    $this
      ->setNode($node);
  }
  function optionsDefinition() {
    $defaults = parent::optionsDefinition();
    $defaults['book_tracking'] = 'all';
    $defaults['outline_list_item_type'] = 'active_tree';
    return $defaults;
  }
  function optionsForm(&$form, &$form_state) {
    $config = $this
      ->optionsDefinition();
    parent::optionsForm($form, $form_state);
    $form['book_tracking'] = array(
      '#title' => t('Completion criteria'),
      '#type' => 'select',
      '#options' => array(
        'one' => 'View any page',
        'all' => '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_outline_list') {
      $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'],
      );
    }
  }

  /**
   * 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') {
      $mlids = array_keys(book_toc($this->node->nid, array(), 99));
      $viewed = array_keys(array_filter($this
        ->getFulfillment()
        ->getOption('book_fulfillment')));
      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('Previous', $prev['href']);
      }
      if ($next = book_next($book_link)) {
        $links['next'] = l('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(),
    ));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CourseHandler::$accessMessages private property
CourseHandler::$config protected property
CourseHandler::$handlerType public property
CourseHandler::$primaryKey public property
CourseHandler::$serializedField public property
CourseHandler::$table public property
CourseHandler::addOptions final public function Merge an array of options onto the existing options.
CourseHandler::getAccessMessages public function Get an array of access messages.
CourseHandler::getDatabaseFields protected function Return an array of database fields. This determines what fields should be serialized instead of stored.
CourseHandler::getId function
CourseHandler::getOption final public function Get an option stored in this CourseObject.
CourseHandler::optionsMerge private function Merge arrays with replace, not append.
CourseHandler::setAccessMessage 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::setOption final public function Set an option for this handler.
CourseHandler::setOptions final public function Set this entire handler's options.
CourseObject::$course private property
CourseObject::$courseObjectFulfillment private property
CourseObject::$user protected property
CourseObject::access public function Access functionality for course objects.
CourseObject::getComponent function Get the object component for this course object.
CourseObject::getCourse function Get the Course that contains this CourseObject.
CourseObject::getCourseNid function Get the course node ID this CourseObject belongs to.
CourseObject::getFulfillment public function Get this course object's fulfillment object.
CourseObject::getInstanceId function Get the instance ID. This could be the external component ID, a Node ID...
CourseObject::getMaxOccurences 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::getModule function Get the module that provides this course object.
CourseObject::getOptions public function Get options, with session options having precedence. Overrides CourseHandler::getOptions
CourseObject::getOptionsSummary public function Get core options summary. Overrides CourseHandler::getOptionsSummary 2
CourseObject::getReport function Let the course object provide its own reports. 4
CourseObject::getReports function Let the course object provide its own reports. 4
CourseObject::getStatus public function Get the user's status in this course object. 1
CourseObject::getTitle function
CourseObject::getUrl public function Return the URL to the course object router.
CourseObject::hasPolling public function Specify whether fulfillment uses asynchronous polling. 2
CourseObject::isActive public function
CourseObject::isGraded function Is this object graded? 2
CourseObject::isRequired public function Is this course object required for course completion?
CourseObject::isTemporary function Checks the temporary status of a course object.
CourseObject::optionFilter private function
CourseObject::poll function Give the course object a chance do asynchronous polling and set completion on demand.
CourseObject::renderOptionsSummary public function Get all course object implementations of getOptionsSummary().
CourseObject::setComponent function Set the object component for this course object.
CourseObject::setCourse public function Set the Course for this CourseObject.
CourseObject::setId function Set the internal course object ID.
CourseObject::setInstanceId function Set this object's instance ID.
CourseObject::setModule function Set the module that provides this course object.
CourseObject::setUser function Set the user fulfilling/creating this course object.
CourseObject::take public function 5
CourseObject::takeCourseObject final public function Take a course object.
CourseObject::unEnroll function Remove any records associated with this course object for the user. 1
CourseObjectBook::create public function Make the book. Overrides CourseObjectNode::create
CourseObjectBook::getCloneAbility public function Returns an translated error message if this object has issues with cloning. Overrides CourseObjectNode::getCloneAbility
CourseObjectBook::getNodeTypes function Return a list of valid node types. Overrides CourseObjectNode::getNodeTypes
CourseObjectBook::grade function Grade (track) the book based on the fulfillment data.
CourseObjectBook::optionsDefinition function Define configuration elements and their defaults. Overrides CourseObjectNode::optionsDefinition
CourseObjectBook::optionsForm function Default options form for all course objects. Overrides CourseObjectNode::optionsForm
CourseObjectBook::overrideNavigation public function Overrides navigation links. Overrides CourseObject::overrideNavigation
CourseObjectBook::overrideOutlineListItem public function Overrides a course outline list item. Overrides CourseObject::overrideOutlineListItem
CourseObjectNode::$node protected property
CourseObjectNode::delete public function Destroy the node instance. Overrides CourseObject::delete
CourseObjectNode::freeze function Freeze data to persist over cloning/exporting. Overrides CourseObject::freeze
CourseObjectNode::getEditUrl public function Get the URL to edit this course object, if any. Overrides CourseObject::getEditUrl
CourseObjectNode::getTakeType public function Simple node course object behavior is to just redirect to the node. Overrides CourseObject::getTakeType 3
CourseObjectNode::getTakeUrl public function Get the URL to take this course object, if any. Overrides CourseObject::getTakeUrl 1
CourseObjectNode::getWarnings public function Return a list of warning strings about this handler. Overrides CourseHandler::getWarnings 2
CourseObjectNode::grant function Grant access to course content before going to it. Overrides CourseObject::grant
CourseObjectNode::hasNodePrivacySupport public function
CourseObjectNode::optionsSubmit public function Save object configs to cache. Overrides CourseObject::optionsSubmit 2
CourseObjectNode::optionsValidate public function Validate the options form. Check the node type. Overrides CourseObject::optionsValidate
CourseObjectNode::revoke function Duration expired (or something) - CourseObject is telling us so. Overrides CourseObject::revoke
CourseObjectNode::save function On object write, set privacy on this node. Overrides CourseObject::save
CourseObjectNode::setNode public function Set the node and instance ID (node ID) of this CourseObjectNode.
CourseObjectNode::thaw function Thaw data frozen from an earlier export/clone. Overrides CourseObject::thaw 3
CourseObjectNode::__construct public function Construct a course object from a database record. Overrides CourseObject::__construct