protected function getValues() { if ($this->values === null) { $this->values = array(); $field = ezfSolrDocumentFieldBase::generateAttributeFieldName($this->contentClassAttribute, ezfSolrDocumentFieldBase::getClassAttributeType($this->contentClassAttribute, null, 'search')); $facets = array('field' => $field, 'name' => $this->attributes['name'], 'limit' => 500, 'sort' => 'alpha'); $currentParameters = $baseParameters = array_merge(OCClassSearchFormHelper::result()->getBaseParameters(), array('SearchContentClassID' => array($this->contentClassAttribute->attribute('contentclass_id')), 'Facet' => array($facets), 'SearchLimit' => 1)); if (OCClassSearchFormHelper::result()->isFetch()) { $currentParameters = array_merge($currentParameters, OCClassSearchFormHelper::result()->getCurrentParameters()); } $data = OCFacetNavgationHelper::navigationList($baseParameters, $currentParameters, OCClassSearchFormHelper::result()->searchText, OCClassSearchFormHelper::result()->isFetch()); if (isset($data[$this->attributes['name']])) { $this->values = $data[$this->attributes['name']]; // setto i valori attivi e inietto il conto nel nome foreach ($this->values as $index => $value) { $current = (array) $this->attributes['value']; if (in_array($value['query'], $current)) { $this->values[$index]['active'] = true; } $this->values[$index]['query'] = OCFacetNavgationHelper::encodeValue($this->values[$index]['query']); $this->values[$index]['raw_name'] = $value['name']; if (isset($value['count']) && $value['count'] > 0) { $this->values[$index]['name'] = $value['name'] . ' (' . $value['count'] . ')'; $this->values[$index]['count'] = $value['count']; } } } } return $this->values; }
/** * Identifies, based on the existing object relations, the type of the subattribute. * * @param eZContentClassAttribute $classAttribute The ezobjectrelation/ezobjectrelationlist attribute * @param $subAttribute The subattribute's name * @return string The type of the subattribute, false otherwise. */ protected static function getTypeForSubattribute( eZContentClassAttribute $classAttribute, $subAttribute, $context = 'search' ) { $q = "SELECT DISTINCT( ezcoa.data_type_string ) FROM ezcontentobject_link AS ezcol, ezcontentobject_attribute AS ezcoa, ezcontentclass_attribute AS ezcca, ezcontentclass_attribute AS ezcca_target WHERE ezcol.contentclassattribute_id={$classAttribute->attribute( 'id' )} AND ezcca_target.identifier='{$subAttribute}' AND ezcca.data_type_string='{$classAttribute->attribute( 'data_type_string' )}' AND ezcca.id=ezcol.contentclassattribute_id AND ezcol.to_contentobject_id = ezcoa.contentobject_id AND ezcoa.contentclassattribute_id = ezcca_target.id; "; $rows = eZDB::instance()->arrayQuery( $q ); if ( $rows and count( $rows ) > 0 ) { if ( count( $rows ) > 1 ) { $msg = "Multiple types were found for subattribute '{$subAttribute}' of class attribute #{$classAttribute->attribute( 'id' )} [{$classAttribute->attribute( 'data_type_string' )}]. This means that objects of different content classes were related through class attribute #{$classAttribute->attribute( 'id' )} and had attributes named '{$subAttribute}' of different datatypes : \n" . print_r( $rows , true ) . " Picking the first one here : {$rows[0]['data_type_string']}"; eZDebug::writeWarning( $msg, __METHOD__ ); } return ezfSolrDocumentFieldBase::getClassAttributeType( new eZContentClassAttribute( $rows[0] ), null, $context ); } return false; }
protected function getArrayRelatedObject(eZContentObject $relatedObject, $contentClassAttribute, $metaData = null) { if ($metaData === null) { $metaData = array(); } if ($relatedObject instanceof eZContentObject && $relatedObject->attribute('main_node_id') > 0) { $objectName = $relatedObject->name(false, $this->ContentObjectAttribute->attribute('language_code')); $fieldName = parent::generateSubattributeFieldName($contentClassAttribute, 'name', self::DEFAULT_SUBATTRIBUTE_TYPE); if (isset($metaData[$fieldName])) { $metaData[$fieldName] = array_merge($metaData[$fieldName], array($objectName)); } else { $metaData[$fieldName] = array($objectName); } /** @var ezfSolrDocumentFieldBase[] $baseList */ $baseList = $this->getBaseList($relatedObject->attribute('current')); foreach ($baseList as $field) { /** @var eZContentClassAttribute $tmpClassAttribute */ $tmpClassAttribute = $field->ContentObjectAttribute->attribute('contentclass_attribute'); $fieldName = $field->ContentObjectAttribute->attribute('contentclass_attribute_identifier'); $fieldNameArray = array(); foreach (array_keys(eZSolr::$fieldTypeContexts) as $context) { $fieldNameArray[] = parent::generateSubattributeFieldName($contentClassAttribute, $fieldName, ezfSolrDocumentFieldBase::getClassAttributeType($tmpClassAttribute, null, $context)); } $fieldNameArray = array_unique($fieldNameArray); if ($tmpClassAttribute->attribute('data_type_string') == 'ezobjectrelation' or $tmpClassAttribute->attribute('data_type_string') == 'ezobjectrelationlist') { /** @var self $field */ $finalValue = $field->getPlainTextRepresentation(); } else { $finalValue = $this->preProcessValue($field->ContentObjectAttribute->metaData(), parent::getClassAttributeType($tmpClassAttribute)); } foreach ($fieldNameArray as $fieldNameValue) { //eZCLI::instance()->output(var_dump($metaData)); if (is_array($finalValue)) { $finalValue = self::recursive_implode($finalValue); } $finalValue = trim($finalValue, "\t\r\n "); if (!empty($finalValue)) { if (isset($metaData[$fieldNameValue])) { $metaData[$fieldNameValue] = array_merge($metaData[$fieldNameValue], array($finalValue)); } else { $metaData[$fieldNameValue] = array($finalValue); } } } } $metaAttributeValues = eZSolr::getMetaAttributesForObject($relatedObject); foreach ($metaAttributeValues as $metaInfo) { $value = ezfSolrDocumentFieldBase::preProcessValue($metaInfo['value'], $metaInfo['fieldType']); if (!is_array($value)) { $value = array($value); } $metaData[ezfSolrDocumentFieldBase::generateSubmetaFieldName($metaInfo['name'], $contentClassAttribute)] = $value; } } return $metaData; }
/** * @dataProvider providerTestGetClassAttributeType() */ public function testGetClassAttributeType($expected, $contentClassAttribute, $options = null) { self::assertEquals($expected, ezfSolrDocumentFieldBase::getClassAttributeType($contentClassAttribute, $options)); }