Пример #1
0
 /**
  * Return a reference to an actual field if not on the blacklist.
  *
  * @param string $name Name of the requested field.
  * @throws Opus_Model_Exception If the requested field is hidden by the blacklist.
  * @return Opus_Model_Field The requested field instance. If no such instance can be found, null is returned.
  */
 public function getField($name)
 {
     if (in_array($name, $this->blacklist)) {
         throw new Opus_Model_Exception('Requested field is hidden by the blacklist.');
     }
     return $this->model->getField($name);
 }
Пример #2
0
 /**
  * Recursively populates model's fields from an Xml DomElement.
  *
  * @param  Opus_Model_Abstract  $model   The model to be populated.
  * @param  DOMElement           $element The DomElement holding the field names and values.
  * @return Opus_Model_Abstract  $model   The populated model.
  */
 protected function _populateModelFromXml(Opus_Model_Abstract $model, DOMElement $element)
 {
     $fieldList = $model->describe();
     // Internal fields exist as attributes
     foreach ($element->attributes as $field) {
         // Implement adding values to multi-value internal fields.
         // This is implemented in store-procedure, not here
         // multi-value internal fields should hold values concatenated because they have only one field in database
         // ignore unknown attributes
         if (true === in_array($field->nodeName, $fieldList)) {
             $callname = 'set' . $field->name;
             if ($field->value === '') {
                 $model->{$callname}(null);
             } else {
                 $model->{$callname}($field->value);
             }
         }
     }
     // External fields exist as child elements
     foreach ($element->childNodes as $externalField) {
         $fieldName = $externalField->nodeName;
         if (in_array($fieldName, $fieldList) === false) {
             throw new Opus_Model_Exception('Field ' . $fieldName . ' not defined');
         } else {
             $modelclass = $model->getField($fieldName)->getValueModelClass();
         }
         $submodel = $this->_createModelFromElement($externalField, $modelclass);
         $submodel = $this->_populateModelFromXml($submodel, $externalField);
         $callname = 'add' . $externalField->nodeName;
         $model->{$callname}($submodel);
     }
     return $model;
 }
Пример #3
0
 /**
  * Update the field values of this model by using
  * another model instance having the same fields.
  *
  * All fields of the given Model that also occur in the
  * the targeted Model (this instance) are used for update.
  *
  * To exclude fields from updating consider using a
  * Opus_Model_Filter decorator for the given update model.
  *
  * @return void
  */
 public function updateFrom(Opus_Model_Abstract $model)
 {
     // use all available fields for update
     foreach ($model->describe() as $fieldname) {
         // find corresponding field to update
         $myfield = $this->_getField($fieldname);
         if (null !== $myfield) {
             // update the field
             $fieldvalue = $model->getField($fieldname)->getValue();
             $myfield->setValue($fieldvalue);
         }
     }
 }
Пример #4
0
 /**
  * Maps attribute model informations to a DOMDocument.
  *
  * @param Opus_Model_Abstract $model      Model informations for attribute mapping.
  * @param DOMDocument         $dom        General DOM document.
  * @param DOMNode             $rootNode   Node where to add created structure.
  * @param boolean             $unTunneled Should only current (true) or all (false, default) fields shown.
  * @return void
  */
 protected function _mapAttributes(Opus_Model_Abstract $model, DOMDocument $dom, DOMNode $rootNode, $unTunneled = false)
 {
     if (true === $unTunneled and $model instanceof Opus_Model_Dependent_Link_Abstract) {
         $fields = $model->describeUntunneled();
     } else {
         if (true === $unTunneled and $model instanceof Opus_Model_Dependent_Abstract) {
             return;
             // short-circuit
         } else {
             $fields = $model->describe();
         }
     }
     $excludeFields = $this->_config->_excludeFields;
     if (count($excludeFields) > 0) {
         $fields_diff = array_diff($fields, $excludeFields);
     } else {
         $fields_diff = $fields;
     }
     foreach ($fields_diff as $fieldname) {
         $field = $model->getField($fieldname);
         $this->_mapField($field, $dom, $rootNode);
     }
 }