Ejemplo n.º 1
0
 function testGetReferencesToTable()
 {
     $refs = CRM_Core_DAO::getReferencesToTable(CRM_Financial_DAO_FinancialType::getTableName());
     $refsBySource = array();
     foreach ($refs as $refSpec) {
         $refsBySource[$refSpec->getReferenceTable()] = $refSpec;
     }
     $this->assertTrue(array_key_exists('civicrm_entity_financial_account', $refsBySource));
     $genericRef = $refsBySource['civicrm_entity_financial_account'];
     $this->assertEquals('entity_id', $genericRef->getReferenceKey());
     $this->assertEquals('entity_table', $genericRef->getTypeColumn());
     $this->assertEquals('id', $genericRef->getTargetKey());
     $this->assertEquals(TRUE, $genericRef->isGeneric());
 }
Ejemplo n.º 2
0
 /**
  * Get array tables and fields that reference civicrm_contact.id.
  *
  * This includes core tables, custom group tables, tables added by the merge
  * hook and (somewhat randomly) the entity_tag table.
  *
  * Refer to CRM-17454 for information on the danger of querying the information
  * schema to derive this.
  *
  * @todo create an 'entity hook' to allow entities to be registered to CiviCRM
  * including all info that is normally in the DAO.
  */
 public static function cidRefs()
 {
     $cidRefs = array();
     $coreReferences = CRM_Core_DAO::getReferencesToTable('civicrm_contact');
     foreach ($coreReferences as $coreReference) {
         if (!is_a($coreReference, 'CRM_Core_Reference_Dynamic')) {
             $cidRefs[$coreReference->getReferenceTable()][] = $coreReference->getReferenceKey();
         }
     }
     self::addCustomTablesExtendingContactsToCidRefs($cidRefs);
     // FixME for time being adding below line statically as no Foreign key constraint defined for table 'civicrm_entity_tag'
     $cidRefs['civicrm_entity_tag'][] = 'entity_id';
     // Allow hook_civicrm_merge() to adjust $cidRefs.
     // @todo consider adding a way to register entities and have them
     // automatically added to this list.
     CRM_Utils_Hook::merge('cidRefs', $cidRefs);
     return $cidRefs;
 }
Ejemplo n.º 3
0
 /**
  * Get array tables and fields that reference civicrm_contact.id.
  *
  * This includes core tables, custom group tables, tables added by the merge
  * hook and (somewhat randomly) the entity_tag table.
  *
  * Refer to CRM-17454 for information on the danger of querying the information
  * schema to derive this.
  *
  * This function calls the merge hook but the entityTypes hook is the recommended
  * way to add tables to this result.
  */
 public static function cidRefs()
 {
     if (isset(\Civi::$statics[__CLASS__]) && isset(\Civi::$statics[__CLASS__]['contact_references'])) {
         return \Civi::$statics[__CLASS__]['contact_references'];
     }
     $contactReferences = array();
     $coreReferences = CRM_Core_DAO::getReferencesToTable('civicrm_contact');
     foreach ($coreReferences as $coreReference) {
         if (!is_a($coreReference, 'CRM_Core_Reference_Dynamic')) {
             $contactReferences[$coreReference->getReferenceTable()][] = $coreReference->getReferenceKey();
         }
     }
     self::addCustomTablesExtendingContactsToCidRefs($contactReferences);
     // FixME for time being adding below line statically as no Foreign key constraint defined for table 'civicrm_entity_tag'
     $contactReferences['civicrm_entity_tag'][] = 'entity_id';
     // Allow hook_civicrm_merge() to adjust $cidRefs.
     // Note that if entities are registered using the entityTypes hook there
     // is no need to use this hook.
     CRM_Utils_Hook::merge('cidRefs', $contactReferences);
     \Civi::$statics[__CLASS__]['contact_references'] = $contactReferences;
     return \Civi::$statics[__CLASS__]['contact_references'];
 }