Esempio n. 1
0
 /**
  * Expands the tree of curriculum entities based on how you got to the
  * current CM page via the curr admin menu
  */
 private function append_path_items()
 {
     global $USER;
     //make sure the current page was reached via the curr admin menu
     if (isset($USER->currentitypath)) {
         $parts = explode('/', $USER->currentitypath);
         //track the last element along the path
         $parent_element_id = 'root';
         //track the last encountered cluster and curriculum ids
         $parent_cluster_id = 0;
         $parent_curriculum_id = 0;
         //track where we are within the curr entity path
         $position_in_path = 0;
         //store the path as we build it up so that newly created links
         //expand the tree as well
         $cumulative_path = '';
         foreach ($parts as $part) {
             //convert to notation used by the tree
             $current_element_id = str_replace('-', '_', $part);
             //create menu item here
             $current_parts = explode('_', $current_element_id);
             //track the last cluster and curriculum id encountered so that we can
             //correctly load the child elements
             if ($current_parts[0] == 'cluster' || $current_parts[0] == 'userset') {
                 $parent_cluster_id = $current_parts[1];
             } else {
                 if ($current_parts[0] == 'curriculum') {
                     $parent_curriculum_id = $current_parts[1];
                 }
             }
             //append the current element to the working path
             if (empty($cumulative_path)) {
                 $cumulative_path = $part;
             } else {
                 $cumulative_path .= '/' . $part;
             }
             //load children for all nodes except for the lowest-level ones
             if ($position_in_path < count($parts) - 1) {
                 //automatically load all correct children
                 if ($children = block_elisadmin_load_menu_children($current_parts[0], !isset($current_parts[1]) ? '' : $current_parts[1], $parent_cluster_id, $parent_curriculum_id, $cumulative_path)) {
                     foreach ($children as $child) {
                         $node = clone $child;
                         //make the loaded node a child of the current one
                         $node->parent = $current_element_id;
                         //ignore the bogus root element
                         if ($node->name !== 'root') {
                             $this->listing[] = $node;
                         }
                     }
                 }
             }
             //force the parent element to expand
             foreach ($this->listing as $listing_key => $listing_entry) {
                 if ($listing_entry->name == $parent_element_id) {
                     $this->listing[$listing_key]->forceexpand = true;
                 }
             }
             $parent_element_id = $current_element_id;
             $position_in_path++;
         }
     }
 }
Esempio n. 2
0
 * @package    block_elisadmin
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @copyright  (C) 2008-2014 Remote Learner.net Inc http://www.remote-learner.net
 *
 */
require_once '../../config.php';
require_once $CFG->dirroot . '/blocks/elisadmin/lib.php';
require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
require_once elispm::lib('data/userset.class.php');
require_once elispm::lib('menuitem.class.php');
$data = required_param('data', PARAM_CLEAN);
$parts = explode('_', $data);
//we are expecting a particular parameter format
if (count($parts) != 5) {
    exit;
}
//retrieve necessary data from parameter
$parent_type = $parts[0];
$id = $parts[1];
$parent_cluster = $parts[2];
$parent_curriculum = $parts[3];
$parent_path = $parts[4];
//load all necessary children
$result_items = block_elisadmin_load_menu_children($parent_type, $id, $parent_cluster, $parent_curriculum, $parent_path);
//guaranteed one element because of 'root'
if (count($result_items) > 1) {
    //spit out the JSON object
    $tree = new treerepresentation(new menuitemlisting($result_items));
    echo $tree->get_js_object();
}