public
Description: PHP Framework
Homepage: http://phpcomodo.com
Clone URL: git://github.com/ecentinela/comodo.git
Added a new private method to set values on object attributes. Used to bypass 
the <readonly> property when loading data on find methods.
ecentinela (author)
Thu Oct 02 13:22:32 -0700 2008
commit  63daba8de76a151f95129f85daa33b92176392e1
tree    d2ea98c1e7a37263d53f7d8b87c0169dc55c56e6
parent  2e24697e2a6d250b42e91fbf154c11af80473ab9
...
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
 
 
460
461
462
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
463
464
465
...
438
439
440
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
0
@@ -438,28 +438,45 @@ abstract class activeRecordBase extends activeRecordBelongsTo {
0
   final public function write_attribute($attribute, $value) {
0
     if ($this->_readonly)
0
       trigger_error('Trying to modify the attribute #<' . $attribute . '> on a read only object #<' . $this->_class_name . '>', E_USER_ERROR);
0
-    else {
0
-      $this->_attributes_before_typecast[$attribute] = $value;
0
-      switch ($this->type_of_attribute($attribute)) {
0
-        case 'integer':
0
-          $this->_attributes[$attribute] = (integer)$value;
0
-          break;
0
-        case 'float':
0
-          $this->_attributes[$attribute] = (float)$value;
0
-          break;
0
-        case 'boolean':
0
-          $this->_attributes[$attribute] = (boolean)$value;
0
-          break;
0
-        case 'string':
0
-          $this->_attributes[$attribute] = (string)$value;
0
-          break;
0
-        default:
0
-          $this->_attributes[$attribute] = $value;
0
-      }
0
-    }
0
+    else
0
+      $this->_set_value($attribute, $value);
0
     return $this;
0
   }
0
 
0
+  # USED INTERNALLY
0
+  # _set_value($attribute, $value)
0
+  # ==============================
0
+  #
0
+  # Sets the given attribute value on the field.
0
+  # This method is used internally for passing the <read_only> attribute on objects on find operations.
0
+  #
0
+  #
0
+  #
0
+  # Arguments
0
+  # ---------
0
+  #
0
+  # * attribute: the attribute you want to set.
0
+  # * value: the value to set on the attribute.
0
+  final public function _set_value($attribute, $value) {
0
+    $this->_attributes_before_typecast[$attribute] = $value;
0
+    switch ($this->type_of_attribute($attribute)) {
0
+      case 'integer':
0
+        $this->_attributes[$attribute] = (integer)$value;
0
+        break;
0
+      case 'float':
0
+        $this->_attributes[$attribute] = (float)$value;
0
+        break;
0
+      case 'boolean':
0
+        $this->_attributes[$attribute] = (boolean)$value;
0
+        break;
0
+      case 'string':
0
+        $this->_attributes[$attribute] = (string)$value;
0
+        break;
0
+      default:
0
+        $this->_attributes[$attribute] = $value;
0
+    }
0
+  }
0
+
0
   # new_record()
0
   # ============
0
   #
...
569
570
571
572
 
573
574
575
...
593
594
595
596
 
 
 
597
598
599
...
569
570
571
 
572
573
574
575
...
593
594
595
 
596
597
598
599
600
601
0
@@ -569,7 +569,7 @@ abstract class activeRecordFind extends activeRecordHasAndBelonsToMany {
0
       foreach ($data as $i => $row)
0
         foreach ($row as $attribute => $value)
0
           $processed_data[$i][$attribute] = in_array($attribute, $this->_serialize) ? unserialize($value) : $value;
0
-      $fn = create_function('$r', 'return new ' . $this->_class_name . '($r, true);');
0
+      $fn = create_function('$r', '$o = new ' . $this->_class_name . '; foreach ($r as $f => $v) $o->_set_value($f, $v); return $o;');
0
       return array_map($fn, $processed_data);
0
     }
0
 
0
@@ -593,7 +593,9 @@ abstract class activeRecordFind extends activeRecordHasAndBelonsToMany {
0
 
0
           $relation = $include_information[$table]['r'];
0
           if (!$relation || !in_array($values[$pk], $items_ids[$table])) {
0
-            $ob = new $include_information[$table]['cn']($values, true);
0
+            $ob = new $include_information[$table]['cn'];
0
+            foreach ($values as $field => $value)
0
+              $ob->_set_value($field, $value);
0
             $items[$table][] = $ob;
0
             $items_ids[$table][] = $values[$pk];
0
             if ($relation) {
...
1
2
3
4
 
5
6
7
...
163
164
165
166
 
167
168
169
...
200
201
202
 
203
204
205
...
1
 
 
 
2
3
4
5
...
161
162
163
 
164
165
166
167
...
198
199
200
201
202
203
204
0
@@ -1,7 +1,5 @@
0
 <?php
0
-/*
0
-:counter_sql - specify a complete SQL statement to fetch the size of the association. If :finder_sql is specified but not :counter_sql, :counter_sql will be generated by replacing SELECT … FROM with SELECT COUNT(*) FROM.
0
-*/
0
+
0
 abstract class activeRecordHasMany extends activeRecordHasOne {
0
 
0
   # USED INTERNALLY
0
@@ -163,7 +161,7 @@ abstract class activeRecordHasMany extends activeRecordHasOne {
0
     $object = new $options['class_name'];
0
 
0
     if ($options['finder_sql']) {
0
-      $sql = string_format($options['finder_sql'], $this->{$this->_primary_key});
0
+      $sql = apply_template($options['finder_sql'], $this->{$this->_primary_key});
0
       return $object->find_by_sql($sql);
0
     }
0
 
0
@@ -200,6 +198,7 @@ abstract class activeRecordHasMany extends activeRecordHasOne {
0
       $this->stringify_ids_conditions($this->{$this->_primary_key}, $object->_table_name . '.' . $options['foreign_key'], $conditions, $values);
0
 
0
     $options['conditions'] = array(implode(' AND ', $conditions), $values);
0
+
0
     return $object->find('all', $options);
0
   }
0
 

Comments