/** * Builds a filter list based on params. * @param array $params * @return App_ListFilter | null */ public function buildFilterList(array $params) { if (!isset($params['type']) || !in_array($params['type'], array(OrgMasterModel::ORG_TYPE, OrgServiceProviderModel::ORG_TYPE, OrgCustomerModel::ORG_TYPE, OrgAggregatorModel::ORG_TYPE))) { return; } $orgType = $params['type']; unset($params['type']); if ($orgType === OrgServiceProviderModel::ORG_TYPE && \App::getOrgUserLogged()->getType() === OrgServiceProviderModel::ORG_TYPE) { if (!isset($params[ServiceProviderFilterFields::SERVICE_PROVIDER_ID_FOR_COMMERCIALS])) { $params[ServiceProviderFilterFields::SERVICE_PROVIDER_ID_FOR_COMMERCIALS] = \App::getOrgUserLogged()->id; } } $factory = new \App_ListFilter_FilterFactory(); $filterFieldsMap = array(OrgMasterModel::ORG_TYPE => '\\Application\\Model\\Filter\\Organization\\MasterFilterFields', OrgServiceProviderModel::ORG_TYPE => '\\Application\\Model\\Filter\\Organization\\ServiceProviderFilterFields', OrgCustomerModel::ORG_TYPE => '\\Application\\Model\\Filter\\Organization\\CustomerFilterFields', OrgAggregatorModel::ORG_TYPE => '\\Application\\Model\\Filter\\Organization\\AggregatorFilterFields'); $filterFieldsValidatorsMap = array(OrgMasterModel::ORG_TYPE => MasterFilterFields::getValidatorSpec(), OrgServiceProviderModel::ORG_TYPE => ServiceProviderFilterFields::getValidatorSpec(), OrgCustomerModel::ORG_TYPE => CustomerFilterFields::getValidatorSpec(), OrgAggregatorModel::ORG_TYPE => AggregatorFilterFields::getValidatorSpec()); if (isset($filterFieldsMap[$orgType])) { $class = $filterFieldsMap[$orgType]; $factory->setWhiteList($class::getWhiteList()); } $filterList = $factory->constructFilter($params); if (isset($class)) { $filterList->setResourceId($class::getResourceId()); } \App::log()->debug('Unused filters [' . implode(',', $factory->getUnusedList()) . ']'); $filterList->setValidators($filterFieldsValidatorsMap[$orgType]); return $filterList->isValid() ? $filterList : null; }