/**
  * Format the result data.
  *
  * @param AjaxChoiceListFormatterInterface $formatter      The ajax formatter
  * @param ChoiceListView                   $choiceListView The choice list view
  *
  * @return array The formatted result data
  */
 public static function formatResultData(AjaxChoiceListFormatterInterface $formatter, ChoiceListView $choiceListView)
 {
     $result = array();
     foreach ($choiceListView->choices as $i => $choiceView) {
         if ($choiceView instanceof ChoiceGroupView) {
             $group = $formatter->formatGroupChoice($choiceView);
             foreach ($choiceView->choices as $j => $subChoiceView) {
                 $group = $formatter->addChoiceInGroup($group, $subChoiceView);
             }
             if (!$formatter->isEmptyGroup($group)) {
                 $result[] = $group;
             }
         } else {
             $result[] = $formatter->formatChoice($choiceView);
         }
     }
     return $result;
 }
 /**
  * Gets the ajax data.
  *
  * @param Request                          $request
  * @param AjaxChoiceLoaderInterface        $choiceLoader
  * @param AjaxChoiceListFormatterInterface $formatter
  * @param string                           $prefix
  *
  * @return array
  */
 public static function getData(Request $request, AjaxChoiceLoaderInterface $choiceLoader, AjaxChoiceListFormatterInterface $formatter, $prefix = '')
 {
     $ajaxIds = $request->get($prefix . 'ids', '');
     if (is_string($ajaxIds) && '' !== $ajaxIds) {
         $ajaxIds = explode(',', $ajaxIds);
     } elseif (!is_array($ajaxIds) || in_array($ajaxIds, array(null, ''))) {
         $ajaxIds = array();
     }
     $choiceLoader->setPageSize(intval($request->get($prefix . 'ps', $choiceLoader->getPageSize())));
     $choiceLoader->setPageNumber(intval($request->get($prefix . 'pn', $choiceLoader->getPageNumber())));
     $choiceLoader->setSearch($request->get($prefix . 's', ''));
     $choiceLoader->setIds($ajaxIds);
     $choiceLoader->reset();
     return $formatter->formatResponseData($choiceLoader);
 }
 public function testFormatGroupResponseData()
 {
     $this->init($this->getMockChoiceGroups());
     $res = $this->formatter->formatResponseData($this->choiceLoader);
     $this->assertEquals($this->getValidGroupResponseData(), $res);
 }