UIX Documentation
  • Namespace
  • Class
  • Tree

Namespaces

  • None
  • uix
    • data
    • ui
      • control

Classes

  • uix\data\data
  • uix\ui
  • uix\ui\box
  • uix\ui\control
  • uix\ui\control\autocomplete
  • uix\ui\control\button
  • uix\ui\control\checkbox
  • uix\ui\control\color
  • uix\ui\control\editor
  • uix\ui\control\email
  • uix\ui\control\file
  • uix\ui\control\hidden
  • uix\ui\control\number
  • uix\ui\control\post_relation
  • uix\ui\control\radio
  • uix\ui\control\select
  • uix\ui\control\separator
  • uix\ui\control\slider
  • uix\ui\control\template
  • uix\ui\control\text
  • uix\ui\control\textarea
  • uix\ui\control\toggle
  • uix\ui\footer
  • uix\ui\grid
  • uix\ui\header
  • uix\ui\help
  • uix\ui\metabox
  • uix\ui\modal
  • uix\ui\notice
  • uix\ui\page
  • uix\ui\panel
  • uix\ui\post_type
  • uix\ui\repeat
  • uix\ui\section
  • uix\ui\uix

Interfaces

  • uix\data\load
  • uix\data\save

Functions

  • uix
  • uix_autoload_class
  1 <?php
  2 /**
  3  * UIX Panel
  4  *
  5  * @package   ui
  6  * @author    David Cramer
  7  * @license   GPL-2.0+
  8  * @link
  9  * @copyright 2016 David Cramer
 10  */
 11 namespace uix\ui;
 12 
 13 /**
 14  * UIX panel. a holder to contain sections. a panel with multiple sections creates a tabbed interface to switch between sections areas.
 15  * 
 16  * @package uix\ui
 17  * @author  David Cramer
 18  */
 19 class panel extends \uix\data\data{
 20 
 21     /**
 22      * The type of object
 23      *
 24      * @since 1.0.0
 25      * @access public
 26      * @var      string
 27      */
 28     public $type = 'panel';
 29 
 30     /**
 31      * Enqueues specific tabs assets for the active pages
 32      *
 33      * @since 1.0.0
 34      * @access protected
 35      */
 36     protected function enqueue_active_assets(){
 37 
 38         ?><style type="text/css">
 39         #panel-<?php echo $this->id(); ?> > .uix-panel-tabs > li[aria-selected="true"] a {
 40             box-shadow: 3px 0 0 <?php echo $this->base_color(); ?> inset;
 41         }
 42         #panel-<?php echo $this->id(); ?>.uix-top-tabs > .uix-panel-tabs > li[aria-selected="true"] a {
 43             box-shadow: 0 3px 0 <?php echo $this->base_color(); ?> inset;
 44         }
 45 
 46         </style>
 47         <?php
 48     }
 49 
 50 
 51     /**
 52      * Define core panel styles ans scripts
 53      *
 54      * @since 1.0.0
 55      * @access public
 56      */
 57     public function set_assets() {
 58 
 59         $this->assets['script']['panel']     =  $this->url . 'assets/js/panel' . UIX_ASSET_DEBUG . '.js';
 60         $this->assets['style']['panel']   =  $this->url . 'assets/css/panel' . UIX_ASSET_DEBUG . '.css';
 61 
 62         parent::set_assets();
 63 
 64     }
 65 
 66 
 67     /**
 68      * Get Data from all controls of this section
 69      *
 70      * @since 1.0.0
 71      * @see \uix\load
 72      * @return array|null Array of sections data structured by the controls or null if none.
 73      */
 74     public function get_data(){
 75 
 76         if( empty( $this->data ) ){
 77 
 78             $data = array(
 79                 $this->slug => array()
 80             );
 81 
 82             foreach ($this->child as $child){
 83                 if ( null !== $child->get_data() )
 84                     $data[$this->slug] += $child->get_data();
 85             }
 86 
 87             if( empty( $data ) )
 88                 $data = null;
 89 
 90             $this->data = $data;
 91         }
 92 
 93 
 94 
 95         return $this->data;
 96     }
 97 
 98     /**
 99      * Sets the data for all children
100      *
101      * @since 1.0.0
102      * @access public
103      */    
104     public function set_data( $data ){
105 
106         if( !empty( $data[ $this->slug ] ) ){
107             foreach ($this->child as $child){
108                 if (method_exists($child, 'set_data'))
109                     $child->set_data($data[$this->slug]);
110 
111             }
112         }
113 
114     }
115 
116     /**
117      * Render the panel
118      *
119      * @since 1.0.0
120      * @access public
121      */
122     public function render(){
123         $output = null;
124 
125         if( $this->child_count() > 0 ) {
126 
127             $output .= '<div id="panel-' . esc_attr( $this->id() ) . '" class="uix-' . esc_attr($this->type) . '-inside ' . esc_attr($this->wrapper_class_names()) . '">';
128             // render a lable
129             $output .= $this->label();
130             // render a desciption
131             $output .= $this->description();
132             // render navigation tabs
133             $output .= $this->navigation();
134             // sections
135             $output .= $this->panel_section();
136 
137 
138             $output .= '</div>';
139         }
140 
141         $output .= $this->render_template();
142 
143         return $output;
144     }
145 
146     /**
147      * Render the panels navigation tabs
148      *
149      * @since 1.0.0
150      * @access public
151      * @return string|null Html of rendered navigation tabs
152      */
153     public function navigation(){
154         $output = null;
155 
156             if( $this->child_count() > 1 ) {
157 
158             $output .= '<ul class="uix-' . esc_attr($this->type) . '-tabs uix-panel-tabs">';
159             $active = 'true';
160             foreach ($this->child as $child) {
161                 if ( $this->is_section_object( $child ) ){
162                     $output .= $this->tab_label($child, $active);
163                     $active = 'false';
164                 }
165                 
166             }
167             $output .= '</ul>';
168         }
169         return $output;
170     }
171 
172     /**
173      * Determines the number of useable children for tab display
174      *
175      * @since 1.0.0
176      * @access public
177      * @return int Number of tabable children
178      */
179     public function child_count(){
180 
181         $count = 0;
182         if( !empty( $this->child ) ){
183             foreach( $this->child as $child ){
184                 if ( $this->is_section_object( $child ) ){
185                     $count++;
186                 }
187             }
188         }
189 
190         return $count;
191     }
192 
193     /**
194      * Render the tabs label
195      *
196      * @since 1.0.0
197      * @param object $child Child object to render tab for.
198      * @param string $active Set the tabactive or not.
199      * @access private
200      * @return string|null html of rendered label
201      */
202     private function tab_label( $child, $active ){
203 
204         $output = null;
205 
206         $label = esc_html( $child->struct['label'] );
207 
208         if( !empty( $child->struct['icon'] ) )
209             $label = '<i class="dashicons ' . $child->struct['icon'] . '"></i><span class="label">' . esc_html( $child->struct['label'] ) . '</span>';
210 
211         $output .= '<li aria-selected="' . esc_attr( $active ) . '">';
212         $output .= '<a href="#' . esc_attr( $child->id() ) . '" data-parent="' . esc_attr( $this->id() ) . '" class="uix-tab-trigger">' . $label . '</a>';
213         $output .= '</li>';
214 
215         return $output;
216     }
217 
218     /**
219      * Render the panels label
220      *
221      * @since 1.0.0
222      * @access public
223      * @return string|null rendered html of label
224      */
225     public function label(){
226         $output = null;
227         if( !empty( $this->struct['label'] ) )
228             $output .= '<div class="uix-' . esc_attr( $this->type ) . '-heading"><h3 class="uix-' . esc_attr( $this->type ) . '-title">' . esc_html( $this->struct['label'] ) . '</h3></div>';
229 
230         return $output;
231     }
232 
233     /**
234      * Render the panels Description
235      *
236      * @since 1.0.0
237      * @access public
238      * @return string|null HTML of rendered description
239      */
240     public function description(){
241         $output = null;
242         if( !empty( $this->struct['description'] ) )
243             $output .= '<div class="uix-' . esc_attr( $this->type ) . '-heading"><p class="uix-' . esc_attr( $this->type ) . '-subtitle description">' . esc_html( $this->struct['description'] ) . '</p></div>';
244 
245         return $output;
246     }
247 
248     /**
249      * Check if child is a section object
250      *
251      * @since 1.0.0
252      * @access public
253      * @param uix Object to test if it is to be rendered in a section
254      * @return string|null HTML of rendered description
255      */
256     public function is_section_object( $section ){
257         return !in_array( $section->type, array( 'help', 'header', 'footer' ) );
258     }
259 
260     /**
261      * Render the panels Description
262      *
263      * @since 1.0.0
264      * @access public
265      * @return string|null HTML of rendered description
266      */
267     public function panel_section(){
268         $output = null;
269 
270         // render the section wrapper
271         $output .= '<div class="uix-' . esc_attr( $this->type ) . '-sections uix-sections">';
272 
273         $hidden = 'false';
274         foreach( $this->child as $section ){
275 
276             if ( !$this->is_section_object( $section ) )
277                 continue;
278 
279             $section->struct['active'] = $hidden;
280             $output .= $section->render();
281             $hidden = 'true';
282         }
283 
284         $output .= '</div>';
285 
286         return $output;
287     }
288 
289     /**
290      * Render a template based object
291      *
292      * @since 1.0.0
293      * @access public
294      * @return string|null HTML of rendered template
295      */
296     public function render_template(){
297         // template
298         $_output = null;
299 
300         if( !empty( $this->struct['template'] ) ){
301             ob_start();
302                 include $this->struct['template'];
303             $_output .= ob_get_clean();
304         }
305 
306         return $_output;
307     }
308 
309 
310     /**
311      * Returns the class names for the tab wrapper
312      *
313      * @since 1.0.0
314      * @access public
315      */
316     public function wrapper_class_names(){
317 
318         $wrapper_class_names = array(
319             'uix-panel-inside'
320         );
321 
322         if( $this->child_count() > 1 )
323             $wrapper_class_names[] = 'uix-has-tabs';
324 
325         if( !empty( $this->struct['top_tabs'] ) )
326             $wrapper_class_names[] = 'uix-top-tabs';
327 
328         return implode( ' ', $wrapper_class_names );
329     }
330 }
UIX Documentation API documentation generated by ApiGen