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 Tree 
  7:  * @author Jaromír Polášek
  8:  * @version 0.7.1.FORM
  9:  * Encoding UTF-8
 10:  */
 11: 
 12: namespace App\Lib\Html;
 13: 
 14: use Nette\Object,
 15:     Nette\Utils\Html,
 16:     App\Interfaces as I,
 17:     App\Lib\Statics\Cons;
 18: /**
 19:  * Generuje Html kód odsazeného seznamu
 20:  */
 21: class Tree extends Object implements I\IHtml{
 22: 
 23:     /** @var \Nette\Database\Selection\ */
 24:     private $tree;
 25:     
 26:     /** @var string */
 27:     private $html = "";
 28: 
 29:     /**
 30:      * Předá pole stromu
 31:      * @param \Nette\Database\Selection\ $tree
 32:      */
 33:     public function __construct($tree = NULL) {
 34:     (!$tree)?:$this->tree = $tree;
 35:     }
 36:     
 37:     /**
 38:      * Vrací Html kód ve formě řetězece
 39:      * @return string
 40:      */
 41:     public function getHtml(){
 42:     return $this->html;
 43:     }
 44:     
 45:     /**
 46:      * Vratí HTML strom v podobě pole
 47:      * @return array
 48:      */
 49:     public function getCode() {
 50:     $level = 0;
 51:     foreach ($this->tree as $item) {
 52:         if ($item[Cons::COLUMN_DEPTH] > 0) {
 53:         $this->setTreePart($item[Cons::COLUMN_DEPTH], $level);
 54:         $level = $item[Cons::COLUMN_DEPTH];
 55:         }    
 56:     }
 57:        $this->setRemainUlLi($level);
 58:     return $this->html;
 59:     }
 60: 
 61:     /**
 62:      * Vrací podstrukturu stromu
 63:      * @param integer $depth
 64:      * @param integer $level
 65:      * @return string
 66:      */
 67:     public function setTreePart($depth, $level) {
 68:     $this->getLiUl($depth, $level);
 69:     $this->getUlLi($depth, $level);
 70:     $this->html .= Html::el('li')->startTag();
 71:     }
 72: 
 73:     /**
 74:      * Vytvoří A tag
 75:      * @param array $name
 76:      * @param URL $link
 77:      * @param boolean $carpet
 78:      * @return string
 79:      */
 80:     public function setA($name,$link = NULL, $carpet = FALSE) {
 81:     $a = HTML::el('a');
 82:     if (!is_null($link)) {
 83:         $a->href($link);
 84:     }
 85:     $a->setText($name);
 86:     if($carpet === TRUE){
 87:         $a->add(Html::el('span class="sb-caret"'));
 88:     }
 89:     $this->html .= $a;
 90:     }
 91:     
 92:     /**
 93:      * Přidá karpet na aktuální pozici
 94:      */
 95:     public function setCarpet(){
 96:     $this->html .= Html::el('span class="sb-caret"');
 97:     }
 98:     
 99:     /**
100:      * Ukončí otevřené <ul> a <li> tagy*
101:      * @param integer $depth
102:      * @param integer $level
103:      */
104:     private function getLiUl($depth, $level) {
105:     if ($depth < $level) {
106:         $dismiss = $level - $depth;
107:         for ($i = 0; $i < $dismiss; ++$i) {
108:         $this->html .= Html::el('li')->endTag(); 
109:         $this->html .= Html::el('ul')->endTag();
110:         }
111:     }
112:     }
113: 
114:     /**
115:      * Ukončí aktuální tag <li> nebo <ul>
116:      * @param integer $depth
117:      * @param integer $level
118:      */
119:     private function getUlLi($depth, $level) {
120:     if ($depth === $level) {
121:         $this->html .= Html::el('li')->endTag();
122:     }
123:     if ($depth > $level) {
124:         $this->html .= Html::el('ul')->startTag();
125:     }
126:     }
127: 
128:     /**
129:      * uzavře všechny otevřené tagy <li> a <ul>
130:      * @param integer $level
131:      */
132:     public function setRemainUlLi($level) {
133:     for ($i = $level; $i >= 1; --$i) {
134:         $this->html .= Html::el('li')->endTag();
135:         $this->html .= Html::el('ul')->endTag();
136:     }   
137:     }
138: }
sberp API API documentation generated by ApiGen