/** * @param mixed[] $filterData An associative array corresponding to the JSON * for a single slider filter. * @return \FACTFinder\Data\SliderFilter */ private function createSliderFilter(array $filterData) { // For sliders, FACT-Finder appends a filter parameter without value to // the 'searchParams' field, which is to be filled with the selected // minimum and maximum like 'filterValue=min-max'. // We split that parameter off, and treat it separately to ensure that // it stays the last parameter when converted to a client URL. preg_match('/ (.*) # match and capture as much of the query as possible [?&]filter # match "?filter" or "&filter" literally ([^&=]*) # group 2, the field name =(?=$|&) # make sure there is a "=" followed by the end of # the string or another parameter (.*) # match the remainder of the query /x', $filterData['searchParams'], $matches); if (!empty($matches)) { $query = $matches[1] . $matches[3]; $fieldName = $matches[2]; } else { // The URL of searchParams was not as expected, propably the current filter was not // added as an empty parameter. Therefore no need to remove it and we can use full searchParams URL. $query = $filterData['searchParams']; $fieldName = $filterData['associatedFieldName']; } if (urldecode($fieldName) != $filterData['associatedFieldName']) { $this->log->warn('Filter parameter of slider does not correspond ' . 'to transmitted "associatedFieldName". Parameter: ' . "{$fieldName}. Field name: " . $filterData['associatedFieldName'] . '.'); } $filterLink = $this->convertServerQueryToClientUrl($query); return FF::getInstance('Data\\SliderFilter', $filterLink, $fieldName, $filterData['absoluteMinValue'], $filterData['absoluteMaxValue'], $filterData['selectedMinValue'], $filterData['selectedMaxValue']); }
private function createCampaigns() { $campaigns = array(); if (!isset($this->parameters['productNumber'])) { $this->log->warn('Product campaigns cannot be loaded without a product ID. ' . 'Use setProductIDs() or addProductIDs() first.'); } else { if ($this->isShoppingCartCampaign) { $jsonData = $this->getResponseContent(); } else { // Use only the first product ID $productIDs = $this->parameters['productNumber']; if (is_array($productIDs)) { $this->parameters['productNumber'] = $productIDs[0]; } $jsonData = $this->getResponseContent(); // Restore IDs $this->parameters['productNumber'] = $productIDs; } foreach ($jsonData as $campaignData) { $campaign = $this->createEmptyCampaignObject($campaignData); $this->fillCampaignWithFeedback($campaign, $campaignData); $this->fillCampaignWithPushedProducts($campaign, $campaignData); $campaigns[] = $campaign; } } $campaignIterator = FF::getInstance('Data\\CampaignIterator', $campaigns); return $campaignIterator; }
/** * Loads parameters from the request and returns a Parameter object. * Also takes care of encoding conversion if necessary. However, the * parameters themselves are not converted (that is ignore, require and * mapping directives in the configuration are not taken into account). * * You won't usually need this method unless you really want to get access * to some parameters that would be ignored or mapped otherwise. * * For use with any other part of the library, use getRequestParameters() * instead, which converts the parameters for usage with the server. * * @return Parameters Array of UTF-8 encoded parameters */ public function getClientRequestParameters() { if (is_null($this->clientRequestParameters)) { if (isset($_SERVER['QUERY_STRING'])) { // TODO: Respect variables_order so that conflicting variables // lead to the same result as in $_REQUEST (save for // $_COOKIE variables). This todo also goes for the second // alternative. $parameters = FF::getInstance('Util\\Parameters', $_SERVER['QUERY_STRING']); $data = $_POST; if (!empty($data)) { foreach ($data as $key => $value) { if (is_array($value)) { unset($data[$key]); } } } $parameters->setAll($data); } else { if (isset($_GET)) { $this->log->warn('$_SERVER[\'QUERY_STRING\'] is not available. ' . 'Using $_GET instead. This may cause problems ' . 'if the query string contains parameters with ' . 'non-[a-zA-Z0-9_] characters.'); // Don't use $_REQUEST, because it also contains $_COOKIE. // Note that we don't have to URL decode here, because _GET is // already URL decoded. $parameters = FF::getInstance('Util\\Parameters', array_merge($_POST, $_GET)); } else { // For CLI use: $parameters = FF::getInstance('Util\\Parameters'); } } // Convert encoding and then the parameters themselves $this->clientRequestParameters = $this->encodingConverter != null ? $this->encodingConverter->decodeClientUrlData($parameters) : $parameters; } return $this->clientRequestParameters; }
/** * Get URL with HTTP authentication. * * @param string $action The action to be targeted on the FACT-Finder * server. * @param FACTFinder\Util\Parameters $parameters The parameters object from * which to build the URL. * * @return string The full URL. */ protected function getHttpAuthenticationUrl($action, \FACTFinder\Util\Parameters $parameters) { $configuration = $this->configuration; $authentication = sprintf('%s:%s@', $configuration->getUserName(), $configuration->getPassword()); if ($authentication == ':@') { $authentication = ''; } $url = $this->buildAddress($action, true) . (count($parameters) ? '?' : '') . $parameters->toJavaQueryString(); $this->log->info("Request Url: " . $url); return $url; }
private function createComparedRecords() { $records = array(); $parameters = $this->request->getParameters(); if (!isset($parameters['ids'])) { $this->log->warn('Compared records cannot be loaded without product IDs. ' . 'Use setProductIDs() first.'); } else { $position = 1; $jsonData = $this->getResponseContent(); foreach ($jsonData['records'] as $recordData) { $records[] = FF::getInstance('Data\\Record', (string) $recordData['id'], $recordData['record'], 100.0, $position++); } } return FF::getInstance('Data\\Result', $records, null, count($records)); }
private function createSimilarRecords() { $records = array(); $parameters = $this->request->getParameters(); if (!isset($parameters['id'])) { $this->log->warn('Similar records cannot be loaded without a product ID. ' . 'Use setProductID() first.'); } else { $position = 1; $jsonData = $this->getResponseContent(); if (parent::isValidResponse($jsonData)) { foreach ($jsonData['records'] as $recordData) { $records[] = $this->createRecord($recordData, $position++); } } } return FF::getInstance('Data\\Result', $records, null, count($records)); }
private function createRecommendations() { $records = array(); $parameters = $this->request->getParameters(); if (!isset($parameters['id'])) { $this->log->warn('Recommendations cannot be loaded without a product ID. ' . 'Use setProductIDs() or addProductIDs() first.'); } else { $position = 1; foreach ($this->getResponseContent() as $recordData) { if ($this->idsOnly) { $records[] = $this->createSparseRecord($recordData); } else { $records[] = $this->createRecord($recordData, $position++); } } } return FF::getInstance('Data\\Result', $records, null, count($records)); }