/** * 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); }
/** * {@inheritdoc} */ public function formatResponseData(AjaxChoiceLoaderInterface $choiceLoader) { $view = $this->choiceListFactory->createView($choiceLoader->loadPaginatedChoiceList(), null, $choiceLoader->getLabel()); return array('size' => $choiceLoader->getSize(), 'pageNumber' => $choiceLoader->getPageNumber(), 'pageSize' => $choiceLoader->getPageSize(), 'search' => $choiceLoader->getSearch(), 'items' => FormatterUtil::formatResultData($this, $view)); }
protected function init(ChoiceListInterface $choiceList) { $this->choiceLoader->expects($this->any())->method('getSize')->will($this->returnValue(count($choiceList->getChoices()))); $this->choiceLoader->expects($this->any())->method('loadPaginatedChoiceList')->will($this->returnValue($choiceList)); }