Overview

Namespaces

  • App
    • Components
    • Interfaces
    • Lib
      • Files
      • Forms
        • Controls
      • Html
      • Repair
      • Statics
    • Model
    • Modules
      • BaseModule
        • Presenters
      • PartnersModule
        • Presenters
      • ProductModule
        • Presenters
      • SaleModule
        • Model
        • Presenters
      • SettingsModule
        • Model
        • Presenters
      • StoreModule
        • Model
        • Presenters
    • Presenters
    • Router
  • PHP

Classes

  • DateTime
  • SplFileInfo

Interfaces

  • ArrayAccess
  • Countable
  • Exception
  • Iterator
  • Traversable
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Download
 1: <?php
 2: 
 3: /**
 4:  * Project sberp
 5:  *
 6:  * @file TreeIntegrity 
 7:  * @author Jaromír Polášek
 8:  * @version 0.6.1 ACL
 9:  * Encoding UTF-8
10:  */
11: 
12: namespace App\Lib;
13: 
14: use App\Interfaces as I,
15:     App\Model\Database,
16:     App\Lib\Statics\Cons;
17: /**
18:  * Knihovna pro kontrolu struktury databáze
19:  */
20: class TreeIntegrity extends Tree implements I\IData, I\ITree{
21:     
22:     
23:      /**
24:      * Předá parametry předkovy se zakázaným testem a konkrétním kořenovým uzlem
25:      * @param string $tableName
26:      * @param \App\Model\Database $database
27:      * @param \Nette\Database\Table\ActiveRow $masterNode
28:      */
29:     public function __construct($tableName, Database $database,$masterNode ) {
30:     parent::__construct($tableName, $database, false, $masterNode); 
31:     }
32:     
33:     /**
34:      * Kontrola Integrity stromu. struktura: Pravá hodnota se musí rovnat dvojnásobku členů.
35:      * Počet oddělujících znaků v cestě musí při setřídění podle hloubky vzrůstat
36:      * pokud je zjištěna nesrovnalost stromu,  provede se oprava.     
37:      * @return boolean (success)
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:      * Testuje a opravuje strukturu pole 'path' ve stromu
51:      * @return boolean true - ok
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: 
sberp API API documentation generated by ApiGen