예제 #1
0
 /**
  * To Object
  * Copies the values from a query result row to an object.
  * Also initializes that object by running get rules, and
  *   refreshing stored values on the object.
  *
  * Finally, if any "instantiations" are requested, those related objects
  *   are created off of query results
  *
  * This is only public so that the iterator can access it.
  *
  * @ignore
  * @param	DataMapper $item Item to configure
  * @param	object $row Query results
  */
 public function _to_object($item, $row)
 {
     // Populate this object with values from first record
     foreach ($row as $key => $value) {
         $item->{$key} = $value;
     }
     foreach ($this->fields as $field) {
         if (!isset($row->{$field})) {
             $item->{$field} = NULL;
         }
     }
     // Force IDs to integers
     foreach ($this->_field_tracking['intval'] as $field) {
         if (isset($item->{$field})) {
             $item->{$field} = intval($item->{$field});
         }
     }
     if (!empty($this->_field_tracking['get_rules'])) {
         $item->_run_get_rules();
     }
     $item->_refresh_stored_values();
     if ($this->_instantiations) {
         foreach ($this->_instantiations as $related_field => $field_map) {
             // convert fields to a 'row' object
             $row = new stdClass();
             foreach ($field_map as $item_field => $c_field) {
                 $row->{$c_field} = $item->{$item_field};
             }
             // get the related item
             $c =& $item->_get_without_auto_populating($related_field);
             // set the values
             $c->_to_object($c, $row);
             // also set up the ->all array
             $c->all = array();
             $c->all[0] = $c->get_clone();
         }
     }
 }