Beispiel #1
0
 public static function build(Sabel_Db_Model $source, Sabel_Db_Join_Structure $structure, $rows)
 {
     $objects = $structure->getJoinObjects();
     $structure = $structure->getStructure();
     $tables = array();
     foreach ($structure as $joinTables) {
         $tables = array_merge($tables, $joinTables);
     }
     $results = array();
     $selfObj = MODEL($source->getName());
     foreach ($rows as $row) {
         $models = self::createModels($row, $tables, $objects);
         foreach ($tables as $tblName) {
             if (!isset($structure[$tblName])) {
                 continue;
             }
             foreach ($structure[$tblName] as $parent) {
                 $name = convert_to_modelname($parent);
                 $models[$tblName]->__set($name, $models[$parent]);
             }
         }
         $self = clone $selfObj;
         $self->setProperties($row);
         $tblName = $source->getTableName();
         foreach ($structure[$tblName] as $parent) {
             $name = convert_to_modelname($parent);
             $self->__set($name, $models[$parent]);
         }
         $results[] = $self;
     }
     return $results;
 }
Beispiel #2
0
 public function __construct($model)
 {
     if (is_string($model)) {
         $model = MODEL($model);
     } elseif (!is_model($model)) {
         $message = __METHOD__ . "() argument must be a string or an instance of model.";
         throw new Sabel_Exception_InvalidArgument($message);
     }
     $this->model = $model;
     $this->tblName = $model->getTableName();
     $this->structure = Sabel_Db_Join_Structure::getInstance();
 }
Beispiel #3
0
 public function add($object, $alias = "", $joinKey = array())
 {
     if (is_string($object)) {
         $object = new Sabel_Db_Join_Object(MODEL($object), $alias, $joinKey);
     } elseif (is_model($object)) {
         $object = new Sabel_Db_Join_Object($object, $alias, $joinKey);
     }
     $structure = Sabel_Db_Join_Structure::getInstance();
     $structure->addJoinObject($this->getName(), $object);
     $object->setChildName($this->getName());
     $this->objects[] = $object;
     if (empty($joinKey)) {
         $name = $object->getModel()->getTableName();
         $object->setJoinKey(create_join_key($this->model, $name));
     }
     return $this;
 }
Beispiel #4
0
 public function add($object, $on = array(), $alias = "", $type = "")
 {
     if (is_string($object) || is_model($object)) {
         $object = new Sabel_Db_Join_Object($object);
     }
     if (!empty($alias)) {
         $object->setAlias($alias);
     }
     if (!empty($type)) {
         $object->setJoinType($type);
     }
     $object->setChildName($this->tblName);
     $this->structure->addJoinObject($this->tblName, $object);
     $this->objects[] = $object;
     if (!empty($on)) {
         $object->on($on);
     } elseif ($object->getOn() === array()) {
         $object->on(create_join_key($this->model, $object->getModel()->getTableName()));
     }
     return $this;
 }
Beispiel #5
0
 public function clear()
 {
     $this->structure = array();
     $this->joinObjects = array();
     self::$instance = null;
 }