1<?php 2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */ 3 4/** 5 * ilCloudFileTree class 6 * 7 * Representation of a node (a file or a folder) in the file tree 8 * 9 * @author Timon Amstutz <timon.amstutz@ilub.unibe.ch> 10 * @version $Id$ 11 * @ingroup ModulesCloud 12 */ 13class ilCloudFileNode 14{ 15 16 /** 17 * @var int 18 */ 19 protected $id = 0; 20 /** 21 * @var string 22 */ 23 protected $path = ""; 24 /** 25 * @var int 26 */ 27 protected $parent_id = -1; 28 /** 29 * @var array 30 */ 31 protected $children = array(); 32 /** 33 * @var bool 34 */ 35 protected $loading_complete = false; 36 /** 37 * @var bool 38 */ 39 protected $is_dir = false; 40 /** 41 * @var int 42 */ 43 protected $size = 0; 44 /** 45 * @var int 46 */ 47 protected $modified = 0; 48 /** 49 * @var int 50 */ 51 protected $created = 0; 52 /** 53 * @var string 54 */ 55 protected $icon_path = ""; 56 /** 57 * @var mixed 58 */ 59 protected $mixed; 60 61 62 /** 63 * @param string $path 64 */ 65 public function __construct($path, $id) 66 { 67 $this->setPath($path); 68 $this->setId($id); 69 } 70 71 72 /** 73 * @param $id 74 */ 75 public function setId($id) 76 { 77 $this->id = $id; 78 } 79 80 81 /** 82 * @return int 83 */ 84 public function getId() 85 { 86 return $this->id; 87 } 88 89 90 /** 91 * @param bool $complete 92 */ 93 public function setLoadingComplete($complete) 94 { 95 $this->loading_complete = $complete; 96 } 97 98 99 /** 100 * @return bool 101 */ 102 public function getLoadingComplete() 103 { 104 return $this->loading_complete; 105 } 106 107 108 /** 109 * @param string $path 110 */ 111 public function setPath($path = "/") 112 { 113 $this->path = ilCloudUtil::normalizePath($path, $this->is_dir); 114 } 115 116 117 /** 118 * @return string 119 */ 120 public function getPath() 121 { 122 return $this->path; 123 } 124 125 126 /** 127 * @param $path 128 */ 129 public function addChild($path) 130 { 131 if (!isset($this->children[$path])) { 132 $this->children[$path] = $path; 133 } 134 } 135 136 137 /** 138 * @param $path 139 */ 140 public function removeChild($path) 141 { 142 if (isset($this->children[$path])) { 143 unset($this->children[$path]); 144 } 145 } 146 147 148 /** 149 * @return array|null 150 */ 151 public function getChildrenPathes() 152 { 153 if ($this->hasChildren()) { 154 return $this->children; 155 } 156 157 return null; 158 } 159 160 161 /** 162 * @return bool 163 */ 164 public function hasChildren() 165 { 166 return (count($this->children) > 0); 167 } 168 169 170 /** 171 * @param $id 172 */ 173 public function setParentId($id) 174 { 175 $this->parent_id = $id; 176 } 177 178 179 /** 180 * @return int 181 */ 182 public function getParentId() 183 { 184 return $this->parent_id; 185 } 186 187 188 /** 189 * @param $is_dir 190 */ 191 public function setIsDir($is_dir) 192 { 193 $this->is_dir = $is_dir; 194 } 195 196 197 /** 198 * @return bool 199 */ 200 public function getIsDir() 201 { 202 return $this->is_dir; 203 } 204 205 206 /** 207 * @param $size 208 */ 209 public function setSize($size) 210 { 211 $this->size = $size; 212 } 213 214 215 /** 216 * @return int 217 */ 218 public function getSize() 219 { 220 return $this->size; 221 } 222 223 224 /** 225 * @param $modified 226 */ 227 public function setModified($modified) 228 { 229 $this->modified = $modified; 230 } 231 232 233 /** 234 * @return int 235 */ 236 public function getModified() 237 { 238 return $this->modified; 239 } 240 241 242 /** 243 * @param $path 244 */ 245 public function setIconPath($path) 246 { 247 $this->icon_path = $path; 248 } 249 250 251 /** 252 * @return string 253 */ 254 public function getIconPath() 255 { 256 return $this->icon_path; 257 } 258 259 260 /** 261 * @param mixed $mixed 262 */ 263 public function setMixed($mixed) 264 { 265 $this->mixed = $mixed; 266 } 267 268 269 /** 270 * @return mixed 271 */ 272 public function getMixed() 273 { 274 return $this->mixed; 275 } 276 277 278 /** 279 * @return array 280 */ 281 public function getJSONEncode() 282 { 283 $node = array(); 284 $node["id"] = $this->getId(); 285 $node["is_dir"] = $this->getIsDir(); 286 $node["path"] = $this->getPath(); 287 $node["parent_id"] = $this->getParentId(); 288 $node["loading_complete"] = $this->getLoadingComplete(); 289 $node["children"] = $this->getChildrenPathes(); 290 $node["size"] = $this->getSize(); 291 292 return $node; 293 } 294} 295