| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 lmb_require('limb/active_record/src/lmbARRelationCollection.class.php'); 10 11 /** 12 * class lmbAROneToManyCollection. 13 * 14 * @package active_record 15 * @version $Id: lmbAROneToManyCollection.class.php 5997 2007-06-18 12:27:21Z pachanga $ 16 */ 17 class lmbAROneToManyCollection extends lmbARRelationCollection 18 { 19 protected function _createDbRecordSet($extra_criteria = null) 20 { 21 $class = $this->relation_info['class']; 22 $object = new $class(null, $this->conn); 23 $criteria = new lmbSQLFieldCriteria($this->relation_info['field'], $this->owner->getId()); 24 25 if($extra_criteria) 26 $criteria->addAnd($extra_criteria); 27 28 return $object->getDbTable()->select($criteria); 29 } 30 31 function add($object) 32 { 33 $property = $object->mapFieldToProperty($this->relation_info['field']); 34 $object->set($property, $this->owner); 35 36 parent :: add($object); 37 } 38 39 function set($objects) 40 { 41 $old_objects = array(); 42 foreach($this as $obj) 43 $old_objects[$obj->getId()] = $obj; 44 45 foreach($objects as $obj) 46 { 47 if(!isset($old_objects[$obj->getId()])) 48 $this->add($obj); 49 else 50 { 51 $obj->save(); 52 unset($old_objects[$obj->getId()]); 53 } 54 } 55 56 foreach($old_objects as $obj) 57 $obj->destroy(); 58 } 59 60 protected function _removeRelatedRecords() 61 { 62 lmbActiveRecord :: delete($this->relation_info['class'], 63 new lmbSQLFieldCriteria($this->relation_info['field'], $this->owner->getId()), 64 $this->conn); 65 } 66 67 protected function _saveObject($object, $error_list = null) 68 { 69 $object->set($this->relation_info['field'], $this->owner->getId()); 70 $object->save($error_list); 71 } 72 73 function nullify() 74 { 75 $rs = $this->find(); 76 foreach($rs as $object) 77 { 78 $object->set($this->relation_info['field'], null); 79 $object->save(); 80 } 81 82 } 83 } 84 85 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Nov 22 03:48:54 2008 | Cross-referenced by PHPXref 0.7 |