View source
<?php
include dirname(__FILE__) . '/includes/opigno_simple_ui.og.inc';
include dirname(__FILE__) . '/includes/opigno_simple_ui.quiz.inc';
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;
}
function opigno_simple_ui_admin_redirect($path) {
drupal_goto($path);
return 'Redirecting...';
}
function opigno_simple_ui_views_api() {
return array(
'api' => '3.0',
);
}
function opigno_simple_ui_views_default_views_alter(&$views) {
if (array_key_exists('opigno_quizzes', $views)) {
$display = $views['opigno_quizzes']->display['default'];
$display->display_options['title'] = t("Lessons");
}
}
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);
}
}
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';
}
}
function opigno_simple_ui_login_redirect($form, &$form_state) {
$destination = variable_get('site_frontpage', '');
if ($destination !== '') {
$form_state['redirect'] = $destination;
}
}
function opigno_simple_ui_form_user_admin_permissions_alter(&$form, $form_state) {
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])) {
$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;
}
$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;
}
}
}
function opigno_simple_ui_menu_alter(&$items) {
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,
);
$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;
$items['node/%/group']['access callback'] = $items['node/%/group/users']['access callback'];
$items['node/%/group']['access arguments'] = $items['node/%/group/users']['access arguments'];
$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'])) {
$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;
}
$items['node/%/group']['page callback'] = $items['node/%/group/users']['page callback'];
$items['node/%/group']['page arguments'] = $items['node/%/group/users']['page arguments'];
$items['node/%node/sort-quizzes']['title'] = t("Sort lessons");
if (isset($items['group/%/%/admin/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;
}
}
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);
}
}
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.");
}
}
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();
}
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);
}
function opigno_simple_ui_modules_enabled($modules) {
$handle = FALSE;
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();
}
}
function opigno_simple_ui_course_view_tab_title($node) {
if ($node->type == OPIGNO_COURSE_BUNDLE || $node->type == 'class') {
return t('Home');
}
return t('View');
}
function opigno_simple_ui_course_edit_tab_title($node) {
if ($node->type == OPIGNO_COURSE_BUNDLE || $node->type == 'class') {
return t('Settings');
}
return t('Edit');
}
function opigno_simple_ui_course_group_tab_title($node) {
return t('Users');
}
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);
}
function opigno_simple_ui_apps_page() {
module_load_include('inc', 'apps', 'apps.pages');
return apps_install_page('opigno');
}
function opigno_simple_ui_wysiwyg_editor_settings_alter(&$settings, $context) {
if ($context['profile']->editor == 'ckeditor') {
$settings['enterMode'] = 2;
$settings['forceEnterMode'] = true;
$settings['shiftEnterMode'] = 1;
}
}