CRM-19925 Add Entity data and date format data to fields array on DAO.
authoreileen <emcnaughton@wikimedia.org>
Tue, 24 Jan 2017 21:56:30 +0000 (10:56 +1300)
committereileen <emcnaughton@wikimedia.org>
Wed, 25 Jan 2017 00:12:07 +0000 (13:12 +1300)
    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.

CRM/Core/CodeGen/Specification.php
xml/schema/Activity/Activity.xml
xml/schema/Contact/Contact.xml
xml/schema/Contribute/Contribution.xml
xml/schema/Event/Participant.xml
xml/schema/Member/Membership.xml
xml/templates/dao.tpl

index 86c211afcf274f3d2384a0f2bb14158c680030b1..1cf0285593477b1c2915289700507eb49043c2ac 100644 (file)
@@ -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
index e2589d56faa673271639d98c44873d3df840db1c..70650731002d18ee5a43354af362235b1db4d5c0 100644 (file)
     <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>
index 8cfc7b76aac2fa5498089a18c3be8b5638343a11..716c82edf360297a3aff8a3f531cc6bb55c31d51 100644 (file)
     <add>1.1</add>
     <html>
       <type>Select Date</type>
+      <format>birth</format>
     </html>
   </field>
   <field>
     <add>1.5</add>
     <html>
       <type>Select Date</type>
+      <format>birth</format>
     </html>
   </field>
   <field>
index c30d2f10e3a71ba73b9b0a237946902c64bddc29..af8869f9536cdfb676add8fb6c6297dbe9be051e 100644 (file)
     <add>1.3</add>
     <html>
      <type>Select Date</type>
+     <format>activityDateTime</format>
    </html>
   </field>
   <field>
     <add>1.3</add>
     <html>
       <type>Select Date</type>
+      <format>activityDateTime</format>
     </html>
   </field>
   <field>
     <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>
     <add>1.3</add>
     <html>
       <type>Select Date</type>
+      <format>activityDateTime</format>
     </html>
   </field>
   <field>
     <comment>Stores the date when revenue should be recognized.</comment>
     <html>
       <type>Select Date</type>
+        <format>activityDateTime</format>
     </html>
     <add>4.7</add>
   </field>
index e668461283b7a9c85602d4054be90a2cf533be85..ca92ae4542612cb7e5cf78394be5e940ebdce5f9 100644 (file)
     <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>
index 53336f081e3fe1b1f8336a418149b53e12980da7..ad00f4dc14ded962d1c31a67559b28cc61fc239a 100644 (file)
@@ -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>
     <add>1.5</add>
     <html>
       <type>Select Date</type>
+      <format>activityDate</format>
     </html>
   </field>
   <field>
index 1c4f3c9e1dfb4fb4891f901c08da9cc019de93a5..c38b82441e88bc80db27321adefe29d6e2c824a2 100644 (file)
@@ -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 *}