/**
  * Sets origin and destination coordinates before updating.
  *
  * Method will only call geocode() if one of the location fields was changed
  * by the user.
  *
  * @param LifecycleEventArgs $eventArgs
  */
 public function preUpdate(LifecycleEventArgs $eventArgs)
 {
     $object = $eventArgs->getEntity();
     if ($object instanceof RouteAwareInterface) {
         if (count(array_intersect(array_keys($eventArgs->getEntityChangeSet()), $this->originFields)) > 0) {
             $this->updateOriginCoordinates($object);
             $this->updateDistance($object);
         }
         if (count(array_intersect(array_keys($eventArgs->getEntityChangeSet()), $this->destinationFields)) > 0) {
             $this->updateDestinationCoordinates($object);
             $this->updateDistance($object);
         }
     }
 }
 /**
  * Sets location coordinates before updating.
  *
  * Method will only call geocode() if one of the location fields was changed
  * by the user.
  *
  * @param LifecycleEventArgs $eventArgs
  */
 public function preUpdate(LifecycleEventArgs $eventArgs)
 {
     $object = $eventArgs->getEntity();
     if ($object instanceof LocationAwareInterface) {
         if (count(array_intersect(array_keys($eventArgs->getEntityChangeSet()), $this->locationFields)) > 0) {
             $this->updateCoordinates($object);
         }
     }
 }
Пример #3
0
 public function preUpdate(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     $token = $this->container->get('security.token_storage')->getToken();
     //OAuth
     if (!$token) {
         return;
     }
     $translator = $this->container->get('translator');
     $annotations = $this->container->get('annotations');
     $utils = $this->container->get('utils');
     $className = $utils->getObjectClass($entity);
     $changes = $args->getEntityChangeSet();
     $meta = $annotations->getAll($className);
     $log = '';
     $idx = 1;
     foreach ($changes as $field => $change) {
         $fieldName = ucfirst(strtolower($field));
         if (isset($meta['properties']['data'][$field])) {
             $fieldName = $meta['properties']['data'][$field]->getTitle();
         }
         // было
         if ($change[0] instanceof \DateTime) {
             $was = $change[0]->format('Y-m-d H:is');
         } else {
             $was = $change[0];
         }
         // стало
         if ($change[1] instanceof \DateTime) {
             $became = $change[1]->format('Y-m-d H:is');
         } else {
             $became = $change[1];
         }
         $log .= "<strong>" . $translator->trans($fieldName, [], 'global') . "</strong><br />";
         $log .= " - " . $translator->trans('It was', [], 'global') . ": " . $was . "<br />";
         $log .= " - " . $translator->trans('It became', [], 'global') . ": " . $became . "<br />";
         if ($idx < count($changes)) {
             $log .= "<br />";
             $idx++;
         }
     }
     if ($this->skipCondition($entity)) {
         $history = new History();
         $history->setCreatedAt(new \DateTime());
         $history->setUser($token->getUser());
         $history->setEntityCode($utils->getUnderscore($className));
         $history->setType('update');
         $history->setEntryId($entity->getId());
         $history->setLog($log);
         $this->history[] = $history;
     }
 }
 /**
  * preUpdatePayment
  * 
  * @param LifecycleEventArgs $args
  */
 protected function preUpdatePayment(LifecycleEventArgs $args)
 {
     $object = $args->getEntity();
     $em = $args->getEntityManager();
     $array_changes = $args->getEntityChangeSet();
     //echo"<pre>";print_r($array_changes['paymentSystem'][0]->getName());echo"</pre>";exit;
     if (isset($array_changes['amount']) or isset($array_changes['paymentSystem']) or isset($array_changes['flag'])) {
         $uow = $em->getUnitOfWork();
         $PaymentChanged = new \Rodina\CrmBundle\Entity\Abonent\PaymentChanged($object, isset($array_changes['amount']) ? $array_changes['amount'][0] : $object->getAmount(), isset($array_changes['comment']) ? $array_changes['comment'][0] : $object->getComment(), isset($array_changes['paySystem']) ? $array_changes['paySystem'][0] : $object->getPaySystem(), isset($array_changes['payType']) ? $array_changes['payType'][0] : $object->getPayType(), isset($array_changes['payServiceComment']) ? $array_changes['payServiceComment'][0] : $object->getPayServiceComment(), isset($array_changes['receipt']) ? $array_changes['receipt'][0] : $object->getReceipt(), isset($array_changes['payDate']) ? $array_changes['payDate'][0] : $object->getPayDate(), isset($array_changes['localDate']) ? $array_changes['localDate'][0] : $object->getLocalDate(), isset($array_changes['flag']) ? $array_changes['flag'][0] : $object->getFlag(), isset($array_changes['paymentSystem']) ? $array_changes['paymentSystem'][0] : $object->getPaymentSystem(), isset($array_changes['manager']) ? $array_changes['manager'][0] : $object->getManager());
         $em->persist($PaymentChanged);
         $object->addChange($PaymentChanged);
         $uow->recomputeSingleEntityChangeSet($em->getClassMetadata("Rodina\\CrmBundle\\Entity\\Abonent\\Payment"), $object);
     }
 }