예제 #1
0
파일: Finder.php 프로젝트: reoring/sabel
 public function __construct($mdlName, $projection = null)
 {
     $this->model = is_model($mdlName) ? $mdlName : MODEL($mdlName);
     if ($projection !== null) {
         $this->p($projection);
     }
 }
예제 #2
0
 public function __construct()
 {
     if ($this->modelName === "") {
         $this->modelName = substr($this->getName(), 8);
     }
     $this->model = MODEL($this->modelName);
 }
예제 #3
0
파일: Result.php 프로젝트: reoring/sabel
 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;
 }
예제 #4
0
파일: Join.php 프로젝트: reoring/sabel
 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();
 }
예제 #5
0
파일: Model.php 프로젝트: reoring/sabel
 public function setModel($model)
 {
     if (is_string($model)) {
         $this->model = MODEL($model);
     } elseif ($model instanceof Sabel_Db_Model) {
         $this->model = $model;
     } else {
         $message = __METHOD__ . "() argument must be a string or an instance of model.";
         throw new Sabel_Exception_Runtime();
     }
     $this->values = $this->model->toArray();
 }
예제 #6
0
파일: Database.php 프로젝트: reoring/sabel
 public function __construct($config = array())
 {
     $this->config = $config;
     if (isset($this->config["namespace"])) {
         $this->namespace = $this->config["namespace"];
     } else {
         $this->namespace = self::DEFUALT_NAMESPACE;
     }
     if (isset($config["model"])) {
         $this->model = MODEL($config["model"]);
     } else {
         $this->model = MODEL("SblPreference");
     }
 }
예제 #7
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;
 }
예제 #8
0
 public function __construct($model, $pageKey = "page")
 {
     if (is_string($model)) {
         $model = MODEL($model);
     }
     if (is_model($model)) {
         $model->autoReinit(false);
     } elseif ($model instanceof Sabel_Db_Join) {
         $model->getModel()->autoReinit(false);
         $this->isJoin = true;
     } else {
         $message = __METHOD__ . "() invalid instance.";
         throw new Sabel_Exception_Runtime($message);
     }
     $this->model = $model;
     $this->attributes["pageKey"] = $pageKey;
 }
예제 #9
0
파일: Paginate.php 프로젝트: reoring/sabel
 public function __construct($model)
 {
     if (is_string($model)) {
         $model = MODEL($model);
     }
     if (is_model($model)) {
         $model->autoReinit(false);
         $this->method = "select";
     } elseif ($model instanceof Sabel_Db_Join) {
         $model->getModel()->autoReinit(false);
         $this->method = "join";
         $this->isJoin = true;
     } else {
         throw new Exception("Paginate::__construct() invalid instance.");
     }
     $this->model = $model;
 }
예제 #10
0
 public function fetchModel($mdlName, $conditions)
 {
     if (is_array($conditions)) {
         $_model = MODEL($mdlName);
         foreach ($conditions as $column => $value) {
             $_model->setCondition($column, $value);
         }
         $model = $_model->selectOne();
     } else {
         $model = MODEL($mdlName, $conditions);
     }
     if ($model->isSelected()) {
         return $model;
     } else {
         $this->notFound();
         return false;
     }
 }
예제 #11
0
 public function testFloatCast()
 {
     $ts = MODEL("TestSchema");
     $ts->floatcol = 1;
     $this->assertTrue(is_float($ts->floatcol));
     $this->assertEquals(1, $ts->floatcol);
     $ts->floatcol = "1";
     $this->assertTrue(is_float($ts->floatcol));
     $this->assertEquals(1, $ts->floatcol);
     $ts->floatcol = "0.123";
     $this->assertTrue(is_float($ts->floatcol));
     $this->assertEquals(0.123, $ts->floatcol);
     $ts->floatcol = "0.123.456";
     $this->assertFalse(is_float($ts->floatcol));
     $this->assertEquals("0.123.456", $ts->floatcol);
     $ts->floatcol = true;
     $this->assertFalse(is_float($ts->floatcol));
     $this->assertEquals(true, $ts->floatcol);
 }
예제 #12
0
파일: Base.php 프로젝트: reoring/sabel
 public function createModel(&$row)
 {
     $name = $this->tblName;
     static $models = array();
     if (isset($models[$name])) {
         $model = clone $models[$name];
     } else {
         $model = MODEL(convert_to_modelname($name));
         $models[$name] = clone $model;
     }
     if ($this->hasAlias()) {
         $name = strtolower($this->aliasName);
     }
     $props = array();
     foreach ($this->columns as $column) {
         $hash = Sabel_Db_Join_ColumnHash::getHash("{$name}.{$column}");
         if (array_key_exists($hash, $row)) {
             $props[$column] = $row[$hash];
             unset($row[$hash]);
         }
     }
     $model->setProperties($props);
     return $model;
 }
예제 #13
0
파일: Fixture.php 프로젝트: reoring/sabel
 protected function export_fixture()
 {
     foreach ($this->arguments as $mdlName) {
         $lines = array();
         $code = array("<?php" . PHP_EOL);
         $code[] = "class Fixture_{$mdlName} extends Sabel_Test_Fixture";
         $code[] = "{";
         $code[] = "  public function upFixture()";
         $code[] = "  {";
         $models = MODEL($mdlName)->select();
         foreach ($models as $model) {
             $code[] = '    $this->insert(' . $this->createLine($model->toArray()) . ');';
         }
         $code[] = "  }" . PHP_EOL;
         $code[] = "  public function downFixture()";
         $code[] = "  {";
         $code[] = '    $this->deleteAll();';
         $code[] = "  }";
         $code[] = "}";
         $path = FIXTURE_DIR . DS . $mdlName . ".php";
         file_put_contents($path, implode(PHP_EOL, $code));
         $this->success("export {$mdlName} Records to '" . substr($path, strlen(RUN_BASE) + 1) . "'");
     }
 }
예제 #14
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();
 }
예제 #15
0
파일: Ibase.php 프로젝트: reoring/sabel
 public function testInit()
 {
     Sabel_Db_Config::add("default", Test_DB_TestConfig::getIbaseConfig());
     MODEL("SblKvs")->delete();
 }
예제 #16
0
파일: Test.php 프로젝트: reoring/sabel
 protected function insertJoinTableData()
 {
     $data = array();
     $data[] = array("id" => 1, "value" => "grandparents1");
     $data[] = array("id" => 2, "value" => "grandparents2");
     $gp = MODEL("Grandparents");
     foreach ($data as $values) {
         $gp->insert($values);
     }
     $data = array();
     $data[] = array("id" => 1, "grandparents_id" => 2, "value" => "parents1");
     $data[] = array("id" => 2, "grandparents_id" => 1, "value" => "parents2");
     $p = MODEL("Parents");
     foreach ($data as $values) {
         $p->insert($values);
     }
     $data = array();
     $data[] = array("id" => 1, "parents_id" => 2, "value" => "children1");
     $data[] = array("id" => 2, "parents_id" => 1, "value" => "children2");
     $c = MODEL("Children");
     foreach ($data as $values) {
         $c->insert($values);
     }
     $data = array();
     $data[] = array("id" => 1, "children_id" => 2, "value" => "grandchildren1");
     $data[] = array("id" => 2, "children_id" => 1, "value" => "grandchildren2");
     $gc = MODEL("Grandchildren");
     foreach ($data as $values) {
         $gc->insert($values);
     }
 }
예제 #17
0
파일: Database.php 프로젝트: reoring/sabel
 public function testUseNamespace()
 {
     $pref = Sabel_Preference::create(new __Preference_Database_Config_Namespace());
     $pref->setInt("test", 1);
     $this->assertEquals(1, MODEL("SblPreference")->getCount("namespace", "myapp"));
 }
예제 #18
0
 protected function clear($mdlName)
 {
     MODEL($mdlName)->delete();
 }
예제 #19
0
 /**
  * @param array $rows
  *
  * @return Sabel_Db_Model[]
  */
 protected function toModels(array $rows)
 {
     $results = array();
     $source = MODEL($this->modelName);
     foreach ($rows as $row) {
         $model = clone $source;
         $model->setProperties($row);
         $results[] = $model;
     }
     return $results;
 }
예제 #20
0
파일: Database.php 프로젝트: reoring/sabel
 private function __construct($mdlName)
 {
     $this->model = MODEL($mdlName);
 }
예제 #21
0
파일: Database.php 프로젝트: reoring/sabel
 protected function getSessionModel($sessionId)
 {
     if (!isset($this->models[$sessionId])) {
         $this->models[$sessionId] = MODEL($this->mdlName, $sessionId);
     }
     return $this->models[$sessionId];
 }