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

Documentation is available at TTimeline.php

  1. <?php
  2. namespace Adianti\Widget\Util;
  3.  
  4. use Adianti\Database\TTransaction;
  5. use Adianti\Widget\Base\TElement;
  6. use Adianti\Control\TAction;
  7. use Adianti\Widget\Form\TDateTime;
  8. use Adianti\Util\AdiantiTemplateHandler;
  9. use Adianti\Widget\Template\THtmlRenderer;
  10.  
  11. use stdClass;
  12. use ApplicationTranslator;
  13.  
  14. /**
  15.  * Timeline
  16.  *
  17.  * @version    7.4
  18.  * @package    widget
  19.  * @subpackage util
  20.  * @author     Artur Comunello
  21.  * @author     Pablo Dall'Oglio
  22.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  23.  * @license    http://www.adianti.com.br/framework-license
  24.  */
  25. class TTimeline extends TElement
  26. {
  27.     protected $useBothSides;
  28.     protected $items;
  29.     protected $finalIcon;
  30.     protected $timeDisplayMask;
  31.     protected $actions;
  32.     protected $itemTemplate;
  33.     protected $templatePath;
  34.     protected $itemDatabase;
  35.     
  36.     /**
  37.      * Class Constructor
  38.      */
  39.     public function __construct()
  40.     {
  41.         parent::__construct('ul');
  42.         $this->{'id''ttimeline_'.mt_rand(10000000001999999999);
  43.         $this->{'class''timeline';
  44.         $this->timeDisplayMask 'yyyy-mm-dd';
  45.         
  46.         $this->items [];
  47.         $this->actions [];
  48.     }
  49.     
  50.     /**
  51.      * Define the final timeline icon
  52.      * @param  $icon icon
  53.      */
  54.     public function setFinalIcon$icon )
  55.     {
  56.         $this->finalIcon $icon;
  57.     }
  58.     
  59.     /**
  60.      * Define the labelmask
  61.      * @param  $mask Mask
  62.      */
  63.     public function setTimeDisplayMask$mask )
  64.     {
  65.         $this->timeDisplayMask $mask;
  66.     }
  67.     
  68.     /**
  69.      * Define the labelmask
  70.      * @param  $mask Mask
  71.      */
  72.     public function setUseBothSides()
  73.     {
  74.         $this->useBothSides true;
  75.     }
  76.     
  77.     /**
  78.      * Set card item template for rendering
  79.      * @param  $template   Template content
  80.      */
  81.     public function setItemTemplate($template)
  82.     {
  83.         $this->itemTemplate $template;
  84.     }
  85.     
  86.     /**
  87.      * Define the item template path
  88.      * @param  $template_path Template path
  89.      */
  90.     public function setTemplatePath$template_path )
  91.     {
  92.         $this->templatePath $template_path;
  93.     }
  94.     
  95.     /**
  96.      * Set item min database
  97.      * @param $database min database
  98.      */
  99.     public function setItemDatabase($database)
  100.     {
  101.         $this->itemDatabase $database;
  102.     }
  103.     
  104.     /**
  105.      * Add Item
  106.      * @param  $id       ID
  107.      * @param  $title    Title
  108.      * @param  $content  Item content
  109.      * @param  $date     Item date
  110.      * @param  $icon     Item icon
  111.      * @param  $align    Item align
  112.      * @param  $object   Item data object
  113.      */
  114.     public function addItem$id$title$content$date$icon$align null$object null  )
  115.     {
  116.         if (is_null($object))
  117.         {
  118.             $object new stdClass;
  119.         }
  120.         
  121.         if (empty($object->{'id'}))
  122.         {
  123.             $object->{'id'$id;
  124.         }
  125.         
  126.         $item new stdClass;
  127.         $item->{'id'}      $id;
  128.         $item->{'title'}   $title;
  129.         $item->{'content'$content;
  130.         $item->{'date'}    $date;
  131.         $item->{'icon'}    $icon;
  132.         $item->{'align'}   $align;
  133.         $item->{'object'}  $object;
  134.         
  135.         $this->items[$item;
  136.     }
  137.     
  138.     /**
  139.      * Add Action
  140.      * @param  $label             Action Label
  141.      * @param  $action            Action
  142.      * @param  $field             Action field
  143.      * @param  $icon              Action icon
  144.      * @param  $btn_class         Action button class
  145.      * @param  $display_condition Action display condition
  146.      */
  147.     public function addAction(TAction $action$label$icon$display_condition null)
  148.     {
  149.         $action->setProperty('label'$label);
  150.         $action->setProperty('icon',  $icon);
  151.         $action->setProperty('display_condition'$display_condition );
  152.         
  153.         $this->actions[$action;
  154.     }
  155.     
  156.     /**
  157.      * Render  Action
  158.      * @param  $object Data object
  159.      */
  160.     private function renderItemActions$object null )
  161.     {
  162.         if ($this->actions)
  163.         {
  164.             $footer new TElement'div' );
  165.             $footer->{'class''timeline-footer';
  166.             
  167.             foreach ($this->actions as $action_template)
  168.             {
  169.                 if empty$object ) )
  170.                 {
  171.                     $action clone $action_template;
  172.                 }
  173.                 else
  174.                 {
  175.                     $action $action_template->prepare($object);
  176.                 }
  177.                 
  178.                 // get the action properties
  179.                 $icon      $action->getProperty('icon');
  180.                 $label     $action->getProperty('label');
  181.                 $condition $action->getProperty('display_condition');
  182.                 
  183.                 if (empty($conditionOR call_user_func($condition$object))
  184.                 {
  185.                     $button new TElement('button');
  186.                     $button->{'onclick'"__adianti_load_page('{$action->serialize()}');return false;";
  187.                     
  188.                     $span new TElement('span');
  189.                     $span->addnew TImage($icon) );
  190.                     $span->add$label );
  191.                     $button->add$span );
  192.                     $button->{'class'$action->getProperty('btn-class'?? 'btn btn-default';
  193.                     
  194.                     $footer->add$button );
  195.                 }
  196.             }
  197.             return $footer;
  198.         }
  199.     }
  200.     
  201.     /**
  202.      * Render label
  203.      * @param $label Label
  204.      */
  205.     private function defaultItemRender$item )
  206.     {
  207.         $span new TElement'span' );
  208.         $span->{'class''time';
  209.         
  210.         if (strlen($item->{'date'}10)
  211.         {
  212.             $span->addnew TImage'far:clock' ) );
  213.             $span->addTDateTime::convertToMask$item->{'date'}'yyyy-mm-dd hh:ii:ss''hh:ii' ) );
  214.         }
  215.         
  216.         $title new TElement'a' );
  217.         $title->addAdiantiTemplateHandler::replace$item->{'title'}$item->{'object') );
  218.         
  219.         if (!empty($item->{'title'}))
  220.         {
  221.             $h3 new TElement'h3' );
  222.             $h3->{'class''timeline-header';
  223.             $h3->add$title );
  224.         }
  225.         
  226.         $div new TElement'div' );
  227.         $div->{'class''timeline-body';
  228.         
  229.         $div->addAdiantiTemplateHandler::replace$item->{'content'}$item->{'object') );
  230.         
  231.         $item_div new TElement'div' );
  232.         $item_div->{'class''timeline-item ';
  233.         
  234.         if$this->useBothSides)
  235.         {
  236.             if empty$item->{'align') )
  237.             {
  238.                 $item->{'align''left';
  239.             }
  240.             
  241.             $item_div->{'class'.= 'timeline-item-' $item->{'align'};
  242.         }
  243.         
  244.         $item_div->add$span );
  245.         if (!empty($h3))
  246.         {
  247.             $item_div->add$h3 );
  248.         }
  249.         $item_div->add$div );
  250.         $item_div->add$this->renderItemActions$item->{'object') );
  251.         
  252.         return $item_div;
  253.     }
  254.     
  255.     /**
  256.      * Render item
  257.      * @param $item Item
  258.      */
  259.     private function renderItem$item )
  260.     {
  261.         if !empty$this->templatePathAND !empty$item->{'object'}) )
  262.         {
  263.             $template new THtmlRenderer$this->templatePath );
  264.             $template->enableSection'main' );
  265.             $content $item->{'object'}->render$template->getContents() );
  266.         }
  267.         else if (!empty($this->itemTemplate))
  268.         {
  269.             $item_template ApplicationTranslator::translateTemplate($this->itemTemplate);
  270.             $item_template AdiantiTemplateHandler::replace($item_template$item->{'object'});
  271.             $content $item_template;
  272.         }
  273.         else
  274.         {
  275.             $content $this->defaultItemRender$item );
  276.         }
  277.         
  278.         $li new TElement'li' );
  279.         $li->addnew TImage$item->{'icon'' line-icon') );
  280.         $li->add$content );
  281.         
  282.         return $li;
  283.     }
  284.     
  285.     /**
  286.      * Render label
  287.      * @param $label Label
  288.      */
  289.     private function renderLabel$label )
  290.     {
  291.         $li new TElement'li' );
  292.         $li->{'class''time-label';
  293.         
  294.         if$this->useBothSides )
  295.         {
  296.             $li->{'class'.= ' time-label-bothsides';
  297.         }
  298.         
  299.         $li->addTElement::tag'span'$label ) );
  300.         
  301.         return $li;
  302.     }
  303.     
  304.     /**
  305.      * Render items
  306.      */
  307.     private function renderItems()
  308.     {
  309.         if ($this->items)
  310.         {
  311.             if (!empty($this->itemDatabase))
  312.             {
  313.                 TTransaction::open($this->itemDatabase);
  314.             }
  315.             
  316.             $first reset$this->items );
  317.             $label TDateTime::convertToMask$first->{'date'}strlen($first->{'date'}10 'yyyy-mm-dd hh:ii:ss' 'yyyy-mm-dd'$this->timeDisplayMask );
  318.             parent::add$this->renderLabel$label ) );
  319.             
  320.             foreach ($this->items as $item)
  321.             {
  322.                 $newLabel TDateTime::convertToMask$item->{'date'}strlen($item->{'date'}10 'yyyy-mm-dd hh:ii:ss' 'yyyy-mm-dd'$this->timeDisplayMask );
  323.                 
  324.                 if$newLabel != $label)
  325.                 {
  326.                     $label $newLabel;
  327.                     parent::add$this->renderLabel$label ) );
  328.                 }
  329.                 
  330.                 parent::add$this->renderItem$item ) );
  331.             }
  332.             
  333.             if (!empty($this->itemDatabase))
  334.             {
  335.                 TTransaction::close();
  336.             }
  337.         }
  338.     }
  339.     
  340.     /**
  341.      * Render final icon
  342.      */
  343.     private function renderFinalIcon()
  344.     {
  345.         if$this->finalIcon )
  346.         {
  347.             $li new TElement'li' );
  348.             $li->addnew TImage$this->finalIcon ' line-icon'));
  349.             
  350.             parent::add$li );
  351.         }
  352.     }
  353.     
  354.     /**
  355.      * Show
  356.      */
  357.     public function show()
  358.     {
  359.         $this->renderItems();
  360.         $this->renderFinalIcon();
  361.         
  362.         if$this->useBothSides )
  363.         {
  364.             $this->{'class'.= ' timeline-bothsides';
  365.         }
  366.         
  367.         parent::show();
  368.     }
  369. }