Beispiel #1
0
 public function render()
 {
     if (!empty($this->_items)) {
         if ($this->_num_rows > 2) {
             $col_xs = @round(12 / ($this->_num_per_rows - 2));
             $col_sm = @round(12 / ($this->_num_per_rows - 1));
         }
         $col_md = round(12 / $this->_num_per_rows);
         $col_lg = round(12 / $this->_num_per_rows);
         $container = new Tag('div', ['class' => 'row']);
         foreach ($this->_items as $key => $item) {
             $column = new Tag('div', $item, ['class' => 'grid-item']);
             if (isset($col_xs)) {
                 $column->add_class('col-xs-' . $col_xs);
             }
             if (isset($col_sm)) {
                 $column->add_class('col-sm-' . $col_sm);
             }
             $column->add_class('col-md-' . $col_md);
             $column->add_class('col-lg-' . $col_lg);
             $this->_items[$key] = $column;
         }
         $container->set_content(implode(PHP_EOL, $this->_items));
         return (new Tag($this->_tag, $container, $this->_attributes))->render();
     }
     return '';
 }
Beispiel #2
0
 public function render()
 {
     if (!empty($this->_items)) {
         if ($this->_type === self::THUMBNAIL_GROUP) {
             $col_xs = round(12 / ($this->_num_per_rows - 2));
             $col_sm = round(12 / ($this->_num_per_rows - 1));
             $col_md = round(12 / $this->_num_per_rows);
             $col_lg = round(12 / $this->_num_per_rows);
             foreach ($this->_items as $key => $item) {
                 $container = new Tag('div', $item, ['class' => 'thumbnail-item']);
                 $container->add_class('col-xs-' . $col_xs);
                 $container->add_class('col-sm-' . $col_sm);
                 $container->add_class('col-md-' . $col_md);
                 $container->add_class('col-lg-' . $col_lg);
                 $this->_items[$key] = $container;
             }
         }
         return (new Tag($this->_tag, implode(PHP_EOL, $this->_items), $this->_attributes))->render();
     }
     return '';
 }
Beispiel #3
0
 public function render()
 {
     switch ($this->_type) {
         case 'text':
             $this->_attributes['type'] = 'text';
             $field = new Tag('input', $this->_attributes);
             break;
         case 'password':
             $this->_attributes['type'] = 'password';
             $field = new Tag('input', $this->_attributes);
             break;
         case 'radio':
             $this->_attributes['type'] = 'radio';
             $field = new Tag('input', $this->_attributes);
             break;
         case 'checkbox':
             $this->_attributes['type'] = 'checkbox';
             $field = new Tag('input', $this->_attributes);
             break;
         case 'number':
             $this->_attributes['type'] = 'number';
             $field = new Tag('input', $this->_attributes);
             break;
         case 'date':
             $this->_attributes['type'] = 'date';
             $field = new Tag('input', $this->_attributes);
             break;
         case 'color':
             $this->_attributes['type'] = 'color';
             $field = new Tag('input', $this->_attributes);
             break;
         case 'month':
             $this->_attributes['type'] = 'month';
             $field = new Tag('input', $this->_attributes);
             break;
         case 'week':
             $this->_attributes['type'] = 'week';
             $field = new Tag('input', $this->_attributes);
             break;
         case 'time':
             $this->_attributes['type'] = 'time';
             $field = new Tag('input', $this->_attributes);
             break;
         case 'datetime':
             $this->_attributes['type'] = 'datetime';
             $field = new Tag('input', $this->_attributes);
             break;
         case 'datetime-local':
             $this->_attributes['type'] = 'datetime-local';
             $field = new Tag('input', $this->_attributes);
             break;
         case 'email':
             $this->_attributes['type'] = 'email';
             $field = new Tag('input', $this->_attributes);
             break;
         case 'search':
             $this->_attributes['type'] = 'search';
             $field = new Tag('input', $this->_attributes);
             break;
         case 'tel':
             $this->_attributes['type'] = 'tel';
             $field = new Tag('input', $this->_attributes);
             break;
         case 'url':
             $this->_attributes['type'] = 'url';
             $field = new Tag('input', $this->_attributes);
             break;
         case 'select':
             $field = new Tag('select', $this->_attributes);
             if (!empty($this->_options)) {
                 foreach ($this->_options as $group => $option) {
                     if (is_array($option)) {
                         $group = new Tag('optgroup', ['label' => $group]);
                         foreach ($option as $value => $label) {
                             $attr = ['value' => $value];
                             if (isset($this->_value)) {
                                 if ($this->_value == $value) {
                                     $attr['selected'] = 'selected';
                                 }
                             }
                             $group->append_content(new Tag('option', $label, $attr));
                         }
                         $field->append_content($group);
                     } elseif (is_string($option) or is_numeric($option)) {
                         $attr = ['value' => $group];
                         if (isset($this->_value)) {
                             if ($this->_value == $group) {
                                 $attr['selected'] = 'selected';
                             }
                         }
                         $field->append_content(new Tag('option', $option, $attr));
                     }
                 }
             }
             break;
         case 'textarea':
             $this->_attributes['type'] = 'textarea';
             $field = new Tag('textarea', $this->_attributes);
             break;
         case 'file':
             $this->_attributes['type'] = 'file';
             $field = new Tag('input', $this->_attributes);
             break;
         case 'featured-image':
             $field = new Tag('div', ['data-role' => 'featured-image']);
             $properties['size'] = isset($this->_properties['size']) ? $this->_properties['size'] : ['width' => 270, 'height' => 270];
             $properties['text'] = isset($this->_properties['text']) ? $this->_properties['text'] : 'Featured Image';
             $image_holder = new Tag('img', array('src' => 'holder.js/' . implode('x', $properties['size']) . '?text=' . $this->_properties['text'], 'data-pattern' => 'image-preview'));
             if (!empty($this->_value)) {
                 $image_holder->add_class('hidden');
                 $image_preview = new Tag('img', array('src' => $this->_value, 'data-role' => 'image-preview'));
                 $field->append_content($image_preview);
             }
             $field->append_content($image_holder);
             $this->_attributes['type'] = 'file';
             $this->_attributes['data-role'] = 'image-input';
             $this->_attributes['accept'] = 'image/*';
             $input_group = new Group(Group::INPUT_GROUP);
             $input_group->add_item(new Tag('span', new Tag('span', '<i class="fa fa-camera"></i>' . new Tag('input', $this->_attributes), array('class' => 'btn btn-file', 'data-role' => 'image-browse', 'title' => 'Browse', 'data-toggle' => 'tooltip')), ['class' => 'input-group-btn']));
             $field->append_content($input_group);
             break;
         case 'textarea':
             $this->_attributes['type'] = 'textarea';
             $field = new Tag('textarea', $this->_attributes);
             break;
         default:
             $field = new Tag($this->_tag, $this->_attributes);
             break;
     }
     $field->add_class('form-control');
     if (isset($this->label)) {
         $group = new Group(Group::FORM_GROUP);
         $group->add_item($this->label);
         $group->add_item($field);
         if (isset($this->help)) {
             $group->add_item($this->help);
         }
         return $group->render();
     }
     return $field->render();
 }
Beispiel #4
0
 public function add_item($item)
 {
     if ($item instanceof Group) {
         $this->_items[] = clone $item;
     } elseif (isset($item['input'])) {
         $group = new Group(Group::FORM_GROUP);
         // Set Input Label
         if (isset($item['label'])) {
             if (isset($item['label']['show']) and $item['label']['show'] === TRUE) {
                 $attr = isset($item['label']['attr']) ? $item['label']['attr'] : ['for' => $item['input']['name']];
                 $label = new Tag('label', $item['label']['text'], $attr);
                 $label->add_class('control-label');
                 if (isset($item['label']['tag'])) {
                     $label->set_tag($item['label']['tag']);
                 }
                 $group->add_item($label);
             }
         }
         // Set Input
         $input = new Input();
         $input->set_type($item['input']['type']);
         $input->set_attributes($item['input']['attr']);
         if (isset($item['input']['options'])) {
             $input->set_options($item['input']['options']);
         }
         $properties = $item['input'];
         unset($properties['type'], $properties['attr'], $properties['options']);
         $input->set_properties($properties);
         // Set Value
         if (!empty($item['input']['value'])) {
             $input->set_value($item['input']['value'], TRUE);
         }
         if (isset($item['container'])) {
             $container = new Tag('div', $input, $item['container']['attr']);
             if (isset($item['container']['tag'])) {
                 $container->set_tag($item['container']['tag']);
             }
             $group->add_item($container);
         } else {
             $group->add_item($input);
         }
         // Set Help
         if (!empty($item['help'])) {
             $group->add_item(new Tag('span', $item['help'], ['class' => 'help-block help-control']));
         }
         $this->_items[] = $group;
     }
 }
Beispiel #5
0
 /**
  * render
  *
  * @return object
  */
 public function render()
 {
     if (isset($this->brand)) {
         if (empty($this->_target)) {
             $this->_target = uniqid('navbar-');
         }
         $toggle = new Button();
         $toggle->append_label(new Tag('span', 'Toggle Navigation', ['class' => 'sr-only']));
         $icons[] = new Tag('span', ['class' => 'icon-bar']);
         $icons[] = new Tag('span', ['class' => 'icon-bar']);
         $icons[] = new Tag('span', ['class' => 'icon-bar']);
         $toggle->append_label(implode(PHP_EOL, $icons));
         $toggle->add_attributes(array('class' => 'navbar-toggle', 'data-toggle' => 'collapse', 'data-target' => '#' . $this->_target));
         $output['header'] = new Tag('div', implode(PHP_EOL, [$toggle, $this->brand]), ['class' => 'navbar-header']);
     }
     $output['collapse'] = new Tag('div', ['id' => $this->_target, 'class' => 'collapse navbar-collapse']);
     $output['collapse']->append_content($this->left);
     $output['collapse']->append_content($this->form);
     $output['collapse']->append_content($this->right);
     $container = new Tag('div', implode(PHP_EOL, $output));
     if ($this->_is_full_width === FALSE) {
         if ($this->_is_fluid === TRUE) {
             $container->add_class('container-fluid');
         } else {
             $container->add_class('container');
         }
     } else {
         $container->add_class('container-full-width');
     }
     return (new Tag($this->_tag, $container, $this->_attributes))->render();
 }