Merge pull request #20951 from eileenmcnaughton/act
[civicrm-core.git] / xml / templates / dao.tpl
index 916a2da59048909e596297c443ab109d5f90c754..f80ab793ac146b4e56fc2d560af809657613de6a 100644 (file)
@@ -7,7 +7,7 @@
  * {$generated}
  * (GenCodeChecksum:{$genCodeChecksum})
  */
-{$useHelper}
+{if isset($useHelper)}{$useHelper}{/if}
 /**
  * Database access object for the {$table.entity} entity.
  */
@@ -24,6 +24,16 @@ class {$table.className} extends CRM_Core_DAO {ldelim}
       */
       public static $_tableName = '{$table.name}';
 
+   {* Only print this variable if it's different than the default in CRM_Core_DAO *}
+   {if count($table.primaryKey.field) !== 1 || $table.primaryKey.field.0 !== 'id'}
+     /**
+      * Primary key field(s).
+      *
+      * @var string[]
+      */
+      public static $_primaryKey = [{if $table.primaryKey.field}'{"', '"|implode:$table.primaryKey.field}'{/if}];
+   {/if}
+
    {if $table.icon}
      /**
       * Icon associated with this entity.
@@ -87,9 +97,19 @@ class {$table.className} extends CRM_Core_DAO {ldelim}
         return $plural ? {$tsFunctionName}('{$table.titlePlural}') : {$tsFunctionName}('{$table.title}');
     {rdelim}
 
+{if !empty($table.description)}
+  /**
+  * Returns user-friendly description of this entity.
+  *
+  * @return string
+  */
+  public static function getEntityDescription() {ldelim}
+    return {$tsFunctionName}('{$table.description|replace:"'":"\'"}');
+  {rdelim}
+{/if}
 
 
-{if $table.foreignKey || $table.dynamicForeignKey}
+{if !empty($table.foreignKey) || !empty($table.dynamicForeignKey)}
     /**
      * Returns foreign keys and entity references.
      *
@@ -99,13 +119,16 @@ class {$table.className} extends CRM_Core_DAO {ldelim}
     public static function getReferenceColumns() {ldelim}
       if (!isset(Civi::$statics[__CLASS__]['links'])) {ldelim}
         Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
+{if isset($table.foreignKey)}
 {foreach from=$table.foreignKey item=foreign}
         Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), '{$foreign.name}', '{$foreign.table}', '{$foreign.key}');
 {/foreach}
-
+{/if}
+{if isset($table.dynamicForeignKey)}
 {foreach from=$table.dynamicForeignKey item=foreign}
         Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName(), '{$foreign.idColumn}', NULL, '{$foreign.key|default:'id'}', '{$foreign.typeColumn}');
 {/foreach}
+{/if}
         CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
       {rdelim}
       return Civi::$statics[__CLASS__]['links'];
@@ -139,19 +162,19 @@ class {$table.className} extends CRM_Core_DAO {ldelim}
 {if $field.required}
                                         'required'  => {$field.required|strtoupper},
 {/if} {* field.required *}
-{if $field.length}
+{if isset($field.length)}
                       'maxlength' => {$field.length},
 {/if} {* field.length *}
-{if $field.precision}
+{if isset($field.precision)}
                       'precision'      => array({$field.precision}),
 {/if}
-{if $field.size}
+{if isset($field.size)}
                       'size'      => {$field.size},
 {/if} {* field.size *}
-{if $field.rows}
+{if isset($field.rows)}
                       'rows'      => {$field.rows},
 {/if} {* field.rows *}
-{if $field.cols}
+{if isset($field.cols)}
                       'cols'      => {$field.cols},
 {/if} {* field.cols *}
 
@@ -181,9 +204,9 @@ class {$table.className} extends CRM_Core_DAO {ldelim}
   'entity' => '{$table.entity}',
   'bao' => '{$table.bao}',
   'localizable' => {if $field.localizable}1{else}0{/if},
-  {if $field.localize_context}'localize_context' => '{$field.localize_context}',{/if}
+  {if isset($field.localize_context)}'localize_context' => '{$field.localize_context}',{/if}
 
-{if $field.FKClassName}
+{if isset($field.FKClassName)}
                       'FKClassName' => '{$field.FKClassName}',
 {/if}
 {if !empty($field.component)}
@@ -261,7 +284,7 @@ class {$table.className} extends CRM_Core_DAO {ldelim}
        */
        public static function &import( $prefix = FALSE ) {ldelim}
             $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, '{$table.labelName}', $prefix, array(
-            {if $table.foreignKey}{foreach from=$table.foreignKey item=foreign}
+            {if isset($table.foreignKey)}{foreach from=$table.foreignKey item=foreign}
               {if $foreign.import}'{$foreign.className}',{/if}
             {/foreach}{/if}
             ));
@@ -277,7 +300,7 @@ class {$table.className} extends CRM_Core_DAO {ldelim}
         */
        public static function &export( $prefix = FALSE ) {ldelim}
             $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, '{$table.labelName}', $prefix, array(
-            {if $table.foreignKey}{foreach from=$table.foreignKey item=foreign}
+            {if isset($table.foreignKey)}{foreach from=$table.foreignKey item=foreign}
               {if $foreign.export}'{$foreign.className}',{/if}
             {/foreach}{/if}
             ));