CRM-14478 - Split CRM_Core_EntityReference into different classes
[civicrm-core.git] / CRM / Core / DAO.php
index 0879ab6cc22945ac0a8dc5063211bfdf5476cf2a..d4c00fa3865289f801f05afa8fddefee3789d76b 100644 (file)
@@ -75,8 +75,8 @@ class CRM_Core_DAO extends DB_DataObject {
   /**
    * Class constructor
    *
-   * @return object
-   * @access public
+   * @return \CRM_Core_DAO
+  @access public
    */
   function __construct() {
     $this->initialize();
@@ -176,6 +176,8 @@ class CRM_Core_DAO extends DB_DataObject {
   /**
    * Factory method to instantiate a new object from a table name.
    *
+   * @param string $table
+   *
    * @return void
    * @access public
    */
@@ -236,7 +238,7 @@ class CRM_Core_DAO extends DB_DataObject {
    * @static
    * @access public
    *
-   * @return array of CRM_Core_EntityReference
+   * @return array of CRM_Core_Reference_Interface
    */
   static function getReferenceColumns() {
     return array();
@@ -519,6 +521,9 @@ LIKE %1
    *
    * @param string $tableName
    *
+   * @param int $maxTablesToCheck
+   * @param string $fieldName
+   *
    * @return array
    * @static
    */
@@ -597,7 +602,10 @@ LIKE %1
   /**
    * Checks if CONSTRAINT keyword exists for a specified table.
    *
-   * @param string $tableName
+   * @param array $tables
+   *
+   * @throws Exception
+   * @internal param string $tableName
    *
    * @return boolean true if CONSTRAINT keyword exists, false otherwise
    */
@@ -878,6 +886,13 @@ FROM   civicrm_domain
    *
    * @param string $query query to be executed
    *
+   * @param array $params
+   * @param bool $abort
+   * @param null $daoName
+   * @param bool $freeDAO
+   * @param bool $i18nRewrite
+   * @param bool $trapException
+   *
    * @return Object CRM_Core_DAO object that holds the results of the query
    * @static
    * @access public
@@ -1162,11 +1177,14 @@ SELECT contact_id
    * of time. This is the inverse function of create. It also stores all the retrieved
    * values in the default array
    *
-   * @param string $daoName  name of the dao object
-   * @param array  $params   (reference ) an assoc array of name/value pairs
-   * @param array  $defaults (reference ) an assoc array to hold the flattened values
-   * @param array  $returnProperities     an assoc array of fields that need to be returned, eg array( 'first_name', 'last_name')
+   * @param string $daoName name of the dao object
+   * @param string $fieldIdName
+   * @param $fieldId
+   * @param $details
+   * @param array $returnProperities an assoc array of fields that need to be returned, eg array( 'first_name', 'last_name')
    *
+   * @internal param array $params (reference ) an assoc array of name/value pairs
+   * @internal param array $defaults (reference ) an assoc array to hold the flattened values
    * @return object an object of type referenced by daoName
    * @access public
    * @static
@@ -1545,13 +1563,15 @@ SELECT contact_id
     }
   }
 
-   /**
-    * Build a list of triggers via hook and add them to (err, reconcile them
-    * with) the database.
-    *
-    * @param $tableName string the specific table requiring a rebuild; or NULL to rebuild all tables
-    * @see CRM-9716
-    */
+  /**
+   * Build a list of triggers via hook and add them to (err, reconcile them
+   * with) the database.
+   *
+   * @param $tableName string the specific table requiring a rebuild; or NULL to rebuild all tables
+   * @param bool $force
+   *
+   * @see CRM-9716
+   */
   static function triggerRebuild($tableName = NULL, $force = FALSE) {
     $info = array();
 
@@ -1721,22 +1741,9 @@ SELECT contact_id
 
     $occurrences = array();
     foreach ($links as $refSpec) {
-      $refColumn = $refSpec->getReferenceKey();
-      $targetColumn = $refSpec->getTargetKey();
-      $params = array(1 => array($this->$targetColumn, 'String'));
-      $sql = <<<EOS
-SELECT id
-FROM {$refSpec->getReferenceTable()}
-WHERE {$refColumn} = %1
-EOS;
-      if ($refSpec->isGeneric()) {
-        $params[2] = array(static::getTableName(), 'String');
-        $sql .= <<<EOS
-    AND {$refSpec->getTypeColumn()} = %2
-EOS;
-      }
+      /** @var $refSpec CRM_Core_Reference_Interface */
       $daoName = CRM_Core_DAO_AllCoreTables::getClassForTable($refSpec->getReferenceTable());
-      $result = self::executeQuery($sql, $params, TRUE, $daoName);
+      $result = $refSpec->findReferences($this);
       while ($result->fetch()) {
         $obj = new $daoName();
         $obj->id = $result->id;
@@ -1768,9 +1775,8 @@ EOS;
       $daoTableName = $daoClassName::getTableName();
 
       foreach ($links as $refSpec) {
-        if ($refSpec->getTargetTable() === $tableName
-              or $refSpec->isGeneric()
-        ) {
+        /** @var $refSpec CRM_Core_Reference_Interface */
+        if ($refSpec->matchesTargetTable($tableName)) {
           $refsFound[] = $refSpec;
         }
       }
@@ -1842,6 +1848,9 @@ EOS;
    * Provides documentation and validation for the buildOptions $context param
    *
    * @param String $context
+   *
+   * @throws Exception
+   * @return array
    */
   public static function buildOptionsContext($context = NULL) {
     $contexts = array(