1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace App\Lib;
13:
14: use App\Interfaces as I,
15: App\Model\Database,
16: App\Lib\Statics\Cons;
17: 18: 19:
20: class TreeIntegrity extends Tree implements I\IData, I\ITree{
21:
22:
23: 24: 25: 26: 27: 28:
29: public function __construct($tableName, Database $database,$masterNode ) {
30: parent::__construct($tableName, $database, false, $masterNode);
31: }
32:
33: 34: 35: 36: 37: 38:
39: public function checkTreeIntegrity() {
40: $struct = ($this->masterNode[Cons::COLUMN_RIGHT] === $this->data->count() * 2);
41: if (!$struct) {
42: $rebuild = new TreeRebuild($this->table, $this->rebuildDatabase, $this->masterNode);
43: $struct = ($struct)? : $rebuild->rebuildTree();
44: }
45: $this->pathTest();
46: Return $struct;
47: }
48:
49: 50: 51: 52:
53: private function pathTest() {
54: $selection = $this->copy->order(Cons::COLUMN_DEPTH);
55: foreach ($selection as $row) {
56: if ($row[Cons::COLUMN_DEPTH] === 1) {
57: ($row[Cons::COLUMN_NAME] === $row[Cons::COLUMN_PATH])?:$this->update($row->id);
58: }
59: if ($row[Cons::COLUMN_DEPTH] > 1) {
60: $count = (\substr_count($row[Cons::COLUMN_PATH], '>') === $row[Cons::COLUMN_DEPTH]-1);
61: ($count)? : $this->update($row->id);
62: }
63: }
64: }
65: }
66: