getData() public méthode

return all the internal data (columns)
public getData ( ) : array
Résultat array an array containing all the properties
Exemple #1
0
 /**
  * Validates a given record and saves possible errors in Doctrine_Validator::$stack
  *
  * @param  Doctrine_Record $record
  * @return void
  */
 public function validateRecord(Doctrine_Record $record)
 {
     $table = $record->getTable();
     // if record is transient all fields will be validated
     // if record is persistent only the modified fields will be validated
     $fields = $record->exists() ? $record->getModified() : $record->getData();
     foreach ($fields as $fieldName => $value) {
         $table->validateField($fieldName, $value, $record);
     }
 }
Exemple #2
0
 /**
  * Dumps a record.
  *
  * This method returns an html representation of a given
  * record, containing keys, state and data.
  *
  * @param Doctrine_Record $record
  * @return string
  */
 public static function getRecordAsString(Doctrine_Record $record)
 {
     $r[] = '<pre>';
     $r[] = 'Component  : ' . $record->getTable()->getComponentName();
     $r[] = 'ID         : ' . Doctrine::dump($record->identifier());
     $r[] = 'References : ' . count($record->getReferences());
     $r[] = 'State      : ' . Doctrine_Lib::getRecordStateAsString($record->state());
     $r[] = 'OID        : ' . $record->getOID();
     $r[] = 'data       : ' . Doctrine::dump($record->getData(), false);
     $r[] = '</pre>';
     return implode("\n", $r) . "<br />";
 }
 /**
  * validates a given record and saves possible errors
  * in Doctrine_Validator::$stack
  *
  * @param Doctrine_Record $record
  * @return void
  */
 public function validateRecord(Doctrine_Record $record)
 {
     $columns = $record->getTable()->getColumns();
     $component = $record->getTable()->getComponentName();
     $errorStack = $record->getErrorStack();
     // if record is transient all fields will be validated
     // if record is persistent only the modified fields will be validated
     $data = $record->exists() ? $record->getModified() : $record->getData();
     $err = array();
     foreach ($data as $key => $value) {
         if ($value === self::$_null) {
             $value = null;
         } elseif ($value instanceof Doctrine_Record) {
             $value = $value->getIncremented();
         }
         $column = $columns[$key];
         if ($column['type'] == 'enum') {
             $value = $record->getTable()->enumIndex($key, $value);
             if ($value === false) {
                 $errorStack->add($key, 'enum');
                 continue;
             }
         }
         if ($record->getTable()->getAttribute(Doctrine::ATTR_AUTO_LENGTH_VLD)) {
             if (!$this->validateLength($column, $key, $value)) {
                 $errorStack->add($key, 'length');
                 continue;
             }
         }
         foreach ($column as $name => $args) {
             if (empty($name) || $name == 'primary' || $name == 'protected' || $name == 'autoincrement' || $name == 'default' || $name == 'values' || $name == 'sequence' || $name == 'zerofill') {
                 continue;
             }
             if (strtolower($name) == 'length') {
                 if (!$record->getTable()->getAttribute(Doctrine::ATTR_AUTO_LENGTH_VLD)) {
                     if (!$this->validateLength($column, $key, $value)) {
                         $errorStack->add($key, 'length');
                     }
                 }
                 continue;
             }
             if (strtolower($name) == 'type') {
                 if (!$record->getTable()->getAttribute(Doctrine::ATTR_AUTO_TYPE_VLD)) {
                     if (!self::isValidType($value, $column['type'])) {
                         $errorStack->add($key, 'type');
                     }
                 }
                 continue;
             }
             $validator = self::getValidator($name);
             if (!$validator->validate($record, $key, $value, $args)) {
                 $errorStack->add($key, $name);
                 //$err[$key] = 'not valid';
                 // errors found quit validation looping for this column
                 //break;
             }
         }
         if ($record->getTable()->getAttribute(Doctrine::ATTR_AUTO_TYPE_VLD)) {
             if (!self::isValidType($value, $column['type'])) {
                 $errorStack->add($key, 'type');
                 continue;
             }
         }
     }
 }
Exemple #4
0
 /**
  * constructor
  *
  * @param Doctrine_Record $record
  */
 public function __construct(Doctrine_Record $record)
 {
     $this->record = $record;
     parent::__construct($record->getData());
 }
Exemple #5
0
 /**
  * Return a recrd as XML. 
  *
  * In order to control how this is done set the "xml" option in a record. 
  * This option is an array that has the keys "ignore_fields" and "include_relations". Both of these are arrays that list the name of fields/relations to include/process. 
  *
  * If you want to insert this xml as a part inside another xml send a 
  * SimpleXMLElement to the function. Because of the nature of SimpleXML the 
  * content you add to this element will be avilable after the function is 
  * complete.
  *
  * @param Doctrine_Record $record
  * @param SimpleXMLElement $xml
  * @return string Xml as string
  */
 public static function getRecordAsXml(Doctrine_Record $record, SimpleXMlElement $incomming_xml = NULL)
 {
     $recordname = $record->getTable()->tableName;
     if (!isset($incomming_xml)) {
         $new_xml_string = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><" . $recordname . "></" . $recordname . ">";
         $xml = new SimpleXMLElement($new_xml_string);
     } else {
         $xml = $incomming_xml->addChild($recordname);
     }
     foreach ($record->obtainIdentifier() as $pk_field => $pk_value) {
         $xml->addChild($pk_field, $pk_value);
     }
     $xml_options = $record->option("xml");
     if (isset($xml_options["record_name"])) {
         $recordname = $xml_options["record_name"];
     }
     foreach ($record->getData() as $field => $value) {
         if (isset($xml_options["ignore_fields"]) && !in_array($field, $xml_options["ignore_fields"]) || !isset($xml_options["ignore_fields"])) {
             if ($value instanceof Doctrine_Null) {
                 $xml->addChild($field);
             } else {
                 $xml->addChild($field, $value);
             }
         }
     }
     if (!isset($xml_options["include_relations"])) {
         return $xml->asXML();
     }
     $relations = $record->getTable()->getRelations();
     foreach ($relations as $name => $relation) {
         if (in_array($name, $xml_options["include_relations"])) {
             $relation_type = $relation->getType();
             $related_records = $record->get($name);
             if ($relation_type == Doctrine_Relation::ONE && $related_records instanceof Doctrine_Record) {
                 Doctrine_Lib::getRecordAsXml($related_records, $xml);
             } else {
                 Doctrine_Lib::getCollectionAsXml($related_records, $xml);
             }
         }
     }
     return $xml->asXML();
 }