|
@@ 41-62 (lines=22) @@
|
| 38 |
|
* @return bool : true on success or false on failure |
| 39 |
|
*/ |
| 40 |
|
|
| 41 |
|
private function disconnectSubtree() : bool { |
| 42 |
|
|
| 43 |
|
$query = ("DELETE rla FROM " . static::$table_relations . " rla ") . |
| 44 |
|
|
| 45 |
|
("JOIN " . static::$table_relations . " rlb ON rlb.descendant = rla.descendant ") . |
| 46 |
|
|
| 47 |
|
("LEFT JOIN " . static::$table_relations . " rlx ") . |
| 48 |
|
|
| 49 |
|
("ON rlx.ancestor = rlb.ancestor AND rlx.descendant = rla.ancestor ") . |
| 50 |
|
|
| 51 |
|
("WHERE rlb.ancestor = " . $this->id . " AND rlx.ancestor IS NULL"); |
| 52 |
|
|
| 53 |
|
if (!(DB::send($query) && DB::getLast()->status)) return false; |
| 54 |
|
|
| 55 |
|
# Set path |
| 56 |
|
|
| 57 |
|
$this->dataset->update(['parent_id' => 0]); |
| 58 |
|
|
| 59 |
|
# ------------------------ |
| 60 |
|
|
| 61 |
|
return true; |
| 62 |
|
} |
| 63 |
|
|
| 64 |
|
/** |
| 65 |
|
* Connect the subtree under the new position |
|
@@ 70-91 (lines=22) @@
|
| 67 |
|
* @return bool : true on success or false on failure |
| 68 |
|
*/ |
| 69 |
|
|
| 70 |
|
private function connectSubtree(int $parent_id) : bool { |
| 71 |
|
|
| 72 |
|
$query = ("INSERT INTO " . static::$table_relations . " (ancestor, descendant, depth) ") . |
| 73 |
|
|
| 74 |
|
("SELECT sup.ancestor, sub.descendant, sup.depth + sub.depth + 1 ") . |
| 75 |
|
|
| 76 |
|
("FROM " . static::$table_relations . " sup ") . |
| 77 |
|
|
| 78 |
|
("JOIN " . static::$table_relations . " sub ") . |
| 79 |
|
|
| 80 |
|
("WHERE sub.ancestor = " . $this->id . " AND sup.descendant = " . $parent_id); |
| 81 |
|
|
| 82 |
|
if (!(DB::send($query) && (DB::getLast()->rows > 0))) return false; |
| 83 |
|
|
| 84 |
|
# Set path |
| 85 |
|
|
| 86 |
|
$this->dataset->update(['parent_id' => $parent_id]); |
| 87 |
|
|
| 88 |
|
# ------------------------ |
| 89 |
|
|
| 90 |
|
return true; |
| 91 |
|
} |
| 92 |
|
|
| 93 |
|
/** |
| 94 |
|
* Create the entity entry in DB |