Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/buildyourownbotnet/assets/js/aci-tree/php/hugeTree.php
1293 views
1
<?php
2
3
// get the huge tree JSON data for the demo
4
// #10 levels deep, #2 folders + #2 files each ... ~ #4K items :)
5
6
$path = dirname(__FILE__);
7
8
require_once("$path/Tree.php");
9
10
// huge tree data class :) just to get demo tree data
11
// it's a simple return based on the $parentId to know where we are
12
// and if it's a valid branch (also limiting to the #10 deep levels)
13
14
class HugeTree extends Tree {
15
/*
16
* $parentId will be the path to the folder.
17
*/
18
19
public function branch($parentId = null) {
20
$branch = array();
21
$path = explode('.', $parentId);
22
$type = array_shift($path);
23
if ((!$type || ($type == 'folder')) && (count($path) <= 10)) {
24
$path = implode('.', $path);
25
for ($i = 0; $i < 2; $i++) {
26
$branch["folder.{$path}.$i"] = "folder-$i";
27
}
28
for ($i = 0; $i < 2; $i++) {
29
$branch["file.{$path}.$i"] = "file-$i";
30
}
31
}
32
return $branch;
33
}
34
35
/*
36
* $itemId will be the path to the file/folder.
37
*/
38
39
public function itemProps($itemId) {
40
$path = explode('.', $itemId);
41
$type = array_shift($path);
42
switch ($type) {
43
case 'folder':
44
return array_merge(parent::itemProps($itemId), array(
45
'inode' => true,
46
'icon' => 'folder'
47
));
48
case 'file':
49
return array_merge(parent::itemProps($itemId), array(
50
'inode' => false,
51
'icon' => 'file'
52
));
53
}
54
return parent::itemProps($itemId);
55
}
56
57
}
58
59
$hugeTree = new HugeTree();
60
61
// what branch was requested?
62
$branch = isset($_GET['branch']) ? $_GET['branch'] : null;
63
64
//$hugeTree->json($branch);
65
66
// this will load the entire tree (comment above and uncomment this)
67
$hugeTree->json($branch, true);
68
69
// note: for large and complex tree structures
70
// probably the best way to do things is to return the first 2-3 levels
71
// starting from the requested branch instead of returning the entire tree
72
73