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(); }
public function execute() { $em = $this->em(); $form = $this->prepareForm(new \ru\nazarov\crm\forms\PersonForm('person-form', 'Add person', '/?action=add_person', \ru\nazarov\crm\forms\Form::METHOD_POST)); if (!$form->isEmpty() && $form->validate()) { $p = new \ru\nazarov\crm\entities\Person(); $p->setName($form->get('name')); $p->setOrganization($em->find('\\ru\\nazarov\\crm\\entities\\Organization', $form->get('org'))); $p->setPosition($form->get('pos')); $p->setComment($form->get('comment')); $p->setLegalEntity($_SESSION['le']); $em->persist($p); $contacts = $form->get(self::CONTACT_VALUES_KEY); if ($contacts != null) { foreach ($form->get(self::CONTACT_TYPES_KEY) as $i => $type) { $c = new \ru\nazarov\crm\entities\Contact(); $c->setPerson($p); $c->setType($em->find('\\ru\\nazarov\\crm\\entities\\ContactType', $type)); $c->setValue($contacts[$i]); $em->persist($c); } } $em->flush(); $form->clean(); } $view = $this->view(); $view->set('form', $form)->set('contact_types_key', self::CONTACT_TYPES_KEY)->set('contact_ids_key', self::CONTACT_ID_KEY)->set('contact_values_key', self::CONTACT_VALUES_KEY); $form->setFieldVals('org', \ru\nazarov\sitebase\Facade::getPersonFormOrgsSelectDp()); if ($form->get('org') == null) { $form->set('org', 'undef'); } if (count($types = $form->get(self::CONTACT_TYPES_KEY)) > 0) { $view->set('contacts', array_map(function ($type, $val) { return (object) array('type' => $type, 'val' => $val); }, $types, $form->get(self::CONTACT_VALUES_KEY))); } parent::execute(); }
protected function fillSelects() { $this->_form->setFieldVals('org', \ru\nazarov\sitebase\Facade::getPersonFormOrgsSelectDp()); }