예제 #1
0
 public function create()
 {
     $grid = new Grid();
     $grid->model = $this->clientFacade->createDSDoctrine();
     $grid->addColumnText('name', 'Name')->setCustomRender(function ($item) {
         $href = $this->linkGenerator->link('Backend:Clients:update', array('id' => $item->id));
         return "<a href ='" . $href . "'>" . $item->name . "</a>";
         /* $el = Html::el('a');
            // $item represents whole row. So you can get here any filed you want.
            $el->setText($item->name);
            $el->addAttributes(array('target'=>"_blank"));
            $el->href = $this->linkGenerator->link(
                'Backend:Clients:product',    // this is how you can generate any link MODULE_NAME:PRESENTER_NAME:ACTION_NAME
                array(
                    // here is a place for path parameters. FE: here you are expecting /admin/<presenter>/<action>[/<id>]
                    // id is a parameter we can set here. FYI [/<id>] means that id is not required parameter, it can be NULL.
                    'id' => $item->id
                )
            );
            return $el;*/
     })->setSortable()->setFilterNumber();
     $grid->addColumnText('product', 'Product')->setCustomRender(function ($item) {
         return $item->product->name;
     })->setSortable()->setFilterText()->setSuggestion();
     $grid->addColumnText('address', 'Address')->setSortable()->setFilterText()->setSuggestion();
     $grid->addActionHref('update', 'Update')->setIcon('pencil');
     $grid->addActionEvent('delete', 'Delete', function ($item) {
         $this->clientFacade->delete($item);
     })->setIcon('trash-o')->setConfirm(function ($item) {
         return "Are you sure you want to delete {$item->name}?";
     });
     return $grid;
 }
예제 #2
0
 public function create($clientId = NULL)
 {
     $form = new ClientsForm();
     // set product collection
     $form->setProductsArray($this->productFacade->getProducts());
     // create form base structure
     $form->create();
     //
     // set default values if clientId is not NULL
     //
     if ($clientId) {
         // get client entity
         $client = $this->clientFacade->find($clientId);
         if ($client == NULL) {
             throw new InvalidArgumentException('Client with id=' . $clientId . ' not found.');
         }
         // basic client fields
         $clientArray = array('name' => $client->getName(), 'address' => $client->getAddress());
         // product
         if ($client->getProduct() !== NULL) {
             $clientArray['product'] = $client->getProduct()->getId();
         }
         $form->setValues($clientArray);
     }
     $form->onSuccess[] = function (ClientsForm $form) use($clientId) {
         $values = $form->getValues(TRUE);
         $this->clientFacade->update($values, $clientId);
     };
     return $form;
 }
예제 #3
0
 public function renderDefault()
 {
     $this->template->clients = $this->clientFacade->getClients();
 }