Lançado Adianti Framework 7.6!
Clique aqui para saber mais
menu

Adianti Solutions

API

Adianti, Framework, PHP, MVC, Active record, Front controller, IDE, RAD, Web, multiplataforma, geração de código, desenvolvimento rápido, relatórios, formulários, listagens, datagrids, gráficos, banco de dados, padrões de projeto, design patterns API do Adianti Framework.
API Docs
code
Selecione a classe

Source for file BootstrapFormWrapper.php

Documentation is available at BootstrapFormWrapper.php

  1. <?php
  2. namespace Adianti\Wrapper;
  3.  
  4. use Adianti\Widget\Wrapper\TQuickForm;
  5. use Adianti\Widget\Wrapper\AdiantiFormBuilder;
  6. use Adianti\Widget\Base\TElement;
  7. use Adianti\Widget\Form\TButton;
  8. use Adianti\Widget\Form\TLabel;
  9. use Adianti\Widget\Form\THidden;
  10. use Adianti\Widget\Form\AdiantiFormInterface;
  11. use Adianti\Widget\Form\AdiantiWidgetInterface;
  12.  
  13. /**
  14.  * Bootstrap form decorator for Adianti Framework
  15.  *
  16.  * @version    7.4
  17.  * @package    wrapper
  18.  * @author     Pablo Dall'Oglio
  19.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  20.  * @license    http://www.adianti.com.br/framework-license
  21.  * @wrapper    TQuickForm
  22.  */
  23. class BootstrapFormWrapper implements AdiantiFormInterface
  24. {
  25.     private $decorated;
  26.     private $currentGroup;
  27.     private $element;
  28.     
  29.     /**
  30.      * Constructor method
  31.      */
  32.     public function __construct(TQuickForm $form$class 'form-horizontal')
  33.     {
  34.         $this->decorated $form;
  35.         
  36.         $this->element   new TElement('form');
  37.         $this->element->{'class'}   $class;
  38.         $this->element->{'type'}    'bootstrap';
  39.         $this->element->{'enctype'"multipart/form-data";
  40.         $this->element->{'method'}  'post';
  41.         $this->element->{'name'}    $this->decorated->getName();
  42.         $this->element->{'id'}      $this->decorated->getName();
  43.         $this->element->{'novalidate'}  '';
  44.     }
  45.     
  46.     /**
  47.      * Turn on/off client validation
  48.      */
  49.     public function setClientValidation($bool)
  50.     {
  51.         if ($bool)
  52.         {
  53.             unset($this->element->{'novalidate'});
  54.         }
  55.         else
  56.         {
  57.             $this->element->{'novalidate'}  '';
  58.         }
  59.     }
  60.     
  61.     /**
  62.      * Return render element
  63.      */
  64.     public function getElement()
  65.     {
  66.         return $this->element;
  67.     }
  68.     
  69.     /**
  70.      * Redirect calls to decorated object
  71.      */
  72.     public function __call($method$parameters)
  73.     {
  74.         return call_user_func_array(array($this->decorated$method),$parameters);
  75.     }
  76.     
  77.     /**
  78.      * Redirect assigns to decorated object
  79.      */
  80.     public function __set($property$value)
  81.     {
  82.         return $this->element->$property $value;
  83.     }
  84.     
  85.     /**
  86.      * Set form name
  87.      */
  88.     public function setName($name)
  89.     {
  90.         return $this->decorated->setName($name);
  91.     }
  92.     
  93.     /**
  94.      * Get form name
  95.      */
  96.     public function getName()
  97.     {
  98.         return $this->decorated->getName();
  99.     }
  100.     
  101.     /**
  102.      * Add form field
  103.      */
  104.     public function addField(AdiantiWidgetInterface $field)
  105.     {
  106.         return $this->decorated->addField($field);
  107.     }
  108.     
  109.     /**
  110.      * Del form field
  111.      */
  112.     public function delField(AdiantiWidgetInterface $field)
  113.     {
  114.         return $this->decorated->delField($field);
  115.     }
  116.     
  117.     /**
  118.      * Set form fields
  119.      */
  120.     public function setFields($fields)
  121.     {
  122.         return $this->decorated->setFields($fields);
  123.     }
  124.     
  125.     /**
  126.      * Return form field
  127.      */
  128.     public function getField($name)
  129.     {
  130.         return $this->decorated->getField($name);
  131.     }
  132.     
  133.     /**
  134.      * Return form fields
  135.      */
  136.     public function getFields()
  137.     {
  138.         return $this->decorated->getFields();
  139.     }
  140.     
  141.     /**
  142.      * Clear form
  143.      */
  144.     public function clear()
  145.     {
  146.         return $this->decorated->clear();
  147.     }
  148.     
  149.     /**
  150.      * Set form data
  151.      */
  152.     public function setData($object)
  153.     {
  154.         return $this->decorated->setData($object);
  155.     }
  156.     
  157.     /**
  158.      * Get form data
  159.      */
  160.     public function getData($class 'StdClass')
  161.     {
  162.         return $this->decorated->getData($class);
  163.     }
  164.     
  165.     /**
  166.      * Validate form data
  167.      */
  168.     public function validate()
  169.     {
  170.         return $this->decorated->validate();
  171.     }
  172.     
  173.     /**
  174.      * Shows the decorated form
  175.      */
  176.     public function show()
  177.     {
  178.         $fieldsByRow $this->decorated->getFieldsByRow();
  179.         if ($this->element->{'class'== 'form-horizontal')
  180.         {
  181.             $classWidth  array(1=>array(3,9)2=>array(2,4)3=>array(2,2));
  182.             $labelClass  $classWidth[$fieldsByRow][0];
  183.             $fieldClass  $classWidth[$fieldsByRow][1];
  184.         }
  185.         
  186.         $fieldCount  0;
  187.         
  188.         $input_rows $this->decorated->getInputRows();
  189.         
  190.         if ($input_rows)
  191.         {
  192.             foreach ($input_rows as $input_row)
  193.             {
  194.                 $field_label  $input_row[0];
  195.                 $fields       $input_row[1];
  196.                 $required     $input_row[2];
  197.                 $original_row $input_row[3];
  198.                 
  199.                 // form vertical doesn't group elements, just change form group grid class
  200.                 if empty($this->currentGroupOR $fieldCount $fieldsByRow == OR (strpos($this->element->{'class'}'form-vertical'!== FALSE) )
  201.                 {
  202.                     // add the field to the container
  203.                     $this->currentGroup new TElement('div');
  204.                     
  205.                     foreach ($original_row->getProperties(as $property => $value)
  206.                     {
  207.                         $this->currentGroup->$property $value;
  208.                     }
  209.                     
  210.                     $this->currentGroup->{'class'}  'row tformrow form-group';
  211.                     $this->currentGroup->{'class'.= ( ( strpos($this->element->{'class'}'form-vertical'!== FALSE ' col-sm-'.(12/$fieldsByRow'');
  212.                     $this->element->add($this->currentGroup);
  213.                 }
  214.                 
  215.                 $group $this->currentGroup;
  216.                 
  217.                 if ($field_label instanceof TLabel)
  218.                 {
  219.                     $label $field_label;
  220.                 }
  221.                 else
  222.                 {
  223.                     $label new TElement('label');
  224.                     $label->add$field_label );
  225.                 }
  226.                 
  227.                 if ($this->element->{'class'== 'form-inline')
  228.                 {
  229.                     $label->{'style''padding-left: 3px; font-weight: bold';
  230.                 }
  231.                 else
  232.                 {
  233.                     $label->{'style''font-weight: bold; margin-bottom: 3px';
  234.                     if ($this->element->{'class'== 'form-horizontal')
  235.                     {
  236.                         $label->{'class''col-sm-'.$labelClass.' control-label';
  237.                     }
  238.                     else
  239.                     {
  240.                         $label->{'class'' control-label';
  241.                     }
  242.                 }
  243.                 
  244.                 if (count($fields)==AND $fields[0instanceof THidden)
  245.                 {
  246.                     $group->add('');
  247.                     $group->{'style''display:none';
  248.                 }
  249.                 else
  250.                 {
  251.                     $group->add($label);
  252.                 }
  253.                 
  254.                 if ($this->element->{'class'!== 'form-inline')
  255.                 {
  256.                     $col new TElement('div');
  257.                     if ($this->element->{'class'== 'form-horizontal')
  258.                     {
  259.                         $col->{'class''col-sm-'.$fieldClass ' fb-field-container';
  260.                     }
  261.                     
  262.                     $group->add($col);
  263.                 }
  264.                 
  265.                 foreach ($fields as $field)
  266.                 {
  267.                     if ($this->element->{'class'== 'form-inline')
  268.                     {
  269.                         $label->{'style'.= ';float:left';
  270.                         $group->add(BootstrapFormBuilder::wrapField($field'inline-block'));
  271.                     }
  272.                     else
  273.                     {
  274.                         $col->add(BootstrapFormBuilder::wrapField($field'inline-block'));
  275.                     }
  276.                 }
  277.                 $fieldCount ++;
  278.             }
  279.         }
  280.         
  281.         if ($this->decorated->getActionButtons())
  282.         {
  283.             $group new TElement('div');
  284.             $group->{'class''form-group';
  285.             $col new TElement('div');
  286.             
  287.             if ($this->element->{'class'== 'form-horizontal')
  288.             {
  289.                 $col->{'class''col-sm-offset-'.$labelClass.' col-sm-'.$fieldClass;
  290.             }
  291.             
  292.             $i 0;
  293.             foreach ($this->decorated->getActionButtons(as $action)
  294.             {
  295.                 $col->add($action);
  296.                 $i ++;
  297.             }
  298.             $group->add($col);
  299.             $this->element->add($group);
  300.         }
  301.         
  302.         $this->element->{'width''100%';
  303.         $this->element->show();
  304.     }
  305. }