Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 public function __construct(Sabel_Db_Model $model)
 {
     $this->model = $model;
     $this->mdlName = $model->getName();
     $this->isUpdate = $model->isSelected();
     $this->messages = Sabel_Db_Validate_Config::getMessages();
     $this->localizedNames = Sabel_Db_Model_Localize::getColumnNames($this->mdlName);
 }
Ejemplo n.º 3
0
 protected function createProjection(Sabel_Db_Statement $stmt)
 {
     if (empty($this->projection)) {
         $projection = array();
         foreach ($this->objects as $object) {
             $projection = array_merge($projection, $object->getProjection($stmt));
         }
         $quotedTblName = $stmt->quoteIdentifier($this->tblName);
         foreach ($this->model->getColumnNames() as $column) {
             $projection[] = $quotedTblName . "." . $stmt->quoteIdentifier($column);
         }
     } else {
         $projection = array();
         foreach ($this->projection as $name => $proj) {
             if (($tblName = convert_to_tablename($name)) === $this->tblName) {
                 foreach ($proj as $column) {
                     $projection[] = $stmt->quoteIdentifier($tblName) . "." . $stmt->quoteIdentifier($column);
                 }
             } else {
                 foreach ($proj as $column) {
                     $as = "{$tblName}.{$column}";
                     if (strlen($as) > 30) {
                         $as = Sabel_Db_Join_ColumnHash::toHash($as);
                     }
                     $p = $stmt->quoteIdentifier($tblName) . "." . $stmt->quoteIdentifier($column);
                     $projection[] = $p . " AS " . $stmt->quoteIdentifier($as);
                 }
             }
         }
     }
     return implode(", ", $projection);
 }
Ejemplo n.º 4
0
 protected function fetch($key, $forUpdate = false)
 {
     if ($forUpdate) {
         $results = $this->model->selectForUpdate($key);
         return isset($results[0]) ? $results[0] : null;
     } else {
         $model = $this->model->selectOne($key);
         return $model->isSelected() ? $model : null;
     }
 }
Ejemplo n.º 5
0
 public function __wakeup()
 {
     l("[form] unserialize form object", SBL_LOG_DEBUG);
     $values = $this->model;
     $this->model = MODEL($this->mdlName);
     if ($this->isSelected) {
         $this->model->setProperties($values);
         $this->model->setUpdateValues($this->updateValues);
     } else {
         $this->model->setValues($values);
     }
     $this->columns = $this->model->getColumns();
 }
Ejemplo n.º 6
0
 /**
  * @param Sabel_Db_Model $model
  *
  * @return void
  */
 protected function _doSelectOne(Sabel_Db_Model $model)
 {
     $stmt = $this->prepareStatement(Sabel_Db_Statement::SELECT);
     $rows = $this->prepareSelect($stmt)->execute();
     if (isset($rows[0])) {
         $model->setProperties($rows[0]);
     }
 }
Ejemplo n.º 7
0
function create_join_key(Sabel_Db_Model $childModel, $parentName)
{
    if ($fkey = $childModel->getMetadata()->getForeignKey()) {
        foreach ($fkey->toArray() as $colName => $fkey) {
            if ($fkey->table === $parentName) {
                return array("id" => $fkey->column, "fkey" => $colName);
            }
        }
    }
    return array("id" => "id", "fkey" => $parentName . "_id");
}