4 * Create DAO ORM classes.
6 class CRM_Core_CodeGen_DAO
extends CRM_Core_CodeGen_BaseTask
{
16 private $tableChecksum;
23 public function __construct($config, $name) {
24 parent
::__construct($config);
30 * TRUE if an update is needed.
32 public function needsUpdate() {
33 if (!file_exists($this->getAbsFileName())) {
37 if ($this->getTableChecksum() !== self
::extractRegex($this->getAbsFileName(), ';\(GenCodeChecksum:([a-zA-Z0-9]+)\);')) {
41 return !$this->isApproxPhpMatch(
42 file_get_contents($this->getAbsFileName()),
46 public function run() {
47 echo "Generating {$this->name} as " . $this->getRelFileName() . "\n";
49 if (empty($this->tables
[$this->name
]['base'])) {
50 echo "No base defined for {$this->name}, skipping output generation\n";
54 $template = new CRM_Core_CodeGen_Util_Template('php');
55 $template->assign('table', $this->tables
[$this->name
]);
56 $template->assign('genCodeChecksum', $this->getTableChecksum());
57 $template->run('dao.tpl', $this->getAbsFileName());
61 * Generate the raw PHP code for the DAO.
65 public function getRaw() {
67 $template = new CRM_Core_CodeGen_Util_Template('php');
68 $template->assign('table', $this->tables
[$this->name
]);
69 $template->assign('genCodeChecksum', 'NEW');
70 $this->raw
= $template->fetch('dao.tpl');
75 public function getRelFileName() {
76 return $this->tables
[$this->name
]['fileName'];
82 public function getAbsFileName() {
83 $directory = $this->config
->phpCodePath
. $this->tables
[$this->name
]['base'];
84 CRM_Core_CodeGen_Util_File
::createDir($directory);
85 $absFileName = $directory . $this->getRelFileName();
90 * Get a unique signature for the table/schema.
94 protected function getTableChecksum() {
95 if (!$this->tableChecksum
) {
96 CRM_Utils_Array
::flatten($this->tables
[$this->name
], $flat);
98 $this->tableChecksum
= md5(json_encode($flat));
100 return $this->tableChecksum
;