*/
private $tsFunctionName;
+ private $useHelper = '';
+
+ private $ext = "'civicrm'";
+
/**
* CRM_Core_CodeGen_DAO constructor.
*
parent::__construct($config);
$this->name = $name;
$this->tsFunctionName = $tsFunctionName;
+ // If this DAO belongs to an extension, add `use` statement and define EXT constant.
+ if (strpos($tsFunctionName, '::ts')) {
+ $this->tsFunctionName = 'E::ts';
+ $this->useHelper = 'use \\' . explode('::', $tsFunctionName)[0] . ' as E;';
+ $this->ext = 'E::LONG_NAME';
+ }
}
/**
return;
}
- $template = new CRM_Core_CodeGen_Util_Template('php');
- $template->assign('table', $this->tables[$this->name]);
- if (empty($this->tables[$this->name]['index'])) {
- $template->assign('indicesPhp', var_export(array(), 1));
- }
- else {
- $template->assign('indicesPhp', var_export($this->tables[$this->name]['index'], 1));
- }
+ $template = $this->getTemplate();
$template->assign('genCodeChecksum', $this->getTableChecksum());
- $template->assign('tsFunctionName', $this->tsFunctionName);
$template->run('dao.tpl', $this->getAbsFileName());
}
*/
public function getRaw() {
if (!$this->raw) {
- $template = new CRM_Core_CodeGen_Util_Template('php');
- $template->assign('table', $this->tables[$this->name]);
- if (empty($this->tables[$this->name]['index'])) {
- $template->assign('indicesPhp', var_export(array(), 1));
- }
- else {
- $template->assign('indicesPhp', var_export($this->tables[$this->name]['index'], 1));
- }
+ $template = $this->getTemplate();
$template->assign('genCodeChecksum', 'NEW');
- $template->assign('tsFunctionName', $this->tsFunctionName);
$this->raw = $template->fetch('dao.tpl');
}
return $this->raw;
}
+ /**
+ * @return CRM_Core_CodeGen_Util_Template
+ */
+ private function getTemplate() {
+ $template = new CRM_Core_CodeGen_Util_Template('php');
+ $template->assign('table', $this->tables[$this->name]);
+ if (empty($this->tables[$this->name]['index'])) {
+ $template->assign('indicesPhp', var_export([], 1));
+ }
+ else {
+ $template->assign('indicesPhp', var_export($this->tables[$this->name]['index'], 1));
+ }
+ $template->assign('tsFunctionName', $this->tsFunctionName);
+ $template->assign('ext', $this->ext);
+ $template->assign('useHelper', $this->useHelper);
+ return $template;
+ }
+
/**
* Get relative file name.
*
*/
protected function getTableChecksum() {
if (!$this->tableChecksum) {
- $flat = array();
+ $flat = [];
CRM_Utils_Array::flatten($this->tables[$this->name], $flat);
ksort($flat);
$this->tableChecksum = md5(json_encode($flat));