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

Documentation is available at TDBSeekButton.php

  1. <?php
  2. namespace Adianti\Widget\Wrapper;
  3.  
  4. use Adianti\Core\AdiantiApplicationConfig;
  5. use Adianti\Core\AdiantiCoreTranslator;
  6. use Adianti\Widget\Form\TSeekButton;
  7. use Adianti\Base\TStandardSeek;
  8. use Adianti\Database\TCriteria;
  9. use Adianti\Database\TTransaction;
  10. use Adianti\Control\TAction;
  11.  
  12. use Exception;
  13.  
  14. /**
  15.  * Abstract Record Lookup Widget: Creates a lookup field used to search values from associated entities
  16.  *
  17.  * @version    7.4
  18.  * @package    widget
  19.  * @subpackage wrapper
  20.  * @author     Pablo Dall'Oglio
  21.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  22.  * @license    http://www.adianti.com.br/framework-license
  23.  */
  24. class TDBSeekButton extends TSeekButton
  25. {
  26.     /**
  27.      * Class Constructor
  28.      * @param  $name name of the form field
  29.      * @param  $database name of the database connection
  30.      * @param  $form name of the parent form
  31.      * @param  $model name of the Active Record to be searched
  32.      * @param  $display_field name of the field to be searched and shown
  33.      * @param  $receive_key name of the form field to receive the primary key
  34.      * @param  $receive_display_field name of the form field to receive the "display field"
  35.      */
  36.     public function __construct($name$database$form$model$display_field$receive_key null$receive_display_field nullTCriteria $criteria NULL$operator 'like')
  37.     {
  38.         parent::__construct($name);
  39.         
  40.         if (empty($database))
  41.         {
  42.             throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required''database'__CLASS__));
  43.         }
  44.         
  45.         if (empty($model))
  46.         {
  47.             throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required''model'__CLASS__));
  48.         }
  49.         
  50.         if (empty($display_field))
  51.         {
  52.             throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required''display_field'__CLASS__));
  53.         }
  54.         
  55.         $obj  new TStandardSeek;
  56.         $ini  AdiantiApplicationConfig::get();
  57.         $seed APPLICATION_NAME !empty($ini['general']['seed']$ini['general']['seed''s8dkld83kf73kf094' );
  58.         
  59.         // define the action parameters
  60.         $action new TAction(array($obj'onSetup'));
  61.         $action->setParameter('hash',          md5("{$seed}{$database}{$model}{$display_field}"));
  62.         $action->setParameter('database',      $database);
  63.         $action->setParameter('parent',        $form);
  64.         $action->setParameter('model',         $model);
  65.         $action->setParameter('display_field'$display_field);
  66.         $action->setParameter('receive_key',   !empty($receive_key$receive_key $name);
  67.         $action->setParameter('receive_field'!empty($receive_display_field$receive_display_field null);
  68.         $action->setParameter('criteria',      base64_encode(serialize($criteria)));
  69.         $action->setParameter('operator',      ($operator == 'ilike''ilike' 'like');
  70.         $action->setParameter('mask',          '');
  71.         $action->setParameter('label',         AdiantiCoreTranslator::translate('Description'));
  72.         parent::setAction($action);
  73.     }
  74.     
  75.     /**
  76.      * Set search criteria
  77.      */
  78.     public function setCriteria(TCriteria $criteria)
  79.     {
  80.         $this->getAction()->setParameter('criteria'base64_encode(serialize($criteria)));
  81.     }
  82.     
  83.     /**
  84.      * Set operator
  85.      */
  86.     public function setOperator($operator)
  87.     {
  88.         $this->getAction()->setParameter('operator'($operator == 'ilike''ilike' 'like');
  89.     }
  90.     
  91.     /**
  92.      * Set display mask
  93.      * @param $mask Display mask
  94.      */
  95.     public function setDisplayMask($mask)
  96.     {
  97.         $this->getAction()->setParameter('mask'$mask);
  98.     }
  99.     
  100.     /**
  101.      * Set display label
  102.      * @param $mask Display label
  103.      */
  104.     public function setDisplayLabel($label)
  105.     {
  106.         $this->getAction()->setParameter('label'$label);
  107.     }
  108.     
  109.     /**
  110.      * Define the field's value
  111.      * @param $value Current value
  112.      */
  113.     public function setValue($value)
  114.     {
  115.         parent::setValue($value);
  116.         
  117.         if (!empty($this->auxiliar))
  118.         {
  119.             $database $this->getAction()->getParameter('database');
  120.             $model    $this->getAction()->getParameter('model');
  121.             $mask     $this->getAction()->getParameter('mask');
  122.             $display_field $this->getAction()->getParameter('display_field');
  123.             
  124.             if (!empty($value))
  125.             {
  126.                 TTransaction::open($database);
  127.                 $activeRecord new $model($value);
  128.                 
  129.                 if (!empty($mask))
  130.                 {
  131.                     $this->auxiliar->setValue($activeRecord->render($mask));
  132.                 }
  133.                 else if (isset($activeRecord->$display_field))
  134.                 {
  135.                     $this->auxiliar->setValue$activeRecord->$display_field );
  136.                 }
  137.                 TTransaction::close();
  138.             }
  139.         }
  140.     }
  141. }