コード例 #1
0
 /**
  * Get an array of class attribute identifiers based on either a class attribute
  * list, or a content classes list
  *
  * @param array $classIDArray
  *        Classes to search in. Either an array of class ID, class identifiers,
  *        a class ID or a class identifier.
  *        Using numerical attribute/class identifiers for $classIDArray is more efficient.
  * @param array $classAttributeID
  *        Class attributes to search in. Either an array of class attribute id,
  *        or a single class attribute. Literal identifiers are not allowed.
  * @param array $fieldTypeExcludeList
  *        filter list. List of field types to exclude. ( set to empty array by default ).
  *
  * @return array List of solr field names.
  */
 protected function getClassAttributes($classIDArray = false, $classAttributeIDArray = false, $fieldTypeExcludeList = null)
 {
     eZDebug::createAccumulator('Class attribute list', 'eZ Find');
     eZDebug::accumulatorStart('Class attribute list');
     $fieldArray = array();
     $classAttributeArray = array();
     // classAttributeIDArray = simple integer (content class attribute ID)
     if (is_numeric($classAttributeIDArray) and $classAttributeIDArray > 0) {
         $classAttributeArray[] = eZContentClassAttribute::fetch($classAttributeIDArray);
     } else {
         if (is_array($classAttributeIDArray)) {
             foreach ($classAttributeIDArray as $classAttributeID) {
                 $classAttributeArray[] = eZContentClassAttribute::fetch($classAttributeID);
             }
         }
     }
     // no class attribute list given, we need a class list
     // this block will create the class attribute array based on $classIDArray
     if (empty($classAttributeArray)) {
         // Fetch class list.
         $condArray = array("is_searchable" => 1, "version" => eZContentClass::VERSION_STATUS_DEFINED);
         if (!$classIDArray) {
             $classIDArray = array();
         } else {
             if (!is_array($classIDArray)) {
                 $classIDArray = array($classIDArray);
             }
         }
         // literal class identifiers are converted to numerical ones
         $tmpClassIDArray = $classIDArray;
         $classIDArray = array();
         foreach ($tmpClassIDArray as $key => $classIdentifier) {
             if (!is_numeric($classIdentifier)) {
                 if (!($contentClass = eZContentClass::fetchByIdentifier($classIdentifier, false))) {
                     eZDebug::writeWarning("Unknown content class identifier '{$classIdentifier}'", __METHOD__);
                 } else {
                     $classIDArray[] = $contentClass['id'];
                 }
             } else {
                 $classIDArray[] = $classIdentifier;
             }
         }
         if (!empty($classIDArray)) {
             $condArray['contentclass_id'] = array($classIDArray);
         }
         $classAttributeArray = eZContentClassAttribute::fetchFilteredList($condArray);
     }
     // $classAttributeArray now contains a list of eZContentClassAttribute
     // we can use to construct the list of fields solr should search in
     // @TODO : retrieve sub attributes here. Mind the types !
     foreach ($classAttributeArray as $classAttribute) {
         $fieldArray = array_merge(ezfSolrDocumentFieldBase::getFieldNameList($classAttribute, $fieldTypeExcludeList), $fieldArray);
     }
     // the array is unified + sorted in order to make it consistent
     $fieldArray = array_unique($fieldArray);
     sort($fieldArray);
     eZDebug::accumulatorStop('Class attribute list');
     return $fieldArray;
 }
コード例 #2
0
 /**
  * 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());
     }
 }