*/
private $raw;
+ /**
+ * @var string
+ * translate function name
+ */
+ private $tsFunctionName;
+
/**
* CRM_Core_CodeGen_DAO constructor.
*
* @param \CRM_Core_CodeGen_Main $config
* @param string $name
+ * @param string $tsFunctionName
*/
- public function __construct($config, $name) {
+ public function __construct($config, $name, $tsFunctionName = 'ts') {
parent::__construct($config);
$this->name = $name;
+ $this->tsFunctionName = $tsFunctionName;
}
/**
$this->getRaw());
}
+ /**
+ * Run generator.
+ */
public function run() {
echo "Generating {$this->name} as " . $this->getRelFileName() . "\n";
$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('genCodeChecksum', $this->getTableChecksum());
+ $template->assign('tsFunctionName', $this->tsFunctionName);
$template->run('dao.tpl', $this->getAbsFileName());
}
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([], 1));
+ }
+ else {
+ $template->assign('indicesPhp', var_export($this->tables[$this->name]['index'], 1));
+ }
$template->assign('genCodeChecksum', 'NEW');
+ $template->assign('tsFunctionName', $this->tsFunctionName);
$this->raw = $template->fetch('dao.tpl');
}
return $this->raw;
}
+ /**
+ * Get relative file name.
+ *
+ * @return string
+ */
public function getRelFileName() {
return $this->tables[$this->name]['fileName'];
}
/**
+ * Get the absolute file name.
+ *
* @return string
*/
public function getAbsFileName() {
*/
protected function getTableChecksum() {
if (!$this->tableChecksum) {
+ $flat = [];
CRM_Utils_Array::flatten($this->tables[$this->name], $flat);
ksort($flat);
$this->tableChecksum = md5(json_encode($flat));