Path: blob/master/web-gui/buildyourownbotnet/assets/js/aci-tree/php/hugeTree.php
1293 views
<?php12// get the huge tree JSON data for the demo3// #10 levels deep, #2 folders + #2 files each ... ~ #4K items :)45$path = dirname(__FILE__);67require_once("$path/Tree.php");89// huge tree data class :) just to get demo tree data10// it's a simple return based on the $parentId to know where we are11// and if it's a valid branch (also limiting to the #10 deep levels)1213class HugeTree extends Tree {14/*15* $parentId will be the path to the folder.16*/1718public function branch($parentId = null) {19$branch = array();20$path = explode('.', $parentId);21$type = array_shift($path);22if ((!$type || ($type == 'folder')) && (count($path) <= 10)) {23$path = implode('.', $path);24for ($i = 0; $i < 2; $i++) {25$branch["folder.{$path}.$i"] = "folder-$i";26}27for ($i = 0; $i < 2; $i++) {28$branch["file.{$path}.$i"] = "file-$i";29}30}31return $branch;32}3334/*35* $itemId will be the path to the file/folder.36*/3738public function itemProps($itemId) {39$path = explode('.', $itemId);40$type = array_shift($path);41switch ($type) {42case 'folder':43return array_merge(parent::itemProps($itemId), array(44'inode' => true,45'icon' => 'folder'46));47case 'file':48return array_merge(parent::itemProps($itemId), array(49'inode' => false,50'icon' => 'file'51));52}53return parent::itemProps($itemId);54}5556}5758$hugeTree = new HugeTree();5960// what branch was requested?61$branch = isset($_GET['branch']) ? $_GET['branch'] : null;6263//$hugeTree->json($branch);6465// this will load the entire tree (comment above and uncomment this)66$hugeTree->json($branch, true);6768// note: for large and complex tree structures69// probably the best way to do things is to return the first 2-3 levels70// starting from the requested branch instead of returning the entire tree717273