CRM-17028: Yearly and Monthly Repeat Reminders send on every cron for 24 hours
[civicrm-core.git] / CRM / Core / DAO.php
index 6edc424c07333935b657ac7e49a4f66f33d8001e..3c5f3294b885d951b5b5ea2f07def7919108a528 100644 (file)
@@ -3,7 +3,7 @@
   +--------------------------------------------------------------------+
   | CiviCRM version 4.6                                                |
   +--------------------------------------------------------------------+
-  | Copyright CiviCRM LLC (c) 2004-2014                                |
+  | Copyright CiviCRM LLC (c) 2004-2015                                |
   +--------------------------------------------------------------------+
   | This file is a part of CiviCRM.                                    |
   |                                                                    |
   | GNU Affero General Public License or the licensing of CiviCRM,     |
   | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
   +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  * Our base DAO class. All DAO classes should inherit from this class.
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -70,7 +70,7 @@ class CRM_Core_DAO extends DB_DataObject {
    */
   static $_testEntitiesToSkip = array();
   /**
-   * The factory class for this application
+   * The factory class for this application.
    * @var object
    */
   static $_factory = NULL;
@@ -78,7 +78,7 @@ class CRM_Core_DAO extends DB_DataObject {
   static $_checkedSqlFunctionsExist = FALSE;
 
   /**
-   * Class constructor
+   * Class constructor.
    *
    * @return \CRM_Core_DAO
    */
@@ -88,14 +88,14 @@ class CRM_Core_DAO extends DB_DataObject {
   }
 
   /**
-   * Empty definition for virtual function
+   * Empty definition for virtual function.
    */
   public static function getTableName() {
     return NULL;
   }
 
   /**
-   * Initialize the DAO object
+   * Initialize the DAO object.
    *
    * @param string $dsn
    *   The database connection string.
@@ -393,7 +393,7 @@ class CRM_Core_DAO extends DB_DataObject {
   }
 
   /**
-   * Returns list of FK relationships
+   * Returns list of FK relationships.
    *
    *
    * @return array
@@ -404,7 +404,7 @@ class CRM_Core_DAO extends DB_DataObject {
   }
 
   /**
-   * Returns all the column names of this table
+   * Returns all the column names of this table.
    *
    *
    * @return array
@@ -459,6 +459,31 @@ class CRM_Core_DAO extends DB_DataObject {
     return $this;
   }
 
+  /**
+   * Deletes items from table which match current objects variables.
+   *
+   * Returns the true on success
+   *
+   * for example
+   *
+   * Designed to be extended
+   *
+   * $object = new mytable();
+   * $object->ID=123;
+   * echo $object->delete(); // builds a conditon
+   *
+   * $object = new mytable();
+   * $object->whereAdd('age > 12');
+   * $object->limit(1);
+   * $object->orderBy('age DESC');
+   * $object->delete(true); // dont use object vars, use the conditions, limit and order.
+   *
+   * @param bool $useWhere (optional) If DB_DATAOBJECT_WHEREADD_ONLY is passed in then
+   *             we will build the condition only using the whereAdd's.  Default is to
+   *             build the condition only using the object parameters.
+   *
+   *     * @return mixed Int (No. of rows affected) on success, false on failure, 0 on no data affected
+   */
   public function delete($useWhere = FALSE) {
     $result = parent::delete($useWhere);
 
@@ -612,7 +637,7 @@ class CRM_Core_DAO extends DB_DataObject {
   }
 
   /**
-   * Get the size and maxLength attributes for this text field
+   * Get the size and maxLength attributes for this text field.
    * (or for all text fields) in the DAO object.
    *
    * @param string $class
@@ -657,7 +682,7 @@ class CRM_Core_DAO extends DB_DataObject {
   }
 
   /**
-   * Check if there is a record with the same name in the db
+   * Check if there is a record with the same name in the db.
    *
    * @param string $value
    *   The value of the field we are checking.
@@ -687,7 +712,7 @@ class CRM_Core_DAO extends DB_DataObject {
   }
 
   /**
-   * Check if there is a given column in a specific table
+   * Check if there is a given column in a specific table.
    *
    * @param string $tableName
    * @param string $columnName
@@ -865,7 +890,7 @@ LIKE %1
   }
 
   /**
-   * Check whether a specific column in a specific table has always the same value
+   * Check whether a specific column in a specific table has always the same value.
    *
    * @param string $tableName
    * @param string $columnName
@@ -883,7 +908,7 @@ LIKE %1
   }
 
   /**
-   * Check whether a specific column in a specific table is always NULL
+   * Check whether a specific column in a specific table is always NULL.
    *
    * @param string $tableName
    * @param string $columnName
@@ -900,7 +925,7 @@ LIKE %1
   }
 
   /**
-   * Check if there is a given table in the database
+   * Check if there is a given table in the database.
    *
    * @param string $tableName
    *
@@ -952,6 +977,19 @@ FROM   civicrm_domain
     return $object;
   }
 
+  /**
+   * Returns all results as array-encoded records.
+   *
+   * @return array
+   */
+  public function fetchAll() {
+    $result = array();
+    while ($this->fetch()) {
+      $result[] = $this->toArray();
+    }
+    return $result;
+  }
+
   /**
    * Given a DAO name, a column name and a column value, find the record and GET the value of another column in that record
    *
@@ -1036,7 +1074,7 @@ FROM   civicrm_domain
   }
 
   /**
-   * Get sort string
+   * Get sort string.
    *
    * @param array|object $sort either array or CRM_Utils_Sort
    * @param string $default
@@ -1062,7 +1100,7 @@ FROM   civicrm_domain
   }
 
   /**
-   * Fetch object based on array of properties
+   * Fetch object based on array of properties.
    *
    * @param string $daoName
    *   Name of the dao object.
@@ -1094,7 +1132,7 @@ FROM   civicrm_domain
   }
 
   /**
-   * Delete the object records that are associated with this contact
+   * Delete the object records that are associated with this contact.
    *
    * @param string $daoName
    *   Name of the dao object.
@@ -1112,7 +1150,7 @@ FROM   civicrm_domain
   }
 
   /**
-   * Execute a query
+   * Execute a query.
    *
    * @param string $query
    *   Query to be executed.
@@ -1168,7 +1206,7 @@ FROM   civicrm_domain
   }
 
   /**
-   * Execute a query and get the single result
+   * Execute a query and get the single result.
    *
    * @param string $query
    *   Query to be executed.
@@ -1289,7 +1327,7 @@ FROM   civicrm_domain
   }
 
   /**
-   * make a shallow copy of an object
+   * make a shallow copy of an object.
    * and all the fields in the object
    *
    * @param string $daoName
@@ -1383,6 +1421,16 @@ FROM   civicrm_domain
     return $newObject;
   }
 
+  /**
+   * Cascade update through related entities.
+   *
+   * @param string $daoName
+   * @param $fromId
+   * @param $toId
+   * @param array $newData
+   *
+   * @return null
+   */
   public static function cascadeUpdate($daoName, $fromId, $toId, $newData = array()) {
     $object = new $daoName();
     $object->id = $fromId;
@@ -1449,7 +1497,7 @@ SELECT contact_id
   }
 
   /**
-   * Fetch object based on array of properties
+   * Fetch object based on array of properties.
    *
    * @param string $daoName
    *   Name of the dao object.
@@ -1664,7 +1712,7 @@ SELECT contact_id
   }
 
   /**
-   * Deletes the this object plus any dependent objects that are associated with it
+   * Deletes the this object plus any dependent objects that are associated with it.
    * ONLY USE FOR TESTING
    *
    * @param string $daoName
@@ -1710,7 +1758,7 @@ SELECT contact_id
   }
 
   /**
-   * Set defaults when creating new entity
+   * Set defaults when creating new entity.
    * (don't call this set defaults as already in use with different signature in some places)
    *
    * @param array $params
@@ -1858,7 +1906,7 @@ SELECT contact_id
   }
 
   /**
-   * Wrapper function to drop triggers
+   * Wrapper function to drop triggers.
    *
    * @param string $tableName
    *   the specific table requiring a rebuild; or NULL to rebuild all tables.
@@ -2169,10 +2217,12 @@ SELECT contact_id
    */
   public static function buildOptionsContext($context = NULL) {
     $contexts = array(
-      'get' => "All options are returned, even if they are disabled. Labels are translated.",
-      'create' => "Options are filtered appropriately for the object being created/updated. Labels are translated.",
-      'search' => "Searchable options are returned. Labels are translated.",
-      'validate' => "All options are returned, even if they are disabled. Machine names are used in place of labels.",
+      'get' => "get: all options are returned, even if they are disabled; labels are translated.",
+      'create' => "create: options are filtered appropriately for the object being created/updated; labels are translated.",
+      'search' => "search: searchable options are returned; labels are translated.",
+      'validate' => "validate: all options are returned, even if they are disabled; machine names are used in place of labels.",
+      'abbreviate' => "abbreviate: enabled options are returned; labels are replaced with abbreviations.",
+      'match' => "match: enabled options are returned using machine names as keys; labels are translated.",
     );
     // Validation: enforce uniformity of this param
     if ($context !== NULL && !isset($contexts[$context])) {
@@ -2237,7 +2287,7 @@ SELECT contact_id
     // http://issues.civicrm.org/jira/browse/CRM-9150 - stick with 'simple' operators for now
     // support for other syntaxes is discussed in ticket but being put off for now
     foreach ($filter as $operator => $criteria) {
-      if (in_array($operator, self::acceptedSQLOperators())) {
+      if (in_array($operator, self::acceptedSQLOperators(), TRUE)) {
         switch ($operator) {
           // unary operators
           case 'IS NULL':