| 1 | <?php |
| 2 | /** |
| 3 | * @package CRM |
| 4 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
| 5 | * |
| 6 | * Generated from {$table.sourceFile} |
| 7 | * {$generated} |
| 8 | * (GenCodeChecksum:{$genCodeChecksum}) |
| 9 | */ |
| 10 | |
| 11 | /** |
| 12 | * Database access object for the {$table.entity} entity. |
| 13 | */ |
| 14 | class {$table.className} extends CRM_Core_DAO {ldelim} |
| 15 | |
| 16 | /** |
| 17 | * Static instance to hold the table name. |
| 18 | * |
| 19 | * @var string |
| 20 | */ |
| 21 | public static $_tableName = '{$table.name}'; |
| 22 | |
| 23 | /** |
| 24 | * Should CiviCRM log any modifications to this table in the civicrm_log table. |
| 25 | * |
| 26 | * @var bool |
| 27 | */ |
| 28 | public static $_log = {$table.log|strtoupper}; |
| 29 | |
| 30 | {foreach from=$table.fields item=field} |
| 31 | /** |
| 32 | {if $field.comment} |
| 33 | * {$field.comment|regex_replace:"/\n[ ]*/":"\n* "} |
| 34 | * |
| 35 | {/if} |
| 36 | * @var {$field.phpType} |
| 37 | */ |
| 38 | public ${$field.name}; |
| 39 | |
| 40 | {/foreach} {* table.fields *} |
| 41 | |
| 42 | /** |
| 43 | * Class constructor. |
| 44 | */ |
| 45 | public function __construct( ) {ldelim} |
| 46 | $this->__table = '{$table.name}'; |
| 47 | |
| 48 | parent::__construct( ); |
| 49 | {rdelim} |
| 50 | |
| 51 | {if $table.foreignKey || $table.dynamicForeignKey} |
| 52 | /** |
| 53 | * Returns foreign keys and entity references. |
| 54 | * |
| 55 | * @return array |
| 56 | * [CRM_Core_Reference_Interface] |
| 57 | */ |
| 58 | public static function getReferenceColumns() {ldelim} |
| 59 | if (!isset(Civi::$statics[__CLASS__]['links'])) {ldelim} |
| 60 | Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__); |
| 61 | {foreach from=$table.foreignKey item=foreign} |
| 62 | Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), '{$foreign.name}', '{$foreign.table}', '{$foreign.key}'); |
| 63 | {/foreach} |
| 64 | |
| 65 | {foreach from=$table.dynamicForeignKey item=foreign} |
| 66 | Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName(), '{$foreign.idColumn}', NULL, '{$foreign.key|default:'id'}', '{$foreign.typeColumn}'); |
| 67 | {/foreach} |
| 68 | CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']); |
| 69 | {rdelim} |
| 70 | return Civi::$statics[__CLASS__]['links']; |
| 71 | {rdelim} |
| 72 | {/if} {* table.foreignKey *} |
| 73 | |
| 74 | /** |
| 75 | * Returns all the column names of this table |
| 76 | * |
| 77 | * @return array |
| 78 | */ |
| 79 | public static function &fields( ) {ldelim} |
| 80 | if ( ! isset(Civi::$statics[__CLASS__]['fields']) ) {ldelim} |
| 81 | Civi::$statics[__CLASS__]['fields'] = array( |
| 82 | {foreach from=$table.fields item=field} |
| 83 | |
| 84 | {if $field.uniqueName} |
| 85 | '{$field.uniqueName}' |
| 86 | {else} |
| 87 | '{$field.name}' |
| 88 | {/if} |
| 89 | => array( |
| 90 | 'name' => '{$field.name}', |
| 91 | 'type' => {$field.crmType}, |
| 92 | {if $field.title} |
| 93 | 'title' => {$tsFunctionName}('{$field.title}'), |
| 94 | {/if} |
| 95 | {if $field.comment} |
| 96 | 'description' => {$tsFunctionName}('{$field.comment|replace:"'":"\'"}'), |
| 97 | {/if} |
| 98 | {if $field.required} |
| 99 | 'required' => {$field.required|strtoupper}, |
| 100 | {/if} {* field.required *} |
| 101 | {if $field.length} |
| 102 | 'maxlength' => {$field.length}, |
| 103 | {/if} {* field.length *} |
| 104 | {if $field.precision} |
| 105 | 'precision' => array({$field.precision}), |
| 106 | {/if} |
| 107 | {if $field.size} |
| 108 | 'size' => {$field.size}, |
| 109 | {/if} {* field.size *} |
| 110 | {if $field.rows} |
| 111 | 'rows' => {$field.rows}, |
| 112 | {/if} {* field.rows *} |
| 113 | {if $field.cols} |
| 114 | 'cols' => {$field.cols}, |
| 115 | {/if} {* field.cols *} |
| 116 | |
| 117 | {if $field.import} |
| 118 | 'import' => {$field.import|strtoupper}, |
| 119 | |
| 120 | {/if} {* field.import *} |
| 121 | 'where' => '{$table.name}.{$field.name}', |
| 122 | {if $field.headerPattern}'headerPattern' => '{$field.headerPattern}',{/if} |
| 123 | {if $field.dataPattern}'dataPattern' => '{$field.dataPattern}',{/if} |
| 124 | {if $field.export} |
| 125 | 'export' => {$field.export|strtoupper}, |
| 126 | {/if} {* field.export *} |
| 127 | {if $field.contactType} |
| 128 | 'contactType' => {if $field.contactType == 'null'}NULL{else}'{$field.contactType}'{/if}, |
| 129 | {/if} |
| 130 | {if $field.rule} |
| 131 | 'rule' => '{$field.rule}', |
| 132 | {/if} {* field.rule *} |
| 133 | {if !empty($field.permission)} |
| 134 | 'permission' => {$field.permission|@print_array}, |
| 135 | {/if} |
| 136 | {if $field.default || $field.default === '0'} |
| 137 | 'default' => '{if ($field.default[0]=="'" or $field.default[0]=='"')}{$field.default|substring:1:-1}{else}{$field.default}{/if}', |
| 138 | {/if} {* field.default *} |
| 139 | 'table_name' => '{$table.name}', |
| 140 | 'entity' => '{$table.entity}', |
| 141 | 'bao' => '{$table.bao}', |
| 142 | 'localizable' => {if $field.localizable}1{else}0{/if}, |
| 143 | {if $field.localize_context}'localize_context' => '{$field.localize_context}',{/if} |
| 144 | |
| 145 | {if $field.FKClassName} |
| 146 | 'FKClassName' => '{$field.FKClassName}', |
| 147 | {/if} |
| 148 | {if $field.serialize} |
| 149 | 'serialize' => self::SERIALIZE_{$field.serialize|strtoupper}, |
| 150 | {/if} |
| 151 | {if $field.uniqueTitle} |
| 152 | 'unique_title' => {$tsFunctionName}('{$field.uniqueTitle}'), |
| 153 | {/if} |
| 154 | {if $field.html} |
| 155 | 'html' => array( |
| 156 | {foreach from=$field.html item=val key=key} |
| 157 | '{$key}' => {if $key eq 'label'}{$tsFunctionName}("{$val}"){else}'{$val}'{/if}, |
| 158 | {/foreach} |
| 159 | ), |
| 160 | {/if} |
| 161 | {if $field.pseudoconstant} |
| 162 | 'pseudoconstant' => {$field.pseudoconstant|@print_array}, |
| 163 | {/if} {* field.pseudoconstant *} ), |
| 164 | {/foreach} {* table.fields *} |
| 165 | ); |
| 166 | CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); |
| 167 | {rdelim} |
| 168 | return Civi::$statics[__CLASS__]['fields']; |
| 169 | {rdelim} |
| 170 | |
| 171 | /** |
| 172 | * Return a mapping from field-name to the corresponding key (as used in fields()). |
| 173 | * |
| 174 | * @return array |
| 175 | * Array(string $name => string $uniqueName). |
| 176 | */ |
| 177 | public static function &fieldKeys( ) {ldelim} |
| 178 | if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {ldelim} |
| 179 | Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields())); |
| 180 | {rdelim} |
| 181 | return Civi::$statics[__CLASS__]['fieldKeys']; |
| 182 | {rdelim} |
| 183 | |
| 184 | /** |
| 185 | * Returns the names of this table |
| 186 | * |
| 187 | * @return string |
| 188 | */ |
| 189 | public static function getTableName( ) {ldelim} |
| 190 | {if $table.localizable} |
| 191 | return CRM_Core_DAO::getLocaleTableName( self::$_tableName ); |
| 192 | {else} |
| 193 | return self::$_tableName; |
| 194 | {/if} |
| 195 | {rdelim} |
| 196 | |
| 197 | /** |
| 198 | * Returns if this table needs to be logged |
| 199 | * |
| 200 | * @return bool |
| 201 | */ |
| 202 | public function getLog( ) {ldelim} |
| 203 | return self::$_log; |
| 204 | {rdelim} |
| 205 | |
| 206 | /** |
| 207 | * Returns the list of fields that can be imported |
| 208 | * |
| 209 | * @param bool $prefix |
| 210 | * |
| 211 | * @return array |
| 212 | */ |
| 213 | public static function &import( $prefix = FALSE ) {ldelim} |
| 214 | $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, '{$table.labelName}', $prefix, array( |
| 215 | {if $table.foreignKey}{foreach from=$table.foreignKey item=foreign} |
| 216 | {if $foreign.import}'{$foreign.className}',{/if} |
| 217 | {/foreach}{/if} |
| 218 | )); |
| 219 | return $r; |
| 220 | {rdelim} |
| 221 | |
| 222 | /** |
| 223 | * Returns the list of fields that can be exported |
| 224 | * |
| 225 | * @param bool $prefix |
| 226 | * |
| 227 | * @return array |
| 228 | */ |
| 229 | public static function &export( $prefix = FALSE ) {ldelim} |
| 230 | $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, '{$table.labelName}', $prefix, array( |
| 231 | {if $table.foreignKey}{foreach from=$table.foreignKey item=foreign} |
| 232 | {if $foreign.export}'{$foreign.className}',{/if} |
| 233 | {/foreach}{/if} |
| 234 | )); |
| 235 | return $r; |
| 236 | {rdelim} |
| 237 | |
| 238 | /** |
| 239 | * Returns the list of indices |
| 240 | * |
| 241 | * @param bool $localize |
| 242 | * |
| 243 | * @return array |
| 244 | */ |
| 245 | public static function indices($localize = TRUE) {ldelim} |
| 246 | $indices = {$indicesPhp}; |
| 247 | return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices; |
| 248 | {rdelim} |
| 249 | |
| 250 | {rdelim} |