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

Documentation is available at TArrowStep.php

  1. <?php
  2.  
  3. use Adianti\Control\TAction;
  4. use Adianti\Core\AdiantiCoreTranslator;
  5. use Adianti\Widget\Base\TElement;
  6. use Adianti\Widget\Base\TScript;
  7. use Adianti\Widget\Base\TStyle;
  8. use Adianti\Widget\Form\AdiantiWidgetInterface;
  9. use Adianti\Widget\Form\TForm;
  10.  
  11. /**
  12.  * Arrow Step
  13.  *
  14.  * @version    7.4
  15.  * @package    widget
  16.  * @subpackage util
  17.  * @author     Lucas Tomasi
  18.  * @author     Matheus Agnes Dias
  19.  * @author     Pablo Dall'Oglio
  20.  * @copyright  Copyright (c) 2006-2014 Adianti Solutions Ltd. (http://www.adianti.com.br)
  21.  * @license    http://www.adianti.com.br/framework-license
  22.  */
  23. class TArrowStep extends TElement implements AdiantiWidgetInterface
  24. {
  25.     protected $container;
  26.     protected $items;
  27.     protected $colorItems;
  28.     protected $action;
  29.     protected $selected;
  30.     protected $height;
  31.     protected $name;
  32.     protected $id;
  33.     protected $color;
  34.     protected $fontColor;
  35.     protected $disableColor;
  36.     protected $disableFontColor;
  37.     protected $hideText;
  38.     protected $fontSize;
  39.     protected $formName;
  40.     protected $className;
  41.     protected $editable;
  42.  
  43.     /**
  44.      * Constructor
  45.      */
  46.     public function __construct($name)
  47.     {
  48.         parent::__construct('div');
  49.  
  50.         $this->id = 'tarrowstep_' mt_rand(10000000001999999999);
  51.  
  52.         $this->className = "arrow_steps_{$name}";
  53.         $this->class $this->className;
  54.         
  55.         $this->container = new TElement('div');
  56.         $this->container->{'class''arrow_steps';
  57.         
  58.         $this->colorItems = [];
  59.  
  60.         $this->name = $name;
  61.         $this->editable = true;
  62.         $this->hideText = false;
  63.         $this->height = 50;
  64.         $this->fontSize = '14px';
  65.         $this->color = "#6c757d";
  66.         $this->fontColor = "#ffffff";
  67.         $this->disableColor = "#e8e8e8";
  68.         $this->disableFontColor = "#333";
  69.  
  70.         parent::add$this->container );
  71.     }
  72.  
  73.     /**
  74.      * Disable field
  75.      * 
  76.      * @param $name name of arrow steps
  77.      */
  78.     public static function disableField($name)
  79.     {
  80.         TScript::create("tarrowstep_disable_field('{$name}');");
  81.     }
  82.  
  83.     /**
  84.      * Enable field
  85.      * 
  86.      * @param $name name of arrow steps
  87.      */
  88.     public static function enableField($name)
  89.     {
  90.         TScript::create("tarrowstep_enable_field('{$name}');");
  91.     }
  92.  
  93.  
  94.     /**
  95.      * Clear currents item on steps
  96.      * 
  97.      * @param $name name of arrow steps
  98.      */
  99.     public static function clearField($name)
  100.     {
  101.         TScript::create("tarrowstep_clear('{$name}');");
  102.     }
  103.  
  104.     /**
  105.      * Define current item on steps
  106.      * 
  107.      * @param $name name of arrow steps
  108.      * @param $value value current
  109.      */
  110.     public static function defineCurrent($name$value)
  111.     {
  112.         TScript::create("tarrowstep_set_current('{$name}', '{$value}');");
  113.     }
  114.     
  115.     /**
  116.      * Define if the field is editable
  117.      * @param $editable A boolean
  118.      */
  119.     public function setEditable($editable)
  120.     {
  121.         $this->editable$editable;
  122.     }
  123.  
  124.     /**
  125.      * Returns if the field is editable
  126.      * @return boolean
  127.      */
  128.     public function getEditable()
  129.     {
  130.         return $this->editable;
  131.     }
  132.  
  133.     /**
  134.      * Return the post data
  135.      */
  136.     public function getPostData()
  137.     {
  138.         if (isset($_POST[$this->name]))
  139.         {
  140.             return $_POST[$this->name];
  141.         }
  142.  
  143.         return null;
  144.     }
  145.  
  146.     /**
  147.      * Validate a field
  148.      */
  149.     public function validate()
  150.     {
  151.         if ($this->validations)
  152.         {
  153.             foreach ($this->validations as $validation)
  154.             {
  155.                 $label      $validation[0];
  156.                 $validator  $validation[1];
  157.                 $parameters $validation[2];
  158.                 
  159.                 $validator->validate($label$this->getValue()$parameters);
  160.             }
  161.         }
  162.     }
  163.     
  164.  
  165.     /**
  166.      * Set form name
  167.      */
  168.     public function setFormName($name)
  169.     {
  170.         $this->formName $name;
  171.     }
  172.  
  173.     /**
  174.      * Set name
  175.      */
  176.     public function setName($name)
  177.     {
  178.         $this->name $name;
  179.     }
  180.  
  181.     /**
  182.      * Get name
  183.      */
  184.     public function getName()
  185.     {
  186.         return $this->name;
  187.     }
  188.  
  189.     /**
  190.      * Set value current step
  191.      */
  192.     public function setValue($value)
  193.     {
  194.         $this->setCurrentKey($value);
  195.     }
  196.  
  197.     /**
  198.      * Get value current step
  199.      */
  200.     public function getValue()
  201.     {
  202.         return $this->getCurrent();
  203.     }
  204.  
  205.     /**
  206.      * Set hide text
  207.      * @param $hide bool
  208.      */
  209.     public function setHideText(bool $hide true)
  210.     {
  211.         $this->hideText $hide;
  212.     }
  213.  
  214.     /**
  215.      * Set font size
  216.      * @param $size string to color
  217.      */
  218.     public function setFontSize($fontSize)
  219.     {
  220.         $fontSize (strstr($fontSize'%'!== FALSE$fontSize "{$fontSize}px";
  221.  
  222.         $this->fontSize $fontSize;
  223.     }
  224.  
  225.     /**
  226.      * Set color arrows
  227.      * @param $color string to color
  228.      * @param $fontColor string to color font
  229.      */
  230.     public function setFilledColor(string $color$fontColor null)
  231.     {
  232.         $this->color $color;
  233.  
  234.         if ($fontColor)
  235.         {
  236.             $this->fontColor $fontColor;
  237.         }
  238.     }
  239.  
  240.     /**
  241.      * Set font color arrows
  242.      * @param $color string to color
  243.      */
  244.     public function setFilledFontColor(string $fontColor)
  245.     {
  246.         $this->fontColor $fontColor;
  247.     }
  248.  
  249.     /**
  250.      * Set color arrows
  251.      * @param $color string to color
  252.      * @param $fontColor string to color font
  253.      */
  254.     public function setUnfilledColor(string $color$fontColor null)
  255.     {
  256.         $this->disableColor $color;
  257.  
  258.         if ($fontColor)
  259.         {
  260.             $this->disableFontColor $fontColor;
  261.         }
  262.     }
  263.  
  264.     /**
  265.      * Set color arrows
  266.      * @param $fontColor string to color font
  267.      */
  268.     public function setUnfilledFontColor(string $color)
  269.     {
  270.         $this->disableFontColor $color;
  271.     }
  272.     
  273.     /**
  274.      * Set height arrows
  275.      * @param $height int|float to height
  276.      */
  277.     public function setHeight($height)
  278.     {
  279.         if (is_numeric($height))
  280.         {
  281.             throw new Exception(AdiantiCoreTranslator::translate('Invalid parameter (^1) in ^2'$height__METHOD__));
  282.         }
  283.  
  284.         $this->height $height;
  285.     }
  286.  
  287.     /**
  288.      * Get heigth
  289.      */
  290.     public function getHeight()
  291.     {
  292.         return $this->height;
  293.     }
  294.  
  295.     /**
  296.      * Get size
  297.      */
  298.     public function getSize()
  299.     {
  300.         return null;
  301.     }
  302.  
  303.     /**
  304.      * Add an item
  305.      * @param $title    Item title
  306.      * @param $id       Item id
  307.      * @param $color    Item color
  308.      */
  309.     public function addItem($title$id null$color null)
  310.     {
  311.         if ($id)
  312.         {
  313.             $this->items[$id$title;
  314.             $this->colorItems[$id$color;
  315.         }
  316.         else
  317.         {
  318.             $this->items[$title;
  319.             $this->colorItems[$color;
  320.         }
  321.     }
  322.  
  323.     /**
  324.      * Set color items
  325.      * @param $colorItems  Items
  326.      */
  327.     public function setColorItems($colorItems)
  328.     {
  329.         $this->colorItems $colorItems;
  330.     }
  331.     
  332.     /**
  333.      * Set items
  334.      * @param $item  Items
  335.      */
  336.     public function setItems($items)
  337.     {
  338.         if ($items)
  339.         {
  340.             $this->items [];
  341.  
  342.             foreach($items as $key => $title)
  343.             {
  344.                 $this->items[$key$title;
  345.             }
  346.         }
  347.     }
  348.     
  349.     /**
  350.      * Get items
  351.      * 
  352.      */
  353.     public function getItems()
  354.     {
  355.         return $this->items;
  356.     }
  357.  
  358.     /**
  359.      * Get item
  360.      * 
  361.      */
  362.     public function getItem($key)
  363.     {
  364.         return empty($this->items[$key]$this->items[$keyNULL;
  365.     }
  366.  
  367.     /**
  368.      * Set action
  369.      * 
  370.      * @param $action Action
  371.      */
  372.     public function setAction(TAction $action)
  373.     {
  374.         $this->action $action;
  375.     }
  376.  
  377.     /**
  378.      * Get action
  379.      * 
  380.      */
  381.     public function getAction()
  382.     {
  383.         return $this->action;
  384.     }
  385.  
  386.     /**
  387.      * Select current item
  388.      */
  389.     public function setCurrentKey($key)
  390.     {
  391.         $this->selected $key;
  392.     }
  393.  
  394.     /**
  395.      * Get current item
  396.      */
  397.     public function getCurrent()
  398.     {
  399.         return $this->selected;
  400.     }
  401.  
  402.     /**
  403.      * Select current item
  404.      */
  405.     public function setCurrent($title)
  406.     {
  407.         if (in_array($title$this->items))
  408.         {
  409.             $this->selected array_search($title$this->items);
  410.         }
  411.     }
  412.     
  413.     /**
  414.      * Get action in serialized way
  415.      */
  416.     private function getSerializedAction($key$value$selected false)
  417.     {
  418.         $this->action->setParameter('value'$value);
  419.         $this->action->setParameter('__selected'$selected);
  420.  
  421.         if (!TForm::getFormByName($this->formNameinstanceof TForm)
  422.         {
  423.             return "__adianti_load_page('{$this->action->serialize(true)}');";
  424.         }
  425.         else
  426.         {
  427.             $string_action $this->action->serialize(FALSE);
  428.  
  429.             $key $this->id ."_" str_replace([' ''-']['''']$key);
  430.  
  431.             return "__adianti_post_lookup('{$this->formName}', '{$string_action}', '{$key}', 'callback')";
  432.         }
  433.     }
  434.  
  435.     /**
  436.      * Make a html of item
  437.      */
  438.     private function makeItem($key$value$selected false)
  439.     {
  440.         $div new TElement('div');
  441.         $div->{'class'}  'step';
  442.         $div->{'data-key'$key;
  443.         $div->{'class'.= $selected && is_null($this->selected' current ' '';
  444.  
  445.         $input new TElement('input');
  446.         $input->{'type''hidden';
  447.         $input->{'id'$this->id ."_" str_replace([' ''-']['''']$key);
  448.         $input->{'value'$key;
  449.  
  450.         $div->add$input );
  451.         $this->container->add$div );
  452.         
  453.         $span new TElement('span');
  454.         $span->add($value);
  455.         
  456.         if ($this->action)
  457.         {
  458.             $div->{'onclick'$this->getSerializedAction($key$value$selected);
  459.         }
  460.         
  461.         if ($this->hideText)
  462.         {
  463.             $div->add($span);
  464.             $this->style 'overflow-x: auto;';
  465.         }
  466.         else
  467.         {
  468.             $div->title $value;
  469.         }
  470.     }
  471.  
  472.     /**
  473.      * Make component style
  474.      */
  475.     private function makeStyle()
  476.     {
  477.         $size1 $this->height/'px';
  478.         $size2 $this->height/'px';
  479.  
  480.         $styles new TElement('style');
  481.         $styles->type 'text/css';
  482.         $styles->media 'screen';
  483.  
  484.         $styleClassHeight new TStyle($this->className.' .arrow_steps');
  485.         $styleClassHeight->height $this->height .'px';
  486.         $styles->add($styleClassHeight);
  487.  
  488.         $styleClassBackground new TStyle($this->className.'::-webkit-scrollbar-thumb,.'.$this->className.' .step.current,.'.$this->className.' .step.preview-current');
  489.         $styleClassBackground->{"background-color"$this->color;
  490.         $styleClassBackground->{"color"$this->fontColor;
  491.         $styles->add($styleClassBackground);
  492.  
  493.         $styleClassBackgroundDisable new TStyle($this->className.' .step');
  494.         $styleClassBackgroundDisable->{"background-color"$this->disableColor;
  495.         $styleClassBackgroundDisable->{"color"$this->disableFontColor;
  496.         $styleClassBackgroundDisable->{"font-size"$this->fontSize;
  497.         $styleClassBackgroundDisable->{"padding-left""{$size2}";
  498.         $styles->add($styleClassBackgroundDisable);
  499.         
  500.         $styleClassBorder new TStyle($this->className.' .step.current:after,.'.$this->className.' .step.preview-current:after');
  501.         $styleClassBorder->{"border-left-color"$this->color;
  502.         $styleClassBorder->{"border-left-width"$size2;
  503.         $styles->add($styleClassBorder);
  504.  
  505.         $styleClassBorderHeight new TStyle($this->className.' .step:after,.'.$this->className.' .step:before');
  506.         $styleClassBorderHeight->{"border-top-width"=  $size1;
  507.         $styleClassBorderHeight->{"border-bottom-width"$size1;
  508.         $styleClassBorderHeight->{"right""-{$size2}";
  509.         $styleClassBorderHeight->{"border-left-width"$size2;
  510.         $styleClassBorderHeight->{"border-left-color"$this->disableColor;
  511.         $styles->add($styleClassBorderHeight);
  512.         
  513.         $styleClassBorderStepBefore new TStyle($this->className.' .step:before');
  514.         $styleClassBorderStepBefore->{'border-left-width'$size2;
  515.         $styleClassBorderStepBefore->{"border-left-color"'white';
  516.         $styles->add($styleClassBorderStepBefore);
  517.  
  518.         $styleClassBorderSpanBefore new TStyle($this->className.' span:before');
  519.         $styleClassBorderSpanBefore->{'left'"-{$size2}";
  520.         $styles->add($styleClassBorderSpanBefore);
  521.  
  522.         if (empty($this->colorItems))
  523.         {
  524.             foreach($this->colorItems as $key => $color)
  525.             {
  526.                 $styleClassBackgroundStep new TStyle("{$this->className} .step.current[data-key=\"{$key}\"],.{$this->className} .step.preview-current[data-key=\"{$key}\"]");
  527.                 $styleClassBackgroundStep->{"background-color"$color;
  528.                 $styles->add($styleClassBackgroundStep);
  529.                 
  530.                 $styleClassBackgroundStepArrow new TStyle("{$this->className} .step.current[data-key=\"{$key}\"]:after,.{$this->className} .step.preview-current[data-key=\"{$key}\"]:after");
  531.                 $styleClassBackgroundStepArrow->{"border-left-color"$color;
  532.                 $styles->add($styleClassBackgroundStepArrow);
  533.             }
  534.         }
  535.  
  536.         parent::add($styles);
  537.     }
  538.  
  539.     /**
  540.      * Show component
  541.      */
  542.     public function show()
  543.     {
  544.         $this->makeStyle();
  545.  
  546.         if ($this->items)
  547.         {
  548.             $selected true;
  549.  
  550.             foreach($this->items as $key => $value)
  551.             {
  552.                 $this->makeItem($key$value$selected);
  553.  
  554.                 if ($this->selected == $key)
  555.                 {
  556.                     $selected false;
  557.                 }
  558.             }
  559.         }
  560.  
  561.         $input new TElement('input');
  562.         $input->{'type''hidden';
  563.         $input->{'id'$this->id;
  564.         $input->{'name'$this->name;
  565.         $input->{'value'$this->selected;
  566.  
  567.         parent::add($input);
  568.  
  569.         if ($this->editable)
  570.         {
  571.             $this->className .= ' disabled ';
  572.         }
  573.  
  574.         parent::setProperty('class'$this->className " div_arrow_steps");
  575.         
  576.         TScript::create("tarrowstep_start('{$this->name}');");
  577.  
  578.         parent::show();
  579.     }
  580. }