ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
json_tree Class Reference
+ Inheritance diagram for json_tree:
+ Collaboration diagram for json_tree:

Public Member Functions

 __construct ($table="tree", $fields=array(), $add_fields=array("title"=> "title", "type"=> "type"))
 
 create_node ($data)
 
 set_data ($data)
 
 rename_node ($data)
 
 move_node ($data)
 
 remove_node ($data)
 
 get_children ($data)
 
 search ($data)
 
 _create_default ()
 
- Public Member Functions inherited from _tree_struct
 __construct ($table="tree", $fields=array())
 
 _get_node ($id)
 
 _get_children ($id, $recursive=false)
 
 _get_path ($id)
 
 _create ($parent, $position)
 
 _remove ($id)
 
 _move ($id, $ref_id, $position=0, $is_copy=false)
 
 _fix_copy ($id, $position)
 
 _reconstruct ()
 
 _analyze ()
 
 _dump ($output=false)
 
 _drop ()
 

Additional Inherited Members

- Protected Attributes inherited from _tree_struct
 $table = ""
 
 $fields
 

Detailed Description

Definition at line 477 of file class.tree.php.

Constructor & Destructor Documentation

◆ __construct()

json_tree::__construct (   $table = "tree",
  $fields = array(),
  $add_fields = array("title" => "title", "type" => "type") 
)

Definition at line 478 of file class.tree.php.

478 {
479 parent::__construct($table, $fields);
480 $this->fields = array_merge($this->fields, $add_fields);
481 $this->add_fields = $add_fields;
482 }
$errors fields
Definition: imgupload.php:51

References _tree_struct\$fields, _tree_struct\$table, and fields.

Member Function Documentation

◆ _create_default()

json_tree::_create_default ( )

Definition at line 561 of file class.tree.php.

561 {
562 $this->_drop();
563 $this->create_node(array(
564 "id" => 1,
565 "position" => 0,
566 "title" => "C:",
567 "type" => "drive"
568 ));
569 $this->create_node(array(
570 "id" => 1,
571 "position" => 1,
572 "title" => "D:",
573 "type" => "drive"
574 ));
575 $this->create_node(array(
576 "id" => 2,
577 "position" => 0,
578 "title" => "_demo",
579 "type" => "folder"
580 ));
581 $this->create_node(array(
582 "id" => 2,
583 "position" => 1,
584 "title" => "_docs",
585 "type" => "folder"
586 ));
587 $this->create_node(array(
588 "id" => 4,
589 "position" => 0,
590 "title" => "index.html",
591 "type" => "default"
592 ));
593 $this->create_node(array(
594 "id" => 5,
595 "position" => 1,
596 "title" => "doc.html",
597 "type" => "default"
598 ));
599 }
create_node($data)
Definition: class.tree.php:484

References _tree_struct\_drop(), and create_node().

Referenced by get_children().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ create_node()

json_tree::create_node (   $data)

Definition at line 484 of file class.tree.php.

484 {
485 $id = parent::_create((int)$data[$this->fields["id"]], (int)$data[$this->fields["position"]]);
486 if($id) {
487 $data["id"] = $id;
488 $this->set_data($data);
489 return "{ \"status\" : 1, \"id\" : ".(int)$id." }";
490 }
491 return "{ \"status\" : 0 }";
492 }
set_data($data)
Definition: class.tree.php:493
if(!array_key_exists('StateId', $_REQUEST)) $id

References $data, $id, fields, and set_data().

Referenced by _create_default().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_children()

json_tree::get_children (   $data)

Definition at line 531 of file class.tree.php.

531 {
532 $tmp = $this->_get_children((int)$data["id"]);
533 if((int)$data["id"] === 1 && count($tmp) === 0) {
534 $this->_create_default();
535 $tmp = $this->_get_children((int)$data["id"]);
536 }
537 $result = array();
538 if((int)$data["id"] === 0) return json_encode($result);
539 foreach($tmp as $k => $v) {
540 $result[] = array(
541 "attr" => array("id" => "node_".$k, "rel" => $v[$this->fields["type"]]),
542 "data" => $v[$this->fields["title"]],
543 "state" => ((int)$v[$this->fields["right"]] - (int)$v[$this->fields["left"]] > 1) ? "closed" : ""
544 );
545 }
546 return json_encode($result);
547 }
$result
_get_children($id, $recursive=false)
Definition: class.tree.php:43
_create_default()
Definition: class.tree.php:561

References $data, $result, _create_default(), _tree_struct\_get_children(), and fields.

+ Here is the call graph for this function:

◆ move_node()

json_tree::move_node (   $data)

Definition at line 506 of file class.tree.php.

506 {
507 $id = parent::_move((int)$data["id"], (int)$data["ref"], (int)$data["position"], (int)$data["copy"]);
508 if(!$id) return "{ \"status\" : 0 }";
509 if((int)$data["copy"] && count($this->add_fields)) {
510 $ids = array_keys($this->_get_children($id, true));
511 $data = $this->_get_children((int)$data["id"], true);
512
513 $i = 0;
514 foreach($data as $dk => $dv) {
515 $s = "UPDATE `".$this->table."` SET `".$this->fields["id"]."` = `".$this->fields["id"]."` ";
516 foreach($this->add_fields as $k => $v) {
517 if(isset($dv[$k])) $s .= ", `".$this->fields[$v]."` = \"".$this->db->escape($dv[$k])."\" ";
518 else $s .= ", `".$this->fields[$v]."` = `".$this->fields[$v]."` ";
519 }
520 $s .= "WHERE `".$this->fields["id"]."` = ".$ids[$i];
521 $this->db->query($s);
522 $i++;
523 }
524 }
525 return "{ \"status\" : 1, \"id\" : ".$id." }";
526 }
$i
Definition: disco.tpl.php:19
$s
Definition: pwgen.php:45

References $data, $i, $id, $s, _tree_struct\_get_children(), and fields.

+ Here is the call graph for this function:

◆ remove_node()

json_tree::remove_node (   $data)

Definition at line 527 of file class.tree.php.

527 {
528 $id = parent::_remove((int)$data["id"]);
529 return "{ \"status\" : 1 }";
530 }

References $data, and $id.

◆ rename_node()

json_tree::rename_node (   $data)

Definition at line 504 of file class.tree.php.

504{ return $this->set_data($data); }

References $data, and set_data().

+ Here is the call graph for this function:

◆ search()

json_tree::search (   $data)

Definition at line 548 of file class.tree.php.

548 {
549 $this->db->query("SELECT `".$this->fields["left"]."`, `".$this->fields["right"]."` FROM `".$this->table."` WHERE `".$this->fields["title"]."` LIKE '%".$this->db->escape($data["search_str"])."%'");
550 if($this->db->nf() === 0) return "[]";
551 $q = "SELECT DISTINCT `".$this->fields["id"]."` FROM `".$this->table."` WHERE 0 ";
552 while($this->db->nextr()) {
553 $q .= " OR (`".$this->fields["left"]."` < ".(int)$this->db->f(0)." AND `".$this->fields["right"]."` > ".(int)$this->db->f(1).") ";
554 }
555 $result = array();
556 $this->db->query($q);
557 while($this->db->nextr()) { $result[] = "#node_".$this->db->f(0); }
558 return json_encode($result);
559 }

References $data, $result, and fields.

◆ set_data()

json_tree::set_data (   $data)

Definition at line 493 of file class.tree.php.

493 {
494 if(count($this->add_fields) == 0) { return "{ \"status\" : 1 }"; }
495 $s = "UPDATE `".$this->table."` SET `".$this->fields["id"]."` = `".$this->fields["id"]."` ";
496 foreach($this->add_fields as $k => $v) {
497 if(isset($data[$k])) $s .= ", `".$this->fields[$v]."` = \"".$this->db->escape($data[$k])."\" ";
498 else $s .= ", `".$this->fields[$v]."` = `".$this->fields[$v]."` ";
499 }
500 $s .= "WHERE `".$this->fields["id"]."` = ".(int)$data["id"];
501 $this->db->query($s);
502 return "{ \"status\" : 1 }";
503 }

References $data, $s, and fields.

Referenced by create_node(), and rename_node().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: