Beispiel #1
0
 /**
  * @static
  * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocatorInterface
  * @return ClientsDAO
  */
 public static function getInstance(ServiceLocatorInterface $serviceLocatorInterface)
 {
     if (self::$instance == null) {
         self::$instance = new ClientsDAO();
         self::$instance->setServiceLocator($serviceLocatorInterface);
     }
     return self::$instance;
 }
 public function dashboardAction()
 {
     $clients = ClientsDAO::getInstance($this->getServiceLocator())->getAllClients();
     $stats['date'] = array();
     $stats['status'] = array('Не обработан' => 0, 'В работе' => 0, 'Согласование' => 0, 'Архив' => 0, 'Пролечен' => 0, 'Записан в календарь' => 0, 'Сорвался' => 0);
     $users = UserDAO::getInstance($this->getServiceLocator())->getAllUsers();
     foreach ($users as $user) {
         $stats['manager'][$user->getDisplayName()] = 0;
     }
     if (!empty($clients)) {
         foreach ($clients as $client) {
             $formattedDate = $client->getDateAdded()->format('Y-m-d');
             $stats['date'][$formattedDate] = isset($stats['date'][$formattedDate]) ? $stats['date'][$formattedDate] + 1 : 1;
             $stats['manager'][$client->getManager()->getDisplayName()] += 1;
             $stats['status'][$client->getStatus()] += 1;
         }
     }
     return array('stats' => $stats);
 }
 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);
 }