Completed
Push — master ( 499e80...f97bb0 )
by Jean-Christophe
01:49
created

DbExport::exports()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 13
nc 4
nop 0
1
<?php
2
namespace Ubiquity\db\export;
3
4
use Ubiquity\controllers\Startup;
5
use Ubiquity\cache\CacheManager;
6
use Ubiquity\orm\parser\ManyToManyParser;
7
8
class DbExport{
9
	protected $manyToManys=[];
10
11
	public function __construct(){
12
13
	}
14
15
	public function exports(){
16
		$result=[];
17
		$config=Startup::getConfig();
18
		$models=CacheManager::getModels($config,true);
19
		foreach ($models as $model){
20
			$tableExport=new TableExport($model);
21
			$result[]=$tableExport->exports($this);
22
		}
23
		foreach ($this->manyToManys as $target=>$ManyToManyParser){
24
			$ManyToManyParser->init();
25
			$sqlExport=new SqlExport();
26
			$fields=[$ManyToManyParser->getFkField(),$ManyToManyParser->getMyFkField()];
27
			$result[]=$sqlExport->exports($target,$fields);
28
		}
29
		return \implode("\n", $result);
30
	}
31
32
	public function addManyToMany($jointable,$memberTargetEntity){
33
		if(!isset($this->manyToManys[$jointable])){
34
			$this->manyToManys[$jointable]=new ManyToManyParser($memberTargetEntity["class"], $memberTargetEntity["member"]);
35
		}
36
	}
37
}
38