Beispiel #1
0
 protected function prepareData()
 {
     parent::prepareData();
     $em = $this->em();
     $storeItem = new \ru\nazarov\crm\entities\StoreItem();
     $storeItem->setCode('code' . rand(0, 100));
     $storeItem->setDescription(md5(rand(0, 1000)));
     $storeItem->setAmount(rand(100, 10000));
     $storeItem->setComment(md5(rand(100, 2355)));
     $storeItem->setMinAmount(rand(10, 100));
     $storeItem->setManufacturerCode(substr(md5(rand(0, 1000)), 10, 5));
     $storeItem->setSupplierCode(substr(md5(rand(0, 1000)), 10, 5));
     //$em->persist($storeItem);
     //$em->flush();
     $items = array_map(function ($item) {
         return $item->getJsonable();
     }, $em->getRepository('ru\\nazarov\\crm\\entities\\StoreItem')->findAll());
     $this->view()->set('content', 'store.tpl')->set('items', $items);
 }
 public function execute()
 {
     $em = $this->em();
     $form = $form = $this->prepareForm(new \ru\nazarov\crm\forms\StoreItemForm('store-item-form', 'Add store item', '/?action=add_store_item', \ru\nazarov\crm\forms\Form::METHOD_POST));
     if (!$form->isEmpty() && $form->validate()) {
         $item = new \ru\nazarov\crm\entities\StoreItem();
         $item->setAmount($form->get('amount'));
         $item->setCode($form->get('code'));
         $item->setComment($form->get('comment'));
         $item->setDescription($form->get('desc'));
         $item->setManufacturerCode($form->get('mancode'));
         $item->setMinAmount($form->get('minamount'));
         $item->setSupplierCode($form->get('supcode'));
         $em->persist($item);
         $em->flush();
         $form->clean();
     }
     $this->view()->set('form', $form);
     parent::execute();
 }