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    5.6
  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.     
  32.     /**
  33.      * Class Constructor
  34.      * @param  $name Widget's name
  35.      */
  36.     public function __construct($name$database$model$key$value$orderColumn NULLTCriteria $criteria NULL)
  37.     {
  38.         // executes the parent class constructor
  39.         parent::__construct($name$database$model$key$value$orderColumn$criteria);
  40.         parent::setMaxSize(1);
  41.         parent::setDefaultOption(TRUE);
  42.         parent::disableMultiple();
  43.         
  44.         $this->tag->{'widget''tdbuniquesearch';
  45.     }
  46.     
  47.     /**
  48.      * Define the field's value
  49.      * @param $value Current value
  50.      */
  51.     public function setValue($value)
  52.     {
  53.         if ($value)
  54.         {
  55.             TTransaction::open($this->database);
  56.             $model $this->model;
  57.             
  58.             $pk constant("{$model}::PRIMARYKEY");
  59.             
  60.             if ($pk === $this->key// key is the primary key (default)
  61.             {
  62.                 // use find because it uses cache
  63.                 $object $model::find$value );
  64.             }
  65.             else // key is an alternative key (uses where->first)
  66.             {
  67.                 $object $model::where$this->key'='$value )->first();
  68.             }
  69.             
  70.             if ($object)
  71.             {
  72.                 $description $object->render($this->mask);
  73.                 $this->value $value// avoid use parent::setValue() because compat mode
  74.                 parent::addItems[$value => $description );
  75.             }
  76.             
  77.             TTransaction::close();
  78.         }
  79.         else
  80.         {
  81.             $this->value null;
  82.             parent::addItems([]);
  83.         }
  84.     }
  85.     
  86.     /**
  87.      * Return the post data
  88.      */
  89.     public function getPostData()
  90.     {
  91.         $name str_replace(['[',']']['','']$this->name);
  92.         
  93.         if (isset($_POST[$name]))
  94.         {
  95.             $val $_POST[$name];
  96.             
  97.             if ($val == ''// empty option
  98.             {
  99.                 return '';
  100.             }
  101.             else
  102.             {
  103.                 return $val;
  104.             }
  105.         }
  106.         else
  107.         {
  108.             return '';
  109.         }
  110.     }
  111.     
  112.     /**
  113.      * Show the component
  114.      */
  115.     public function show()
  116.     {
  117.         $this->tag->{'name'}  $this->name// tag name
  118.         parent::show();
  119.     }
  120. }