Esempio n. 1
0
 /**
  * @return string
  */
 public function format()
 {
     switch ($this->log->getAction()) {
         case 'create':
             return str_replace(['{user_name}', '{resource_id}'], [$this->log->getUserName(), $this->log->getResourceId()], $this->messages['create']);
             break;
         case 'change_status':
             $data = json_decode($this->log->getData(), true);
             return str_replace(['{user_name}', '{resource_id}', '{from}', '{to}'], [$this->log->getUserName(), $this->log->getResourceId(), $data['from'], $data['to']], $this->messages['change_status']);
             break;
         case 'update':
             return str_replace(['{user_name}', '{resource_id}'], [$this->log->getUserName(), $this->log->getResourceId()], $this->messages['update']);
             break;
         default:
             return $this->log->getFormattedMessage();
             break;
     }
 }
Esempio n. 2
0
 /**
  * @return string
  */
 public function format()
 {
     switch ($this->log->getAction()) {
         case 'create':
             return str_replace(['{user_name}', '{resource_id}'], [$this->log->getUserName(), $this->log->getResourceId()], $this->messages['create']);
             break;
         case 'update':
             return str_replace(['{user_name}', '{resource_id}'], [$this->log->getUserName(), $this->log->getResourceId()], $this->messages['update']);
             break;
         default:
             return $this->log->getFormattedMessage();
             break;
     }
 }
Esempio n. 3
0
 /**
  * @param User $user
  * @param $resourceType
  * @param $resourceId
  * @param $action
  * @param array $data
  * @param null $message
  * @return Log
  */
 private function log(User $user, $resourceType, $resourceId, $action, array $data, $message = null)
 {
     $log = new Log();
     $log->setUser($user);
     $log->setUserName($user->getName());
     $log->setResourceId($resourceId);
     $log->setResourceType($resourceType);
     $log->setAction($action);
     $log->setData(json_encode($data));
     $log->setMessage($message ? $message : '');
     $this->em()->persist($log);
     $this->em()->flush();
     return $log;
 }