Ubiquity  2.0.2
php rapid development framework
TableExport.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Ubiquity\db\export;
4 
7 
8 class TableExport extends DataExport{
9  protected $model;
10  protected $metas;
11  public function __construct($model,$batchSize=20){
12  parent::__construct($batchSize);
13  $this->model=$model;
14  $this->batchSize=$batchSize;
15  }
16 
17  public function exports(DbExport $dbExport,$condition=""){
18  $table=OrmUtils::getTableName($this->model);
19  $this->metas=OrmUtils::getModelMetadata($this->model);
20  $manyToManys=[];
21  if(isset($this->metas["#manyToMany"]))
22  $manyToManys=$this->metas["#manyToMany"];
23  $this->scanManyToManys($dbExport, $manyToManys);
24  $fields=\array_diff($this->metas["#fieldNames"],$this->metas["#notSerializable"]);
25  $datas=DAO::getAll($this->model,$condition);
26  return $this->generateInsert($table, $fields, $datas);
27  }
28 
29  protected function scanManyToManys(DbExport $dbExport,$manyToManys){
30  foreach ($manyToManys as $member=>$manyToMany){
31  if(isset($this->metas["#joinTable"][$member])){
32  $annotJoinTable=$this->metas["#joinTable"][$member];
33  $dbExport->addManyToMany($annotJoinTable["name"], ["member"=>$member,"class"=>$this->model]);
34  }
35  }
36  }
37 }
generateInsert($table, $fields, $datas)
Definition: DataExport.php:14
scanManyToManys(DbExport $dbExport, $manyToManys)
Definition: TableExport.php:29
exports(DbExport $dbExport, $condition="")
Definition: TableExport.php:17
static getAll($className, $condition='', $loadManyToOne=true, $loadOneToMany=false, $useCache=NULL)
Returns an array of $className objects from the database.
Definition: DAO.php:193
addManyToMany($jointable, $memberTargetEntity)
Definition: DbExport.php:32
__construct($model, $batchSize=20)
Definition: TableExport.php:11
static getModelMetadata($className)
Definition: OrmUtils.php:18
static getTableName($class)
Definition: OrmUtils.php:61