Beispiel #1
0
 /**
  * Create service
  *
  * @param ServiceLocatorInterface $sm
  * @return mixed
  */
 public function createService(ServiceLocatorInterface $sm)
 {
     $dataGrid = new \ZfcDatagrid\Service\DatagridFactory();
     $dataGrid = $dataGrid->createService($sm);
     $dataGrid->setTitle('Seo');
     $dataGrid->setDefaultItemsPerPage(20);
     $em = $sm->get('doctrine.entitymanager.orm_default');
     $qb = $em->createQueryBuilder();
     $qb->select('s');
     $qb->from('Seo\\Entity\\Seo', 's');
     $dataGrid->setDataSource($qb);
     $col = new Column\Select('id', 's');
     $col->setWidth(1);
     $col->setSortDefault(1, 'DESC');
     $col->setIdentity();
     $col->setHidden(false);
     $col->setLabel('Id');
     $dataGrid->addColumn($col);
     $col = new Column\Select('pageId', 's');
     $col->setLabel('PageId');
     $dataGrid->addColumn($col);
     $col = new Column\Select('type', 's');
     $col->setLabel('Type');
     //    $col->setReplaceValues(array(
     //        'BUILDER' => 'Builder',
     //        'JOB' => 'Job',
     //        'HOMEOWNER' => 'Homeowner'
     //    ));
     $dataGrid->addColumn($col);
     $col = new Column\Select('title', 's');
     $col->setLabel('Title');
     $dataGrid->addColumn($col);
     $col = new Column\Select('description', 's');
     $col->setLabel('Description');
     $dataGrid->addColumn($col);
     $col = new Column\Select('keywords', 's');
     $col->setLabel('Keywords');
     $dataGrid->addColumn($col);
     $action2 = new Column\Action\Icon();
     $action2->setIconClass('icon-edit');
     $action2->setAttribute('href', "/seo/update/" . $action2->getRowIdPlaceholder());
     $action2->setAttribute('data-toggle', 'modal');
     $action2->setAttribute('data-target', '#updateModal');
     $action3 = new Column\Action\Icon();
     $action3->setIconClass('icon-remove');
     $action3->setAttribute('href', '/seo/remove/' . $action3->getRowIdPlaceholder());
     $action3->setAttribute('data-toggle', 'modal');
     $action3->setAttribute('data-target', '#removeModal');
     $col = new Column\Action();
     $col->setLabel('Actions');
     $col->setWidth(1);
     $col->addAction($action2);
     $col->addAction($action3);
     $dataGrid->addColumn($col);
     return $dataGrid;
 }
 /**
  * Consumers list
  *
  * @return \ZfcDatagrid\Datagrid
  */
 public function getDatagrid()
 {
     $grid = $this->getGrid();
     $grid->setTitle('Customers');
     $grid->setId('customerGrid');
     $grid->setToolbarTemplateVariables(array('globalActions' => array(_('New Customer') => '/admin/customer/add'), array(_('New Customer') => '/admin/customer/add')));
     $dbAdapter = $this->adapter;
     $select = new Select();
     $select->from(array('c' => 'customer'));
     $select->join('user', 'c.user_id = user.user_id', array('email'), 'left');
     $select->join('base_status', 'status_id = base_status.id', array('id'), 'left');
     // Status array
     $arrStatus = array();
     $status = $this->statusservice->findAll('customers');
     foreach ($status as $s) {
         $arrStatus[$s->getId()] = $s->getStatus();
     }
     $grid->setDefaultItemsPerPage($this->settings->getValueByParameter('Customer', 'recordsperpage'));
     $grid->setDataSource($select, $dbAdapter);
     $col = new Column\Select('id', 'c');
     $col->setLabel('Id');
     $col->setIdentity();
     $grid->addColumn($col);
     $col = new Column\Select('company', 'c');
     $col->setLabel(_('Company'));
     $col->setWidth(40);
     $grid->addColumn($col);
     $col = new Column\Select('firstname', 'c');
     $col->setLabel(_('Last name'));
     $col->setWidth(15);
     $grid->addColumn($col);
     $col = new Column\Select('lastname', 'c');
     $col->setLabel(_('First name'));
     $col->setWidth(15);
     $grid->addColumn($col);
     $colType = new Type\DateTime('Y-m-d H:i:s', \IntlDateFormatter::SHORT, \IntlDateFormatter::SHORT);
     $colType->setSourceTimezone('Europe/Rome');
     $colType->setOutputTimezone('UTC');
     $colType->setLocale('it_IT');
     $col = new Column\Select('id', 'base_status');
     $col->setLabel('Status');
     $col->setWidth(10);
     $col->setReplaceValues($arrStatus);
     $col->setFilterSelectOptions($arrStatus);
     $col->setTranslationEnabled(true);
     $grid->addColumn($col);
     $col = new Column\Select('email', 'user');
     $col->setLabel(_('Email'));
     $col->addFormatter(new Formatter\Email());
     $col->addStyle(new Style\Bold());
     $col->setWidth(15);
     $grid->addColumn($col);
     $col = new Column\Select('createdat', 'c');
     $col->setType($colType);
     $col->setLabel(_('Created At'));
     $grid->addColumn($col);
     // Add actions to the grid
     $showaction = new Column\Action\Icon();
     $showaction->setAttribute('href', "/admin/customer/edit/" . $showaction->getColumnValuePlaceholder(new Column\Select('id', 'c')));
     $showaction->setAttribute('class', 'btn btn-xs btn-success');
     $showaction->setIconClass('glyphicon glyphicon-pencil');
     $delaction = new Column\Action\Icon();
     $delaction->setAttribute('href', '/admin/customer/delete/' . $delaction->getRowIdPlaceholder());
     $delaction->setAttribute('onclick', "return confirm('Are you sure?')");
     $delaction->setAttribute('class', 'btn btn-xs btn-danger');
     $delaction->setIconClass('glyphicon glyphicon-remove');
     $col = new Column\Action();
     $col->addAction($showaction);
     $col->addAction($delaction);
     $grid->addColumn($col);
     $grid->addMassAction(new Action\Mass(_('Enable'), '/admin/customer/massaction/enable', true));
     $grid->addMassAction(new Action\Mass(_('Disable'), '/admin/customer/massaction/disable', true));
     $grid->addMassAction(new Action\Mass(_('Delete'), '/admin/customer/massaction/delete', true));
     #$grid->setToolbarTemplateVariables(['myVariable' => 123]);
     #$grid->setToolbarTemplate('zfc-datagrid/toolbar/customer');
     return $grid;
 }