Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Dúvida sobre TDBSeekButton Pessoal, me deparei com uma situação que não estou conseguindo uma solução: Neste TDBSeekButton coloquei o campo "description_codprod" (concatenação de codigo+description) que na verdade é um get na minha model Product , funciona perfeitamente até eu fazer uma pesquisa, aí recebo a mensagem que o campo não existe. Como posso resolver ? já tentei usar TCriteria mais não tive sucesso...
AR
Dúvida sobre TDBSeekButton  
Fechado
Pessoal, me deparei com uma situação que não estou conseguindo uma solução:
Neste TDBSeekButton coloquei o campo "description_codprod" (concatenação de codigo+description) que na verdade é um get na minha model Product , funciona perfeitamente até eu fazer uma pesquisa, aí recebo a mensagem que o campo não existe. Como posso resolver ? já tentei usar TCriteria mais não tive sucesso.
Grato.


  1. <?php    $product_id     = new  ">TDBSeekButton('product_id''catalogo'$this->form->getName(), 'Product''description_codprod''product_id''product_name',$criteria);?>

Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto Quero me inscrever agora!

Comentários (5)


NR

Acredito que você tenha que criar uma seek manual. A TDBSeekButton usa o mesmo parâmetro para exibição e busca...
AR

Grato Nataniel. Vou tentar
AR

Ficou perfeito Nataniel, muito grato.
EE

Adriano, também tenho a mesma dificuldade. Poderia postar sua solução?
Obrigado.
AR

Olá Emanoel, vamos lá:
Vou tentar explicar, sou iniciante em PHP .

No primeiro bloco é o meu form, onde instancio ProductSeek que uso para pesquisa pelo o ID e ProductSeekCodigo para pesquisa pelo codigo, esse criado em minha tabela/model (Product como index unique) e consequentemente em SaleItem .

Então, no meu form SaleForm, posso chamar o produto tanto pelo o ID quanto pelo codigo, em campos distintos. Ficou legal. Se a sua dúvida persistir, estou a disposição.

Tudo exemplificado no Tutor:
//-------------------------------------
//Sale form (Master/detail)
www.adianti.com.br/framework_files/tutor/index.php?class=SaleForm&am
//-------------------------------------
//Seek manual
www.adianti.com.br/framework_files/tutor/index.php?class=FormSeekBut



//bl 1
  1. <?php 
  2. //SaleForm
  3.         $product_id     = new TSeekButton('product_id');
  4.         $product_name   = new TEntry('product_name');
  5.         $codigo         = new TSeekButton('product_codigo');
  6.       
  7.         // define the action for city_id1
  8.         $obj = new ProductSeek;
  9.         $action = new TAction(array($obj'onReload'));
  10.         $product_id->setAction($action);
  11.        
  12.        //preciso mexer 
  13.         $obj2 = new ProductSeekCodigo;
  14.         $action2 = new TAction(array($obj2'onReload'));
  15.         $codigo->setAction($action2);
  16. //--------------------------------------
  17.         $subtable_product->addRowSet$label_product    = new TLabel('Produto (*)'), array($product_id,$product_name) );
  18.         $subtable_product->addRowSet$label_codigo    = new TLabel('Codigo (*)'), array($codigo));       
  19. ?>



//bl2
  1. <?php
  2. /**
  3.  * Product Seek
  4.  *
  5.  * @version    1.0
  6.  * @package    samples
  7.  * @subpackage tutor
  8.  * @author     Pablo Dall'Oglio
  9.  * @copyright  Copyright (c) 2006-2014 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10.  * @license    http://www.adianti.com.br/framework-license
  11.  */
  12. class ProductSeekCodigo extends TWindow
  13. {
  14.     private $form;      // form
  15.     private $datagrid;  // datagrid
  16.     private $pageNavigation;
  17.     private $loaded;
  18.     
  19.     /**
  20.      * Class constructor
  21.      * Creates the page, the search form and the listing
  22.      */
  23.     public function __construct()
  24.     {
  25.         parent::__construct();
  26.         parent::setSize(700500);
  27.         parent::setTitle('Search record');
  28.         new TSession;
  29.         
  30.         // creates the form
  31.         $this->form = new TQuickForm('form_search_product');
  32.         $this->form->class 'tform';
  33.         $this->form->setFormTitle('Produtos');
  34.         
  35.         // create the form fields
  36.         $codigo   = new TEntry('codigo');
  37.         $codigo->setValue(TSession::getValue('product_codigo'));
  38.         $description = new TEntry('description');
  39.         $description->setValue(TSession::getValue('product_name'));
  40.        
  41.         
  42.         // add the form fields
  43.         $this->form->addQuickField('Código'$codigo,  60);
  44.         $this->form->addQuickField('Descrição'$description,  200);
  45.         // define the form action
  46.         $this->form->addQuickAction('Find', new TAction(array($this'onSearch')), 'ico_find.png');
  47.         
  48.         // creates a DataGrid
  49.         $this->datagrid = new TQuickGrid;
  50.         $this->datagrid->style 'width: 100%';
  51.         $this->datagrid->setHeight(230);
  52.         $this->datagrid->enablePopover('Title''Descrição {description}');
  53.         
  54.         // creates the datagrid columns
  55.         $this->datagrid->addQuickColumn('Id''id''right'40);
  56.         $this->datagrid->addQuickColumn('Código''codigo''right'40);
  57.         $this->datagrid->addQuickColumn('Descrição''description''left'340);
  58.         // creates two datagrid actions
  59.         $this->datagrid->addQuickAction('Select', new TDataGridAction(array($this'onSelect')), 'codigo''ico_apply.png');
  60.         
  61.         // create the datagrid model
  62.         $this->datagrid->createModel();
  63.         
  64.         // creates the page navigation
  65.         $this->pageNavigation = new TPageNavigation;
  66.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  67.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  68.         
  69.         // creates a container
  70.         $container = new TVBox;
  71.         $container->style 'width: 100%';
  72.         $container->add($this->form);
  73.         $container->add($this->datagrid);
  74.         $container->add($this->pageNavigation);
  75.         
  76.         // add the container inside the page
  77.         parent::add($container);
  78.     }
  79.     
  80.     /**
  81.      * method onSearch()
  82.      * Register the filter in the session when the user performs a search
  83.      */
  84.     function onSearch()
  85.     {
  86.         // get the search form data
  87.         $data $this->form->getData();
  88.         
  89.         
  90.     //    TSession::setValue('product_name',  NULL);
  91.      //   TSession::setValue('product_codigo',  NULL);
  92.           TSession::setValue('product_filter',  NULL);
  93.         
  94.         // check if the user has filled the form
  95.         if (isset($data->description) and ($data->description))
  96.         {
  97.             // creates a filter using what the user has typed
  98.             $filter = new TFilter('description''like'"%{$data->description}%");
  99.             
  100.             // stores the filter in the session
  101.             TSession::setValue('product_filter'$filter);
  102.             TSession::setValue('product_name',   $data->description);
  103.             
  104.             // fill the form with data again
  105.             $this->form->setData($data);
  106.         }
  107.         
  108.       //  if (isset($data->codigo) and $data->codigo)
  109.       if ($data->codigo)
  110.         {
  111.             // creates a filter using what the user has typed
  112.             $filter = new TFilter('codigo''='"{$data->codigo}");
  113.             
  114.             // stores the filter in the session
  115.             TSession::setValue('product_filter'$filter);
  116.             TSession::setValue('product_codigo'$data->codigo);
  117.             
  118.             // fill the form with data again
  119.             $this->form->setData($data);
  120.         }
  121.         
  122.         
  123.         // redefine the parameters for reload method
  124.         $param=array();
  125.         $param['offset']    =0;
  126.         $param['first_page']=1;
  127.         $this->onReload($param);
  128.     }
  129.     
  130.     /**
  131.      * Load the datagrid with the database objects
  132.      */
  133.     function onReload($param NULL)
  134.     {
  135.         try
  136.         {
  137.             // open a transaction with database 'samples'
  138.             TTransaction::open('catalogo');
  139.             
  140.             // creates a repository for Product
  141.             $repository = new TRepository('Product');
  142.             $limit 10;
  143.             // creates a criteria
  144.             $criteria = new TCriteria;
  145.             
  146.             // default order
  147.             if (!isset($param['order']))
  148.             {
  149.                 $param['order'] = 'id';
  150.                 $param['direction'] = 'asc';
  151.             }
  152.             
  153.             $criteria->setProperties($param); // order, offset
  154.             $criteria->setProperty('limit'$limit);
  155.             
  156.             if (TSession::getValue('product_filter'))
  157.             {
  158.                 // add the filter stored in the session to the criteria
  159.                 $criteria->add(TSession::getValue('product_filter'));
  160.             }
  161.             
  162.           //  TTransaction::setLogger(new TLoggerSTD); // standard output
  163.           //  TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  164.             // load the objects according to the criteria
  165.             $products $repository->load($criteria);
  166.             
  167.             
  168.             
  169.             $this->datagrid->clear();
  170.             if ($products)
  171.             {
  172.                 foreach ($products as $product)
  173.                 {
  174.                     // add the object inside the datagrid
  175.                     $this->datagrid->addItem($product);
  176.                 }
  177.             }
  178.             
  179.             // reset the criteria for record count
  180.             $criteria->resetProperties();
  181.             $count$repository->count($criteria);
  182.             
  183.             $this->pageNavigation->setCount($count); // count of records
  184.             $this->pageNavigation->setProperties($param); // order, page
  185.             $this->pageNavigation->setLimit($limit); // limit
  186.             
  187.             // close the transaction
  188.             TTransaction::close();
  189.             $this->loaded true;
  190.         }
  191.         catch (Exception $e// in case of exception
  192.         {
  193.             // shows the exception error message
  194.             new TMessage('error'$e->getMessage());
  195.             // undo all pending operations
  196.             TTransaction::rollback();
  197.         }
  198.     }
  199.     
  200.     /**
  201.      * Executed when the user chooses the record
  202.      */
  203.     public function onSelect($param)
  204.     {
  205.         try
  206.         {
  207.             $key $param['key'];
  208.             TTransaction::open('catalogo');
  209.             
  210.             // load the active record
  211.             
  212.             // creates a repository for Product
  213.             $repository = new TRepository('Product');
  214.             $limit 10;
  215.             // creates a criteria
  216.             $criteria = new TCriteria;
  217.             $criteria->setProperties($param); // order, offset
  218.             $criteria->setProperty('limit'$limit);
  219.             
  220.   
  221.              $filter = new TFilter('codigo''='$key);
  222.              TSession::setValue('product_filter'$filter); 
  223.                 // add the filter stored in the session to the criteria
  224.                 $criteria->add(TSession::getValue('product_filter'));
  225.            
  226.             
  227.           //  TTransaction::setLogger(new TLoggerSTD); // standard output
  228.           //  TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  229.             // load the objects according to the criteria
  230.             $products $repository->load($criteria);
  231.             //$product = new Product($key);
  232.             foreach ($products as $product)
  233.              {
  234.                  $product = new Product($product->id);
  235.               }   
  236.             
  237.             // closes the transaction
  238.             TTransaction::close();
  239.             
  240.             $object = new StdClass;
  241.             $object->product_id   $product->id;
  242.             $object->product_name $product->description;
  243.             $object->product_codigo $product->codigo;
  244.             $object->product_price $product->sale_price;
  245.             
  246.             TForm::sendData('form_Sale'$object);
  247.             parent::closeWindow(); // closes the window
  248.         }
  249.         catch (Exception $e// em caso de exceção
  250.         {
  251.             // clear fields
  252.             $object = new StdClass;
  253.             $object->product_id   '';
  254.             $object->product_name '';
  255.             $object->product_codigo  '';
  256.             $object->product_price ='';
  257.             
  258.             TForm::sendData('form_Sale'$object);
  259.             
  260.             // undo pending operations
  261.             TTransaction::rollback();
  262.         }
  263.     }
  264.     
  265.     /**
  266.      * Shows the page
  267.      */
  268.     function show()
  269.     {
  270.         // if the datagrid was not loaded yet
  271.         if (!$this->loaded)
  272.         {
  273.             $this->onReload();
  274.         }
  275.         parent::show();
  276.     }
  277. }
  278. ?>




//bl3

  1. <?php
  2. /**
  3.  * Product Seek
  4.  *
  5.  * @version    1.0
  6.  * @package    samples
  7.  * @subpackage tutor
  8.  * @author     Pablo Dall'Oglio
  9.  * @copyright  Copyright (c) 2006-2014 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10.  * @license    http://www.adianti.com.br/framework-license
  11.  */
  12. class ProductSeek extends TWindow
  13. {
  14.     private $form;      // form
  15.     private $datagrid;  // datagrid
  16.     private $pageNavigation;
  17.     private $loaded;
  18.     
  19.     /**
  20.      * Class constructor
  21.      * Creates the page, the search form and the listing
  22.      */
  23.     public function __construct()
  24.     {
  25.         parent::__construct();
  26.         parent::setSize(700500);
  27.         parent::setTitle('Search record');
  28.         new TSession;
  29.         
  30.         // creates the form
  31.         $this->form = new TQuickForm('form_search_product');
  32.         $this->form->class 'tform';
  33.         $this->form->setFormTitle('Produtos');
  34.         
  35.         // create the form fields
  36.         $codigo   = new TEntry('codigo');
  37.         $codigo->setValue(TSession::getValue('product_codigo'));
  38.         $description = new TEntry('description');
  39.         $description->setValue(TSession::getValue('product_name'));
  40.        
  41.         
  42.         // add the form fields
  43.         $this->form->addQuickField('Código'$codigo,  60);
  44.         $this->form->addQuickField('Descrição'$description,  200);
  45.         // define the form action
  46.         $this->form->addQuickAction('Find', new TAction(array($this'onSearch')), 'ico_find.png');
  47.         
  48.         // creates a DataGrid
  49.         $this->datagrid = new TQuickGrid;
  50.         $this->datagrid->style 'width: 100%';
  51.         $this->datagrid->setHeight(230);
  52.         $this->datagrid->enablePopover('Title''Descrição {description}');
  53.         
  54.         // creates the datagrid columns
  55.         $this->datagrid->addQuickColumn('Id''id''right'40);
  56.         $this->datagrid->addQuickColumn('Código''codigo''right'40);
  57.         $this->datagrid->addQuickColumn('Descrição''description''left'340);
  58.         // creates two datagrid actions
  59.         $this->datagrid->addQuickAction('Select', new TDataGridAction(array($this'onSelect')), 'id''ico_apply.png');
  60.         
  61.         // create the datagrid model
  62.         $this->datagrid->createModel();
  63.         
  64.         // creates the page navigation
  65.         $this->pageNavigation = new TPageNavigation;
  66.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  67.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  68.         
  69.         // creates a container
  70.         $container = new TVBox;
  71.         $container->style 'width: 100%';
  72.         $container->add($this->form);
  73.         $container->add($this->datagrid);
  74.         $container->add($this->pageNavigation);
  75.         
  76.         // add the container inside the page
  77.         parent::add($container);
  78.     }
  79.     
  80.     /**
  81.      * method onSearch()
  82.      * Register the filter in the session when the user performs a search
  83.      */
  84.     function onSearch()
  85.     {
  86.         // get the search form data
  87.         $data $this->form->getData();
  88.         
  89.         
  90.     //    TSession::setValue('product_name',  NULL);
  91.      //   TSession::setValue('product_codigo',  NULL);
  92.           TSession::setValue('product_filter',  NULL);
  93.         
  94.         // check if the user has filled the form
  95.         if (isset($data->description) and ($data->description))
  96.         {
  97.             // creates a filter using what the user has typed
  98.             $filter = new TFilter('description''like'"%{$data->description}%");
  99.             
  100.             // stores the filter in the session
  101.             TSession::setValue('product_filter'$filter);
  102.             TSession::setValue('product_name',   $data->description);
  103.             
  104.             // fill the form with data again
  105.             $this->form->setData($data);
  106.         }
  107.         
  108.       //  if (isset($data->codigo) and $data->codigo)
  109.       if ($data->codigo)
  110.         {
  111.             // creates a filter using what the user has typed
  112.             $filter = new TFilter('codigo''='"{$data->codigo}");
  113.             
  114.             // stores the filter in the session
  115.             TSession::setValue('product_filter'$filter);
  116.             TSession::setValue('product_codigo'$data->codigo);
  117.             
  118.             // fill the form with data again
  119.             $this->form->setData($data);
  120.         }
  121.         
  122.         
  123.         // redefine the parameters for reload method
  124.         $param=array();
  125.         $param['offset']    =0;
  126.         $param['first_page']=1;
  127.         $this->onReload($param);
  128.     }
  129.     
  130.     /**
  131.      * Load the datagrid with the database objects
  132.      */
  133.     function onReload($param NULL)
  134.     {
  135.         try
  136.         {
  137.             // open a transaction with database 'samples'
  138.             TTransaction::open('catalogo');
  139.             
  140.             // creates a repository for Product
  141.             $repository = new TRepository('Product');
  142.             $limit 10;
  143.             // creates a criteria
  144.             $criteria = new TCriteria;
  145.             
  146.             // default order
  147.             if (!isset($param['order']))
  148.             {
  149.                 $param['order'] = 'id';
  150.                 $param['direction'] = 'asc';
  151.             }
  152.             
  153.             $criteria->setProperties($param); // order, offset
  154.             $criteria->setProperty('limit'$limit);
  155.             
  156.             if (TSession::getValue('product_filter'))
  157.             {
  158.                 // add the filter stored in the session to the criteria
  159.                 $criteria->add(TSession::getValue('product_filter'));
  160.             }
  161.             
  162.             TTransaction::setLogger(new TLoggerSTD); // standard output
  163.             TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  164.             // load the objects according to the criteria
  165.             $products $repository->load($criteria);
  166.             
  167.             
  168.             
  169.             $this->datagrid->clear();
  170.             if ($products)
  171.             {
  172.                 foreach ($products as $product)
  173.                 {
  174.                     // add the object inside the datagrid
  175.                     $this->datagrid->addItem($product);
  176.                 }
  177.             }
  178.             
  179.             // reset the criteria for record count
  180.             $criteria->resetProperties();
  181.             $count$repository->count($criteria);
  182.             
  183.             $this->pageNavigation->setCount($count); // count of records
  184.             $this->pageNavigation->setProperties($param); // order, page
  185.             $this->pageNavigation->setLimit($limit); // limit
  186.             
  187.             // close the transaction
  188.             TTransaction::close();
  189.             $this->loaded true;
  190.         }
  191.         catch (Exception $e// in case of exception
  192.         {
  193.             // shows the exception error message
  194.             new TMessage('error'$e->getMessage());
  195.             // undo all pending operations
  196.             TTransaction::rollback();
  197.         }
  198.     }
  199.     
  200.     /**
  201.      * Executed when the user chooses the record
  202.      */
  203.     public function onSelect($param)
  204.     {
  205.         try
  206.         {
  207.             $key $param['key'];
  208.             TTransaction::open('catalogo');
  209.             
  210.             // load the active record
  211.             $product = new Product($key);
  212.             
  213.             // closes the transaction
  214.             TTransaction::close();
  215.             
  216.             $object = new StdClass;
  217.             $object->product_id   $product->id;
  218.             $object->product_name $product->description;
  219.             $object->product_codigo $product->codigo;
  220.             $object->product_price $product->sale_price;
  221.             
  222.             TForm::sendData('form_Sale'$object);
  223.             parent::closeWindow(); // closes the window
  224.         }
  225.         catch (Exception $e// em caso de exceção
  226.         {
  227.             // clear fields
  228.             $object = new StdClass;
  229.             $object->product_id   '';
  230.             $object->product_name '';
  231.             $object->product_codigo  '';
  232.             $object->product_price ='';
  233.             
  234.             TForm::sendData('form_Sale'$object);
  235.             
  236.             // undo pending operations
  237.             TTransaction::rollback();
  238.         }
  239.     }
  240.     
  241.     /**
  242.      * Shows the page
  243.      */
  244.     function show()
  245.     {
  246.         // if the datagrid was not loaded yet
  247.         if (!$this->loaded)
  248.         {
  249.             $this->onReload();
  250.         }
  251.         parent::show();
  252.     }
  253. }
  254. ?>