From: eileen <emcnaughton@wikimedia.org> Date: Tue, 24 Jan 2017 21:56:30 +0000 (+1300) Subject: CRM-19925 Add Entity data and date format data to fields array on DAO. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=3cef3c00ce1e3de5ee93ee44bc1a1d1d3d406385;p=civicrm-core.git CRM-19925 Add Entity data and date format data to fields array on DAO. Per ticket this is intended to reduce in-code calculations by effectively caching some commonly used data into the DAO. In many cases civicrm compiles a large fields array & then twists itself up trying to distinguish the fields from each other. This makes the entity info readily available. Also moved to metadata is the format of core date fields. --- diff --git a/CRM/Core/CodeGen/Specification.php b/CRM/Core/CodeGen/Specification.php index 86c211afcf..1cf0285593 100644 --- a/CRM/Core/CodeGen/Specification.php +++ b/CRM/Core/CodeGen/Specification.php @@ -21,11 +21,9 @@ class CRM_Core_CodeGen_Specification { echo "Parsing schema description " . $schemaPath . "\n"; $dbXML = CRM_Core_CodeGen_Util_Xml::parse($schemaPath); - // print_r( $dbXML ); echo "Extracting database information\n"; $this->database = &$this->getDatabase($dbXML); - // print_r( $this->database ); $this->classNames = array(); @@ -37,7 +35,6 @@ class CRM_Core_CodeGen_Specification { $this->tables = $this->orderTables($this->tables); // add archive tables here - $archiveTables = array(); foreach ($this->tables as $name => $table) { if ($table['archive'] == 'true') { $name = 'archive_' . $table['name']; @@ -187,6 +184,7 @@ class CRM_Core_CodeGen_Specification { $base = $this->value('base', $tableXML); $sourceFile = "xml/schema/{$base}/{$klass}.xml"; $daoPath = "{$base}/DAO/"; + $baoPath = __DIR__ . '/../../../' . str_replace(' ', '', "{$base}/BAO/"); $pre = str_replace('/', '_', $daoPath); $this->classNames[$name] = $pre . $klass; @@ -206,6 +204,9 @@ class CRM_Core_CodeGen_Specification { 'objectName' => $klass, 'labelName' => substr($name, 8), 'className' => $this->classNames[$name], + 'baopath' => $baoPath . $klass . '.php', + 'bao' => (file_exists($baoPath . $klass . '.php') ? str_replace('DAO', 'BAO', $this->classNames[$name]) : $this->classNames[$name]), + 'entity' => $klass, 'attributes_simple' => trim($database['tableAttributes_simple']), 'attributes_modern' => trim($database['tableAttributes_modern']), 'comment' => $this->value('comment', $tableXML), @@ -365,6 +366,7 @@ class CRM_Core_CodeGen_Specification { if (!empty($field['html'])) { $validOptions = array( 'type', + 'format', /* Fixme: prior to CRM-13497 these were in a flat structure // CRM-13497 moved them to be nested within 'html' but there's no point // making that change in the DAOs right now since we are in the process of diff --git a/xml/schema/Activity/Activity.xml b/xml/schema/Activity/Activity.xml index e2589d56fa..7065073100 100644 --- a/xml/schema/Activity/Activity.xml +++ b/xml/schema/Activity/Activity.xml @@ -134,6 +134,7 @@ <comment>Date and time this activity is scheduled to occur. Formerly named scheduled_date_time.</comment> <html> <type>Select Date</type> + <format>activityDateTime</format> </html> <add>2.0</add> </field> diff --git a/xml/schema/Contact/Contact.xml b/xml/schema/Contact/Contact.xml index 8cfc7b76aa..716c82edf3 100644 --- a/xml/schema/Contact/Contact.xml +++ b/xml/schema/Contact/Contact.xml @@ -668,6 +668,7 @@ <add>1.1</add> <html> <type>Select Date</type> + <format>birth</format> </html> </field> <field> @@ -693,6 +694,7 @@ <add>1.5</add> <html> <type>Select Date</type> + <format>birth</format> </html> </field> <field> diff --git a/xml/schema/Contribute/Contribution.xml b/xml/schema/Contribute/Contribution.xml index c30d2f10e3..af8869f953 100644 --- a/xml/schema/Contribute/Contribution.xml +++ b/xml/schema/Contribute/Contribution.xml @@ -149,6 +149,7 @@ <add>1.3</add> <html> <type>Select Date</type> + <format>activityDateTime</format> </html> </field> <field> @@ -264,6 +265,7 @@ <add>1.3</add> <html> <type>Select Date</type> + <format>activityDateTime</format> </html> </field> <field> @@ -285,6 +287,7 @@ <comment>when (if) receipt was sent. populated automatically for online donations w/ automatic receipting</comment> <html> <type>Select Date</type> + <format>activityDateTime</format> </html> <add>1.3</add> </field> @@ -299,6 +302,7 @@ <add>1.3</add> <html> <type>Select Date</type> + <format>activityDateTime</format> </html> </field> <field> @@ -508,6 +512,7 @@ <comment>Stores the date when revenue should be recognized.</comment> <html> <type>Select Date</type> + <format>activityDateTime</format> </html> <add>4.7</add> </field> diff --git a/xml/schema/Event/Participant.xml b/xml/schema/Event/Participant.xml index e668461283..ca92ae4542 100644 --- a/xml/schema/Event/Participant.xml +++ b/xml/schema/Event/Participant.xml @@ -119,6 +119,10 @@ <type>datetime</type> <comment>When did contact register for event?</comment> <add>1.7</add> + <html> + <type>Select Date</type> + <format>activityDateTime</format> + </html> </field> <field> <name>source</name> diff --git a/xml/schema/Member/Membership.xml b/xml/schema/Member/Membership.xml index 53336f081e..ad00f4dc14 100644 --- a/xml/schema/Member/Membership.xml +++ b/xml/schema/Member/Membership.xml @@ -82,6 +82,7 @@ <add>1.5</add> <html> <type>Select Date</type> + <format>activityDate</format> </html> </field> <field> @@ -96,6 +97,7 @@ <add>1.5</add> <html> <type>Select Date</type> + <format>activityDate</format> </html> </field> <field> @@ -110,6 +112,7 @@ <add>1.5</add> <html> <type>Select Date</type> + <format>activityDate</format> </html> </field> <field> diff --git a/xml/templates/dao.tpl b/xml/templates/dao.tpl index 1c4f3c9e1d..c38b82441e 100644 --- a/xml/templates/dao.tpl +++ b/xml/templates/dao.tpl @@ -111,12 +111,12 @@ class {$table.className} extends CRM_Core_DAO {ldelim} {foreach from=$table.fields item=field} {if $field.uniqueName} - '{$field.uniqueName}' + '{$field.uniqueName}' {else} '{$field.name}' {/if} => array( - 'name' => '{$field.name}', + 'name' => '{$field.name}', 'type' => {$field.crmType}, {if $field.title} 'title' => ts('{$field.title}'), @@ -163,6 +163,9 @@ class {$table.className} extends CRM_Core_DAO {ldelim} {if $field.default} 'default' => '{if ($field.default[0]=="'" or $field.default[0]=='"')}{$field.default|substring:1:-1}{else}{$field.default}{/if}', {/if} {* field.default *} + 'table_name' => '{$table.name}', + 'entity' => '{$table.entity}', + 'bao' => '{$table.bao}', {if $field.FKClassName} 'FKClassName' => '{$field.FKClassName}', @@ -181,8 +184,8 @@ class {$table.className} extends CRM_Core_DAO {ldelim} 'pseudoconstant' => array( {*{$pseudoOptions|@print_array}*} {foreach from=$pseudoOptions key=optionKey item=optionValue} - '{$optionKey}' => '{$optionValue}', - {/foreach} + '{$optionKey}' => '{$optionValue}', +{/foreach} ) {/if} {* field.pseudoconstant *} ), {/foreach} {* table.fields *}