コード例 #1
0
 /**
  * Create a filter url for the field named $title
  * and identified by $key which consists of
  * alias and field. $options holds all link
  * parameters like "alt, class" and so on.
  *
  * $key example: "article.title"
  *
  * @param SlidingPagination $pagination
  * @param array             $fields
  * @param array             $options
  * @param array             $params
  *
  * @return array
  */
 public function filter(SlidingPagination $pagination, array $fields, $options = array(), $params = array())
 {
     $options = array_merge(array('absolute' => defined('Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface::ABSOLUTE_PATH') ? UrlGeneratorInterface::ABSOLUTE_PATH : false, 'translationParameters' => array(), 'translationDomain' => null, 'button' => 'Filter'), $options);
     $params = array_merge($pagination->getParams(), $params);
     $params[$pagination->getPaginatorOption('pageParameterName')] = 1;
     // reset to 1 on filter
     $filterFieldName = $pagination->getPaginatorOption('filterFieldParameterName');
     $filterValueName = $pagination->getPaginatorOption('filterValueParameterName');
     $selectedField = isset($params[$filterFieldName]) ? $params[$filterFieldName] : null;
     $selectedValue = isset($params[$filterValueName]) ? $params[$filterValueName] : null;
     $action = $this->router->generate($pagination->getRoute(), $params, $options['absolute']);
     foreach ($fields as $field => $title) {
         $fields[$field] = $this->translator->trans($title, $options['translationParameters'], $options['translationDomain']);
     }
     $options['button'] = $this->translator->trans($options['button'], $options['translationParameters'], $options['translationDomain']);
     unset($options['absolute'], $options['translationDomain'], $options['translationParameters']);
     return array_merge($pagination->getPaginatorOptions(), $pagination->getCustomParameters(), compact('fields', 'action', 'filterFieldName', 'filterValueName', 'selectedField', 'selectedValue', 'options'));
 }