Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class AcaoEtapaFotosDetalhe extends TPage {
- private $form;
- private $datagrid;
- public function __construct() {
- parent::__construct();
- $this->form = new BootstrapFormBuilder('detalhe_acaoetapafotos');
- $this->form->setFormTitle('Detalhe de Fotos de Etapa da Ação');
- $this->form->class = 'detalhe_acaoetapafotos';
- $id = new THidden('id');
- $acaoetapa_id = new THidden('acaoetapa_id');
- $acaoetapa_id->setValue(filter_input(INPUT_GET, 'fk'));
- TTransaction::open('database');
- $nomeEtapa = new AcaoEtapaRecord(filter_input(INPUT_GET, 'fk'));
- TTransaction::close();
- $nomeEtapa = new TLabel('<b>' . $nomeEtapa->nomeetapa . '</b>');
- $descricaofoto = new TText('descricaofoto');
- $nomearquivo = new TFile('nomearquivo');
- $nomearquivo->setProperty('accept', 'image/jpeg');
- $latitude = new TEntry('latitude');
- $longitude = new TEntry('longitude');
- //$nomearquivo->setMaxLength(50);
- $latitude->setMaxLength(20);
- $longitude->setMaxLength(20);
- $latitude->{'placeholder'} = '90º';
- $longitude->{'placeholder'} = '90º';
- $acaoetapa_id->addValidation('Ação Etapa' , new TRequiredValidator);
- $nomearquivo->addValidation('Foto' , new TRequiredValidator);
- $descricaofoto->addValidation('Descrição da Foto' , new TRequiredValidator);
- $action1 = new TAction(array($this, 'onSave'));
- $action1->setParameter('key', '' . filter_input(INPUT_GET, 'key') . '');
- $action1->setParameter('fk', '' . filter_input(INPUT_GET, 'fk') . '');
- $action1->setParameter('did', '' . filter_input(INPUT_GET, 'did') . '');
- $action2 = new TAction(array('AcaoEtapaDetalhe', 'onReload'));
- $action2->setParameter('key', '' . filter_input(INPUT_GET, 'key') . '');
- $action2->setParameter('fk', '' . filter_input(INPUT_GET, 'did') . '');
- $this->form->addFields([$id]);
- $this->form->addFields([$acaoetapa_id]);
- $this->form->addFields([new TLabel('Nome da Etapa <i>*</i>')], [$nomeEtapa]);
- $this->form->addFields([new TLabel('Descrição da Foto <i>*</i>')], [$descricaofoto]);
- $this->form->addFields([new TLabel('Foto')], [$nomearquivo]);
- $this->form->addFields([new TLabel('Latitude')], [$latitude]);
- $this->form->addFields([new TLabel('Longitude')], [$longitude]);
- $this->form->addFields([new TLabel('')], [TElement::tag('label', '<i>* Campos obrigatórios</i>' ) ]);
- $this->form->addAction('Salvar', $action1, 'fa:save')->class = 'btn btn-sm btn-primary';
- $this->form->addAction('Voltar', $action2, 'fa:arrow-left')->class = 'btn btn-sm btn-primary';
- $this->datagrid = new TDatagridTables;
- $dgacaoetapa_id = new TDataGridColumn('nome_acaoEtapa', 'Ação Etapa', 'left', 200);
- $dgdescricaofoto = new TDataGridColumn('descricaofoto', 'Descrição da Foto', 'left', 200);
- $dgnomearquivo = new TDataGridColumn('icone_preview', 'Foto', 'left', 200);
- $dglatitude = new TDataGridColumn('latitude', 'Latitude', 'left', 200);
- $dglongitude = new TDataGridColumn('longitude', 'Longitude', 'left', 200);
- $this->datagrid->addColumn($dgacaoetapa_id);
- $this->datagrid->addColumn($dgdescricaofoto);
- $this->datagrid->addColumn($dgnomearquivo);
- $this->datagrid->addColumn($dglatitude);
- $this->datagrid->addColumn($dglongitude);
- $actionEdit = new TDataGridAction(array($this, 'onEdit'));
- $actionEdit->setButtonClass("btn btn-default");
- $actionEdit->setLabel('Editar');
- $actionEdit->setImage("fa:pencil-square-o blue fa-lg");
- $actionEdit->setField('id');
- $actionEdit->setFk('acaoetapa_id');
- $actionEdit->setParameter('did', filter_input(INPUT_GET,'did'));
- $actionDelete = new TDataGridAction(array($this, 'onDelete'));
- $actionDelete->setButtonClass("btn btn-default");
- $actionDelete->setLabel('Deletar');
- $actionDelete->setImage("fa:trash-o red fa-lg");
- $actionDelete->setField('id');
- $actionDelete->setFk('acaoetapa_id');
- $actionDelete->setParameter('did', filter_input(INPUT_GET,'did'));
- $this->datagrid->addAction($actionEdit);
- $this->datagrid->addAction($actionDelete);
- $this->datagrid->createModel();
- $container = new TVBox;
- $container->style = "width: 100%";
- $container->add($this->form);
- $container->add(TPanelGroup::pack(NULL, $this->datagrid));
- parent::add($container);
- }
- function onReload()
- {
- TTransaction::open('database');
- $repository = new TRepository('AcaoEtapaFotosRecord');
- $criteria = new TCriteria;
- $criteria->add(new TFilter('acaoetapa_id', '=', filter_input(INPUT_GET, 'fk')));
- $objects = $repository->load($criteria, FALSE);
- $this->datagrid->clear();
- if (!empty($objects)) {
- foreach ($objects as $object) {
- $this->datagrid->addItem($object);
- }
- }
- TTransaction::close();
- $this->loaded = true;
- }
- function onDelete($param = NULL)
- {
- if (isset($param["key"])) {
- $param = [
- "key" => $param[ "key" ],
- "fk" => $param[ "fk" ],
- "did" => $param[ "did" ],
- ];
- $action_ok = new TAction([$this, "Delete"]);
- $action_cancel = new TAction([$this, "onReload"]);
- $action_ok->setParameters( $param );
- $action_cancel->setParameters( $param );
- $this->onReload( $param );
- new TQuestion("Deseja remover o registro?", $action_ok, $action_cancel);
- }
- }
- function Delete($param = NULL)
- {
- $key = $param['key'];
- try {
- TTransaction::open('database');
- $object = new AcaoEtapaFotosRecord($key);
- $object->delete();
- $this->onReload( $param );
- new TMessage("info", "Registro deletado com sucesso!");
- TTransaction::close();
- } catch (Exception $ex) {
- new TMessage('error', $ex->getMessage());
- TTransaction::rollback();
- }
- $this->onReload();
- }
- function onSave($param = NULL)
- {
- try {
- TTransaction::open('database');
- $this->form->validate();
- $object = $this->form->getData('AcaoEtapaFotosRecord');
- $source_file = 'tmp/' . $object->nomearquivo;
- $extensao = strtolower(pathinfo(strtolower($object->nomearquivo), PATHINFO_EXTENSION));
- if ($extensao == 'jpg' || $extensao == 'jpeg') {
- $object->nomearquivo = 'temp';
- $object->store();
- $caminho = 'app/images/fotos_etapas/foto_' . $object->id . '.' . $extensao;
- $object->nomearquivo = 'foto_' . $object->id . '.' . $extensao;
- rename($source_file, $caminho);
- $object->store();
- $action = new TAction( [ "AcaoEtapaFotosDetalhe", "onReload" ] );
- $action->setParameters( ["fk" => $param[ "fk" ], "did" => $param[ "did" ] ] );
- new TMessage("info", "Registro salvo com sucesso!", $action);
- } else {
- new TMessage('error', 'Apenas imagens do tipo JPG e JPEG!');
- }
- TTransaction::close();
- } catch (Exception $ex) {
- new TMessage('error', $ex->getMessage());
- TTransaction::rollback();
- }
- }
- function onEdit($param = NULL)
- {
- try {
- if (isset($param['key'])) {
- $key = $param['key'];
- TTransaction::open('database');
- $obj = new AcaoEtapaFotosRecord($key);
- $this->form->setData($obj);
- TTransaction::close();
- }
- } catch (Exception $ex) {
- new TMessage("Error", "Ocorreu um erro ao tentar carregar o registro para edição!<br><br>" . $ex->getMessage());
- TTransaction::rollback();
- }
- }
- function show()
- {
- $this->onReload();
- parent::show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement