Ejemplo n.º 1
0
Archivo: Task.php Proyecto: arbi/MyCode
 private function setComment(Logger $logger, $oldDataGeneral, $oldDataStaff, $newData, $actionsSet = [])
 {
     /**
      * @var \DDD\Domain\Task\Task $oldDataGeneral
      * @var \DDD\Domain\Task\Staff[] $oldDataStaff
      * @var \DDD\Dao\User\UserManager $usersDao
      * @var \DDD\Dao\Team\Team $teamsDao
      * @var \DDD\Domain\User\User $user
      * @var \DDD\Domain\Team\Team $oldTeam
      */
     $auth = $this->getServiceLocator()->get('library_backoffice_auth');
     $usersDao = $this->getServiceLocator()->get('dao_user_user_manager');
     $authId = $auth->getIdentity()->id;
     $timestamp = $newData['last_update_time'];
     // Log Status Changes
     if (isset($newData['task_status']) && $oldDataGeneral->getTask_status() != $newData['task_status']) {
         $logger->save(Logger::MODULE_TASK, $oldDataGeneral->getId(), self::getTaskStatusMapping()[$newData['task_status']], 1, $authId, $timestamp);
         if ($newData['task_status'] == self::STATUS_DONE && (isset($newData['verifier_id']) && $newData['verifier_id'] == User::AUTO_VERIFY_USER_ID || empty($actionsSet[self::ACTION_MANAGE_STAFF]) && $oldDataGeneral->getVerifierId() == User::AUTO_VERIFY_USER_ID)) {
             $logger->save(Logger::MODULE_TASK, $oldDataGeneral->getId(), Logger::ACTION_TASK_AUTO_VERIFY, 'Auto Verified', UserMain::SYSTEM_USER_ID, $timestamp);
         }
     }
     // Log Priority Changes
     if (isset($newData['task_priority']) && $oldDataGeneral->getPriority() != $newData['task_priority']) {
         $logger->save(Logger::MODULE_TASK, $oldDataGeneral->getId(), Logger::ACTION_PRIORITY, self::getTaskPriorityMapping()[$newData['task_priority']], $authId, $timestamp);
     }
     // Log Team Changes
     if (isset($newData['team_id']) && $oldDataGeneral->getTeamId() != $newData['team_id']) {
         $teamsDao = $this->getServiceLocator()->get('dao_team_team');
         $oldTeam = $teamsDao->fetchOne(['id' => $oldDataGeneral->getTeamId()]);
         $newTeam = $teamsDao->fetchOne(['id' => $newData['team_id']]);
         if ($oldTeam) {
             if ($newTeam) {
                 $teamValue = '<b>' . $oldTeam->getName() . '</b> to <b>' . $newTeam->getName() . '</b>';
             } else {
                 $teamValue = '<b>' . $oldTeam->getName() . '</b> to <b>Unassigned</b>.';
             }
             $logger->save(Logger::MODULE_TASK, $oldDataGeneral->getId(), Logger::ACTION_TASK_TEAM, $teamValue, $authId, $timestamp);
         }
     }
     // Log Date Changes
     if (isset($newData['date'])) {
         $date = $newData['date'] ? date('Y-m-d', strtotime($newData['date'])) : null;
         if ($oldDataGeneral->getDate() != $date) {
             $logger->save(Logger::MODULE_TASK, $oldDataGeneral->getId(), Logger::ACTION_TASK_DATE_SET, $date, $authId, $timestamp);
         }
     }
     if (!empty($actionsSet[self::ACTION_MANAGE_STAFF])) {
         $staffKeyMapping = [self::STAFF_RESPONSIBLE => 'responsible_id', self::STAFF_VERIFIER => 'verifier_id', self::STAFF_HELPER => 'helper_ids', self::STAFF_FOLLOWER => 'follower_ids'];
         $ifNoOldStaffButNew = ['responsible_id' => 'responsible_id', 'verifier_id' => 'verifier_id'];
         if ($oldDataStaff) {
             foreach ($oldDataStaff as $oldStaffPerson) {
                 switch ($oldStaffPerson->getType()) {
                     case self::STAFF_RESPONSIBLE:
                     case self::STAFF_VERIFIER:
                         if (isset($newData[$staffKeyMapping[$oldStaffPerson->getType()]])) {
                             if (!$newData[$staffKeyMapping[$oldStaffPerson->getType()]] || $oldStaffPerson->getId() != $newData[$staffKeyMapping[$oldStaffPerson->getType()]]) {
                                 $changedTo = 'nobody';
                                 if ($newData[$staffKeyMapping[$oldStaffPerson->getType()]]) {
                                     $user = $usersDao->fetchOne(['id' => $newData[$staffKeyMapping[$oldStaffPerson->getType()]]]);
                                     $changedTo = $user->getFullName();
                                 }
                                 $logger->save(Logger::MODULE_TASK, $oldDataGeneral->getId(), Logger::ACTION_TASK_STAFF_CHANGE, [str_replace('_id', '', $staffKeyMapping[$oldStaffPerson->getType()]), $oldStaffPerson->getName(), $changedTo], $authId, $timestamp);
                                 if (isset($ifNoOldStaffButNew[$staffKeyMapping[$oldStaffPerson->getType()]])) {
                                     unset($ifNoOldStaffButNew[$staffKeyMapping[$oldStaffPerson->getType()]]);
                                 }
                             } else {
                                 unset($newData[$staffKeyMapping[$oldStaffPerson->getType()]]);
                             }
                         }
                         break;
                     case self::STAFF_HELPER:
                     case self::STAFF_FOLLOWER:
                         if (isset($newData[$staffKeyMapping[$oldStaffPerson->getType()]])) {
                             if (!$newData[$staffKeyMapping[$oldStaffPerson->getType()]] || !in_array($oldStaffPerson->getId(), $newData[$staffKeyMapping[$oldStaffPerson->getType()]])) {
                                 $logger->save(Logger::MODULE_TASK, $oldDataGeneral->getId(), Logger::ACTION_TASK_STAFF_REMOVE, [str_replace('_id', '', $staffKeyMapping[$oldStaffPerson->getType()]), $oldStaffPerson->getName()], $authId, $timestamp);
                             } else {
                                 $newData[$staffKeyMapping[$oldStaffPerson->getType()]] = array_flip($newData[$staffKeyMapping[$oldStaffPerson->getType()]]);
                                 unset($newData[$staffKeyMapping[$oldStaffPerson->getType()]][$oldStaffPerson->getId()]);
                                 $newData[$staffKeyMapping[$oldStaffPerson->getType()]] = array_flip($newData[$staffKeyMapping[$oldStaffPerson->getType()]]);
                             }
                             break;
                         }
                 }
             }
         }
         //if there was no old data, but there is new one
         foreach ($ifNoOldStaffButNew as $item) {
             if (!empty($newData[$item])) {
                 $user = $usersDao->fetchOne(['id' => $newData[$item]]);
                 $logger->save(Logger::MODULE_TASK, $oldDataGeneral->getId(), Logger::ACTION_TASK_STAFF_CHANGE, [str_replace('_id', '', $item), 'nobody', $user->getFullName()], $authId, $timestamp);
             }
         }
         if (isset($newData['helper_ids']) && count($newData['helper_ids'])) {
             foreach ($newData['helper_ids'] as $helperId) {
                 $user = $usersDao->fetchOne(['id' => $helperId]);
                 $logger->save(Logger::MODULE_TASK, $oldDataGeneral->getId(), Logger::ACTION_TASK_STAFF_ADD, ['helper', $user->getFirstName() . ' ' . $user->getLastName()], $authId, $timestamp);
             }
         }
         if (isset($newData['follower_ids']) && count($newData['follower_ids'])) {
             foreach ($newData['follower_ids'] as $followerId) {
                 $user = $usersDao->fetchOne(['id' => $followerId]);
                 $logger->save(Logger::MODULE_TASK, $oldDataGeneral->getId(), Logger::ACTION_TASK_STAFF_ADD, ['follower', $user->getFirstName() . ' ' . $user->getLastName()], $authId, $timestamp);
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * @param \DDD\Domain\Booking\ChannelReservation|null $bookingDomain
  */
 private function logDuplicateCancellation($bookingDomain)
 {
     $msg = 'Reservation Number: ' . $bookingDomain->getResNumber() . ', Cancellation Date: ' . $bookingDomain->getDateFrom() . ', Detected Date: ' . date('Y-m-d H:i:s') . ', Detected Status: ' . BookingService::$bookingStatuses[$bookingDomain->getStatus()];
     $logger = new ALogger($this->getServiceLocator());
     $logger->save(ALogger::MODULE_BOOKING, $bookingDomain->getId(), ALogger::ACTION_DUPLICATE_CANCELLATION, $msg);
 }