/**
  * Initializes a level two ezpContentFieldSet from a content object data map
  * @param array $dataMap
  * @return ezpContentFieldSet
  */
 public static function fromDataMap($dataMap)
 {
     $set = new ezpContentFieldSet();
     foreach ($dataMap as $attribute) {
         $identifier = $attribute->attribute('contentclass_attribute_identifier');
         $set->fields[$identifier] = ezpContentField::fromContentObjectAttribute($attribute);
     }
     $set->initIterator();
     return $set;
 }
 public static function attributeOutputData(ezpContentField $field, ezpRestRequest $currentRequest = null, ezcMvcRouter $router = null)
 {
     $attributeValue = $stringValue = array();
     switch ($field->data_type_string) {
         case 'ezxmltext':
             $html = $field->content->attribute('output')->attribute('output_text');
             $attributeValue = array($html);
             $stringValue = array(strip_tags($html));
             break;
         case 'ezimage':
             if ($field->hasContent()) {
                 $strRepImage = $field->toString();
                 $delimPos = strpos($strRepImage, '|');
                 if ($delimPos !== false) {
                     $strRepImage = substr($strRepImage, 0, $delimPos);
                 }
                 $attributeValue = array(self::getHostURIFromRequest($currentRequest) . '/' . $strRepImage);
                 $stringValue = array($field->toString());
             }
             break;
         case 'ezbinaryfile':
             if ($field->hasContent()) {
                 $file = $field->content();
                 $filePath = "content/download/{$field->attribute('contentobject_id')}/{$field->attribute('id')}/{$field->content()->attribute('original_filename')}";
                 $attributeValue = array(self::getHostURIFromRequest($currentRequest) . '/' . $filePath);
                 $stringValue = array($field->toString());
             } else {
                 $attributeValue = array(null);
                 $stringValue = array(null);
             }
             break;
         case 'ezobjectrelationlist':
             $attributeValue = array();
             $stringValueArray = array();
             if ($currentRequest && $router) {
                 if ($field->hasContent()) {
                     $relations = $field->content();
                     foreach ($relations['relation_list'] as $relation) {
                         $id = $relation['contentobject_id'];
                         $object = eZContentObject::fetch($id);
                         if ($object instanceof eZContentObject && $object->attribute('main_node') instanceof eZContentObjectTreeNode) {
                             if ($object->attribute('can_read')) {
                                 $content = ezpContent::fromObject($object);
                                 $objectMetadata = OCOpenDataContentModel::getMetadataByContent($content);
                                 $contentQueryString = $currentRequest->getContentQueryString(true);
                                 try {
                                     if ($content->main_node) {
                                         $node = $content->main_node;
                                         $location = ezpContentLocation::fromNode($node);
                                         $objectMetadata = array_merge($objectMetadata, self::getMetadataByLocation($location));
                                         $stringValueArray[] = $id;
                                     } else {
                                         throw new Exception("Node not found for object id #{$id}");
                                     }
                                 } catch (Exception $e) {
                                 }
                                 $objectMetadata['link'] = self::getHostURIFromRequest($currentRequest) . $router->generateUrl('ezpObject', array('objectId' => $id)) . $contentQueryString;
                                 $attributeValue[] = $objectMetadata;
                             }
                             //else
                             //{
                             //    $attributeValue[] = "Access not allowed for content $id";
                             //}
                         }
                     }
                 }
             }
             $stringValue = array(implode('-', $stringValueArray));
             break;
         case 'ezobjectrelation':
             $attributeValue = array();
             $stringValue = array($field->toString());
             if ($currentRequest && $router) {
                 if ($field->hasContent()) {
                     $relation = $field->content();
                     if ($relation->attribute('can_read')) {
                         $id = $relation->attribute('id');
                         $content = ezpContent::fromObject($relation);
                         $objectMetadata = OCOpenDataContentModel::getMetadataByContent($content);
                         $objectMetadata['link'] = self::getHostURIFromRequest($currentRequest) . $router->generateUrl('ezpObject', array('objectId' => $id));
                         $attributeValue[] = $objectMetadata;
                     }
                 }
             }
             break;
         default:
             $datatypeBlacklist = self::getDatatypeBlackList();
             if (isset($datatypeBlacklist[$field->data_type_string])) {
                 $attributeValue = array(null);
                 $stringValue = array(null);
             } elseif ($field->hasContent()) {
                 $attributeValue = array($field->toString());
                 $stringValue = array($field->toString());
             }
             break;
     }
     if (count($attributeValue) == 0) {
         $attributeValue = false;
     } elseif (count($attributeValue) == 1) {
         $attributeValue = current($attributeValue);
     }
     if (count($stringValue) == 0) {
         $stringValue = false;
     } elseif (count($stringValue) == 1) {
         $stringValue = current($stringValue);
     }
     $return = array('name' => $field->contentclass_attribute_name, 'description' => $field->contentclass_attribute->attribute('description'), 'identifier' => $field->contentclass_attribute_identifier, 'id' => (int) $field->id, 'classattribute_id' => (int) $field->contentclassattribute_id, 'type' => $field->data_type_string, 'value' => $attributeValue, 'string_value' => $stringValue);
     return $return;
 }
Example #3
0
 /**
  * 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);
 }
 /**
  * Transforms an ezpContentField in an array representation
  * @todo Refactor, this doesn't really belong here. Either in ezpContentField, or in an extend class
  * @param ezpContentField $field
  * @return array Associative array with following keys :
  *                  - type => Field type (datatype string)
  *                  - identifier => Attribute identifier
  *                  - value => String representation of field content
  *                  - id => Attribute numerical ID
  *                  - classattribute_id => Numerical class attribute ID
  */
 public static function attributeOutputData(ezpContentField $field)
 {
     // @TODO move to datatype representation layer
     switch ($field->data_type_string) {
         case 'ezxmltext':
             $html = $field->content->attribute('output')->attribute('output_text');
             $attributeValue = array(strip_tags($html));
             break;
         case 'ezimage':
             $strRepImage = $field->toString();
             $delimPos = strpos($strRepImage, '|');
             if ($delimPos !== false) {
                 $strRepImage = substr($strRepImage, 0, $delimPos);
             }
             $attributeValue = array($strRepImage);
             break;
         default:
             $datatypeBlacklist = array_fill_keys(eZINI::instance()->variable('ContentSettings', 'DatatypeBlackListForExternal'), true);
             if (isset($datatypeBlacklist[$field->data_type_string])) {
                 $attributeValue = array(null);
             } else {
                 $attributeValue = array($field->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;
     } else {
         if (count($attributeValue) == 1) {
             $attributeValue = current($attributeValue);
         }
     }
     return array('type' => $field->data_type_string, 'identifier' => $field->contentclass_attribute_identifier, 'value' => $attributeValue, 'id' => (int) $field->id, 'classattribute_id' => (int) $field->contentclassattribute_id);
 }