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 TTime.php

Documentation is available at TTime.php

  1. <?php
  2. namespace Adianti\Widget\Form;
  3.  
  4. use Adianti\Control\TAction;
  5. use Adianti\Core\AdiantiCoreTranslator;
  6. use Adianti\Widget\Form\AdiantiWidgetInterface;
  7. use Adianti\Widget\Base\TScript;
  8. use Adianti\Widget\Form\TEntry;
  9.  
  10. use Exception;
  11.  
  12. /**
  13.  * TimePicker Widget
  14.  *
  15.  * @version    7.4
  16.  * @package    widget
  17.  * @subpackage form
  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.  */
  22. class TTime extends TEntry implements AdiantiWidgetInterface
  23. {
  24.     private $mask;
  25.     protected $id;
  26.     protected $size;
  27.     protected $value;
  28.     protected $options;
  29.     protected $replaceOnPost;
  30.     protected $changeFunction;
  31.     protected $changeAction;
  32.  
  33.     /**
  34.      * Class Constructor
  35.      * @param $name Name of the widget
  36.      */
  37.     public function __construct($name)
  38.     {
  39.         parent::__construct($name);
  40.         $this->id   = 'ttime_' mt_rand(10000000001999999999);
  41.         $this->mask 'hh:ii';
  42.         $this->options = [];
  43.  
  44.         $this->setOption('startView'1);
  45.         $this->setOption('pickDate'false);
  46.         $this->setOption('formatViewType''time');
  47.         $this->setOption('fontAwesome'true);
  48.  
  49.         $newmask $this->mask;
  50.         $newmask str_replace('hh',   '99',   $newmask);
  51.         $newmask str_replace('ii',   '99',   $newmask);
  52.         $newmask str_replace('ss',   '99',   $newmask);
  53.         parent::setMask($newmask);
  54.         $this->tag->{'widget''ttime';
  55.     }
  56.  
  57.     /**
  58.      * Define the field's mask
  59.      * @param $mask  Mask for the field (dd-mm-yyyy)
  60.      */
  61.     public function setMask($mask$replaceOnPost FALSE)
  62.     {
  63.         $this->mask $mask;
  64.         $this->replaceOnPost $replaceOnPost;
  65.  
  66.         $newmask $this->mask;
  67.         $newmask str_replace('hh',   '99',   $newmask);
  68.         $newmask str_replace('ii',   '99',   $newmask);
  69.         $newmask str_replace('ss',   '99',   $newmask);
  70.  
  71.         parent::setMask($newmask$replaceOnPost);
  72.     }
  73.  
  74.     /**
  75.      * Set extra datepicker options
  76.      * @link https://www.malot.fr/bootstrap-datetimepicker/
  77.      */
  78.     public function setOption($option$value)
  79.     {
  80.         $this->options[$option$value;
  81.     }
  82.  
  83.     /**
  84.      * Define the action to be executed when the user changes the field
  85.      * @param $action TAction object
  86.      */
  87.     public function setExitAction(TAction $action)
  88.     {
  89.         $this->setChangeAction($action);
  90.     }
  91.  
  92.     /**
  93.      * Define the action to be executed when the user changes the field
  94.      * @param $action TAction object
  95.      */
  96.     public function setChangeAction(TAction $action)
  97.     {
  98.         if ($action->isStatic())
  99.         {
  100.             $this->changeAction $action;
  101.         }
  102.         else
  103.         {
  104.             $string_action $action->toString();
  105.             throw new Exception(AdiantiCoreTranslator::translate('Action (^1) must be static to be used in ^2'$string_action__METHOD__));
  106.         }
  107.     }
  108.  
  109.     /**
  110.      * Set change function
  111.      */
  112.     public function setChangeFunction($function)
  113.     {
  114.         $this->changeFunction $function;
  115.     }
  116.  
  117.     /**
  118.      * Enable the field
  119.      * @param $form_name Form name
  120.      * @param $field Field name
  121.      */
  122.     public static function enableField($form_name$field)
  123.     {
  124.         TScript::create" tdate_enable_field('{$form_name}', '{$field}'); );
  125.     }
  126.  
  127.     /**
  128.      * Disable the field
  129.      * @param $form_name Form name
  130.      * @param $field Field name
  131.      */
  132.     public static function disableField($form_name$field)
  133.     {
  134.         TScript::create" tdate_disable_field('{$form_name}', '{$field}'); );
  135.     }
  136.  
  137.     /**
  138.      * Shows the widget at the screen
  139.      */
  140.     public function show()
  141.     {
  142.         $language strtolowerAdiantiCoreTranslator::getLanguage() );
  143.         $options json_encode($this->options);
  144.  
  145.         if (parent::getEditable())
  146.         {
  147.             $outer_size 'undefined';
  148.             if (strstr((string) $this->size'%'!== FALSE)
  149.             {
  150.                 $outer_size $this->size;
  151.                 $this->size '100%';
  152.             }
  153.         }
  154.  
  155.         if (isset($this->changeAction))
  156.         {
  157.             if (!TForm::getFormByName($this->formNameinstanceof TForm)
  158.             {
  159.                 throw new Exception(AdiantiCoreTranslator::translate('You must pass the ^1 (^2) as a parameter to ^3'__CLASS__$this->name'TForm::setFields()') );
  160.             }
  161.  
  162.             $string_action $this->changeAction->serialize(FALSE);
  163.             $this->setProperty('changeaction'"__adianti_post_lookup('{$this->formName}', '{$string_action}', '{$this->id}', 'callback')");
  164.             $this->setProperty('onChange'$this->getProperty('changeaction'));
  165.         }
  166.  
  167.         if (isset($this->changeFunction))
  168.         {
  169.             $this->setProperty('changeaction'$this->changeFunctionFALSE);
  170.             $this->setProperty('onChange'$this->changeFunctionFALSE);
  171.         }
  172.  
  173.         parent::show();
  174.  
  175.         if (parent::getEditable())
  176.         {
  177.             TScript::create"tdatetime_start( '#{$this->id}', '{$this->mask}', '{$language}', '{$outer_size}', '{$options}');");
  178.         }
  179.     }
  180. }