Bridge/Symfony/Serializer/Normalizer/TicketNormalizer.php
public function normalize($ticket, $format = null, array $context = [])
    {
        if ($this->contextHasGroup(['Default', 'Ticket'], $context)) {
            $formatter = $this->getFormatter();
            $customer = $ticket->getCustomer();

            $data = [
                'id'           => $ticket->getId(),
                'number'       => $ticket->getNumber(),
                'state'        => $ticket->getState(),
                'subject'      => $ticket->getSubject(),
                // TODO customer, order, quote ?
                'created_at'   => ($date = $ticket->getCreatedAt()) ? $date->format('Y-m-d H:i:s') : null,
                'f_created_at' => ($date = $ticket->getCreatedAt()) ? $formatter->dateTime($date) : null,
                'updated_at'   => ($date = $ticket->getUpdatedAt()) ? $date->format('Y-m-d H:i:s') : null,
                'f_updated_at' => ($date = $ticket->getUpdatedAt()) ? $formatter->dateTime($date) : null,
                'customer' => [
                    'id' => $customer->getId(),
                    'first_name' => $customer->getFirstName(),
                    'last_name' => $customer->getLastName(),
                    'company' => $customer->getCompany(),
                ],
                'orders' => [],
                'quotes' => [],
            ];

            foreach ($ticket->getQuotes() as $quote) {
                $data['quotes'][] = [
                    'id'     => $quote->getId(),
                    'number' => $quote->getNumber(),
                ];
            }

            foreach ($ticket->getOrders() as $order) {
                $data['orders'][] = [
                    'id'     => $order->getId(),
                    'number' => $order->getNumber(),
                ];
            }

            if ($this->contextHasGroup('Ticket', $context)) {
                $data += ['messages' => []];

                foreach ($this->filterMessages($ticket) as $message) {
                    $data['messages'][] = $this->normalizeObject($message, $format, $context);
                }
            }

            return $data;
        }

        return parent::normalize($ticket, $format, $context);
    }
public function normalize($ticket, $format = null, array $context = [])
    {
        if ($this->contextHasGroup(['Default', 'Ticket'], $context)) {
            $formatter = $this->getFormatter();
            $customer = $ticket->getCustomer();

            $data = [
                'id'           => $ticket->getId(),
                'number'       => $ticket->getNumber(),
                'state'        => $ticket->getState(),
                'subject'      => $ticket->getSubject(),
                // TODO customer, order, quote ?
                'created_at'   => ($date = $ticket->getCreatedAt()) ? $date->format('Y-m-d H:i:s') : null,
                'f_created_at' => ($date = $ticket->getCreatedAt()) ? $formatter->dateTime($date) : null,
                'updated_at'   => ($date = $ticket->getUpdatedAt()) ? $date->format('Y-m-d H:i:s') : null,
                'f_updated_at' => ($date = $ticket->getUpdatedAt()) ? $formatter->dateTime($date) : null,
                'customer' => [
                    'id' => $customer->getId(),
                    'first_name' => $customer->getFirstName(),
                    'last_name' => $customer->getLastName(),
                    'company' => $customer->getCompany(),
                ],
                'orders' => [],
                'quotes' => [],
            ];

            foreach ($ticket->getQuotes() as $quote) {
                $data['quotes'][] = [
                    'id'     => $quote->getId(),
                    'number' => $quote->getNumber(),
                ];
            }

            foreach ($ticket->getOrders() as $order) {
                $data['orders'][] = [
                    'id'     => $order->getId(),
                    'number' => $order->getNumber(),
                ];
            }

            if ($this->contextHasGroup('Ticket', $context)) {
                $data += ['messages' => []];

                foreach ($this->filterMessages($ticket) as $message) {
                    $data['messages'][] = $this->normalizeObject($message, $format, $context);
                }
            }

            return $data;
        }

        return parent::normalize($ticket, $format, $context);
    }
public function normalize ( $ ticket , $ format = null , array $ context = [ ] ) { if ( $ this -> contextHasGroup ( [ 'Default' , 'Ticket' ] , $ context ) ) { $ formatter = $ this -> getFormatter ( ) ; $ customer = $ ticket -> getCustomer ( ) ; $ data = [ 'id' => $ ticket -> getId ( ) , 'number' => $ ticket -> getNumber ( ) , 'state' => $ ticket -> getState ( ) , 'subject' => $ ticket -> getSubject ( ) , // TODO customer, order, quote ? 'created_at' => ( $ date = $ ticket -> getCreatedAt ( ) ) ? $ date -> format ( 'Y-m-d H:i:s' ) : null , 'f_created_at' => ( $ date = $ ticket -> getCreatedAt ( ) ) ? $ formatter -> dateTime ( $ date ) : null , 'updated_at' => ( $ date = $ ticket -> getUpdatedAt ( ) ) ? $ date -> format ( 'Y-m-d H:i:s' ) : null , 'f_updated_at' => ( $ date = $ ticket -> getUpdatedAt ( ) ) ? $ formatter -> dateTime ( $ date ) : null , 'customer' => [ 'id' => $ customer -> getId ( ) , 'first_name' => $ customer -> getFirstName ( ) , 'last_name' => $ customer -> getLastName ( ) , 'company' => $ customer -> getCompany ( ) , ] , 'orders' => [ ] , 'quotes' => [ ] , ] ; foreach ( $ ticket -> getQuotes ( ) as $ quote ) { $ data [ 'quotes' ] [ ] = [ 'id' => $ quote -> getId ( ) , 'number' => $ quote -> getNumber ( ) , ] ; } foreach ( $ ticket -> getOrders ( ) as $ order ) { $ data [ 'orders' ] [ ] = [ 'id' => $ order -> getId ( ) , 'number' => $ order -> getNumber ( ) , ] ; } if ( $ this -> contextHasGroup ( 'Ticket' , $ context ) ) { $ data += [ 'messages' => [ ] ] ; foreach ( $ this -> filterMessages ( $ ticket ) as $ message ) { $ data [ 'messages' ] [ ] = $ this -> normalizeObject ( $ message , $ format , $ context ) ; } } return $ data ; } return parent :: normalize ( $ ticket , $ format , $ context ) ; }
@inheritDoc

@param TicketInterface $ticket
@inheritDoc