<commit_before><?php
/**
 * FACT-Finder PHP Framework
 *
 * @category  Library
 * @package   FACTFinder\Xml67
 * @copyright Copyright (c) 2012 Omikron Data Quality GmbH (www.omikron.net)
 */

/**
 * search adapter using the xml interface. expects a xml formated string from the dataprovider
 *
 * @author    <NAME> <<EMAIL>>
 * @version   $Id: SearchAdapter.php 25985 2010-06-30 15:31:53Z rb $
 * @package   FACTFinder\Xml67
 */
class FACTFinder_Xml67_SearchAdapter extends FACTFinder_Xml66_SearchAdapter
{	
    /**
     * @return array of FACTFinder_Campaign objects
     */
    protected function createCampaigns()
    {
        $campaigns = array();
        $xmlResult = $this->getData();

        if (!empty($xmlResult->campaigns)) {
            $encodingHandler = $this->getEncodingHandler();
			$paramsParser = $this->getParamsParser();
			
            foreach ($xmlResult->campaigns->campaign AS $xmlCampaign) {
                //get redirect
                $redirectUrl = '';
                if ($xmlCampaign->attributes()->flavour == 'REDIRECT') {
                    $redirectUrl = $encodingHandler->encodeServerUrlForPageUrl(strval($xmlCampaign->target->destination));
                }

                $campaign = FF::getInstance('campaign',
                    $encodingHandler->encodeServerContentForPage(strval($xmlCampaign->attributes()->name)),
                    $encodingHandler->encodeServerContentForPage(strval($xmlCampaign->attributes()->category)),
                    $redirectUrl
                );

                // get feedback
				
				if ($xmlCampaign->attributes()->flavour == 'FEEDBACK') {
				
					// here is the new feature: getting feedback texts from labels instead of number indices, if available
					if (!empty($xmlCampaign->feedback)) {
						$feedback = array();
						foreach ($xmlCampaign->feedback->text as $text) {
							if(isset($text->attributes()->label)) {
								$label = trim($text->attributes()->label);
							} else {
								$label = trim($text->attributes()->nr);
							}
							$feedback[$label] = $encodingHandler->encodeServerContentForPage((string)$text);
						}
						$campaign->addFeedback($feedback);
					}

					//get pushed products
					if (!empty($xmlCampaign->pushedProducts)) {
						$pushedProducts = array();
						foreach ($xmlCampaign->pushedProducts->product AS $xmlProduct) {
							$product = FF::getInstance('record', $xmlProduct->attributes()->id, 100);

							// fetch product values
							$fieldValues = array();
							foreach($xmlProduct->field AS $current_field){
								$currentFieldname = (string) $current_field->attributes()->name;
								$fieldValues[$currentFieldname] = (string) $current_field;
							}
							$product->setValues($encodingHandler->encodeServerContentForPage($fieldValues));
							$pushedProducts[] = $product;
						}
						$campaign->addPushedProducts($pushedProducts);
					}
				}
				
				//get advisor
				if ($xmlCampaign->attributes()->flavour == 'ADVISOR') {
					$activeQuestions = array();
					
					// The active questions can still be empty if we have already moved down the whole question tree (while the search query still fulfills the campaign condition)
					if (!empty($xmlCampaign->advisor->activeQuestions)) {
						foreach($xmlCampaign->advisor->activeQuestions->question AS $xmlQuestion) {
							$activeQuestions[] = $this->loadAdvisorQuestion($xmlQuestion);
						}
					}
					$campaign->addActiveQuestions($activeQuestions);
					
					// Fetch advisor tree if it exists
					$advisorTree = array();
					
					if (!empty($xmlCampaign->advisor->advisorTree)) {
						foreach($xmlCampaign->advisor->advisorTree->question AS $xmlQuestion) {
							$advisorTree[] = $this->loadAdvisorQuestion($xmlQuestion, true);
						}
					}
					$campaign->addToAdvisorTree($advisorTree);
				}

                $campaigns[] = $campaign;
            }
        }
        $campaignIterator = FF::getInstance('campaignIterator', $campaigns);
        return $campaignIterator;
    }
	
	protected function loadAdvisorQuestion($xmlQuestion, $recursive = false) {
		$encodingHandler = $this->getEncodingHandler();
		$paramsParser = $this->getParamsParser();
		
		$answers = array();
		
		// Fetch answers. Follow-up questions are ignored here.
		foreach($xmlQuestion->answer AS $xmlAnswer) {
			$text = $encodingHandler->encodeServerContentForPage((string)$xmlAnswer->text);
			$params = $paramsParser->createPageLink($paramsParser->parseParamsFromResultString($xmlAnswer->params));
			$subquestions = array();
			if ($recursive) {
				foreach($xmlAnswer->question AS $xmlSubquestion) {
					$subquestions[] = $this->loadAdvisorQuestion($xmlSubquestion, true);
				}
			}
			$answer = FF::getInstance('advisorAnswer', $text, $params, $subquestions);
			$answers[] = $answer;
		}
		
		return FF::getInstance('advisorQuestion', $encodingHandler->encodeServerContentForPage((string)$xmlQuestion->text), $answers);
	}
}<commit_msg>[~TASK] Updated FF PHP framework.<commit_after><?php
/**
 * FACT-Finder PHP Framework
 *
 * @category  Library
 * @package   FACTFinder\Xml67
 * @copyright Copyright (c) 2012 Omikron Data Quality GmbH (www.omikron.net)
 */

/**
 * search adapter using the xml interface. expects a xml formated string from the dataprovider
 *
 * @author    <NAME> <<EMAIL>>
 * @version   $Id: SearchAdapter.php 25985 2010-06-30 15:31:53Z rb $
 * @package   FACTFinder\Xml67
 */
class FACTFinder_Xml67_SearchAdapter extends FACTFinder_Xml66_SearchAdapter
{	
    /**
     * @return array of FACTFinder_Campaign objects
     */
    protected function createCampaigns()
    {
        $campaigns = array();
        $xmlResult = $this->getData();

        if (!empty($xmlResult->campaigns)) {
            $encodingHandler = $this->getEncodingHandler();
			$paramsParser = $this->getParamsParser();
			
            foreach ($xmlResult->campaigns->campaign AS $xmlCampaign) {
                //get redirect
                $redirectUrl = '';
                if ($xmlCampaign->attributes()->flavour == 'REDIRECT') {
                    $redirectUrl = $encodingHandler->encodeServerUrlForPageUrl(strval($xmlCampaign->target->destination));
                }

                $campaign = FF::getInstance('campaign',
                    $encodingHandler->encodeServerContentForPage(strval($xmlCampaign->attributes()->name)),
                    $encodingHandler->encodeServerContentForPage(strval($xmlCampaign->attributes()->category)),
                    $redirectUrl
                );

                // get feedback
				
				if ($xmlCampaign->attributes()->flavour == 'FEEDBACK') {
				
					// here is the new feature: getting feedback texts from labels instead of number indices, if available
					if (!empty($xmlCampaign->feedback)) {
						$feedback = array();
						foreach ($xmlCampaign->feedback->text as $text) {
							if(isset($text->attributes()->label)) {
								$label = trim($text->attributes()->label);
                                $feedback[$label] = $encodingHandler->encodeServerContentForPage((string)$text);
							}
                            if(isset($text->attributes()->nr)) {
								$label = trim($text->attributes()->nr);
                                $feedback[$label] = $encodingHandler->encodeServerContentForPage((string)$text);
							}
						}
						$campaign->addFeedback($feedback);
					}

					//get pushed products
					if (!empty($xmlCampaign->pushedProducts)) {
						$pushedProducts = array();
						foreach ($xmlCampaign->pushedProducts->product AS $xmlProduct) {
							$product = FF::getInstance('record', $xmlProduct->attributes()->id, 100);

							// fetch product values
							$fieldValues = array();
							foreach($xmlProduct->field AS $current_field){
								$currentFieldname = (string) $current_field->attributes()->name;
								$fieldValues[$currentFieldname] = (string) $current_field;
							}
							$product->setValues($encodingHandler->encodeServerContentForPage($fieldValues));
							$pushedProducts[] = $product;
						}
						$campaign->addPushedProducts($pushedProducts);
					}
				}
				
				//get advisor
				if ($xmlCampaign->attributes()->flavour == 'ADVISOR') {
					$activeQuestions = array();
					
					// The active questions can still be empty if we have already moved down the whole question tree (while the search query still fulfills the campaign condition)
					if (!empty($xmlCampaign->advisor->activeQuestions)) {
						foreach($xmlCampaign->advisor->activeQuestions->question AS $xmlQuestion) {
							$activeQuestions[] = $this->loadAdvisorQuestion($xmlQuestion);
						}
					}
					$campaign->addActiveQuestions($activeQuestions);
					
					// Fetch advisor tree if it exists
					$advisorTree = array();
					
					if (!empty($xmlCampaign->advisor->advisorTree)) {
						foreach($xmlCampaign->advisor->advisorTree->question AS $xmlQuestion) {
							$advisorTree[] = $this->loadAdvisorQuestion($xmlQuestion, true);
						}
					}
					$campaign->addToAdvisorTree($advisorTree);
				}

                $campaigns[] = $campaign;
            }
        }
        $campaignIterator = FF::getInstance('campaignIterator', $campaigns);
        return $campaignIterator;
    }
	
	protected function loadAdvisorQuestion($xmlQuestion, $recursive = false) {
		$encodingHandler = $this->getEncodingHandler();
		$paramsParser = $this->getParamsParser();
		
		$answers = array();
		
		// Fetch answers. Follow-up questions are ignored here.
		foreach($xmlQuestion->answer AS $xmlAnswer) {
			$text = $encodingHandler->encodeServerContentForPage((string)$xmlAnswer->text);
			$params = $paramsParser->createPageLink($paramsParser->parseParamsFromResultString($xmlAnswer->params));
			$subquestions = array();
			if ($recursive) {
				foreach($xmlAnswer->question AS $xmlSubquestion) {
					$subquestions[] = $this->loadAdvisorQuestion($xmlSubquestion, true);
				}
			}
			$answer = FF::getInstance('advisorAnswer', $text, $params, $subquestions);
			$answers[] = $answer;
		}
		
		return FF::getInstance('advisorQuestion', $encodingHandler->encodeServerContentForPage((string)$xmlQuestion->text), $answers);
	}
}
{'fraction_non_alphanumeric': 0.13835670551056686, 'fraction_numerical': 0.006715386134702746, 'mean_word_length': 3.0011853022520745, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 150, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 72}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3214225', 'n_tokens_mistral': 3515, 'n_tokens_neox': 2690, 'n_words': 534}