Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Aplicar cor no TCardView Estou tentando aplicar uma cor no card gerado pelo Adianti Builder, mas não está aplicando. Estou usando o $this->cardView->setColorAttribute("#5950F1"); O que pode estar dando errado? ...
CA
Aplicar cor no TCardView  
Estou tentando aplicar uma cor no card gerado pelo Adianti Builder, mas não está aplicando.

Estou usando o $this->cardView->setColorAttribute("#5950F1");

O que pode estar dando errado?


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 (3)


CA

  1. <?php
  2. class MidiasCardList extends TPage
  3. {
  4.     private $form// form
  5.     private $cardView// listing
  6.     private $pageNavigation;
  7.     private $loaded;
  8.     private $filter_criteria;
  9.     private static $database 'portal_educacao';
  10.     private static $activeRecord 'Midias';
  11.     private static $primaryKey 'id';
  12.     private static $formName 'formCardList_Midias';
  13.     private $showMethods = ['onReload''onSearch'];
  14.     /**
  15.      * Class constructor
  16.      * Creates the page, the form and the listing
  17.      */
  18.     public function __construct()
  19.     {
  20.         parent::__construct();
  21.         // creates the form
  22.         $this->form = new BootstrapFormBuilder(self::$formName);
  23.         // define the form title
  24.         $this->form->setFormTitle("Busca de Conteúdos Multimídia");
  25.         $titulo = new TEntry('titulo');
  26.         $descricao = new TEntry('descricao');
  27.         $data_pulicacao = new TDate('data_pulicacao');
  28.         $tipo_id = new TDBCombo('tipo_id''portal_educacao''Tipo''id''{descricao}','id asc'  );
  29.         $categoria_id = new TDBCombo('categoria_id''portal_educacao''Categoria''id''{descricao}','id asc'  );
  30.         $data_pulicacao->setMask('dd/mm/yyyy');
  31.         $titulo->setMaxLength(200);
  32.         $data_pulicacao->setDatabaseMask('yyyy-mm-dd');
  33.         $titulo->setSize('100%');
  34.         $tipo_id->setSize('100%');
  35.         $descricao->setSize('100%');
  36.         $data_pulicacao->setSize(110);
  37.         $categoria_id->setSize('100%');
  38.         $row1 $this->form->addFields([new TLabel("Título:"null'14px'null)],[$titulo]);
  39.         $row2 $this->form->addFields([new TLabel("Descrição:"null'14px'null)],[$descricao]);
  40.         $row3 $this->form->addFields([new TLabel("Data pulicação:"null'14px'null)],[$data_pulicacao]);
  41.         $row4 $this->form->addFields([new TLabel("Tipo:"null'14px'null)],[$tipo_id]);
  42.         $row5 $this->form->addFields([new TLabel("Categoria:"null'14px'null)],[$categoria_id]);
  43.         // keep the form filled during navigation with session data
  44.         $this->form->setDataTSession::getValue(__CLASS__.'_filter_data') );
  45.         $btn_onsearch $this->form->addAction("Buscar", new TAction([$this'onSearch']), 'fas:search #ffffff');
  46.         $this->btn_onsearch $btn_onsearch;
  47.         $btn_onsearch->addStyleClass('btn-primary');
  48.         $this->cardView = new TCardView;
  49.         $this->cardView->setColorAttribute('#f15050');
  50.        $this->cardView->setContentHeight(250);
  51.        $this->cardView->setTitleTemplate("<div style=\"height:50px\"><p style=\"max-width: 300px; overflow: hidden;
  52.         display: -webkit-box;  -webkit-line-clamp: 2;  -webkit-box-orient: vertical;\">{titulo}</p></div>");
  53.        $this->cardView->setItemTemplate("<div style=\"width:100%; display: flex;  align-items: center;  justify-content: center\">
  54.           <img style=\"height:200px;width:250px \" src=\"https://drive.google.com/thumbnail?id={link_imagem} \">
  55.           </div>
  56.           <br><br>
  57.           <p style=\"text-align: justify; max-width: 300px; overflow: hidden;
  58.             display: -webkit-box;  -webkit-line-clamp: 7;  -webkit-box-orient: vertical;\"> {descricao} </p>");
  59.         $this->cardView->setItemDatabase(self::$database);
  60.         $this->filter_criteria = new TCriteria;
  61.         $action_MidiasForm_onDocumento = new TAction(['MidiasCardList''onDocumento'], ['key'=> '{id}']);
  62.         $this->cardView->addAction($action_MidiasForm_onDocumento"Documentos"'far:file #478fca');
  63.        $action_MidiasCardList_onVideo = new TAction(['MidiasCardList''onVideo'], ['key'=> '{id}']);
  64.        $this->cardView->addAction($action_MidiasCardList_onVideo"Vídeo"'fa:video #dd5a43');
  65.        $action_MidiasCardList_onAudio = new TAction(['MidiasCardList''onAudio'], ['key'=> '{id}']);
  66.        $this->cardView->addAction($action_MidiasCardList_onAudio"Podcast"'fa:podcast #dd5a43');
  67.         // creates the page navigation
  68.         $this->pageNavigation = new TPageNavigation;
  69.         $this->pageNavigation->enableCounters();
  70.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  71.         $panel = new TPanelGroup;
  72.         $panel->add($this->cardView);
  73.         $panel->addFooter($this->pageNavigation);
  74.         // vertical box container
  75.         $container = new TVBox;
  76.         $container->style 'width: 100%';
  77.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  78.         $container->add($this->form);
  79.         $container->add($panel);
  80.         parent::add($container);
  81.     }
  82.     public function onDelete($param null)
  83.     {
  84.         if(isset($param['delete']) && $param['delete'] == 1)
  85.         {
  86.             try
  87.             {
  88.                 // get the paramseter $key
  89.                 $key $param['key'];
  90.                 // open a transaction with database
  91.                 TTransaction::open(self::$database);
  92.                 // instantiates object
  93.                 $object = new Midias($keyFALSE);
  94.                 // deletes the object from the database
  95.                 $object->delete();
  96.                 // close the transaction
  97.                 TTransaction::close();
  98.                 // reload the listing
  99.                 $this->onReload$param );
  100.                 // shows the success message
  101.                 new TMessage('info'AdiantiCoreTranslator::translate('Record deleted'));
  102.             }
  103.             catch (Exception $e// in case of exception
  104.             {
  105.                 // shows the exception error message
  106.                 new TMessage('error'$e->getMessage());
  107.                 // undo all pending operations
  108.                 TTransaction::rollback();
  109.             }
  110.         }
  111.         else
  112.         {
  113.             // define the delete action
  114.             $action = new TAction(array($this'onDelete'));
  115.             $action->setParameters($param); // pass the key paramseter ahead
  116.             $action->setParameter('delete'1);
  117.             // shows a dialog to the user
  118.             new TQuestion(AdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  119.         }
  120.     }
  121.     /**
  122.      * Register the filter in the session
  123.      */
  124.     public function onSearch()
  125.     {
  126.         // get the search form data
  127.         $data $this->form->getData();
  128.         $filters = [];
  129.         TSession::setValue(__CLASS__.'_filter_data'NULL);
  130.         TSession::setValue(__CLASS__.'_filters'NULL);
  131.         if (isset($data->titulo) AND ( (is_scalar($data->titulo) AND $data->titulo !== '') OR (is_array($data->titulo) AND (!empty($data->titulo)) )) )
  132.         {
  133.             $filters[] = new TFilter('titulo''like'"%{$data->titulo}%");// create the filter
  134.         }
  135.         if (isset($data->descricao) AND ( (is_scalar($data->descricao) AND $data->descricao !== '') OR (is_array($data->descricao) AND (!empty($data->descricao)) )) )
  136.         {
  137.             $filters[] = new TFilter('descricao''like'"%{$data->descricao}%");// create the filter
  138.         }
  139.         if (isset($data->data_pulicacao) AND ( (is_scalar($data->data_pulicacao) AND $data->data_pulicacao !== '') OR (is_array($data->data_pulicacao) AND (!empty($data->data_pulicacao)) )) )
  140.         {
  141.             $filters[] = new TFilter('data_pulicacao''='$data->data_pulicacao);// create the filter
  142.         }
  143.         if (isset($data->tipo_id) AND ( (is_scalar($data->tipo_id) AND $data->tipo_id !== '') OR (is_array($data->tipo_id) AND (!empty($data->tipo_id)) )) )
  144.         {
  145.             $filters[] = new TFilter('tipo_id''='$data->tipo_id);// create the filter
  146.         }
  147.         if (isset($data->categoria_id) AND ( (is_scalar($data->categoria_id) AND $data->categoria_id !== '') OR (is_array($data->categoria_id) AND (!empty($data->categoria_id)) )) )
  148.         {
  149.             $filters[] = new TFilter('categoria_id''='$data->categoria_id);// create the filter
  150.         }
  151.         $param = array();
  152.         $param['offset']     = 0;
  153.         $param['first_page'] = 1;
  154.         // fill the form with data again
  155.         $this->form->setData($data);
  156.         // keep the search data in the session
  157.         TSession::setValue(__CLASS__.'_filter_data'$data);
  158.         TSession::setValue(__CLASS__.'_filters'$filters);
  159.         $this->onReload($param);
  160.     }
  161.     public function onReload($param NULL)
  162.     {
  163.         try
  164.         {
  165.             // open a transaction with database 'portal_educacao'
  166.             TTransaction::open(self::$database);
  167.             // creates a repository for Midias
  168.             $repository = new TRepository(self::$activeRecord);
  169.             $limit 20;
  170.             $criteria = clone $this->filter_criteria;
  171.             if (empty($param['order']))
  172.             {
  173.                 $param['order'] = 'id';
  174.             }
  175.             if (empty($param['direction']))
  176.             {
  177.                 $param['direction'] = 'desc';
  178.             }
  179.             $criteria->setProperties($param); // order, offset
  180.             $criteria->setProperty('limit'$limit);
  181.             if($filters TSession::getValue(__CLASS__.'_filters'))
  182.             {
  183.                 foreach ($filters as $filter)
  184.                 {
  185.                     $criteria->add($filter);
  186.                 }
  187.             }
  188.             // load the objects according to criteria
  189.             $objects $repository->load($criteriaFALSE);
  190.             $this->cardView->clear();
  191.             if ($objects)
  192.             {
  193.                 // iterate the collection of active records
  194.                 foreach ($objects as $object)
  195.                 {
  196.                     $this->cardView->addItem($object);
  197.                 }
  198.             }
  199.             // reset the criteria for record count
  200.             $criteria->resetProperties();
  201.             $count$repository->count($criteria);
  202.             $this->pageNavigation->setCount($count); // count of records
  203.             $this->pageNavigation->setProperties($param); // order, page
  204.             $this->pageNavigation->setLimit($limit); // limit
  205.             // close the transaction
  206.             TTransaction::close();
  207.             $this->loaded true;
  208.         }
  209.         catch (Exception $e// in case of exception
  210.         {
  211.             // shows the exception error message
  212.             new TMessage('error'$e->getMessage());
  213.             // undo all pending operations
  214.             TTransaction::rollback();
  215.         }
  216.     }
  217.     public function onVideo($param null)
  218.     {
  219.     TTransaction::open('portal_educacao');
  220.     $id=$param['key'];
  221.     $objeto Midias::find$id );
  222.     $link=$objeto->link_video;
  223.         TScript::create("window.open('{$link}')");
  224.      TTransaction::close();
  225.     }
  226.     public function onAudio($param null)
  227.     {
  228.     TTransaction::open('portal_educacao');
  229.     $id=$param['key'];
  230.     $objeto Midias::find$id );
  231.     $link=$objeto->link_podcast;
  232.         TScript::create("window.open('{$link}')");
  233.      TTransaction::close();
  234.     }
  235.     public function onDocumento($param null)
  236.     {
  237.     TTransaction::open('portal_educacao');
  238.     $id=$param['key'];
  239.     $objeto Midias::find$id );
  240.     $link=$objeto->link_material;
  241.         TScript::create("window.open('{$link}')");
  242.      TTransaction::close();
  243.     }
  244.     public function onShow($param null)
  245.     {
  246.     }
  247.     /**
  248.      * method show()
  249.      * Shows the page
  250.      */
  251.     public function show()
  252.     {
  253.         if (!$this->loaded AND (!isset($_GET['method']) OR !(in_array($_GET['method'],  $this->showMethods))) )
  254.         {
  255.             if (func_num_args() > 0)
  256.             {
  257.                 $this->onReloadfunc_get_arg(0) );
  258.             }
  259.             else
  260.             {
  261.                 $this->onReload();
  262.             }
  263.         }
  264.         parent::show();
  265.     }
  266. }
  267. ?>
NR

A função setColorAttribute serve para identificar o atributo de cada objeto que contém a cor desejada, permitindo assim que cada item tenha uma cor diferente da outra. Como aparentemente você não tem esse atributo, pode fazer o seguinte:
  1. <?php
  2. $this->cardView->setColorAttribute('cor');
  3. // function onReload
  4. ...
  5. foreach ($objects as $object)
  6. {
  7.     $object->cor '#f15050';
  8.     $this->cardView->addItem($object);
  9. }
  10. ?>

Exemplo no tutor:
https://adianti.com.br/framework_files/tutor/index.php?class=CardView
CA

Nataniel,

deu certo! Muito obrigado.