Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • AlterEvent
  1 <?php
  2 
  3 /*
  4  * This file is part of the Icybee package.
  5  *
  6  * (c) Olivier Laviale <olivier.laviale@gmail.com>
  7  *
  8  * For the full copyright and license information, please view the LICENSE
  9  * file that was distributed with this source code.
 10  */
 11 
 12 namespace Icybee\Modules\Pages;
 13 
 14 use ICanBoogie\Event;
 15 
 16 use Brickrouge\Element;
 17 
 18 class NavigationElement extends Element // TODO-20120922: rewrite this element
 19 {
 20     public function __construct()
 21     {
 22         // this is fake :(
 23     }
 24 
 25     static protected function render_navigation_tree(array $tree, $depth=1)
 26     {
 27         $rc = '';
 28 
 29         foreach ($tree as $branch)
 30         {
 31             $record = $branch->record;
 32             $class = $record->css_class('-constructor -slug');
 33 
 34             $rc .=  $class ? '<li class="' . $class . '">' : '<li>';
 35             $rc .= '<a href="' . $record->url . '">' . $record->label . '</a>';
 36 
 37             if ($branch->children)
 38             {
 39                 $rc .= static::render_navigation_tree($branch->children, $depth + 1);
 40             }
 41 
 42             $rc .= '</li>';
 43         }
 44 
 45         return '<ol class="' . ($depth == 1 ? 'nav' : 'dropdown-menu') . ' lv' . $depth . '">' . $rc . '</ol>';
 46     }
 47 
 48     static public function markup(array $args, \Patron\Engine $patron, $template)
 49     {
 50         global $core;
 51 
 52         $page = $core->request->context->page;
 53         $mode = $args['mode'];
 54 
 55         if ($mode == 'leaf')
 56         {
 57             $node = $page;
 58 
 59             while ($node)
 60             {
 61                 if ($node->navigation_children)
 62                 {
 63                     break;
 64                 }
 65 
 66                 $node = $node->parent;
 67             }
 68 
 69             if (!$node)
 70             {
 71                 return;
 72             }
 73 
 74             return $patron($template, $node);
 75         }
 76 
 77 
 78         $model = $core->models['pages'];
 79 
 80 
 81 
 82 
 83 
 84 
 85 
 86 
 87 
 88 
 89 
 90 
 91 
 92 
 93 
 94         $depth = $args['depth'];
 95 
 96         if ($args['from-level'])
 97         {
 98             $node = $page;
 99             $from_level = $args['from-level'];
100 
101             #
102             # The current page level is smaller than the page level requested, the navigation is
103             # canceled.
104             #
105 
106             if ($node->depth < $from_level)
107             {
108                 return;
109             }
110 
111             while ($node->depth > $from_level)
112             {
113                 $node = $node->parent;
114             }
115 
116 //          \ICanBoogie\log('from node: \1', array($node));
117 
118             $parentid = $node->nid;
119         }
120         else
121         {
122             $parentid = $args['parent'];
123 
124             if (is_object($parentid))
125             {
126                 $parentid = $parentid->nid;
127             }
128             else
129             {
130                 if ($parentid && !is_numeric($parentid))
131                 {
132                     $parent = $model->find_by_path($parentid);
133 
134                     $parentid = $parent->nid;
135                 }
136             }
137         }
138 
139         $blueprint = $model->blueprint($page->siteid);
140         $min_child = $args['min-child'];
141 
142         $subset = $blueprint->subset
143         (
144             $parentid, $depth === null ? null : $depth - 1, function($branch) use($min_child)
145             {
146                 if ($min_child && count($branch->children) < $min_child)
147                 {
148                     return true;
149                 }
150 
151                 return (!$branch->is_online || $branch->is_navigation_excluded || $branch->pattern);
152             }
153         );
154 
155         $html = null;
156         $tree = $subset->tree;
157 
158         if ($tree)
159         {
160             $subset->populate();
161 
162             $html = $template ? $patron($template, $tree) : static::render_navigation_tree($tree);
163         }
164 
165         new NavigationElement\AlterEvent(new self, $html, $page, $blueprint, $args);
166 
167         return $html;
168     }
169 }
170 
171 namespace Icybee\Modules\Pages\NavigationElement;
172 
173 use Icybee\Modules\Pages\Blueprint;
174 use Icybee\Modules\Pages\NavigationElement;
175 use Icybee\Modules\Pages\Page;
176 
177 class AlterEvent extends \ICanBoogie\Event
178 {
179     /**
180      * Reference to the rendered HTML.
181      *
182      * @var string
183      */
184     public $html;
185 
186     /**
187      * Page for which the navigation is rendered.
188      *
189      * @var Page
190      */
191     public $page;
192 
193     /**
194      * Blueprint of the navigation.
195      *
196      * @var Blueprint
197      */
198     public $blueprint;
199 
200     /**
201      * Options of the navigation.
202      *
203      * @var array
204      */
205     public $options;
206 
207     /**
208      * The event is constructed with the type `alter`.
209      *
210      * @param NavigationElement $target
211      * @param string $html
212      * @param Page $page
213      * @param Blueprint $blueprint
214      * @param array $options
215      */
216     public function __construct(NavigationElement $target, &$html, Page $page, Blueprint $blueprint, array $options)
217     {
218         $this->html = &$html;
219         $this->page = $page;
220         $this->blueprint = $blueprint;
221         $this->options = $options;
222 
223         parent::__construct($target, 'alter');
224     }
225 }
Autodoc API documentation generated by ApiGen 2.8.0