You are here

function course_menu in Course 7.2

Same name and namespace in other branches
  1. 8.3 course.module \course_menu()
  2. 8.2 course.module \course_menu()
  3. 6 course.module \course_menu()
  4. 7 course.module \course_menu()
  5. 3.x course.module \course_menu()

Implements hook_menu().

File

./course.module, line 17
course.module Core functionality for Courses.

Code

function course_menu() {
  $items = array();

  // Base configuration.
  $items['admin/course'] = array(
    'title' => 'Course',
    'description' => 'Configure courses.',
    'page callback' => 'course_settings_overview',
    'access callback' => 'course_admin_access',
    'file' => 'includes/course.settings.inc',
  );

  // Default tab for settings.
  $items['admin/course/overview'] = array(
    'title' => 'Overview',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
  );
  $items['course/autocomplete/node/%'] = array(
    'page callback' => 'course_object_autocomplete_node',
    'access arguments' => array(
      'access content',
    ),
    'page arguments' => array(
      3,
      4,
    ),
  );

  // Course settings handler forms. This gives organization and consistency to
  // form placement for each module that defines settings handlers through
  // hook_course_handlers().
  $modules = course_get_handlers('settings');
  $default_set = array();
  $handlers = array();
  $packages = array();

  // Flatten each module's settings handlers into one array, so we can get info
  // about any other handler-package while looping over each handler below.
  foreach ($modules as $module_key => $settings) {
    if (is_array($settings)) {

      // Define
      foreach ($settings as $handler_key => $handler_info) {

        // Manually set the implementing module key. It would be unnecessary to
        // force implementing modules to set this, since we can get it here.
        $handler_info['module'] = $module_key;

        // Manually set which package the handler belongs in. If one is not
        // defined, assume the handler is it's own package.
        $handler_info['package'] = isset($handler_info['package']) ? $handler_info['package'] : $handler_key;

        // Build the array of handlers. Add this handler with a combined key,
        // so module defined settings handlers can avoid namespace conflicts.
        $module_handler_key = "{$module_key}_{$handler_key}";
        $handlers[$module_handler_key] = $handler_info;

        // Build a reverse array of handler keys - keyed by package - so we can
        // get package info below when we need it. If there are duplicate
        // handler/package keys, use the first one for grouping the others.
        $package_key = $handler_info['package'] ? $handler_info['package'] : $handler_key;
        if (!isset($packages[$package_key])) {
          $packages[$package_key] = $module_handler_key;
        }
      }
    }
  }

  // Loop over each handler, and set tabs accordingly.
  foreach ($handlers as $module_handler_key => $handler_info) {

    // Get package info for this handler.
    $package_key = $handler_info['package'];
    $package_info = $handlers[$packages[$package_key]];

    // Define a path for the handler's specified package.
    $package_router = "admin/course/{$package_key}";

    // Define a path for the handler.
    $handler_router = "admin/course/{$package_key}/{$module_handler_key}";

    // Add the handler item, either as the default page content
    // (MENU_NORMAL_ITEM will work with the MENU_DEFAULT_LOCAL_TASK below)
    // or as one of the other MENU_LOCAL_TASK tabs). If this is the deafult
    // page content, the router path and title will be taken from the
    // handler which defined the package.
    $item_router = !isset($default_set[$package_key]) ? $package_router : $handler_router;
    $item_title = !isset($default_set[$package_key]) ? $package_info['name'] : $handler_info['name'];
    $item_type = MENU_NORMAL_ITEM;
    $items[$item_router] = array(
      'title' => $item_title,
      'description' => $handler_info['description'],
      'access arguments' => array(
        'administer course',
      ),
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        $handler_info['callback'],
      ),
      'type' => MENU_NORMAL_ITEM,
    );

    // Append file info to $items, if specified.
    $file_info = array();
    if (isset($handler_info['file'])) {

      // Define the item 'file' key.
      $items[$item_router]['file'] = $handler_info['file'];

      // Define the item 'file path' key.
      if (isset($handler_info['file path'])) {

        // Use the path if provided. If not provided, we need to specify the
        // handler provider module path, otherwise hook_menu() assumes
        // 'file path' is the path to it's implementing module (Course).
        $items[$item_router]['file path'] = $handler_info['file path'] ? $handler_info['file path'] : drupal_get_path('module', $handler_info['module']);
      }
    }

    // Check if a default tab has already been set for this module.
    if (!isset($default_set[$package_key])) {

      // Add the default tab with the handler router item and name. We do
      // this here so the first handler settings form always displays as the
      // default page content at the module router item path.
      $items[$handler_router] = array(
        'title' => t('Settings'),
        'type' => MENU_NORMAL_ITEM,
      );

      // Flag MENU_DEFAULT_LOCAL_TASK as set for this module.
      $default_set[$package_key] = TRUE;
    }
  }

  // Landing page for course completion.
  $items['node/%course/course-outline'] = array(
    'title' => 'Course outline',
    'access callback' => 'node_access',
    'access arguments' => array(
      'update',
      1,
    ),
    'page arguments' => array(
      'course_outline_overview_form',
    ),
    'page callback' => 'drupal_get_form',
    'type' => MENU_LOCAL_TASK,
    'file' => 'includes/course.outline.inc',
  );

  // Landing page for course completion.
  $items['node/%course/course-complete'] = array(
    'title' => 'Course complete',
    'access arguments' => array(
      1,
    ),
    'access callback' => 'course_completion_page_access',
    'page arguments' => array(
      1,
    ),
    'page callback' => 'course_completion_page',
    'file' => 'includes/course.outline.inc',
  );

  // Display the 'Take course' menu item as a tab or link, depending.
  $items['node/%course/takecourse'] = array(
    'title' => 'Take course',
    'title callback' => 'course_takecourse_title',
    'title arguments' => array(
      1,
    ),
    'description' => 'Take course.',
    'page callback' => 'course_take_course',
    'page arguments' => array(
      1,
    ),
    'access callback' => 'course_take_course_menu_access',
    'access arguments' => array(
      1,
    ),
    'type' => variable_get('course_takecourse_tab_display', 1) ? MENU_LOCAL_TASK : MENU_CALLBACK,
  );

  // Reports page listing each course object.
  $items['node/%course/course-reports/objects'] = array(
    'title' => 'Course objects',
    'type' => MENU_LOCAL_TASK,
    'page callback' => 'course_object_reports_page',
    'page arguments' => array(
      1,
    ),
    'access callback' => '_course_reports_access',
    'access arguments' => array(
      1,
    ),
    'file' => 'includes/course.reports.inc',
  );

  // Global report area
  $items['admin/reports/course'] = array(
    'title' => 'Course reports',
    'description' => 'View and download course information.',
    'access arguments' => array(
      'access all course reports',
    ),
    'page callback' => 'system_admin_menu_block_page',
    'file path' => drupal_get_path('module', 'system'),
    'file' => 'system.admin.inc',
  );

  // Course object
  $items['node/%course/course-object/%course_object'] = array(
    'title' => 'Course object router',
    'page callback' => 'course_object_take',
    'page arguments' => array(
      3,
    ),
    'access callback' => 'course_access_object',
    'access arguments' => array(
      1,
      3,
    ),
    'weight' => 2,
  );

  // Course object edit
  $items['node/%course/course-object/%ctools_js/%course_object/options'] = array(
    'title' => 'Course object settings',
    'page callback' => 'course_object_options',
    'page arguments' => array(
      1,
      3,
      4,
    ),
    'access callback' => 'node_access',
    'access arguments' => array(
      'update',
      1,
    ),
  );

  // Course object edit
  $items['node/%course/course-object/%ctools_js/%course_object/restore'] = array(
    'page callback' => 'course_object_restore',
    'page arguments' => array(
      1,
      3,
      4,
    ),
    'access callback' => 'node_access',
    'access arguments' => array(
      'update',
      1,
    ),
    'type' => MENU_CALLBACK,
  );

  // AHAH handler.
  $items['node/%course/course-outline/%ctools_js/more/%'] = array(
    'page callback' => 'course_outline_overview_js_more',
    'access callback' => 'node_access',
    'access arguments' => array(
      'update',
      1,
    ),
    'type' => MENU_CALLBACK,
    'page arguments' => array(
      1,
      3,
      5,
    ),
  );

  // JS handler for AJAX navigation check.
  $items['node/%course/course-object/%course_object/%ctools_js/nav'] = array(
    'page callback' => 'course_ajax_fulfullment_check',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
    'page arguments' => array(
      1,
      3,
      4,
    ),
  );
  if (module_exists('devel_generate')) {
    $items['admin/config/development/generate/course'] = array(
      'title' => 'Generate course',
      'description' => 'Generate a given number of courses and object.',
      'access arguments' => array(
        'administer course',
      ),
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'course_generate_form',
      ),
      'file' => 'course.devel.inc',
    );
  }
  return $items;
}