Esempio n. 1
0
 public function addAction()
 {
     $form = new CountryForm();
     $form->get('submit')->setValue('Add');
     // CSS
     $form->get('name')->setAttribute('class', 'form-control');
     $form->get('name')->setAttribute('placeholder', 'Ej.: Francia');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $country = new Country();
         $form->setInputFilter($country->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $country->exchangeArray($form->getData());
             $this->getEntityManager()->persist($country);
             $this->getEntityManager()->flush();
             // Redirect to Country List
             return $this->redirect()->toRoute('country');
         }
     }
     return array('form' => $form);
 }
 /**
  * {@inheritDoc}
  */
 public function getNationality()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getNationality', array());
     return parent::getNationality();
 }
 public function addAction()
 {
     $config = $this->getServiceLocator()->get('config');
     $applicationManager = ApplicationManager::getInstance($this->getServiceLocator());
     $form = new ClientsForm(array('services' => $applicationManager->prepareFormServices(), 'clinics' => $applicationManager->prepareFormClinics(), 'doctors' => $applicationManager->prepareFormDoctors(), 'countries' => $applicationManager->prepareFormCountries()));
     $request = $this->getRequest();
     if ($request->isPost()) {
         $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $form->setData($post);
         if ($form->isValid()) {
             $data = $form->getData();
             $dateTime = new \DateTime();
             $dateTime->setTimestamp(strtotime($data['dos']));
             $data['dos'] = $dateTime;
             $dateTime = new \DateTime();
             $dateTime->setTimestamp(strtotime($data['nextContactDate']));
             $data['nextContactDate'] = $dateTime;
             $dateTime = new \DateTime();
             $dateTime->setTimestamp(time());
             $now = $dateTime;
             if (!empty($data['newClinic'])) {
                 $newClinic = new Clinic();
                 $newClinic->setName($data['newClinic']);
                 ClinicDAO::getInstance($this->getServiceLocator())->save($newClinic);
                 $data['clinic'] = $newClinic->getId();
             }
             if (!empty($data['newDoctor'])) {
                 $newDoctor = new Doctor();
                 $newDoctor->setName($data['newDoctor']);
                 DoctorDAO::getInstance($this->getServiceLocator())->save($newDoctor);
                 $data['doctor'] = $newDoctor->getId();
             }
             if (!empty($data['newCountry'])) {
                 $newCountry = new Country();
                 $newCountry->setName($data['newCountry']);
                 CountryDAO::getInstance($this->getServiceLocator())->save($newCountry);
                 $data['country'] = $newDoctor->getId();
             }
             if (!empty($post['attachments'])) {
                 foreach ($post['attachments'] as $attach) {
                     if (!empty($attach['name'])) {
                         $attach['name'] = str_replace(' ', '_', $attach['name']);
                         move_uploaded_file($attach['tmp_name'], $config['app']['uploads_path'] . $attach['name']);
                         $attachmentNames[] = 'uploads/' . $attach['name'];
                     }
                 }
             }
             if (!empty($post['conclusions'])) {
                 foreach ($post['conclusions'] as $conclusion) {
                     if (!empty($conclusion['name'])) {
                         $conclusion['name'] = str_replace(' ', '_', $conclusion['name']);
                         move_uploaded_file($conclusion['tmp_name'], $config['app']['uploads_path'] . $conclusion['name']);
                         $conclusionNames[] = 'uploads/' . $conclusion['name'];
                     }
                 }
             } else {
                 $conclusionNames = array();
             }
             $client = new Clients();
             $client->setFio($data['fio']);
             $client->setService(ServiceDAO::getInstance($this->getServiceLocator())->findOneById($data['service']));
             $client->setDiagnosis($data['diagnosis']);
             $client->setContacts($data['contacts']);
             $client->setDOS($data['dos']);
             $client->setStatus($data['status']);
             $client->setComments($data['comments']);
             $client->setCountry(CountryDAO::getInstance($this->getServiceLocator())->findOneById($data['country']));
             $client->setNextContactDate($data['nextContactDate']);
             $client->setNextContactComment($data['nextContactComment']);
             $client->setAttachments(serialize($attachmentNames));
             $client->setClinic(ClinicDAO::getInstance($this->getServiceLocator())->findOneById($data['clinic']));
             $client->setDoctor(DoctorDAO::getInstance($this->getServiceLocator())->findOneById($data['doctor']));
             $client->setConclusion(serialize(array_unique($conclusionNames)));
             $client->setPayment($data['payment']);
             $client->setInformed((int) $data['informed']);
             $client->setDateAdded($now);
             $client->setManager($applicationManager->getCurrentUser());
             ClientsDAO::getInstance($this->getServiceLocator())->save($client);
             if (!empty($data['nextContactDate'])) {
                 $calendarDAO = CalendarDAO::getInstance($this->getServiceLocator());
                 $event = new Calendar();
                 $event->setTitle($data['fio']);
                 $event->setDescription($client->getNextContactComment());
                 $event->setDate($client->getNextContactDate());
                 $event->setClient($client);
                 $calendarDAO->save($event);
             }
             return $this->redirect()->toRoute('clients');
         }
     }
     return array('form' => $form);
 }
Esempio n. 4
0
 public function __invoke(Country $country)
 {
     return '<a href="' . $this->getView()->url('country', ['code' => $country->getCode()]) . '">' . $country->getName() . '</a>';
 }
 /**
  * {@inheritDoc}
  */
 public function getInputFilter()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getInputFilter', array());
     return parent::getInputFilter();
 }