04.01
php
saved
dardosordi
Note
fixed AD7Six polymorphic behavior
fixed AD7Six polymorphic behavior
- <?php
- /* SVN FILE: $Id: polymorphic.php 18 2008-03-07 12:56:09Z andy $ */
- /**
- * Polymorphic Behavior.
- *
- * Allow the model to be associated with any other model object
- *
- * Copyright (c), Andy Dawson
- *
- * Licensed under The MIT License
- * Redistributions of files must retain the above copyright notice.
- *
- * @filesource
- * @author Andy Dawson (AD7six)
- * @version $Revision: 18 $
- * @modifiedby $LastChangedBy: andy $
- * @lastmodified $Date: 2008-03-07 13:56:09 +0100 (Fri, 07 Mar 2008) $
- * @license http://www.opensource.org/licenses/mit-license.php The MIT License
- */
- class PolymorphicBehavior extends ModelBehavior {
- $this->settings[$model->name] = am (array('classField' => 'class', 'foreignKey' => 'foreign_id'),$config);
- }
- function afterFind (&$model, $results, $primary = false) {
- foreach ($results as $key => $result) {
- $class = $result[$model->alias][$classField];
- $foreignId = $result[$model->alias][$foreignKey];
- if ($class && $foreignId) {
- $result = $result[$model->alias];
- 'foreignKey' => $foreignKey
- )
- )));
- }
- null, null, -1);
- $associated[$class]['display_field'] = $associated[$class][$model->$class->displayField];
- $results[$key][$class] = $associated[$class];
- }
- }
- $class = $results[$model->alias][$classField];
- $foreignId = $results[$model->alias][$foreignKey];
- if ($class && $foreignId) {
- $result = $results[$model->alias];
- 'foreignKey' => $foreignKey
- )
- )));
- }
- $associated[$class]['display_field'] = $associated[$class][$model->$class->displayField];
- $results[$class] = $associated[$class];
- }
- }
- return $results;
- }
- }
- ?>
Parsed in 0.128 seconds, using GeSHi 1.0.7.14