コード例 #1
0
ファイル: pagemenu.php プロジェクト: nadavkav/MoodleTAO
/**
 * Add content to a block instance. This
 * method should fail gracefully.  Do not
 * call something like error()
 *
 * @param object $block Passed by refernce: this is the block instance object
 *                      Course Module Record is $block->cm
 *                      Module Record is $block->module
 *                      Module Instance Record is $block->moduleinstance
 *                      Course Record is $block->course
 *
 * @return boolean If an error occures, just return false and 
 *                 optionally set error message to $block->content->text
 *                 Otherwise keep $block->content->text empty on errors
 **/
function pagemenu_set_instance(&$block)
{
    global $CFG;
    if ($block->moduleinstance->displayname) {
        $block->hideheader = false;
    } else {
        $block->hideheader = true;
    }
    if (has_capability('mod/pagemenu:view', get_context_instance(CONTEXT_MODULE, $block->cm->id))) {
        require_once $CFG->dirroot . '/mod/pagemenu/locallib.php';
        $block->content->text = pagemenu_build_menu($block->moduleinstance->id);
    }
    return true;
}
コード例 #2
0
/**
 * Bulk menu builder
 *
 * @param array $pagemenus An array of pagemenu course module records with id, instance and visible set
 * @param string $render The renderer to use for all menus
 * @param boolean $menuinfo True, returns menu information object.  False, return menu HTML
 * @param int $courseid ID of the course that the menus belong
 * @return array
 **/
function pagemenu_build_menus($pagemenus, $render = 'list', $menuinfo = false, $courseid = NULL)
{
    global $COURSE;
    if ($courseid === NULL) {
        $courseid = $COURSE->id;
    }
    /// Filter out the menus that the user cannot see
    $canviewhidden = has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE, $courseid));
    // Load all the context instances at once
    $instances = get_context_instance(CONTEXT_MODULE, array_keys($pagemenus));
    $pagemenuids = array();
    foreach ($pagemenus as $pagemenu) {
        if (has_capability('mod/pagemenu:view', $instances[$pagemenu->id]) and ($pagemenu->visible or $canviewhidden)) {
            $pagemenuids[$pagemenu->id] = $pagemenu->instance;
        }
    }
    if (empty($pagemenuids)) {
        // Cannot see any of them
        return false;
    }
    /// Start fetching links and link data for ALL of the menus
    if (!($links = get_records_list('pagemenu_links', 'pagemenuid', implode(',', $pagemenuids)))) {
        // None of the menus have links...
        return false;
    }
    $data = pagemenu_get_link_data($links);
    /// Find all the first link IDs - this avoids going to the db
    /// for each menu or looping through all links for each module
    $firstlinkids = array();
    foreach ($links as $link) {
        if ($link->previd == 0) {
            $firstlinkids[$link->pagemenuid] = $link->id;
        }
    }
    $menus = array();
    foreach ($pagemenuids as $cmid => $pagemenuid) {
        if (array_key_exists($pagemenuid, $firstlinkids)) {
            $firstlinkid = $firstlinkids[$pagemenuid];
        } else {
            $firstlinkid = false;
        }
        $menus[$cmid] = pagemenu_build_menu($pagemenuid, $render, $menuinfo, $links, $data, $firstlinkid);
    }
    return $menus;
}
コード例 #3
0
ファイル: view.php プロジェクト: nadavkav/MoodleTAO
<?php

/**
 * Landing page for this module
 *
 * @author Mark Nielsen
 * @version $Id$
 * @package pagemenu
 **/
require_once '../../config.php';
require_once $CFG->dirroot . '/mod/pagemenu/locallib.php';
$id = optional_param('id', 0, PARAM_INT);
// Course Module ID
$a = optional_param('a', 0, PARAM_INT);
// Instance ID
list($cm, $course, $pagemenu) = pagemenu_get_basics($id, $a);
require_login($course->id);
require_capability('mod/pagemenu:view', get_context_instance(CONTEXT_MODULE, $cm->id));
pagemenu_print_header($cm, $course, $pagemenu);
print_box(pagemenu_build_menu($pagemenu->id), 'boxwidthnormal boxaligncenter');
print_footer($course);
コード例 #4
0
ファイル: edit.php プロジェクト: nadavkav/MoodleTAO
            $link->save($data);
        }
        pagemenu_set_message(get_string('menuupdated', 'pagemenu'), 'notifysuccess');
        redirect("{$CFG->wwwroot}/mod/pagemenu/edit.php?id={$cm->id}");
    } else {
        if (!empty($linkaction)) {
            // These are special link actions that can be invoked by
            // a link class.  EG: hide show page menu items
            if (!confirm_sesskey()) {
                error(get_string('confirmsesskeybad', 'error'));
            }
            if (!in_array($linkaction, pagemenu_get_links())) {
                error('Invalide link type');
            }
            $link = mod_pagemenu_link::factory($linkaction);
            $link->handle_action();
            redirect("{$CFG->wwwroot}/mod/pagemenu/edit.php?id={$cm->id}");
        }
    }
}
pagemenu_print_header($cm, $course, $pagemenu, 'edit', $mform->focus());
// Don't display menu when editing a single link
if (!($action == 'edit' and $linkid)) {
    echo pagemenu_build_menu($pagemenu->id, true);
}
// Print the form - remember it has duel purposes
print_box_start('boxwidthwide boxaligncenter');
$mform->set_data($formdata);
$mform->display();
print_box_end();
print_footer($course);
コード例 #5
0
            $link->save($data);
        }
        pagemenu_set_message(get_string('menuupdated', 'pagemenu'), 'notifysuccess');
        redirect("{$CFG->wwwroot}/mod/pagemenu/edit.php?id={$cm->id}");
    } else {
        if (!empty($linkaction)) {
            // These are special link actions that can be invoked by
            // a link class.  EG: hide show page menu items
            if (!confirm_sesskey()) {
                error(get_string('confirmsesskeybad', 'error'));
            }
            if (!in_array($linkaction, pagemenu_get_links())) {
                error('Invalide link type');
            }
            $link = mod_pagemenu_link::factory($linkaction);
            $link->handle_action();
            redirect("{$CFG->wwwroot}/mod/pagemenu/edit.php?id={$cm->id}");
        }
    }
}
pagemenu_print_header($cm, $course, $pagemenu, 'edit', $mform->focus());
// Don't display menu when editing a single link
if (!($action == 'edit' and $linkid)) {
    echo pagemenu_build_menu($pagemenu->id, 'edit');
}
// Print the form - remember it has duel purposes
print_box_start('boxwidthwide boxaligncenter');
$mform->set_data($formdata);
$mform->display();
print_box_end();
print_footer($course);