コード例 #1
0
 /**
  * @param \Searchperience\Api\Client\Domain\AbstractEntity $enrichment
  * @return array
  */
 protected function buildRequestArray(\Searchperience\Api\Client\Domain\AbstractEntity $enrichment)
 {
     $valueArray = array();
     if (!is_null($enrichment->getId())) {
         $valueArray['id'] = $enrichment->getId();
     }
     if (!is_null($enrichment->getDescription())) {
         $valueArray['description'] = $enrichment->getDescription();
     }
     if (!is_null($enrichment->getEnabled())) {
         $valueArray['status'] = $enrichment->getEnabled() ? 1 : 0;
     }
     if (!is_null($enrichment->getTitle())) {
         $valueArray['title'] = $enrichment->getTitle();
     }
     if (!is_null($enrichment->getAddBoost())) {
         $valueArray['addBoost'] = $enrichment->getAddBoost();
     }
     if (!is_null($enrichment->getMatchingRulesCombinationType())) {
         $valueArray['matchingRuleCombinationType'] = $enrichment->getMatchingRulesCombinationType();
     }
     if (!is_null($enrichment->getMatchingRulesExpectedResult())) {
         $valueArray['matchingRuleExpectedResult'] = $enrichment->getMatchingRulesExpectedResult() ? 1 : 0;
     }
     foreach ($enrichment->getFieldEnrichments() as $key => $fieldEnrichment) {
         /**
          * @var $fieldEnrichment FieldEnrichment
          */
         $data = array();
         $data['fieldName'] = $fieldEnrichment->getFieldName();
         $data['content'] = $fieldEnrichment->getContent();
         $valueArray['fieldEnrichments'][$key] = $data;
     }
     foreach ($enrichment->getMatchingRules() as $key => $matchingRule) {
         /**
          * @var $matchingRule MatchingRule
          */
         $data = array();
         $data['fieldName'] = $matchingRule->getFieldName();
         $data['operator'] = $matchingRule->getOperator();
         $data['operandValue'] = $matchingRule->getOperandValue();
         $valueArray['matchingRules'][$key] = $data;
     }
     $valueArray['contextsBoosting'] = [];
     /** @var ContextsBoostingCollection $enrichmentContextsBoostingCollection */
     $enrichmentContextsBoostingCollection = $enrichment->getContextsBoosting();
     if ($enrichmentContextsBoostingCollection->getCount() != 0) {
         foreach ($enrichmentContextsBoostingCollection as $key => $contextsBoosting) {
             /** @var ContextsBoosting $contextsBoosting */
             $data = [];
             $data['boostFieldName'] = $contextsBoosting->getBoostFieldName();
             $data['boostFieldValue'] = $contextsBoosting->getBoostFieldValue();
             $data['boostOptionName'] = $contextsBoosting->getBoostOptionName();
             $data['boostOptionValue'] = (bool) (int) $contextsBoosting->getBoostOptionValue() ? 1 : 0;
             $data['boostingValue'] = (double) $contextsBoosting->getBoostingValue();
             $valueArray['contextsBoosting'][$key] = $data;
         }
     }
     return $valueArray;
 }