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