public function execute() { $em = $this->em(); $form = $this->prepareForm(new \ru\nazarov\crm\forms\AppForm('app-form', 'Add request', '/?action=add_app', \ru\nazarov\crm\forms\Form::METHOD_POST, 'multipart/form-data')); if (!$form->isEmpty() && $form->validate()) { $app = new \ru\nazarov\crm\entities\Application(); $app->setClient($em->find('\\ru\\nazarov\\crm\\entities\\Organization', $form->get('client'))); $app->setSupplier($em->find('\\ru\\nazarov\\crm\\entities\\Organization', $form->get('supplier'))); $app->setDate(new \DateTime($form->get('date'))); $app->setComment($form->get('comment')); $app->setLegalEntity($_SESSION['le']); $em->persist($app); $em->flush(); \ru\nazarov\sitebase\Facade::notifyHeads('New request.', 'New request added.', '/?action=edit_app&id=' . $app->getId()); if (($attachments = $form->get(self::ATTACHMENT_KEY)) != null) { \ru\nazarov\sitebase\Facade::saveAttachments($app->getId(), 'application', $attachments); $em->flush(); } $form->clean(); } $form->setFieldVals('supplier', array_map(function ($org) { return (object) array('label' => htmlspecialchars($org->getName()), 'val' => $org->getId()); }, $em->getRepository('\\ru\\nazarov\\crm\\entities\\Organization')->findBy(array('type' => 1), array('name' => 'ASC'))))->setFieldVals('client', array_map(function ($org) { return (object) array('label' => htmlspecialchars($org->getName()), 'val' => $org->getId()); }, $em->getRepository('\\ru\\nazarov\\crm\\entities\\Organization')->findBy(array('type' => 2), array('name' => 'ASC')))); $view = $this->view(); $view->set('form', $form); parent::execute(); }
public function execute() { $em = $this->em(); $form = $this->prepareForm(new \ru\nazarov\crm\forms\ReportForm('report-form', 'Add report', '/?action=add_report', \ru\nazarov\crm\forms\Form::METHOD_POST)); if (!$form->isEmpty() && $form->validate()) { $r = new \ru\nazarov\crm\entities\Report(); $r->setComment($form->get('comment')); $r->setContact($em->find('\\ru\\nazarov\\crm\\entities\\Contact', $form->get('contact'))); $r->setDate(new \DateTime($form->get('date'))); $r->setLegalEntity($_SESSION['le']); $r->setApp($em->find('\\ru\\nazarov\\crm\\entities\\Application', $form->get('app'))); $em->persist($r); $em->flush(); \ru\nazarov\sitebase\Facade::notifyHeads('New report.', 'New report added.', '/?action=edit_report&id=' . $r->getId()); $form->clean(); } $types = array_map(function ($type) { return (object) array('label' => $type->getCode(), 'val' => $type->getId()); }, $em->getRepository('\\ru\\nazarov\\crm\\entities\\OrganizationType')->findAll()); //$form->setFieldVals('type', $types); $this->view()->set('form', $form)->set('types', $types); parent::execute(); }