protected function getBounds($includeCurrentParameters = false) { $start = $end = false; $sortField = ezfSolrDocumentFieldBase::getFieldName($this->contentClassAttribute, null, 'sort'); $currentParameters = array(); if ($includeCurrentParameters) { $currentParameters = OCClassSearchFormHelper::result()->getCurrentParameters(); } $fieldName = ezfSolrDocumentFieldBase::getFieldName($this->contentClassAttribute, null, 'search'); $params = array_merge(OCClassSearchFormHelper::result()->getBaseParameters(), $currentParameters, array('SearchContentClassID' => $this->contentClassAttribute->attribute('contentclass_id'), 'SearchLimit' => 1, 'SortBy' => array($sortField => 'asc'))); $startSearch = OCFacetNavgationHelper::fetch($params, OCClassSearchFormHelper::result()->searchText); /** @var $startSearchResults eZFindResultNode[] */ $startSearchResults = $startSearch['SearchResult']; if (isset($startSearchResults[0])) { $dataMap = $startSearchResults[0]->attribute('object')->attribute('data_map'); $start = $dataMap[$this->contentClassAttribute->attribute('identifier')]; } $params['SortBy'] = array($sortField => 'desc'); $endSearch = OCFacetNavgationHelper::fetch($params, OCClassSearchFormHelper::result()->searchText); /** @var $endSearchResults eZFindResultNode[] */ $endSearchResults = $endSearch['SearchResult']; if (isset($endSearchResults[0])) { $dataMap = $endSearchResults[0]->attribute('object')->attribute('data_map'); $end = $dataMap[$this->contentClassAttribute->attribute('identifier')]; } $className = $this->getBoundsClassName(); /** @var OCClassSearchFormFieldBoundsInterface $bounds */ $bounds = new $className(); $bounds->setStart($start); $bounds->setEnd($end); return $bounds; }
public function buildFetch(OCClassSearchFormFetcher $fetcher, $requestKey, $requestValue, &$filters) { if (is_array($requestValue) && count($requestValue) == 1) { $requestValue = array_shift($requestValue); } $fieldName = ezfSolrDocumentFieldBase::getFieldName($this->contentClassAttribute, null, 'search'); if (is_array($requestValue)) { $values = array('or'); foreach ($requestValue as $v) { $values[] = $fieldName . ':' . $fetcher->encode($v, true); } $filters[] = $values; } else { $filters[] = $fieldName . ':' . $fetcher->encode($requestValue, true); } $fetcher->addFetchField(array('name' => $this->contentClassAttribute->attribute('name'), 'value' => $requestValue, 'remove_view_parameters' => $fetcher->getViewParametersString(array($requestKey)))); }
/** * Get solr field name, from base name. The base name may either be a * meta-data name, or an eZ Publish content class attribute, specified by * <class identifier>/<attribute identifier>[/<option>] * * @param string $baseName Base field name. * @param boolean $includingClassID conditions the structure of the answer. See return value explanation. * @param $context is introduced in ez find 2.2 to allow for more optimal sorting, faceting, filtering * * @return mixed Internal base name. Returns null if no valid base name was provided. * If $includingClassID is true, an associative array will be returned, as shown below : * <code> * array( 'fieldName' => 'attr_title_t', * 'contentClassId' => 16 ); * </code> */ static function getFieldName( $baseName, $includingClassID = false, $context = 'search' ) { // If the base name is a meta field, get the correct field name. if ( eZSolr::hasMetaAttributeType( $baseName, $context ) ) { return eZSolr::getMetaFieldName( $baseName, $context ); } else { // Get class and attribute identifiers + optional option. $subattribute = null; $fieldDef = explode( '/', $baseName ); // Check if content class attribute ID is provided. if ( is_numeric( $fieldDef[0] ) ) { if ( count( $fieldDef ) == 1 ) { $contentClassAttributeID = $fieldDef[0]; } else if ( count( $fieldDef ) == 2 ) { list( $contentClassAttributeID, $subattribute ) = $fieldDef; } } else { switch( count( $fieldDef ) ) { case 1: { // Return fieldname as is. return $baseName; } break; case 2: { // Field def contains class indentifier and class attribute identifier. list( $classIdentifier, $attributeIdentifier ) = $fieldDef; } break; case 3: { // Field def contains class indentifier, class attribute identifier and optional specification. list( $classIdentifier, $attributeIdentifier, $subattribute ) = $fieldDef; } break; } $contentClassAttributeID = eZContentObjectTreeNode::classAttributeIDByIdentifier( $classIdentifier . '/' . $attributeIdentifier ); } if ( !$contentClassAttributeID ) { eZDebug::writeNotice( 'Could not get content class from base name: ' . $baseName, __METHOD__ ); return null; } $contentClassAttribute = eZContentClassAttribute::fetch( $contentClassAttributeID ); $fieldName = ezfSolrDocumentFieldBase::getFieldName( $contentClassAttribute, $subattribute, $context ); if ( $includingClassID ) { return array( 'fieldName' => $fieldName, 'contentClassId' => $contentClassAttribute->attribute( 'contentclass_id' ) ); } else return $fieldName; } }
/** * test for getData() */ public function testGetData() { $providerArray = array(); #start 1 : the simplest attribute $content1 = "Hello world"; $ezcca1 = new eZContentClassAttribute(array('identifier' => 'title', 'data_type_string' => 'ezstring')); $ezcoa1 = new eZContentObjectAttributeTester(array("data_type_string" => 'ezstring', "id" => 100123, "data_text" => $content1, "contentclass_attribute" => $ezcca1)); $fieldName1 = ezfSolrDocumentFieldBase::getFieldName($ezcca1); $expectedData1 = array($fieldName1 => $content1); $providerArray[] = array($expectedData1, $ezcoa1); #end 1 #start 2 : attribute with subattributes $ezcca2 = new eZContentClassAttribute(array('identifier' => 'dummy', 'data_type_string' => 'dummy_example')); $ezcoa2 = new eZContentObjectAttributeTester(array("data_type_string" => 'dummy_example', "id" => 100124, "contentclass_attribute" => $ezcca2)); $fieldList2 = ezfSolrDocumentFieldBase::getFieldNameList($ezcca2); $expectedData2 = array(); foreach ($fieldList2 as $fieldName) { $expectedData2[$fieldName] = 'DATA_FOR_' . $fieldName; } $fieldName2 = ezfSolrDocumentFieldBase::getFieldName($ezcca2); $providerArray[] = array($expectedData2, $ezcoa2); #end 2 #start 3 : object relations $expectedData3 = array(); $tester3 = new ezfSolrDocumentFieldObjectRelationTester(new eZContentObjectAttribute(array())); $time3 = time(); $image3 = new ezpObject("image", 2); $image3->name = __METHOD__ . $time3; $image3->caption = __METHOD__ . $time3; $imageId3 = $image3->publish(); // $image3->object->clearCache(); $dataMapImage3 = $image3->dataMap; // eZContentObjectAttribute objects, attributes of the related Image $imageName3 = $dataMapImage3['name']; $imageCaption3 = $dataMapImage3['caption']; $article3 = new ezpObject("article", 2); $articleId3 = $article3->publish(); // Create object relation $article3->object->addContentObjectRelation($imageId3, $article3->current_version, 154, eZContentObject::RELATION_ATTRIBUTE); $dataMapArticle3 = $article3->attribute('data_map'); $ezcoa3 = $dataMapArticle3['image']; $ezcoa3->setAttribute('data_int', $imageId3); $ezcoa3->store(); $ezcca3 = $ezcoa3->attribute('contentclass_attribute'); $defaultFieldName3 = ezfSolrDocumentFieldBase::generateAttributeFieldName($ezcca3, ezfSolrDocumentFieldObjectRelation::$subattributesDefinition[ezfSolrDocumentFieldObjectRelation::DEFAULT_SUBATTRIBUTE]); $expectedData3[$defaultFieldName3] = $tester3->getPlainTextRepresentation($ezcoa3); // required to allow another call to metaData() // on $ezcoa3 in getPlainTextRepresentation, called from the getData() method : eZContentObject::recursionProtectionEnd(); $fieldNameImageName3 = ezfSolrDocumentFieldBase::generateSubattributeFieldName($ezcca3, $imageName3->attribute('contentclass_attribute_identifier'), ezfSolrDocumentFieldObjectRelation::getClassAttributeType($imageName3->attribute('contentclass_attribute'))); $expectedData3[$fieldNameImageName3] = trim(implode(' ', array_values(ezfSolrDocumentFieldBase::getInstance($imageName3)->getData())), "\t\r\n "); $fieldNameImageCaption3 = ezfSolrDocumentFieldBase::generateSubattributeFieldName($ezcca3, $imageCaption3->attribute('contentclass_attribute_identifier'), ezfSolrDocumentFieldObjectRelation::getClassAttributeType($imageCaption3->attribute('contentclass_attribute'))); $expectedData3[$fieldNameImageCaption3] = trim(implode(' ', array_values(ezfSolrDocumentFieldBase::getInstance($imageCaption3)->getData())), "\t\r\n "); $image3 = eZContentObject::fetch($imageId3); $metaAttributeValues = eZSolr::getMetaAttributesForObject($image3); foreach ($metaAttributeValues as $metaInfo) { $expectedData3[ezfSolrDocumentFieldBase::generateSubmetaFieldName($metaInfo['name'], $ezcca3)] = ezfSolrDocumentFieldBase::preProcessValue($metaInfo['value'], $metaInfo['fieldType']); } $providerArray[] = array($expectedData3, $ezcoa3); #end 3 // Let's perform the actual testing : foreach ($providerArray as $input) { $expected = $input[0]; $contentObjectAttribute = $input[1]; $instance = ezfSolrDocumentFieldBase::getInstance($contentObjectAttribute); self::assertEquals($expected, $instance->getData()); } }