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 Table 
  7:  * @author Jaromír Polášek
  8:  * @version 0.5.1
  9:  * Encoding UTF-8
 10:  */
 11: 
 12: namespace App\Lib;
 13: 
 14: use Nette\Object,
 15:     App\Model\Database,
 16:     App\Interfaces,
 17:     App\Lib\Statics\Cons;
 18: 
 19: /**
 20:  * Třída pro základní operace s daty
 21:  */
 22: class Table extends Object implements Interfaces\IData {
 23: 
 24:     /** @var Nette\Database\Context\Table (data) */
 25:     protected $data;
 26: 
 27:     /** @var Nette\Database\Context\Table (info) */
 28:     private $info;
 29: 
 30:     /** @var String tableName */
 31:     protected $table;
 32: 
 33:     /** @var string Database Name */
 34:     private $database;
 35: 
 36:     /** @var boolean Výsledek ověření správnosti dat. public přístup pro čtení, protected pro zápis */
 37:     private $state = false;
 38: 
 39:     /**
 40:      * Konstruktor přijmá jméno tabulky stromu a 
 41:      * @param String $tableName
 42:      * @param App\Model\Database $database
 43:      */
 44:     public function __construct($tableName, Database $databases) {
 45:     $this->table = $tableName;
 46:     $this->info = $databases->info->table(Cons::TABLE_INFO);
 47:     $this->data = $databases->data->table($this->table);
 48:     $this->database = $databases->name or Cons::UNKNOWN;
 49:     }
 50: 
 51:     /**
 52:      * Vrací celou tabulku
 53:      * @return Nette\Database\Table\Selection
 54:      */
 55:     public function getData() {
 56:     return $this->data;
 57:     }
 58: 
 59:     /**
 60:      * Vrací kopii Tabulky
 61:      * @return Nette\Database\Table\Selection
 62:      */
 63:     public function getCopy() {
 64:     return $this->data->createSelectionInstance();
 65:     }
 66: 
 67:     /**
 68:      * Přidá řádek do tabulky
 69:      * @param array $data
 70:      * @return integer afected row or exception 
 71:      */
 72:     public function insert($data) {
 73:     return $this->data->insert($data);
 74:     }
 75: 
 76:     /**
 77:      * Odstraní řádek z tabulky
 78:      * @param integer $id
 79:      * @return Nette\Database\Table\Selection\ActiveRow
 80:      */
 81:     public function delete($id) {
 82:     return $this->findById($id)->delete();
 83:     }
 84: 
 85:     /**
 86:      * Nastaví řádek tabulky
 87:      * @param integer $id
 88:      * @param array $data
 89:      * @return integer afected row or exception 
 90:      */
 91:     public function update($id, $data) {
 92:     return $this->findById($id)->update($data);
 93:     }
 94: 
 95:     /**
 96:      * Vrací pole dat uživatele
 97:      * @param type $id
 98:      * @return Nette\Database\Table\ActiveRow
 99:      */
100:     public function findById($id) {
101:     return $this->data->get($id);
102:     }
103: 
104:     /**
105:      * Zpřístupní promněnou state (Výsledek ověření správnosti dat.)
106:      * @return boolean
107:      */
108:     public function getState() {
109:     return $this->state;
110:     }
111: 
112:     /* Protected */
113: 
114:     /**
115:      * Potomek zapíše výsledek ověření správnosti dat
116:      * @param boolean $state
117:      */
118:     protected function setState($state) {
119:     $this->state = $state;
120:     }
121: 
122:     /**
123:      * Vrací komentář k tabulce
124:      * @return String Tablecomment
125:      */
126:     protected function getTableComent() {
127:     return $this->info
128:             ->where("table_schema = ?", $this->database)
129:             ->where("table_name = ?", $this->table) or Cons::UNKNOWN;
130:     }
131: 
132:     /**
133:      * Vrací komentáře ke sloupcům. klíčem jsou jejách názvy
134:      * @return Nette\Database\Table\ActiveRow 
135:      */
136:     protected function getTableColumnsComent() {
137:     return $this->info
138:             ->where("table_name = ?", $this->table)
139:             ->where("COLUMN_COMMENT !=", '')
140:             ->where("COLUMN_COMMENT !=", NULL) or Cons::UNKNOWN;
141:     }
142: }
143: 
sberp API API documentation generated by ApiGen