/**
 * Get an array of link type classes
 *
 * @return array
 **/
function pagemenu_get_link_classes()
{
    $return = array();
    foreach (pagemenu_get_links() as $type) {
        $return[$type] = mod_pagemenu_link::factory($type);
    }
    return $return;
}
 /**
  * Constructor - basic setup
  *
  * @param int $pagemenuid Page menu instance ID
  * @param array $links Page menu link records that belong to this page menu
  * @param array $data Link data for the links
  * @param int $firstlinkid First link ID
  * @return void
  **/
 public function __construct($pagemenuid, $links = NULL, $data = NULL, $firstlinkid = false)
 {
     $this->pagemenuid = $pagemenuid;
     if ($links === NULL) {
         $links = get_records('pagemenu_links', 'pagemenuid', $this->pagemenuid);
     }
     if (!$firstlinkid) {
         $firstlinkid = pagemenu_get_first_linkid($this->pagemenuid);
     }
     if ($data === NULL) {
         if (!empty($links)) {
             $data = pagemenu_get_link_data($links);
         } else {
             $data = array();
         }
     }
     if (!empty($links) and !empty($firstlinkid)) {
         $linkid = $firstlinkid;
         while ($linkid) {
             if (array_key_exists($linkid, $data)) {
                 $datum = $data[$linkid];
             } else {
                 $datum = NULL;
             }
             $link = $links[$linkid];
             $linkid = $link->nextid;
             $this->links[$link->id] = mod_pagemenu_link::factory($link->type, $link, $datum);
         }
     }
     $this->init();
 }
Exemplo n.º 3
0
/**
 * Generates a menu
 *
 * @param int $pagemenuid ID of the instance to print
 * @param boolean $editing True if your currently editing the menu
 * @param boolean $yui Turn YUI Menu support On/Off - If On, then extra divs and classes will be added and full trees are printed
 * @param boolean $menuinfo True, returns menu information object.  False, return menu HTML
 * @param array $links All of the links used by this menu
 * @param array $data All of the data for the links used by this menu
 * @param array $firstlinkids This is an array of IDs that are the first link for a pagemenu.  Array keys are pagemenu IDs.
 * @return mixed
 **/
function pagemenu_build_menu($pagemenuid, $editing = false, $yui = false, $menuinfo = false, $links = NULL, $data = NULL, $firstlinkids = array())
{
    global $CFG;
    $info = new stdClass();
    $info->html = '';
    $info->menuitems = array();
    $info->active = false;
    // Set links if not already passed
    if ($links === NULL) {
        $links = get_records('pagemenu_links', 'pagemenuid', $pagemenuid);
    }
    // Check passed array first, otherwise go to DB
    if (array_key_exists($pagemenuid, $firstlinkids)) {
        $linkid = $firstlinkids[$pagemenuid];
    } else {
        $linkid = pagemenu_get_first_linkid($pagemenuid);
    }
    if (!empty($links) and !empty($linkid)) {
        // Get all link config data if we don't have it already
        if ($data === NULL) {
            $data = pagemenu_get_link_data($links);
        }
        if ($editing) {
            $action = optional_param('action', '', PARAM_ALPHA);
            if ($action == 'move') {
                $moveid = required_param('linkid', PARAM_INT);
                $alt = s(get_string('movehere'));
                $movewidget = "<a title=\"{$alt}\" href=\"{$CFG->wwwroot}/mod/pagemenu/edit.php?a={$pagemenuid}&amp;action=movehere&amp;linkid={$moveid}&amp;sesskey=" . sesskey() . '&amp;after=%d">' . "<img src=\"{$CFG->pixpath}/movehere.gif\" border=\"0\" alt=\"{$alt}\" /></a>";
                $move = true;
            } else {
                $move = false;
            }
            $table = new stdClass();
            $table->id = 'edit-table';
            $table->width = '90%';
            $table->tablealign = 'center';
            $table->cellpadding = '5px';
            $table->cellspacing = '0';
            $table->data = array();
            if ($move) {
                $table->head = array(get_string('movingcancel', 'pagemenu', "{$CFG->wwwroot}/mod/pagemenu/edit.php?a={$pagemenuid}"));
                $table->wrap = array('nowrap');
                $table->data[] = array(sprintf($movewidget, 0));
            } else {
                $table->head = array(get_string('linktype', 'pagemenu'), get_string('actions', 'pagemenu'), get_string('rendered', 'pagemenu'));
                $table->align = array('left', 'center', '');
                $table->size = array('*', '*', '100%');
                $table->wrap = array('nowrap', 'nowrap', 'nowrap');
            }
        }
        while ($linkid) {
            if (array_key_exists($linkid, $data)) {
                $datum = $data[$linkid];
            } else {
                $datum = NULL;
            }
            $link = $links[$linkid];
            $linkid = $link->nextid;
            $link = mod_pagemenu_link::factory($link->type, $link, $datum);
            $menuitem = $link->get_menuitem($editing, $yui);
            // Update info
            if ($link->active) {
                $info->active = true;
            }
            if ($menuitem) {
                $info->menuitems[] = $menuitem;
            }
            if ($editing) {
                if (!$menuitem) {
                    $html = get_string('linkitemerror', 'pagemenu');
                } else {
                    $html = pagemenu_menuitems_to_html(array($menuitem));
                }
                if ($move) {
                    if ($moveid != $link->link->id) {
                        $table->data[] = array($html);
                        $table->data[] = array(sprintf($movewidget, $link->link->id));
                    }
                } else {
                    $widgets = array();
                    foreach (array('move', 'edit', 'delete') as $widget) {
                        $alt = s(get_string($widget));
                        $widgets[] = "<a title=\"{$alt}\" href=\"{$CFG->wwwroot}/mod/pagemenu/edit.php?a={$pagemenuid}&amp;action={$widget}&amp;linkid={$link->link->id}&amp;sesskey=" . sesskey() . '">' . "<img src=\"{$CFG->pixpath}/t/{$widget}.gif\" height=\"11\" width=\"11\" border=\"0\" alt=\"{$alt}\" /></a>";
                    }
                    $table->data[] = array($link->get_name(), implode('&nbsp;', $widgets), $html);
                }
            }
        }
        if ($editing) {
            $info->html = print_table($table, true);
        } else {
            $info->html = pagemenu_menuitems_to_html($info->menuitems, 0, $yui);
        }
    } else {
        $info->html = print_box(get_string('nolinksinmenu', 'pagemenu'), 'generalbox boxaligncenter boxwidthnarrow centerpara', 'pagemenu-empty', true);
    }
    if ($menuinfo) {
        return $info;
    }
    return $info->html;
}
Exemplo n.º 4
0
        foreach (pagemenu_get_link_classes() as $link) {
            $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();