예제 #1
0
 public function execute()
 {
     $em = $this->em();
     $form = $this->prepareForm(new \ru\nazarov\crm\forms\OfferForm('offer-form', 'Add offer', '/?action=add_offer', \ru\nazarov\crm\forms\Form::METHOD_POST, 'multipart/form-data'));
     if (!$form->isEmpty() && $form->validate()) {
         //$offerId = $em->getRepository('\ru\nazarov\crm\entities\OfferId')->findOneBy(array());
         $offer = new \ru\nazarov\crm\entities\Offer();
         $offer->setOrg($em->find('\\ru\\nazarov\\crm\\entities\\Organization', $form->get('org')));
         $offer->setApp($em->find('\\ru\\nazarov\\crm\\entities\\Application', $form->get('app')));
         $offer->setDate(new \DateTime($form->get('date')));
         $offer->setComment($form->get('comment'));
         $offer->setLegalEntity($_SESSION['le']);
         $offer->setOfferId($form->get('offer_id'));
         //$offer->setOfferId($offerId->getPrefix() . str_pad($offerId->getNextId(), 4, '0', STR_PAD_LEFT));
         $em->persist($offer);
         //$offerId->setNextId($offerId->getNextId() + 1);
         $em->flush();
         if (($attachments = $form->get(AddAppAction::ATTACHMENT_KEY)) != null) {
             \ru\nazarov\sitebase\Facade::saveAttachments($offer->getId(), 'offer', $attachments);
             $em->flush();
         }
         $form->clean();
     }
     if ($form->get('org') == null) {
         $form->set('org', 'undef');
     }
     $form->setFieldVals('org', \ru\nazarov\sitebase\Facade::getPersonFormOrgsSelectDp());
     $this->view()->set('form', $form)->set('apps', \ru\nazarov\sitebase\Facade::getAppsSelectDp());
     parent::execute();
 }
예제 #2
0
 protected function prepareData()
 {
     parent::prepareData();
     $em = $this->em();
     $attachments = $em->getRepository('\\ru\\nazarov\\crm\\entities\\Attachment')->findBy(array('owner' => $this->_item->getId(), 'type' => $em->getRepository('\\ru\\nazarov\\crm\\entities\\AttachmentType')->findBy(array('code' => 'offer'))));
     $this->view()->set('apps', \ru\nazarov\sitebase\Facade::getAppsSelectDp())->set('attachment_key', AddAppAction::ATTACHMENT_KEY)->set('attachments', array_map(function ($a) {
         return (object) array('name' => $a->getName(), 'id' => $a->getId());
     }, $attachments));
 }