/** * Class Constructor * @param $name Name of the widget */ public function __construct($name) { parent::__construct($name); $this->widget = new GtkFileChooserButton(AdiantiCoreTranslator::translate('Open'), GTK::FILE_CHOOSER_ACTION_OPEN); parent::add($this->widget); $this->setSize(200); }
public function onSave() { try { // open a transaction with database TTransaction::open($this->database); // get the form data $object = $this->form->getData($this->activeRecord); // validate data $this->form->validate(); // stores the object $object->store(); // fill the form with the active record data $this->form->setData($object); // close the transaction TTransaction::close(); // shows the success message //new TMessage('info', AdiantiCoreTranslator::translate('Record saved')); parent::add(new TAlert('info', AdiantiCoreTranslator::translate('Record saved'))); // reload the listing $this->onReload(); return $object; } catch (Exception $e) { // get the form data $object = $this->form->getData($this->activeRecord); // fill the form with the active record data $this->form->setData($object); // shows the exception error message new TMessage('error', $e->getMessage()); // undo all pending operations TTransaction::rollback(); } }
/** * Class Constructor * @param $name widget's name * @param $database database name * @param $model model class name * @param $key table field to be used as key in the combo * @param $value table field to be listed in the combo * @param $ordercolumn column to order the fields (optional) * @param $criteria criteria (TCriteria object) to filter the model (optional) */ public function __construct($name, $database, $model, $key, $value, $ordercolumn = NULL, TCriteria $criteria = NULL) { // executes the parent class constructor parent::__construct($name); if (empty($database)) { throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'database', __CLASS__)); } if (empty($model)) { throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'model', __CLASS__)); } if (empty($key)) { throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'key', __CLASS__)); } if (empty($value)) { throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'value', __CLASS__)); } // carrega objetos do banco de dados TTransaction::open($database); // instancia um repositório de Estado $repository = new TRepository($model); if (is_null($criteria)) { $criteria = new TCriteria(); } $criteria->setProperty('order', isset($ordercolumn) ? $ordercolumn : $key); // carrega todos objetos $collection = $repository->load($criteria, FALSE); // adiciona objetos na combo if ($collection) { $items = array(); foreach ($collection as $object) { if (is_array($value)) { foreach ($value as $k => $v) { if ($k == 0) { $items[$object->{$key}] = str_pad($object->{$v}, 3, 0, STR_PAD_LEFT); } else { $items[$object->{$key}] .= ' - ' . $object->{$v}; } } } else { $items[$object->{$key}] = $object->{$value}; } } parent::addItems($items); } TTransaction::close(); }
/** * Assign a Logger strategy * @param $logger A TLogger child object */ public static function setLogger(LoggerInterface $logger) { if (isset(self::$conn[self::$counter])) { self::$logger[self::$counter] = $logger; } else { // if there's no active transaction opened throw new Exception(AdiantiCoreTranslator::translate('No active transactions') . ': ' . __METHOD__); } }
/** * Validate a given value * @param $label Identifies the value to be validated in case of exception * @param $value Value to be validated in case of 00:00 */ public function validate($label, $value, $parameters = NULL) { if (!trim($value) or trim($value) == '00:00:00') { throw new Exception(AdiantiCoreTranslator::translate('The field ^1 is required', $label)); } }
/** * method deleteCollection() * Delete many records */ public function deleteCollection($param) { // decode json with record id's $selected = json_decode($param['selected']); try { TTransaction::open('sample'); if ($selected) { // delete each record from collection foreach ($selected as $id) { $object = new telefone(); $object->delete($id); } $posAction = new TAction(array($this, 'onReload')); $posAction->setParameters($param); new TMessage('info', AdiantiCoreTranslator::translate('Records deleted'), $posAction); } TTransaction::close(); } catch (Exception $e) { new TMessage('error', $e->getMessage()); TTransaction::rollback(); } }
/** * Page constructor */ public function __construct() { parent::__construct(); parent::setDatabase('sample'); // defines the database parent::setActiveRecord('Cliente'); // defines the active record parent::setDefaultOrder('id', 'asc'); // defines the default order // parent::setCriteria($criteria) // define a standard filter parent::addFilterField('nome', 'like', 'nome'); // filterField, operator, formField // creates the form $this->form = new TQuickForm('form_search_Cliente'); $this->form->class = 'tform'; // change CSS class $this->form = new BootstrapFormWrapper($this->form); $this->form->style = 'display: table;width:100%'; // change style $this->form->setFormTitle('Cliente'); // create the form fields $nome = new TEntry('nome'); // add the fields $this->form->addQuickField('Nome', $nome, 200); // keep the form filled during navigation with session data $this->form->setData(TSession::getValue('Cliente_filter_data')); // add the search form actions $this->form->addQuickAction(_t('Find'), new TAction(array($this, 'onSearch')), 'fa:search'); $this->form->addQuickAction(_t('New'), new TAction(array('ClienteForm', 'onEdit')), 'bs:plus-sign green'); // creates a DataGrid $this->datagrid = new TDataGrid(); $this->datagrid = new BootstrapDatagridWrapper($this->datagrid); $this->datagrid->style = 'width: 100%'; $this->datagrid->setHeight(320); // $this->datagrid->datatable = 'true'; // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>'); // creates the datagrid columns $column_check = new TDataGridColumn('check', '', 'center'); $column_id = new TDataGridColumn('id', 'Id', 'right'); $column_nome = new TDataGridColumn('nome', 'Nome', 'left'); // add the columns to the DataGrid $this->datagrid->addColumn($column_check); $this->datagrid->addColumn($column_id); $this->datagrid->addColumn($column_nome); // create EDIT action $action_edit = new TDataGridAction(array('ClienteForm', 'onEdit')); $action_edit->setUseButton(TRUE); $action_edit->setButtonClass('btn btn-default'); $action_edit->setLabel(_t('Edit')); $action_edit->setImage('fa:pencil-square-o blue fa-lg'); $action_edit->setField('id'); $action_edit->setDisplayCondition(array($this, 'checkEdit')); $this->datagrid->addAction($action_edit); // create DELETE action $action_del = new TDataGridAction(array($this, 'onDelete')); $action_del->setUseButton(TRUE); $action_del->setButtonClass('btn btn-default'); $action_del->setLabel(_t('Delete')); $action_del->setImage('fa:trash-o red fa-lg'); $action_del->setField('id'); $action_del->setDisplayCondition(array($this, 'checkDelete')); $this->datagrid->addAction($action_del); $telefone_action = new TDataGridAction(array('telefoneList', 'onReload')); $telefone_action->setLabel('Telefones'); $telefone_action->setImage('bs:search blue'); $telefone_action->setField('id'); $this->datagrid->addAction($telefone_action); $email_action = new TDataGridAction(array('emailList', 'onReload')); $email_action->setLabel('Email'); $email_action->setImage('bs:search blue'); $email_action->setField('id'); $this->datagrid->addAction($email_action); // create the datagrid model $this->datagrid->createModel(); // create the page navigation $this->pageNavigation = new TPageNavigation(); $this->pageNavigation->setAction(new TAction(array($this, 'onReload'))); $this->pageNavigation->setWidth($this->datagrid->getWidth()); $this->datagrid->disableDefaultClick(); // put datagrid inside a form $this->formgrid = new TForm(); $this->formgrid->add($this->datagrid); // creates the delete collection button $this->deleteButton = new TButton('delete_collection'); $this->deleteButton->setAction(new TAction(array($this, 'onDeleteCollection')), AdiantiCoreTranslator::translate('Delete selected')); $this->deleteButton->setImage('fa:remove red'); $this->formgrid->addField($this->deleteButton); $gridpack = new TVBox(); $gridpack->style = 'width: 100%'; $gridpack->add($this->formgrid); $gridpack->add($this->deleteButton)->style = 'background:whiteSmoke;border:1px solid #cccccc; padding: 3px;padding: 5px;'; $this->transformCallback = array($this, 'onBeforeLoad'); // vertical box container $container = new TVBox(); $container->style = 'width: 90%'; // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__)); $container->add(TPanelGroup::pack('Title', $this->form)); $container->add($gridpack); $container->add($this->pageNavigation); parent::add($container); }