/**
  * Returns the list of field names this handler sends to Solr backend
  *
  * @static
  *
  * @param eZContentClassAttribute $classAttribute
  * @param array $exclusiveTypeFilter
  *
  * @return array
  */
 public static function getFieldNameList(eZContentClassAttribute $classAttribute, $exclusiveTypeFilter = array())
 {
     $fieldsList = array();
     if (empty($exclusiveTypeFilter) || !in_array('lckeyword', $exclusiveTypeFilter)) {
         $fieldsList[] = parent::generateAttributeFieldName($classAttribute, 'lckeyword');
     }
     if (empty($exclusiveTypeFilter) || !in_array('text', $exclusiveTypeFilter)) {
         $fieldsList[] = parent::generateAttributeFieldName($classAttribute, 'text');
     }
     if (empty($exclusiveTypeFilter) || !in_array('sint', $exclusiveTypeFilter)) {
         $fieldsList[] = parent::generateSubattributeFieldName($classAttribute, 'tag_ids', 'sint');
     }
     return $fieldsList;
 }
 public static function getFieldName(eZContentClassAttribute $classAttribute, $subAttribute = null, $context = 'search')
 {
     switch ($classAttribute->attribute('data_type_string')) {
         case 'ezmatrix':
             if ($subAttribute and $subAttribute !== '') {
                 // A subattribute was passed
                 return parent::generateSubattributeFieldName($classAttribute, $subAttribute, self::DEFAULT_SUBATTRIBUTE_TYPE);
             } else {
                 // return the default field name here.
                 return parent::generateAttributeFieldName($classAttribute, self::getClassAttributeType($classAttribute, null, $context));
             }
             break;
     }
     return null;
 }
 public static function getFieldNameList(eZContentClassAttribute $classAttribute, $exclusiveTypeFilter = array())
 {
     // Generate the list of subfield names.
     $subfields = array();
     //   Handle first the default subattribute
     $subattributesDefinition = self::$subattributesDefinition;
     if (!in_array($subattributesDefinition[self::DEFAULT_SUBATTRIBUTE], $exclusiveTypeFilter)) {
         $subfields[] = parent::generateAttributeFieldName($classAttribute, $subattributesDefinition[self::DEFAULT_SUBATTRIBUTE]);
     }
     unset($subattributesDefinition[self::DEFAULT_SUBATTRIBUTE]);
     //   Then hanlde all other subattributes
     foreach ($subattributesDefinition as $name => $type) {
         if (empty($exclusiveTypeFilter) or !in_array($type, $exclusiveTypeFilter)) {
             $subfields[] = parent::generateSubattributeFieldName($classAttribute, $name, $type);
         }
     }
     return $subfields;
 }
    /**
     * @see ezfSolrDocumentFieldBase::getData()
     */
    public function getData()
    {
        $contentClassAttribute = $this->ContentObjectAttribute->attribute( 'contentclass_attribute' );

        switch ( $contentClassAttribute->attribute( 'data_type_string' ) )
        {
            case 'ezobjectrelation' :
                $returnArray = array();

                $defaultFieldName = parent::generateAttributeFieldName( $contentClassAttribute,
                                                                        self::$subattributesDefinition[self::DEFAULT_SUBATTRIBUTE] );
                $returnArray[$defaultFieldName] = $this->getPlainTextRepresentation();
                $relatedObject = $this->ContentObjectAttribute->content();

                if ( $relatedObject && $relatedObject->attribute( 'status' ) == eZContentObject::STATUS_PUBLISHED )
                {
                    // 1st, add content fields of the related object.
                    $baseList = $this->getBaseList( $relatedObject->attribute( 'current' ) );

                    foreach ( $baseList as $field )
                    {
                        $tmpClassAttribute = $field->ContentObjectAttribute->attribute( 'contentclass_attribute' );
                        $fieldName = $field->ContentObjectAttribute->attribute( 'contentclass_attribute_identifier' );
                        $fieldName = parent::generateSubattributeFieldName( $contentClassAttribute,
                                                                            $fieldName,
                                                                            self::getClassAttributeType( $tmpClassAttribute ) );

                        $finalValue = '';
                        if ( $tmpClassAttribute->attribute( 'data_type_string' ) == 'ezobjectrelation' or
                             $tmpClassAttribute->attribute( 'data_type_string' ) == 'ezobjectrelationlist' )
                        {
                            // The subattribute is in turn an object relation. Stop recursion and get full text representation.
                            $finalValue = $field->getPlainTextRepresentation();
                        }
                        else
                        {
                            $values = array_values( $field->getData() );
                            foreach ( $values as $value )
                            {
                                if ( is_array( $value ) )
                                {
                                    $finalValue .= implode( ' ', $value );
                                }
                                else
                                {
                                    $finalValue .= ' ' . $value;
                                }
                            }
                        }

                        $returnArray[$fieldName] = trim( $finalValue, "\t\r\n " );
                    }

                    // 2ndly, add meta fields of the related object.
                    $metaAttributeValues = eZSolr::getMetaAttributesForObject( $relatedObject );
                    foreach ( $metaAttributeValues as $metaInfo )
                    {
                        $returnArray[ezfSolrDocumentFieldBase::generateSubmetaFieldName( $metaInfo['name'], $contentClassAttribute )] = ezfSolrDocumentFieldBase::preProcessValue( $metaInfo['value'], $metaInfo['fieldType'] );
                    }

                    return $returnArray;
                }
                break;
            case 'ezobjectrelationlist' :
            {
                $returnArray = array();
                $content = $this->ContentObjectAttribute->content();

                foreach ( $content['relation_list'] as $relationItem )
                {
                    $subObjectID = $relationItem['contentobject_id'];
                    if ( !$subObjectID )
                        continue;
                    $subObject = eZContentObjectVersion::fetchVersion( $relationItem['contentobject_version'], $subObjectID );
                    if ( !$subObject || $relationItem['in_trash'] )
                        continue;

                    // 1st create aggregated metadata fields
                    $metaAttributeValues = eZSolr::getMetaAttributesForObject( $subObject->attribute( 'contentobject' ) );
                    foreach ( $metaAttributeValues as $metaInfo )
                    {
                        $submetaFieldName = ezfSolrDocumentFieldBase::generateSubmetaFieldName( $metaInfo['name'], $contentClassAttribute );
                        if ( isset( $returnArray[$submetaFieldName] ) )
                        {
                            $returnArray[$submetaFieldName] = array_merge( $returnArray[$submetaFieldName], array( ezfSolrDocumentFieldBase::preProcessValue( $metaInfo['value'], $metaInfo['fieldType'] ) ) );
                        }
                        else
                        {
                            $returnArray[$submetaFieldName] = array( ezfSolrDocumentFieldBase::preProcessValue( $metaInfo['value'], $metaInfo['fieldType'] ) );
                        }
                    }
                }

                $defaultFieldName = parent::generateAttributeFieldName( $contentClassAttribute,
                                                                        self::$subattributesDefinition[self::DEFAULT_SUBATTRIBUTE] );
                $returnArray[$defaultFieldName] = $this->getPlainTextRepresentation();
                return $returnArray;
            }
                break;
            default:
            {
            } break;
        }
    }
 /**
  * @see ezfSolrDocumentFieldBase::getData()
  */
 public function getData()
 {
     /** @var eZContentClassAttribute $contentClassAttribute */
     $contentClassAttribute = $this->ContentObjectAttribute->attribute('contentclass_attribute');
     switch ($contentClassAttribute->attribute('data_type_string')) {
         case 'ezobjectrelation':
             $returnArray = array();
             /** @var eZContentObject $relatedObject */
             $relatedObject = $this->ContentObjectAttribute->content();
             if ($relatedObject) {
                 $returnArray = $this->getArrayRelatedObject($relatedObject, $contentClassAttribute);
                 eZContentObject::clearCache(array($relatedObject->attribute('id')));
             }
             return $returnArray;
             break;
         case 'ezobjectrelationlist':
             $returnArray = array();
             $returnArrayRelatedObject = array();
             $content = $this->ContentObjectAttribute->content();
             $relationCount = count($content['relation_list']);
             foreach ($content['relation_list'] as $relationItem) {
                 $subObjectID = $relationItem['contentobject_id'];
                 if (!$subObjectID) {
                     continue;
                 }
                 /** @var eZContentObjectVersion $subObject */
                 $subObject = eZContentObjectVersion::fetchVersion($relationItem['contentobject_version'], $subObjectID);
                 if (!$subObject instanceof eZContentObjectVersion) {
                     $subObjectWrapper = eZContentObject::fetch($subObjectID);
                     if ($subObjectWrapper instanceof eZContentObject) {
                         $subObject = $subObjectWrapper->currentVersion();
                     } else {
                         continue;
                     }
                 }
                 /** @var eZContentObject $subContentObject */
                 $subContentObject = $subObject->attribute('contentobject');
                 if (intval($subContentObject->attribute('main_node_id')) == 0) {
                     continue;
                 }
                 $metaAttributeValues = eZSolr::getMetaAttributesForObject($subContentObject);
                 foreach ($metaAttributeValues as $metaInfo) {
                     $submetaFieldName = ezfSolrDocumentFieldBase::generateSubmetaFieldName($metaInfo['name'], $contentClassAttribute);
                     if (isset($returnArray[$submetaFieldName])) {
                         $returnArray[$submetaFieldName] = array_merge($returnArray[$submetaFieldName], array(ezfSolrDocumentFieldBase::preProcessValue($metaInfo['value'], $metaInfo['fieldType'])));
                     } else {
                         $returnArray[$submetaFieldName] = array(ezfSolrDocumentFieldBase::preProcessValue($metaInfo['value'], $metaInfo['fieldType']));
                     }
                 }
                 $nodeAttributeValues = array();
                 $nodePathArray = array();
                 /** @var eZContentObjectTreeNode $contentNode */
                 foreach ($subContentObject->attribute('assigned_nodes') as $contentNode) {
                     foreach (eZSolr::nodeAttributes() as $attributeName => $fieldType) {
                         $nodeAttributeValues[] = array('name' => $attributeName, 'value' => $contentNode->attribute($attributeName), 'fieldType' => $fieldType);
                     }
                     $nodePathArray[] = $contentNode->attribute('path_array');
                 }
                 //@todo questo non va... occorre correggere schema.xml?
                 //foreach ( $nodeAttributeValues as $metaInfo )
                 //{
                 //    $submetaFieldName = ezfSolrDocumentFieldBase::generateSubmetaFieldName( $metaInfo['name'], $contentClassAttribute );
                 //    if ( isset( $returnArray[$submetaFieldName] ) )
                 //    {
                 //        $returnArray[$submetaFieldName] = array_merge( $returnArray[$submetaFieldName],
                 //                                                       array( ezfSolrDocumentFieldBase::preProcessValue( $metaInfo['value'], $metaInfo['fieldType'] ) ) );
                 //    }
                 //    else
                 //    {
                 //        $returnArray[$submetaFieldName] = array( ezfSolrDocumentFieldBase::preProcessValue( $metaInfo['value'], $metaInfo['fieldType'] ) );
                 //    }
                 //}
                 foreach ($nodePathArray as $pathArray) {
                     $submetaFieldName = ezfSolrDocumentFieldBase::generateSubmetaFieldName('path', $contentClassAttribute);
                     foreach ($pathArray as $pathNodeID) {
                         if (isset($returnArray[$submetaFieldName])) {
                             $returnArray[$submetaFieldName] = array_merge($returnArray[$submetaFieldName], array($pathNodeID));
                         } else {
                             $returnArray[$submetaFieldName] = array($pathNodeID);
                         }
                     }
                 }
                 if ($relationCount < 200) {
                     $returnArrayRelatedObject = $this->getArrayRelatedObject($subContentObject, $contentClassAttribute, $returnArrayRelatedObject);
                 } else {
                     $objectName = $subContentObject->name(false, $this->ContentObjectAttribute->attribute('language_code'));
                     $fieldName = parent::generateSubattributeFieldName($contentClassAttribute, 'name', self::DEFAULT_SUBATTRIBUTE_TYPE);
                     if (isset($returnArrayRelatedObject[$fieldName])) {
                         $returnArrayRelatedObject[$fieldName][] = $objectName;
                     } else {
                         $returnArrayRelatedObject[$fieldName] = array($objectName);
                     }
                 }
                 $returnArray = array_merge_recursive($returnArray, $returnArrayRelatedObject);
                 eZContentObject::clearCache(array($subContentObject->attribute('id')));
             }
             $defaultFieldName = parent::generateAttributeFieldName($contentClassAttribute, self::$subattributesDefinition[self::DEFAULT_SUBATTRIBUTE]);
             $stringFieldName = parent::generateAttributeFieldName($contentClassAttribute, 'string');
             $returnArray[$defaultFieldName] = $this->getPlainTextRepresentation();
             $returnArray[$stringFieldName] = $this->getPlainTextRepresentation();
             $result = array();
             foreach ($returnArray as $key => $value) {
                 if (is_array($value)) {
                     $value = array_unique($value);
                 }
                 $result[$key] = $value;
             }
             return $result;
             break;
     }
     return array();
 }
 /**
  * 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());
     }
 }