src/Sulu/Bundle/ContactBundle/Controller/AccountController.php
public function getContactsAction($id, Request $request)
    {
        if ('true' == $request->get('flat')) {
            /* @var AccountInterface $account */
            $account = $this->getRepository()->findById($id);

            /** @var RestHelperInterface $restHelper */
            $restHelper = $this->getRestHelper();

            /** @var DoctrineListBuilderFactory $factory */
            $factory = $this->get('sulu_core.doctrine_list_builder_factory');

            $listBuilder = $factory->create(self::$accountContactEntityName);

            $fieldDescriptors = $this->getAccountContactFieldDescriptors();
            $restHelper->initializeListBuilder($listBuilder, $fieldDescriptors);

            $listBuilder->addSelectField($fieldDescriptors['contactId']);
            $listBuilder->setIdField($fieldDescriptors['id']);
            $listBuilder->where($fieldDescriptors['account'], $id);
            $listBuilder->sort($fieldDescriptors['lastName'], $listBuilder::SORTORDER_ASC);

            $values = $listBuilder->execute();

            foreach ($values as &$value) {
                // Substitute id since we are interested in the contact id not the accountContact id.
                $value['id'] = $value['contactId'];
                unset($value['contactId']);

                if (null != $account->getMainContact() && $value['id'] === $account->getMainContact()->getId()) {
                    $value['isMainContact'] = true;
                } else {
                    $value['isMainContact'] = false;
                }
            }

            $list = new ListRepresentation(
                $values,
                'contacts',
                'get_account_contacts',
                array_merge(['id' => $id], $request->query->all()),
                $listBuilder->getCurrentPage(),
                $listBuilder->getLimit(),
                $listBuilder->count()
            );
        } else {
            $contactManager = $this->getAccountManager();
            $locale = $this->getUser()->getLocale();
            $contacts = $contactManager->findContactsByAccountId($id, $locale, false);
            $list = new CollectionRepresentation($contacts, self::$contactEntityKey);
        }
        $view = $this->view($list, 200);

        return $this->handleView($view);
    }
public function getContactsAction($id, Request $request)
    {
        if ('true' == $request->get('flat')) {
            /* @var AccountInterface $account */
            $account = $this->getRepository()->findById($id);

            /** @var RestHelperInterface $restHelper */
            $restHelper = $this->getRestHelper();

            /** @var DoctrineListBuilderFactory $factory */
            $factory = $this->get('sulu_core.doctrine_list_builder_factory');

            $listBuilder = $factory->create(self::$accountContactEntityName);

            $fieldDescriptors = $this->getAccountContactFieldDescriptors();
            $restHelper->initializeListBuilder($listBuilder, $fieldDescriptors);

            $listBuilder->addSelectField($fieldDescriptors['contactId']);
            $listBuilder->setIdField($fieldDescriptors['id']);
            $listBuilder->where($fieldDescriptors['account'], $id);
            $listBuilder->sort($fieldDescriptors['lastName'], $listBuilder::SORTORDER_ASC);

            $values = $listBuilder->execute();

            foreach ($values as &$value) {
                // Substitute id since we are interested in the contact id not the accountContact id.
                $value['id'] = $value['contactId'];
                unset($value['contactId']);

                if (null != $account->getMainContact() && $value['id'] === $account->getMainContact()->getId()) {
                    $value['isMainContact'] = true;
                } else {
                    $value['isMainContact'] = false;
                }
            }

            $list = new ListRepresentation(
                $values,
                'contacts',
                'get_account_contacts',
                array_merge(['id' => $id], $request->query->all()),
                $listBuilder->getCurrentPage(),
                $listBuilder->getLimit(),
                $listBuilder->count()
            );
        } else {
            $contactManager = $this->getAccountManager();
            $locale = $this->getUser()->getLocale();
            $contacts = $contactManager->findContactsByAccountId($id, $locale, false);
            $list = new CollectionRepresentation($contacts, self::$contactEntityKey);
        }
        $view = $this->view($list, 200);

        return $this->handleView($view);
    }
public function getContactsAction ( $ id , Request $ request ) { if ( 'true' == $ request -> get ( 'flat' ) ) { /* @var AccountInterface $account */ $ account = $ this -> getRepository ( ) -> findById ( $ id ) ; /** @var RestHelperInterface $restHelper */ $ restHelper = $ this -> getRestHelper ( ) ; /** @var DoctrineListBuilderFactory $factory */ $ factory = $ this -> get ( 'sulu_core.doctrine_list_builder_factory' ) ; $ listBuilder = $ factory -> create ( self :: $ accountContactEntityName ) ; $ fieldDescriptors = $ this -> getAccountContactFieldDescriptors ( ) ; $ restHelper -> initializeListBuilder ( $ listBuilder , $ fieldDescriptors ) ; $ listBuilder -> addSelectField ( $ fieldDescriptors [ 'contactId' ] ) ; $ listBuilder -> setIdField ( $ fieldDescriptors [ 'id' ] ) ; $ listBuilder -> where ( $ fieldDescriptors [ 'account' ] , $ id ) ; $ listBuilder -> sort ( $ fieldDescriptors [ 'lastName' ] , $ listBuilder :: SORTORDER_ASC ) ; $ values = $ listBuilder -> execute ( ) ; foreach ( $ values as & $ value ) { // Substitute id since we are interested in the contact id not the accountContact id. $ value [ 'id' ] = $ value [ 'contactId' ] ; unset ( $ value [ 'contactId' ] ) ; if ( null != $ account -> getMainContact ( ) && $ value [ 'id' ] === $ account -> getMainContact ( ) -> getId ( ) ) { $ value [ 'isMainContact' ] = true ; } else { $ value [ 'isMainContact' ] = false ; } } $ list = new ListRepresentation ( $ values , 'contacts' , 'get_account_contacts' , array_merge ( [ 'id' => $ id ] , $ request -> query -> all ( ) ) , $ listBuilder -> getCurrentPage ( ) , $ listBuilder -> getLimit ( ) , $ listBuilder -> count ( ) ) ; } else { $ contactManager = $ this -> getAccountManager ( ) ; $ locale = $ this -> getUser ( ) -> getLocale ( ) ; $ contacts = $ contactManager -> findContactsByAccountId ( $ id , $ locale , false ) ; $ list = new CollectionRepresentation ( $ contacts , self :: $ contactEntityKey ) ; } $ view = $ this -> view ( $ list , 200 ) ; return $ this -> handleView ( $ view ) ; }
Lists all contacts of an account.
optional parameter 'flat' calls listAction.

@param int $id
@param Request $request

@return Response
Lists all contacts of an account . optional parameter flat calls listAction .