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

Documentation is available at TDBUniqueSearch.php

  1. <?php
  2. namespace Adianti\Widget\Wrapper;
  3.  
  4. use Adianti\Widget\Form\TMultiSearch;
  5. use Adianti\Widget\Form\AdiantiWidgetInterface;
  6. use Adianti\Widget\Form\TUniqueSearch;
  7. use Adianti\Widget\Wrapper\TDBMultiSearch;
  8. use Adianti\Core\AdiantiApplicationConfig;
  9. use Adianti\Database\TTransaction;
  10. use Adianti\Database\TCriteria;
  11.  
  12. use Exception;
  13.  
  14. /**
  15.  * DBUnique Search Widget
  16.  *
  17.  * @version    7.4
  18.  * @package    widget
  19.  * @subpackage form
  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. {
  25.     protected $database;
  26.     protected $model;
  27.     protected $mask;
  28.     protected $key;
  29.     protected $column;
  30.     protected $items;
  31.     protected $size;
  32.     
  33.     /**
  34.      * Class Constructor
  35.      * @param  $name Widget's name
  36.      */
  37.     public function __construct($name$database$model$key$value$orderColumn NULLTCriteria $criteria NULL)
  38.     {
  39.         // executes the parent class constructor
  40.         parent::__construct($name$database$model$key$value$orderColumn$criteria);
  41.         parent::setMaxSize(1);
  42.         parent::setDefaultOption(TRUE);
  43.         parent::disableMultiple();
  44.         
  45.         $this->tag->{'widget''tdbuniquesearch';
  46.     }
  47.     
  48.     /**
  49.      * Define the field's value
  50.      * @param $value Current value
  51.      */
  52.     public function setValue($value)
  53.     {
  54.         if ($value)
  55.         {
  56.             TTransaction::open($this->database);
  57.             $model $this->model;
  58.             
  59.             $pk constant("{$model}::PRIMARYKEY");
  60.             
  61.             if ($pk === $this->key// key is the primary key (default)
  62.             {
  63.                 // use find because it uses cache
  64.                 $object $model::find$value );
  65.             }
  66.             else // key is an alternative key (uses where->first)
  67.             {
  68.                 $object $model::where$this->key'='$value )->first();
  69.             }
  70.             
  71.             if ($object)
  72.             {
  73.                 $description $object->render($this->mask);
  74.                 $this->value $value// avoid use parent::setValue() because compat mode
  75.                 parent::addItems[$value => $description );
  76.             }
  77.             
  78.             TTransaction::close();
  79.         }
  80.         else
  81.         {
  82.             $this->value null;
  83.             parent::addItems([]);
  84.         }
  85.     }
  86.     
  87.     /**
  88.      * Return the post data
  89.      */
  90.     public function getPostData()
  91.     {
  92.         $name str_replace(['[',']']['','']$this->name);
  93.         
  94.         if (isset($_POST[$name]))
  95.         {
  96.             $val $_POST[$name];
  97.             
  98.             if ($val == ''// empty option
  99.             {
  100.                 return '';
  101.             }
  102.             else
  103.             {
  104.                 return $val;
  105.             }
  106.         }
  107.         else
  108.         {
  109.             return '';
  110.         }
  111.     }
  112.     
  113.     /**
  114.      * Returns the size
  115.      */
  116.     public function getSize()
  117.     {
  118.         return $this->size;
  119.     }
  120.     
  121.     /**
  122.      * Show the component
  123.      */
  124.     public function show()
  125.     {
  126.         $this->tag->{'name'}  $this->name// tag name
  127.         parent::show();
  128.     }
  129. }