| [ 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 lmbARManyToManyCollection. 13 * 14 * @package active_record 15 * @version $Id: lmbARManyToManyCollection.class.php 6017 2007-06-27 08:19:09Z serega $ 16 */ 17 class lmbARManyToManyCollection extends lmbARRelationCollection 18 { 19 protected function _createDbRecordSet2($criteria = null) 20 { 21 $class = $this->relation_info['class']; 22 $object = new $class(); 23 $table = $object->getTableName(); 24 25 $join_table = $this->relation_info['table']; 26 $field = $this->relation_info['field']; 27 $foreign_field = $this->relation_info['foreign_field']; 28 29 $sql = "SELECT {$table}.* FROM {$table}, {$join_table} 30 WHERE {$table}.id={$join_table}.$foreign_field AND 31 {$join_table}.{$field}=" . $this->owner->getId() . ' %where%'; 32 33 $query = new lmbSelectQuery($sql, $this->conn); 34 if($criteria) 35 $query->addCriteria($criteria); 36 return $query->getRecordSet(); 37 } 38 39 protected function _createDbRecordSet($criteria = null) 40 { 41 $class = $this->relation_info['class']; 42 $object = new $class(); 43 $table = $this->conn->quoteIdentifier($object->getTableName()); 44 45 $join_table = $this->conn->quoteIdentifier($this->relation_info['table']); 46 $field = $this->conn->quoteIdentifier($this->relation_info['field']); 47 $foreign_field = $this->conn->quoteIdentifier($this->relation_info['foreign_field']); 48 49 $sql = "SELECT $table.* FROM $table, $join_table 50 WHERE $table.id=$join_table.$foreign_field AND 51 $join_table.$field=" . $this->owner->getId() . ' %where%'; 52 53 $query = new lmbSelectQuery($sql, $this->conn); 54 if($criteria) 55 $query->addCriteria($criteria); 56 return $query->getRecordSet(); 57 } 58 59 function set($objects) 60 { 61 $this->removeAll(); 62 foreach($objects as $object) 63 $this->add($object); 64 } 65 66 protected function _removeRelatedRecords() 67 { 68 $table = new lmbTableGateway($this->relation_info['table'], $this->conn); 69 $criteria = new lmbSQLCriteria(); 70 $criteria->addAnd(new lmbSQLFieldCriteria($this->relation_info['field'], $this->owner->getId())); 71 $criteria->addAnd(new lmbSQLFieldCriteria($this->relation_info['foreign_field'], 'NULL', lmbSQLFieldCriteria :: NOT_EQUAL)); 72 73 $table->delete($criteria); 74 } 75 76 protected function _saveObject($object, $error_list = null) 77 { 78 $table = new lmbTableGateway($this->relation_info['table'], $this->conn); 79 $object->save($error_list); 80 $table->insert(array($this->relation_info['field'] => $this->owner->getId(), 81 $this->relation_info['foreign_field'] => $object->getId())); 82 } 83 } 84 85 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Oct 7 05:02:03 2008 | Cross-referenced by PHPXref 0.7 |