/** * Creates a new instance of a filter based on a configuration * of a filter registered in this manager with the given name * * @param string $name A filter name * @param array $params An additional parameters of a new filter * @return FilterInterface * @throws \Exception */ public function createFilter($name, array $params = null) { $defaultParams = ['type' => $name]; if ($params !== null && !empty($params)) { $params = array_merge($defaultParams, $params); } switch ($name) { case 'string': $filter = new StringFilter($this->formFactory, new FilterUtility()); break; case 'datetime': $filter = new DateTimeRangeFilter($this->formFactory, new FilterUtility()); break; default: throw new \Exception(sprintf('Not implementer in this test filter: "%s".', $name)); } $filter->init($name, $params); return $filter; }
/** * @param QueryBuilder $qb * @param array $filterData * @param string $rangeField * @param string $activityListAlias */ public function addFiltersToQuery(QueryBuilder $qb, $filterData, $rangeField = 'updatedAt', $activityListAlias = 'activity') { $dataSourceAdapter = new OrmFilterDatasourceAdapter($qb); if (isset($filterData['dateRange'])) { $this->dateTimeRangeFilter->init($rangeField, ['data_name' => sprintf('%s.%s', $activityListAlias, $rangeField)]); $datetimeForm = $this->dateTimeRangeFilter->getForm(); if (!$datetimeForm->isSubmitted()) { $datetimeForm->submit($filterData['dateRange']); } $this->dateTimeRangeFilter->apply($dataSourceAdapter, $datetimeForm->getData()); } if (isset($filterData['activityType'])) { $routingHelper = $this->routingHelper; $filterData['activityType']['value'] = array_map(function ($activityClass) use($routingHelper) { return $routingHelper->resolveEntityClass($activityClass); }, $filterData['activityType']['value']); $this->choiceFilter->init('relatedActivityClass', ['data_name' => sprintf('%s.relatedActivityClass', $activityListAlias), 'options' => ['field_options' => ['multiple' => true, 'choices' => array_flip($this->chainProvider->getSupportedActivities())]]]); $typeForm = $this->choiceFilter->getForm(); if (!$typeForm->isSubmitted()) { $typeForm->submit($filterData['activityType']); } $this->choiceFilter->apply($dataSourceAdapter, $typeForm->getData()); } }
/** * Creates a new instance of a filter based on a configuration * of a filter registered in this manager with the given name * * @param string $name A filter name * @param array $params An additional parameters of a new filter * * @return FilterInterface * @throws \Exception */ public function createFilter($name, array $params = null) { $defaultParams = ['type' => $name]; if ($params !== null && !empty($params)) { $params = array_merge($defaultParams, $params); } switch ($name) { case 'string': $filter = new StringFilter($this->formFactory, new FilterUtility()); break; case 'datetime': $localeSetting = $this->getMockBuilder('Oro\\Bundle\\LocaleBundle\\Model\\LocaleSettings')->disableOriginalConstructor()->getMock(); $localeSetting->expects($this->any())->method('getTimeZone')->will($this->returnValue('UTC')); $filter = new DateTimeRangeFilter($this->formFactory, new FilterUtility(), new DateFilterUtility($localeSetting)); break; default: throw new \Exception(sprintf('Not implementer in this test filter: "%s".', $name)); } $filter->init($name, $params); return $filter; }