[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 3 /* 4 * This file is part of the symfony package. 5 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com> 6 * 7 * For the full copyright and license information, please view the LICENSE 8 * file that was distributed with this source code. 9 */ 10 11 /** 12 * 13 * @package symfony 14 * @subpackage util 15 * @author Nick Lane <nick.lane@internode.on.net> 16 * @author Fabien Potencier <fabien.potencier@symfony-project.com> 17 * @version SVN: $Id: sfPropelManyToMany.class.php 1931 2006-09-02 17:56:18Z fabien $ 18 */ 19 class sfPropelManyToMany 20 { 21 public static function getColumn($class, $middleClass) 22 { 23 // find the related class 24 $tableMap = call_user_func(array($middleClass.'Peer', 'getTableMap')); 25 $object_table_name = constant($class.'Peer::TABLE_NAME'); 26 foreach ($tableMap->getColumns() as $column) 27 { 28 if ($column->isForeignKey() && $object_table_name == $column->getRelatedTableName()) 29 { 30 return $column; 31 } 32 } 33 } 34 35 public static function getRelatedColumn($class, $middleClass) 36 { 37 // find the related class 38 $tableMap = call_user_func(array($middleClass.'Peer', 'getTableMap')); 39 $object_table_name = constant($class.'Peer::TABLE_NAME'); 40 foreach ($tableMap->getColumns() as $column) 41 { 42 if ($column->isForeignKey() && $object_table_name != $column->getRelatedTableName()) 43 { 44 return $column; 45 } 46 } 47 } 48 49 public static function getRelatedClass($class, $middleClass) 50 { 51 $column = self::getRelatedColumn($class, $middleClass); 52 53 // we must load all map builder classes 54 $classes = sfFinder::type('file')->name('*MapBuilder.php')->in(sfLoader::getModelDirs()); 55 foreach ($classes as $class) 56 { 57 $class_map_builder = basename($class, '.php'); 58 $map = new $class_map_builder(); 59 $map->doBuild(); 60 } 61 62 $tableMap = call_user_func(array($middleClass.'Peer', 'getTableMap')); 63 64 return $tableMap->getDatabaseMap()->getTable($column->getRelatedTableName())->getPhpName(); 65 } 66 67 public static function getAllObjects($object, $middleClass, $criteria = null) 68 { 69 if (null === $criteria) 70 { 71 $criteria = new Criteria(); 72 } 73 74 $relatedClass = self::getRelatedClass(get_class($object), $middleClass); 75 76 return call_user_func(array($relatedClass.'Peer', 'doSelect'), $criteria); 77 } 78 79 /** 80 * Gets objects related by a many-to-many relationship, with a middle table. 81 * 82 * @param $object The object to get related objects for. 83 * @param $middleClass The middle class used for the many-to-many relationship. 84 * @param $criteria Criteria to apply to the selection. 85 */ 86 public static function getRelatedObjects($object, $middleClass, $criteria = null) 87 { 88 if (null === $criteria) 89 { 90 $criteria = new Criteria(); 91 } 92 93 $relatedClass = self::getRelatedClass(get_class($object), $middleClass); 94 95 $relatedObjects = array(); 96 $objectMethod = 'get'.$middleClass.'sJoin'.$relatedClass; 97 $relatedMethod = 'get'.$relatedClass; 98 $rels = $object->$objectMethod($criteria); 99 foreach ($rels as $rel) 100 { 101 $relatedObjects[] = $rel->$relatedMethod(); 102 } 103 104 return $relatedObjects; 105 } 106 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |