__construct()
15: function __construct() {
17: $this->class_name = get_class($this);
18:
20: if(!isset($this->table)) {
21: $this->table = inflector :: tableize($this->class_name);
22: }
23:
25: if(!isset($this->primary_key)) {
26: $this->primary_key = 'id';
27: }
28:
30: $db_config = __db_config();
32: $adapter = ucwords($db_config['adapter']) . "Adapter";
33: $this->adapter = new $adapter(& $this);
34:
35: }
File: lib/model/active_record.php, #line 15
find($options)
45: public function find($options) {
46: $this->adapter->options_to_sql(&$options);
47: return $this->adapter->select($options);
48: }
File: lib/model/active_record.php, #line 45
find_by_sql($sql)
58: public function find_by_sql($sql) {
59: return $this->adapter->select(array('sql' => $sql));
60: }
File: lib/model/active_record.php, #line 58
find_all($options = array())
67: public function find_all($options = array()) {
68: $this->adapter->options_to_sql(&$options);
69: return $this->adapter->select($options);
70: }
File: lib/model/active_record.php, #line 67
find_last($options = array())
77: public function find_last($options = array()) {
78: $options['last'] = true;
79: $this->adapter->options_to_sql(&$options);
80: return $this->adapter->select($options);
81: }
File: lib/model/active_record.php, #line 77
find_first($options = array())
88: public function find_first($options = array()) {
89: $options['first'] = true;
90: $this->adapter->options_to_sql(&$options);
91: return $this->adapter->select($options);
92: }
File: lib/model/active_record.php, #line 88
size($options = array())
94: public function size($options = array()) {
95: $this->adapter->options_to_sql(&$options);
96: return $this->adapter->size($options);
97: }
File: lib/model/active_record.php, #line 94
create($attributes = false)
106: public function create($attributes = false) {
108: $object = new $this->class_name;
110: $object->params = $this->params;
111:
113: if(is_array($attributes)) {
114: foreach($attributes as $key => $param) {
115: $object-> $key = $param;
116: }
117: }
118:
119: return $object;
120: }
File: lib/model/active_record.php, #line 106
save()
127: public function save() {
129: $this->callback('before_validate');
131: new Validation(& $this);
133: $this->callback('after_validate');
135: if($this->field_error) {
136: return false;
137: } else {
139: if(isset($this->id)) {
141: return $this->update();
142: } else {
144: $this->callback('before_save');
146: $save = $this->adapter->save();
148: $this->callback('after_save');
149: return $save;
150: }
151: }
152: }
File: lib/model/active_record.php, #line 127
update()
161: public function update() {
163: $this->callback('before_validate');
165: new Validation(& $this);
167: $this->callback('after_validate');
169: if($this->field_error) {
170: return false;
171: } else {
173: $this->callback('before_update');
174: $return = $this->adapter->update();
176: $this->callback('after_update');
177: return $return;
178: }
179: }
File: lib/model/active_record.php, #line 161
update_attributes($attributes = array())
192: public function update_attributes($attributes = array()) {
194: $this->callback('before_validate');
196: new Validation(& $this);
198: $this->callback('after_validate');
200: if($this->field_error) {
201: return false;
202: } else {
204: $this->callback('before_update');
205: $return = $this->adapter->update_attributes($attributes);
207: $this->callback('after_update');
208: return $return;
209: }
210: }
File: lib/model/active_record.php, #line 192
update_attribute($name = false, $value = false)
217: public function update_attribute($name = false, $value = false) {
225: if($this->field_error) {
226: return false;
227: } else {
229: $this->callback('before_update');
230: $return = $this->adapter->update_attribute($name, $value);
232: $this->callback('after_update');
233: return $return;
234: }
235: }
File: lib/model/active_record.php, #line 217
update_all($attributes = array(), $conditions = array())
242: public function update_all($attributes = array(), $conditions = array()) {
244: $this->callback('before_validate');
246: new Validation(& $this);
248: $this->callback('after_validate');
250: if($this->field_error) {
251: return false;
252: } else {
254: $this->callback('before_update');
255: $return = $this->adapter->update_all($attributes, $conditions);
257: $this->callback('after_update');
258: return $return;
259: }
260: }
File: lib/model/active_record.php, #line 242
destroy()
267: public function destroy() {
268: return $this->adapter->destroy();
269: }
File: lib/model/active_record.php, #line 267
valid()
276: public function valid() {
277: new Validation(& $this);
278: if($this->field_error) {
279: return false;
280: } else {
281: return true;
282: }
283: }
File: lib/model/active_record.php, #line 276
error_add($attribute, $msg)
290: public function error_add($attribute, $msg) {
291: $table = strtolower(inflector :: underscore($this->class_name));
292: $this->field_error["{$table}/{$attribute}"] = $msg;
293: }
File: lib/model/active_record.php, #line 290
__call($method, $args)
348: public function __call($method, $args) {
349: if(preg_match('/find_all_by/', $method)) {
350: $args['conditions']['all'] = true;
351: return $this->find_by($method, $args);
352: }
353: elseif(preg_match('/find_by/', $method)) {
354: $args['conditions']['limit'] = 1;
355: return $this->find_by($method, $args);
356: } else {
357: trigger_error("Method {$method}() doesn't exist in Active Record");
358: }
359: }
File: lib/model/active_record.php, #line 348
__get($associate)
368: public function __get($associate) {
369: if(isset($this->has_many)) {
370: if(array_key_exists($associate, $this->has_many)) {
371: if(!isset($this-> $associate)) {
372: $this->$associate = $this->adapter->has_many($this->has_many[$associate], $associate);
373: return $this->$associate;
374: }
375: }
376: }
377:
378: if(isset($this->has_one)) {
379: if(array_key_exists($associate, $this->has_one)) {
380: if(!isset($this-> $associate)) {
381: $this->$associate = $this->adapter->has_one($this->has_one[$associate], $associate);
382: return $this->$associate;
383: }
384: }
385: }
386:
387: if(isset($this->belongs_to)) {
388: if(array_key_exists($associate, $this->belongs_to)) {
389: if(!isset($this-> $associate)) {
390: $this->$associate = $this->adapter->belongs_to($this->belongs_to[$associate], $associate);
391: return $this->$associate;
392: }
393: }
394: }
395:
396: if(isset($this->has_and_belongs_to_many)) {
397: if(array_key_exists($associate, $this->has_and_belongs_to_many)) {
398: $this->$associate = $this->adapter->has_and_belongs_to_many($this->has_and_belongs_to_many[$associate], $associate);
399: return $this->$associate;
400: }
401: }
402: }
File: lib/model/active_record.php, #line 368
