/**
  * @return \Application\\Entity\User
  */
 public function getCurrentUser()
 {
     if ($this->currentUser === null) {
         $identity = $this->getServiceLocator()->get('AuthService')->getIdentity();
         if ($identity === null) {
             $this->currentUser = null;
         } else {
             if ($identity instanceof User) {
                 $this->currentUser = $identity;
             } else {
                 if (is_string($identity)) {
                     $this->currentUser = UserDAO::getInstance($this->getServiceLocator())->findOneByIdentity($identity, false, true);
                 }
             }
         }
     }
     return $this->currentUser;
 }
 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 deleteAction()
 {
     $userId = (int) $this->params()->fromRoute('id', '');
     if ($userId) {
         $userDAO = UserDAO::getInstance($this->getServiceLocator());
         $removableUser = $userDAO->findOneById($userId);
         if ($removableUser !== null) {
             $userDAO->removeById($userId);
         }
     }
     return $this->redirect()->toRoute('users');
 }
 /**
  * @param string $email
  * @return \Application\Entity\User
  */
 public function findUserByEmail($email)
 {
     return UserDAO::getInstance($this->getServiceLocator())->findOneByIdentity($email);
 }