Beispiel #1
0
 /**
  * {@inheritdoc}
  *
  * @todo: It seems that we need to implement a view handler for FOS Rest Bundle
  * @todo: https://magecore.atlassian.net/browse/BAP-8351
  */
 protected function buildResponse($data, $action, $contextValues = [], $status = Codes::HTTP_OK)
 {
     if ($status === Codes::HTTP_OK) {
         $format = $this->getRequest()->getRequestFormat();
         if ($format === 'binary') {
             if ($action !== self::ACTION_READ) {
                 throw new BadRequestHttpException('Only single file can be returned in the binary format');
             }
             return $this->getBinaryResponse($data, $action, $contextValues, $status);
         } else {
             if ($data instanceof View) {
                 $data->setData($this->postProcessResponseData($data->getData(), $action, $format));
             } elseif (!empty($data)) {
                 $data = $this->postProcessResponseData($data, $action, $format);
             }
             return parent::buildResponse($data, $action, $contextValues, $status);
         }
     } else {
         return parent::buildResponse($data, $action, $contextValues, $status);
     }
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 protected function getPreparedItem($entity, $resultFields = [])
 {
     /** @var Audit $entity */
     $result = parent::getPreparedItem($entity, $resultFields);
     // process relations
     $result['user'] = $entity->getUser() ? $entity->getUser()->getId() : null;
     // prevent BC breaks
     // @deprecated since 1.4.1
     $result['object_class'] = $result['objectClass'];
     $result['object_name'] = $result['objectName'];
     $result['username'] = $entity->getUser() ? $entity->getUser()->getUsername() : null;
     unset($result['fields']);
     $result['data'] = $entity->getData();
     return $result;
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 protected function transformEntityField($field, &$value)
 {
     switch ($field) {
         case 'fromEmailAddress':
             if ($value) {
                 /** @var EmailAddress $value */
                 $value = $value->getEmail();
             }
             break;
         case 'folder':
             if ($value) {
                 /** @var EmailFolder $value */
                 $value = $value->getFullName();
             }
             break;
         case 'emailBody':
             if ($value) {
                 /** @var EmailBody $value */
                 $value = array('content' => $value->getBodyContent(), 'isText' => $value->getBodyIsText(), 'hasAttachments' => $value->getHasAttachments());
             }
             break;
         case 'recipients':
             if ($value) {
                 $result = array();
                 /** @var $recipient EmailRecipient */
                 foreach ($value as $index => $recipient) {
                     $result[$index] = array('name' => $recipient->getName(), 'type' => $recipient->getType(), 'emailAddress' => $recipient->getEmailAddress() ? $recipient->getEmailAddress()->getEmail() : null);
                 }
                 $value = $result;
             }
             break;
         default:
             parent::transformEntityField($field, $value);
     }
 }