示例#1
0
 /**
  * Map field information to a DOMDocument.
  *
  * @param Opus_Model_Field $field    Contains informations about mapping field.
  * @param DOMDocument      $dom      General DOM document.
  * @param DOMNode          $rootNode Node where to add created structure.
  * @return void
  *
  * FIXME: remove code duplication (duplicates Opus_Model_Xml_Version*)
  */
 protected function _mapField(Opus_Model_Field $field, DOMDocument $dom, DOMNode $rootNode)
 {
     $fieldName = $field->getName();
     $modelClass = $field->getValueModelClass();
     $fieldValues = $field->getValue();
     if (true === $this->_config->_excludeEmpty) {
         if (true === is_null($fieldValues) or is_string($fieldValues) && trim($fieldValues) == '' or is_array($fieldValues) && empty($fieldValues)) {
             return;
         }
     }
     if (null === $modelClass) {
         // workaround for simple fields with multiple values
         if (true === $field->hasMultipleValues()) {
             $fieldValues = implode(',', $fieldValues);
         }
         if ($fieldValues instanceof DateTimeZone) {
             $fieldValues = $fieldValues->getName();
         }
         // Replace invalid XML-1.0-Characters by UTF-8 replacement character.
         $fieldValues = preg_replace('/[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F]/', "� ", $fieldValues);
         $rootNode->setAttribute($fieldName, $fieldValues);
     } else {
         if (!is_array($fieldValues)) {
             $fieldValues = array($fieldValues);
         }
         foreach ($fieldValues as $value) {
             $childNode = $dom->createElement($fieldName);
             if ($value instanceof Opus_Model_AbstractDb) {
                 if ($value instanceof Opus_Model_Dependent_Link_Abstract) {
                     $modelId = $value->getLinkedModelId();
                 } else {
                     $modelId = $value->getId();
                 }
                 // Ignore compound keys.
                 if (false === is_array($modelId)) {
                     $childNode->setAttribute('Id', $modelId);
                 }
             }
             $rootNode->appendChild($childNode);
             // if a field has no value then is nothing more to do
             // TODO maybe must be there an other solution
             // FIXME remove code duplication (duplicates Opus_Model_Xml_Version*)
             if (is_null($value)) {
                 continue;
             }
             // delivers a URI if a mapping for the given model exists
             $uri = $this->_createXlinkRef($value);
             if (null !== $uri) {
                 $childNode->setAttribute('xlink:type', 'simple');
                 $childNode->setAttribute('xlink:href', $uri);
                 $this->_mapAttributes($value, $dom, $childNode, true);
             } else {
                 $this->_mapAttributes($value, $dom, $childNode);
             }
         }
     }
 }
示例#2
0
 /**
  * Implements adder mechanism.
  *
  * @param Opus_Model_Field $field The field to work on.
  * @param mixed  $arguments Arguments passed in the get-call.
  *
  * @return Opus_Model_Abstract The added model (can be a new model).
  */
 protected function _addFieldValue(Opus_Model_Field $field, $value)
 {
     if (is_null($value)) {
         $modelclass = $field->getValueModelClass();
         if (is_null($modelclass)) {
             throw new Opus_Model_Exception('Add accessor without parameter currently only available for fields holding models.');
         }
         $value = new $modelclass();
     }
     $field->addValue($value);
     return $value;
 }
示例#3
0
 /**
  * Map field information to a DOMDocument.
  *
  * @param Opus_Model_Field $field    Contains informations about mapping field.
  * @param DOMDocument      $dom      General DOM document.
  * @param DOMNode          $rootNode Node where to add created structure.
  * @return void
  *
  * FIXME: remove code duplication (duplicates Opus_Model_Xml_Version*)
  */
 protected function _mapField(Opus_Model_Field $field, DOMDocument $dom, DOMNode $rootNode)
 {
     $fieldName = $field->getName();
     $modelClass = $field->getValueModelClass();
     $fieldValues = $field->getValue();
     if (true === $this->_config->_excludeEmpty) {
         if (true === is_null($fieldValues) or is_string($fieldValues) && trim($fieldValues) == '' or is_array($fieldValues) && empty($fieldValues)) {
             return;
         }
     }
     if (null === $modelClass) {
         // create a new element
         $element = $dom->createElement($fieldName);
         // workaround for simple fields with multiple values
         if (true === $field->hasMultipleValues()) {
             $fieldValues = implode(',', $fieldValues);
         }
         if ($fieldValues instanceof DateTimeZone) {
             $fieldValues = $fieldValues->getName();
         }
         // set value
         //if (empty($fieldValues) === false)
         $element->nodeValue = htmlspecialchars($fieldValues);
         $rootNode->appendChild($element);
     } else {
         if (!is_array($fieldValues)) {
             $fieldValues = array($fieldValues);
         }
         foreach ($fieldValues as $value) {
             $childNode = $dom->createElement($fieldName);
             $rootNode->appendChild($childNode);
             // if a field has no value then is nothing more to do
             // TODO maybe must be there an other solution
             // FIXME remove code duplication (duplicates Opus_Model_Xml_Version*)
             if (is_null($value)) {
                 continue;
             }
             // delivers a URI if a mapping for the given model exists
             $uri = $this->_createXlinkRef($value);
             if (null !== $uri) {
                 $childNode->setAttribute('xlink:type', 'simple');
                 $childNode->setAttribute('xlink:href', $uri);
                 $this->_mapAttributes($value, $dom, $childNode, true);
             } else {
                 $this->_mapAttributes($value, $dom, $childNode);
             }
         }
     }
 }