*/
/**
- * Our base DAO class. All DAO classes should inherit from this class.
+ * Base Database Access Object class.
+ *
+ * All DAO classes should inherit from this class.
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* Factory method to instantiate a new object from a table name.
*
* @param string $table
+ * @return \DataObject|\PEAR_Error
*/
public function factory($table = '') {
if (!isset(self::$_factory)) {
/**
* Defines the default key as 'id'.
*
- *
* @return array
*/
public function keys() {
* (associative)
*/
public function table() {
- $fields = &$this->fields();
+ $fields = $this->fields();
$table = array();
if ($fields) {
* Did we copy all null values into the object
*/
public function copyValues(&$params) {
- $fields = &$this->fields();
+ $fields = $this->fields();
$allNull = TRUE;
foreach ($fields as $name => $value) {
$dbName = $value['name'];
* (reference ) associative array of name/value pairs.
*/
public static function storeValues(&$object, &$values) {
- $fields = &$object->fields();
+ $fields = $object->fields();
foreach ($fields as $name => $value) {
$dbName = $value['name'];
if (isset($object->$dbName) && $object->$dbName !== 'null') {
*/
public static function getAttribute($class, $fieldName = NULL) {
$object = new $class();
- $fields = &$object->fields();
+ $fields = $object->fields();
if ($fieldName != NULL) {
$field = CRM_Utils_Array::value($fieldName, $fields);
return self::makeAttribute($field);
return NULL;
}
- /**
- * @param $type
- *
- * @throws Exception
- */
- public static function transaction($type) {
- CRM_Core_Error::fatal('This function is obsolete, please use CRM_Core_Transaction');
- }
-
/**
* Check if there is a record with the same name in the db.
*
* @param int $id
* Id of the DAO object being searched for.
*
- * @return object
+ * @return CRM_Core_DAO
* Object of the type of the class that called this function.
+ *
+ * @throws Exception
*/
public static function findById($id) {
$object = new static();
* Default sort value.
*
* @return string
- * sortString
*/
public static function getSortString($sort, $default = NULL) {
// check if sort is of type CRM_Utils_Sort
return $sort->orderBy();
}
+ $sortString = '';
+
// is it an array specified as $field => $sortDirection ?
if ($sort) {
foreach ($sort as $k => $v) {
}
/**
- * make a shallow copy of an object.
- * and all the fields in the object
+ * Make a shallow copy of an object and all the fields in the object.
*
* @param string $daoName
* Name of the dao.
* @param array $criteria
* Array of all the fields & values.
- * on which basis to copy
+ * on which basis to copy
* @param array $newData
* Array of all the fields & values.
- * to be copied besides the other fields
+ * to be copied besides the other fields
* @param string $fieldsFix
* Array of fields that you want to prefix/suffix/replace.
* @param string $blockCopyOfDependencies
* Fields that you want to block from.
- * getting copied
- *
+ * getting copied
*
* @return CRM_Core_DAO
* the newly created copy of the object
$newObject = new $daoName();
- $fields = &$object->fields();
+ $fields = $object->fields();
if (!is_array($fieldsFix)) {
$fieldsToPrefix = array();
$fieldsToSuffix = array();
$newObject->id = $toId;
if ($newObject->find(TRUE)) {
- $fields = &$object->fields();
+ $fields = $object->fields();
foreach ($fields as $name => $value) {
if ($name == 'id' || $value['name'] == 'id') {
// copy everything but the id!
return $details;
}
+ /**
+ * Drop all CiviCRM tables.
+ *
+ * @throws \CRM_Exception
+ */
public static function dropAllTables() {
// first drop all the custom tables we've created
/** @var CRM_Core_DAO $object */
$object = new $daoName();
- $fields = &$object->fields();
+ $fields = $object->fields();
foreach ($fields as $fieldName => $fieldDef) {
$dbName = $fieldDef['name'];
$FKClassName = CRM_Utils_Array::value('FKClassName', $fieldDef);
$deletions = array(); // array(array(0 => $daoName, 1 => $daoParams))
if ($object->find(TRUE)) {
- $fields = &$object->fields();
+ $fields = $object->fields();
foreach ($fields as $name => $value) {
$dbName = $value['name'];