/** * Transforms an ezpContentField in an array representation * @todo Refactor, this doesn't really belong here. Either in ezpContentField, or in an extend class */ protected function attributeOutputData(ezpContentField $attribute) { // The following seems like an odd strategy. // $sXml = simplexml_import_dom( $attribute->serializedXML ); // var_dump( $sXml->asXML() ); // // $attributeType = (string)$sXml['type']; // // // get ezremote NS elements in order to get the attribute identifier // $ezremoteAttributes = $sXml->attributes( 'http://ez.no/ezobject' ); // $attributeIdentifier = (string)$ezremoteAttributes['identifier']; // // // attribute value // $children = $sXml->children(); // $attributeValue = array(); // foreach( $children as $child ) // { // // simple value // if ( count( $child->children() ) == 0 ) // { // // complex value, probably a native eZ Publish XML // $attributeValue[$child->getName()] = (string)$child; // } // else // { // if ( $attributeType == 'ezxmltext' ) // { // $html = $attribute->content->attribute( 'output' )->attribute( 'output_text' ); // $attributeValue = array( strip_tags( $html ) ); // } // } // } // @TODO move to datatype representation layer switch ($attribute->data_type_string) { case 'ezxmltext': $html = $attribute->content->attribute('output')->attribute('output_text'); $attributeValue = array(strip_tags($html)); break; case 'ezimage': $strRepImage = $attribute->tostring(); $delimPos = strpos($strRepImage, '|'); if ($delimPos !== false) { $strRepImage = substr($strRepImage, 0, $delimPos); } $attributeValue = array($strRepImage); break; default: $attributeValue = array($attribute->tostring()); break; } // cleanup values so that the result is consistent: // - no array if one item // - false if no values if (count($attributeValue) == 0) { $attributeValue = false; } elseif (count($attributeValue) == 1) { $attributeValue = current($attributeValue); } return array('type' => $attribute->data_type_string, 'identifier' => $attribute->contentclass_attribute_identifier, 'value' => $attributeValue); }