You are here

opigno_simple_ui.module in Opigno 7

File

modules/simple_ui/opigno_simple_ui.module
View source
<?php

/**
 * @file
 * The Opigno Simple UI module simplifies the platform interface by providing shortcuts
 * and hiding unnecessary complexity.
 */
include dirname(__FILE__) . '/includes/opigno_simple_ui.og.inc';
include dirname(__FILE__) . '/includes/opigno_simple_ui.quiz.inc';

/**
 * Implements hook_menu().
 */
function opigno_simple_ui_menu() {
  $items = array();
  if (module_exists('og_ui')) {
    $items = array_merge($items, opigno_simple_ui_og_menu());
  }
  $items['admin/opigno/system/users'] = array(
    'title' => "Manage users",
    'description' => "Manage platform users",
    'page callback' => 'opigno_simple_ui_admin_redirect',
    'page arguments' => array(
      'admin/people',
    ),
    'access arguments' => array(
      'administer users',
    ),
  );
  $items['admin/opigno/appearance/settings'] = array(
    'title' => "Manage display settings",
    'description' => "Manage platform theme settings",
    'page callback' => 'opigno_simple_ui_admin_redirect',
    'page arguments' => array(
      'admin/appearance/settings/' . variable_get('theme_default', 'platon'),
    ),
    'access arguments' => array(
      'administer themes',
    ),
  );
  if (variable_get('theme_default', 'platon') === 'platon') {
    $default_theme_settings = variable_get('theme_platon_settings', array());
    if (!empty($default_theme_settings['platon_menu_source'])) {
      $items['admin/opigno/appearance/menu'] = array(
        'title' => "Manage menu",
        'description' => "Manage the main menu items",
        'page callback' => 'opigno_simple_ui_admin_redirect',
        'page arguments' => array(
          'admin/structure/menu/manage/' . $default_theme_settings['platon_menu_source'],
        ),
        'access arguments' => array(
          'administer menu',
        ),
      );
    }
  }
  $items['admin/opigno/content/default-tools'] = array(
    'title' => "Set default course tools",
    'description' => "Manage the tools that are activated by default for new courses.",
    'page callback' => 'opigno_simple_ui_admin_redirect',
    'page arguments' => array(
      'admin/structure/types/manage/course/fields/opigno_course_tools',
    ),
    'access arguments' => array(
      'administer content types',
    ),
  );
  $items['admin/opigno/content/forums'] = array(
    'title' => "Manage forums",
    'description' => "Manage the different forums and forum containers.",
    'page callback' => 'opigno_simple_ui_admin_redirect',
    'page arguments' => array(
      'admin/structure/forum',
    ),
    'access arguments' => array(
      'administer taxonomy',
    ),
  );
  if (module_exists('apps')) {
    $items['admin/opigno/system/apps'] = array(
      'title' => "Apps",
      'description' => "Manage and install apps for your platform",
      'page callback' => 'opigno_simple_ui_apps_page',
      'access arguments' => array(
        'administer apps',
      ),
    );
  }
  return $items;
}

/**
 * Menu callback: provide a redirect functionality for creating shortcuts to system admin pages
 * via the admin/opigno section.
 */
function opigno_simple_ui_admin_redirect($path) {
  drupal_goto($path);
  return 'Redirecting...';
}

/**
 * Implements hook_views_api().
 */
function opigno_simple_ui_views_api() {
  return array(
    'api' => '3.0',
  );
}

/**
 * Implements of hook_views_default_views_alter().
 */
function opigno_simple_ui_views_default_views_alter(&$views) {

  // Group the courses by class.
  if (array_key_exists('opigno_quizzes', $views)) {
    $display = $views['opigno_quizzes']->display['default'];
    $display->display_options['title'] = t("Lessons");
  }
}

/**
 * Implements hook_form_BASE_FORM_ID_alter() for node_form.
 */
function opigno_simple_ui_form_node_form_alter(&$form, $form_state) {
  if (module_exists('quiz') && in_array($form['type']['#value'], array_keys(_quiz_question_get_implementations()))) {
    module_load_include('inc', 'opigno_simple_ui', 'includes/opigno_simple_ui.quiz');
    opigno_simple_ui_question_typesform_alter($form, $form_state);
  }
}

/**
 * Implements hook_form_alter().
 */
function opigno_simple_ui_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'user_login_block') {
    $form['user_login_fieldset'] = array(
      '#type' => 'fieldset',
      '#title' => t('User login'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    $form['user_login_fieldset']['name'] = $form['name'];
    $form['user_login_fieldset']['pass'] = $form['pass'];
    $form['user_login_fieldset']['actions'] = $form['actions'];
    $form['user_login_fieldset']['links'] = $form['links'];
    unset($form['name']);
    unset($form['pass']);
    unset($form['actions']);
    unset($form['links']);
  }
  if ($form_id == 'user_login') {
    $form['#submit'][] = 'opigno_simple_ui_login_redirect';
  }
}

/*
 * Submit handler for the user login form to redirect the user to the
 * default front homepage.
 */
function opigno_simple_ui_login_redirect($form, &$form_state) {
  $destination = variable_get('site_frontpage', '');
  if ($destination !== '') {
    $form_state['redirect'] = $destination;
  }
}

/**
 * Implements hook_form_FORM_ID_alter() for user_admin_permissions.
 */
function opigno_simple_ui_form_user_admin_permissions_alter(&$form, $form_state) {

  // If in distribution context, order the roles by importance.
  if (function_exists('opigno_lms_get_platform_role_id')) {
    $admin_rid = opigno_lms_get_platform_role_id(OPIGNO_LMS_ADMIN_ROLE);
    $student_manager_rid = opigno_lms_get_platform_role_id(OPIGNO_LMS_STUDENT_MANAGER_ROLE);
    if (isset($form['role_names'][$admin_rid]) && count($form['role_names']) > 3) {
      if (isset($form['role_names'][$student_manager_rid])) {

        // This will add it to the end of the list.
        $student_manager_header = $form['role_names'][$student_manager_rid];
        unset($form['role_names'][$student_manager_rid]);
        $form['role_names'][$student_manager_rid] = $student_manager_header;
        $student_manager_perms = $form['checkboxes'][$student_manager_rid];
        unset($form['checkboxes'][$student_manager_rid]);
        $form['checkboxes'][$student_manager_rid] = $student_manager_perms;
      }

      // This will add it to the end of the list.
      $admin_header = $form['role_names'][$admin_rid];
      unset($form['role_names'][$admin_rid]);
      $form['role_names'][$admin_rid] = $admin_header;
      $admin_perms = $form['checkboxes'][$admin_rid];
      unset($form['checkboxes'][$admin_rid]);
      $form['checkboxes'][$admin_rid] = $admin_perms;
    }
  }
}

/**
 * Implements hook_menu_alter().
 */
function opigno_simple_ui_menu_alter(&$items) {

  // Change the default node tabs title on a course node.
  unset($items['node/%node/view']['title']);
  $items['node/%node/view']['title callback'] = 'opigno_simple_ui_course_view_tab_title';
  $items['node/%node/view']['title arguments'] = array(
    1,
  );
  unset($items['node/%node/edit']['title']);
  $items['node/%node/edit']['title callback'] = 'opigno_simple_ui_course_edit_tab_title';
  $items['node/%node/edit']['title arguments'] = array(
    1,
  );
  unset($items['node/%/group']['title']);
  $items['node/%/group']['title callback'] = 'opigno_simple_ui_course_group_tab_title';
  $items['node/%/group']['title arguments'] = array(
    1,
  );

  // Add a new secondary tab "Members".
  $items['node/%/group/users'] = $items['group/%/%/admin/people'];
  $items['node/%/group/users']['title'] = "Members";
  $items['node/%/group/users']['title callback'] = 't';
  unset($items['node/%/group/users']['title arguments']);
  $items['node/%/group/users']['page arguments'][0] = 'node';
  $items['node/%/group/users']['page arguments'][1] = 1;
  $items['node/%/group/users']['access arguments'][1] = 'node';
  $items['node/%/group/users']['access arguments'][2] = 1;
  $items['node/%/group/users']['type'] = MENU_DEFAULT_LOCAL_TASK;

  // Make parent inherit this access control.
  $items['node/%/group']['access callback'] = $items['node/%/group/users']['access callback'];
  $items['node/%/group']['access arguments'] = $items['node/%/group/users']['access arguments'];

  // Add a new secondary tab "Add members".
  $items['node/%/group/add'] = $items['group/%/%/admin/people/add-user'];
  $items['node/%/group/add']['page arguments'][1] = 'node';
  $items['node/%/group/add']['page arguments'][2] = 1;
  $items['node/%/group/add']['access arguments'][1] = 'node';
  $items['node/%/group/add']['access arguments'][2] = 1;
  $items['node/%/group/add']['type'] = MENU_LOCAL_TASK;
  if (isset($items['group/%/%/admin/people/mass-add-user'])) {

    // Add a new secondary tab "Add multiple members".
    $items['node/%/group/mass-add'] = $items['group/%/%/admin/people/mass-add-user'];
    $items['node/%/group/mass-add']['title'] = "Add multiple members";
    $items['node/%/group/mass-add']['page arguments'][1] = 'node';
    $items['node/%/group/mass-add']['page arguments'][2] = 1;
    $items['node/%/group/mass-add']['access arguments'][1] = 'node';
    $items['node/%/group/mass-add']['access arguments'][2] = 1;
    $items['node/%/group/mass-add']['type'] = MENU_LOCAL_TASK;
  }

  // Make parent tab point to "Members" page.
  $items['node/%/group']['page callback'] = $items['node/%/group/users']['page callback'];
  $items['node/%/group']['page arguments'] = $items['node/%/group/users']['page arguments'];

  // Correct sort quizzes page title.
  $items['node/%node/sort-quizzes']['title'] = t("Sort lessons");
  if (isset($items['group/%/%/admin/permissions'])) {

    // Per group og permissions.
    $items['node/%/group/permissions'] = $items['group/%/%/admin/permissions'];
    $items['node/%/group/permissions']['title arguments'][1] = 'node';
    $items['node/%/group/permissions']['title arguments'][2] = 1;
    $items['node/%/group/permissions']['access arguments'][1] = 'node';
    $items['node/%/group/permissions']['access arguments'][2] = 1;
    $items['node/%/group/permissions']['page arguments'][1] = 'node';
    $items['node/%/group/permissions']['page arguments'][2] = 1;
    $items['node/%/group/permissions']['type'] = MENU_LOCAL_TASK;
    $items['node/%/group/permissions']['weight'] = 10;
  }
}

/**
 * Implements hook_theme_registry_alter().
 */
function opigno_simple_ui_theme_registry_alter(&$theme_registry) {
  if (isset($theme_registry['menu_local_task'])) {
    $theme_registry['menu_local_task']['function'] = 'theme_opigno_simple_ui_local_task';
  }
  if (module_exists('quiz')) {
    opigno_simple_ui_quiz_theme_registry_alter($theme_registry);
  }
}

/**
 * Implements hook_opigno_tool_alter().
 */
function opigno_simple_ui_opigno_tool_alter(&$tools, $node = NULL) {
  if (isset($tools['quiz'])) {
    $tools['quiz']['name'] = t("Lessons");
    $tools['quiz']['weight'] = -20;
    $tools['quiz']['description'] = t("Lessons allow teachers to assess students and provide slideshows with course content and/or questions.");
  }
}

/**
 * Implements hook_modules_installed().
 */
function opigno_simple_ui_modules_installed($modules) {
  module_load_include('inc', 'opigno_simple_ui', 'includes/opigno_simple_ui.install');
  opigno_simple_ui_change_quiz_question_bundles_names();
}

/**
 * Implements hook_menu_local_tasks_alter().
 */
function opigno_simple_ui_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  if ($root_path == 'admin/opigno/content/course-administration' || $root_path == 'my-trainings' || $root_path == 'training-catalogue') {
    $item = menu_get_item('node/add/' . OPIGNO_COURSE_BUNDLE);
    if ($item['access']) {
      $item['title'] = t("Add a new course");
      $item['options']['attributes']['class'][] = $item['localized_options']['attributes']['class'][] = 'add-course';
      $item['options']['attributes']['class'][] = $item['localized_options']['attributes']['class'][] = 'opigno-simple-ui-add-course';
      $item['options']['attributes']['class'][] = $item['localized_options']['attributes']['class'][] = 'opigno-simple-ui-course-administration-add-course-link';
      $data['actions']['output'][] = array(
        '#theme' => 'menu_local_action',
        '#link' => $item,
      );
    }
  }
  module_load_include('inc', 'opigno_simple_ui', 'includes/opigno_simple_ui.quiz');
  opigno_simple_ui_quiz_menu_local_tasks_alter($data, $router_item, $root_path);
}

/**
 * Implements hook_modules_enabled().
 */
function opigno_simple_ui_modules_enabled($modules) {
  $handle = FALSE;

  // We cannot use _quiz_question_implementations(), as the modules
  // are not enabled yet... Update this list if we find new question
  // types.
  foreach (array(
    'quiz',
    'matching',
    'multichoice',
    'quizfileupload',
    'quiz_ddlines',
    'quiz_directions',
    'scale',
    'short_answer',
    'truefalse',
    'long_answer',
  ) as $module) {
    if (in_array($module, $modules)) {
      $handle = TRUE;
      break;
    }
  }
  if ($handle) {
    module_load_include('inc', 'opigno_simple_ui', 'includes/opigno_simple_ui.quiz');
    opigno_simple_ui_update_quiz_labels();
  }
}

/**
 * Change the "View" tab title on course node pages.
 *
 * @param  stdClass $node
 *
 * @return string
 */
function opigno_simple_ui_course_view_tab_title($node) {
  if ($node->type == OPIGNO_COURSE_BUNDLE || $node->type == 'class') {
    return t('Home');
  }
  return t('View');
}

/**
 * Change the "Edit" tab title on course node pages.
 *
 * @param  stdClass $node
 *
 * @return string
 */
function opigno_simple_ui_course_edit_tab_title($node) {
  if ($node->type == OPIGNO_COURSE_BUNDLE || $node->type == 'class') {
    return t('Settings');
  }
  return t('Edit');
}

/**
 * Change the "Group" tab title on course node pages.
 *
 * @param  stdClass $node
 *
 * @return string
 */
function opigno_simple_ui_course_group_tab_title($node) {
  return t('Users');
}

/**
 * Alter the way tabs are rendered to add custom classes.
 *
 * @param  array $vars
 *
 * @return string
 */
function theme_opigno_simple_ui_local_task(&$vars) {
  $class = 'node-tab';
  if (isset($vars['element']['#link']['path'])) {
    switch ($vars['element']['#link']['path']) {
      case 'node/%/view':
        $class .= ' node-view-tab';
        break;
      case 'node/%/edit':
        $class .= ' node-edit-tab';
        break;
      case 'node/%/tools':
        $class .= ' node-tools-tab';
        break;
      case 'node/%/group':
        $class .= ' node-group-tab';
        break;
      case 'node/%/certificate':
        $class .= ' node-certificate-tab';
        break;
    }
  }
  $vars['element']['#link']['localized_options']['attributes']['class'][] = $class;
  return theme_menu_local_task($vars);
}

/**
 * Page callback for the apps page.
 * Fetches the apps administration page from the apps module and returns it.
 */
function opigno_simple_ui_apps_page() {
  module_load_include('inc', 'apps', 'apps.pages');
  return apps_install_page('opigno');
}

/**
 * Fix for ckeditor <p>&nbsp;</p>
 */
function opigno_simple_ui_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'ckeditor') {

    // set various CKEditor option to address problem with extra p tags being added
    $settings['enterMode'] = 2;
    $settings['forceEnterMode'] = true;
    $settings['shiftEnterMode'] = 1;
  }
}

Functions

Namesort descending Description
opigno_simple_ui_admin_redirect Menu callback: provide a redirect functionality for creating shortcuts to system admin pages via the admin/opigno section.
opigno_simple_ui_apps_page Page callback for the apps page. Fetches the apps administration page from the apps module and returns it.
opigno_simple_ui_course_edit_tab_title Change the "Edit" tab title on course node pages.
opigno_simple_ui_course_group_tab_title Change the "Group" tab title on course node pages.
opigno_simple_ui_course_view_tab_title Change the "View" tab title on course node pages.
opigno_simple_ui_form_alter Implements hook_form_alter().
opigno_simple_ui_form_node_form_alter Implements hook_form_BASE_FORM_ID_alter() for node_form.
opigno_simple_ui_form_user_admin_permissions_alter Implements hook_form_FORM_ID_alter() for user_admin_permissions.
opigno_simple_ui_login_redirect
opigno_simple_ui_menu Implements hook_menu().
opigno_simple_ui_menu_alter Implements hook_menu_alter().
opigno_simple_ui_menu_local_tasks_alter Implements hook_menu_local_tasks_alter().
opigno_simple_ui_modules_enabled Implements hook_modules_enabled().
opigno_simple_ui_modules_installed Implements hook_modules_installed().
opigno_simple_ui_opigno_tool_alter Implements hook_opigno_tool_alter().
opigno_simple_ui_theme_registry_alter Implements hook_theme_registry_alter().
opigno_simple_ui_views_api Implements hook_views_api().
opigno_simple_ui_views_default_views_alter Implements of hook_views_default_views_alter().
opigno_simple_ui_wysiwyg_editor_settings_alter Fix for ckeditor <p>&nbsp;</p>
theme_opigno_simple_ui_local_task Alter the way tabs are rendered to add custom classes.