/** * Constructor allows plugins to modify the data model. * @var int $id ID of the record to load. If null then creates a new record. If -1 then the ORM * object is not initialised, providing access to the variables only. */ public function __construct($id = NULL) { if (is_object($id) || $id != -1) { // use caching, so things don't slow down if there are lots of plugins. the object_name does not // exist yet as we haven't called the parent construct, so we build our own. $object_name = strtolower(substr(get_class($this), 0, -6)); $cacheId = 'orm-' . $object_name; $this->cache = Cache::instance(); $ormRelations = $this->cache->get($cacheId); if ($ormRelations === null) { // now look for modules which plugin to tweak the orm relationships. foreach (Kohana::config('config.modules') as $path) { $plugin = basename($path); if (file_exists("{$path}/plugins/{$plugin}.php")) { require_once "{$path}/plugins/{$plugin}.php"; if (function_exists($plugin . '_extend_orm')) { $extends = call_user_func($plugin . '_extend_orm'); if (isset($extends[$object_name])) { if (isset($extends[$object_name]['has_one'])) { $this->has_one = array_merge($this->has_one, $extends[$object_name]['has_one']); } if (isset($extends[$object_name]['has_many'])) { $this->has_many = array_merge($this->has_many, $extends[$object_name]['has_many']); } if (isset($extends[$object_name]['belongs_to'])) { $this->belongs_to = array_merge($this->belongs_to, $extends[$object_name]['belongs_to']); } if (isset($extends[$object_name]['has_and_belongs_to_many'])) { $this->has_and_belongs_to_many = array_merge($this->has_and_belongs_to_many, $extends[$object_name]['has_and_belongs_to_many']); } } } } } $cacheArray = array('has_one' => $this->has_one, 'has_many' => $this->has_many, 'belongs_to' => $this->belongs_to, 'has_and_belongs_to_many' => $this->has_and_belongs_to_many); $this->cache->set($cacheId, $cacheArray); } else { $this->has_one = $ormRelations['has_one']; $this->has_many = $ormRelations['has_many']; $this->belongs_to = $ormRelations['belongs_to']; $this->has_and_belongs_to_many = $ormRelations['has_and_belongs_to_many']; } parent::__construct($id); } }
/** * Set up the formo ignore and the model * @Developer brandon * @Date May 18, 2010 */ public function __construct($id = NULL) { parent::__construct($id); $this->formo_ignores = array_merge($this->formo_ignores, array('id', 'created_at', 'updated_at')); }