// Initialise (only actually happens if it hasn't already been done yet
$this->page->navigation->initialise();
$navigation = clone($this->page->navigation);
+ $expansionlimit = null;
+ if (!empty($this->config->expansionlimit)) {
+ $expansionlimit = $this->config->expansionlimit;
+ $navigation->set_expansion_limit($this->config->expansionlimit);
+ }
$this->trim($navigation, $trimmode, $trimlength, ceil($trimlength/2));
if (!empty($this->config->showmyhistory) && $this->config->showmyhistory=='yes') {
// Get the expandable items so we can pass them to JS
$expandable = array();
- $this->page->navigation->find_expandable($expandable);
+ $navigation->find_expandable($expandable);
// Initialise the JS tree object
$module = array('name'=>'block_navigation', 'fullpath'=>'/blocks/navigation/navigation.js', 'requires'=>array('core_dock', 'io', 'node', 'dom', 'event-custom', 'json-parse'));
// Grab the items to display
$renderer = $this->page->get_renderer('block_navigation');
- $this->content->text = $renderer->navigation_tree($this->page->navigation);
+ $this->content->text = $renderer->navigation_tree($navigation, $expansionlimit);
$reloadlink = new moodle_url($this->page->url, array('regenerate'=>'navigation'));
$mform->addElement('text', 'config_trimlength', get_string('trimlength', $this->block->blockname));
$mform->setDefault('config_trimlength', 50);
$mform->setType('config_trimlength', PARAM_INT);
+
+ $options = array(
+ 0 => get_string('everything', $this->block->blockname),
+ global_navigation::TYPE_COURSE => get_string('courses', $this->block->blockname),
+ global_navigation::TYPE_SECTION => get_string('coursestructures', $this->block->blockname),
+ global_navigation::TYPE_ACTIVITY => get_string('courseactivities', $this->block->blockname)
+ );
+ $mform->addElement('select', 'config_expansionlimit', get_string('expansionlimit', $this->block->blockname), $options);
+ $mform->setType('config_expansionlimit', PARAM_INT);
+
}
}
\ No newline at end of file
$string['courseactivities'] = 'Categories, courses, and course Activities';
$string['enablehoverexpansiondesc'] = 'Enable mouseover expansion of this block';
$string['enabledockdesc'] = 'Allow the user to dock this block';
+$string['expansionlimit'] = 'Generate navigation for the following';
$string['pluginname'] = 'Navigation';
$string['showmyhistorydesc'] = 'Show my history as a branch in the navigation';
$string['showmyhistorytitle'] = 'My history';
class block_navigation_renderer extends plugin_renderer_base {
- public function navigation_tree(global_navigation $navigation) {
- $content = $this->navigation_node(array($navigation), array('class'=>'block_tree list'));
+ public function navigation_tree(global_navigation $navigation, $expansionlimit) {
+ $content = $this->navigation_node(array($navigation), array('class'=>'block_tree list'), $expansionlimit);
if (isset($navigation->id) && !is_numeric($navigation->id) && !empty($content)) {
$content = $this->output->box($content, 'block_tree_box', $navigation->id);
}
return $content;
}
- protected function navigation_node($items, $attrs=array()) {
+ protected function navigation_node($items, $attrs=array(), $expansionlimit=null) {
// exit if empty, we don't want an empty ul element
if (count($items)==0) {
$liattr = array('class'=>join(' ',$liclasses));
// class attribute on the div item which only contains the item content
$divclasses = array('tree_item');
- if ($item->children->count() > 0 || ($item->nodetype == navigation_node::NODETYPE_BRANCH && $item->children->count()==0 && isloggedin())) {
+ if ((empty($expansionlimit) || $item->type != $expansionlimit) && ($item->children->count() > 0 || ($item->nodetype == navigation_node::NODETYPE_BRANCH && $item->children->count()==0 && isloggedin()))) {
$divclasses[] = 'branch';
} else {
$divclasses[] = 'leaf';
if (!empty($item->id)) {
$divattr['id'] = $item->id;
}
- $content = html_writer::tag('p', $content, $divattr) . $this->navigation_node($item->children);
+ $content = html_writer::tag('p', $content, $divattr) . $this->navigation_node($item->children, array(), $expansionlimit);
if (!empty($item->preceedwithhr) && $item->preceedwithhr===true) {
$content = html_writer::empty_tag('hr') . $content;
}
// Create a global nav object
$navigation = new global_navigation_for_ajax($PAGE);
- // If set to true then we need to call toggle display
- $toggledisplay = false;
if ($instanceid!==null) {
// Get the db record for the block instance
- $blockrecords = $DB->get_record('block_instances', array('id'=>$instanceid,'blockname'=>'navigation'));
- if ($blockrecords!=false) {
+ $blockrecord = $DB->get_record('block_instances', array('id'=>$instanceid,'blockname'=>'navigation'));
+ if ($blockrecord!=false) {
// Instantiate a block_instance object so we can access config
- $block = block_instance('navigation', $blockrecords);
+ $block = block_instance('navigation', $blockrecord);
$trimmode = block_navigation::TRIM_RIGHT;
$trimlength = 50;
// Create a navigation object to use, we can't guarantee PAGE will be complete
$expandable = $navigation->initialise($branchtype, $branchid);
+ if (isset($block) && !empty($block->config->expansionlimit)) {
+ $navigation->set_expansion_limit($block->config->expansionlimit);
+ }
if (isset($block)) {
$block->trim($navigation, $trimmode, $trimlength, ceil($trimlength/2));
}
$editpage->set_pagelayout('admin');
$editpage->set_course($this->page->course);
$editpage->set_context($block->context);
+ if ($this->page->cm) {
+ $editpage->set_cm($this->page->cm);
+ }
$editurlbase = str_replace($CFG->wwwroot . '/', '/', $this->page->url->out_omit_querystring());
$editurlparams = $this->page->url->params();
$editurlparams['bui_editid'] = $blockid;
return;
}
foreach ($this->children as &$child) {
- if ($child->nodetype == self::NODETYPE_BRANCH && $child->children->count()==0) {
+ if ($child->nodetype == self::NODETYPE_BRANCH && $child->children->count()==0 && $child->display) {
$child->id = 'expandable_branch_'.(count($expandable)+1);
$this->add_class('canexpand');
$expandable[] = array('id'=>$child->id,'branchid'=>$child->key,'type'=>$child->type);
$child->find_expandable($expandable);
}
}
+
+ public function find_all_of_type($type) {
+ $nodes = $this->children->type($type);
+ foreach ($this->children as &$node) {
+ $childnodes = $node->find_all_of_type($type);
+ $nodes = array_merge($nodes, $childnodes);
+ }
+ return $nodes;
+ }
}
/**
protected $cache;
/** @var array */
protected $addedcourses = array();
+ /** @var int */
+ protected $expansionlimit = 0;
+
/**
* Constructs a new global navigation
*
public function clear_cache() {
$this->cache->clear();
}
+
+ public function set_expansion_limit($type) {
+ $nodes = $this->find_all_of_type($type);
+ foreach ($nodes as &$node) {
+ foreach ($node->children as &$child) {
+ $child->display = false;
+ }
+ }
+ return true;
+ }
}
/**