if ($fields) {
foreach ($fields as $name => $value) {
$table[$value['name']] = $value['type'];
- if (CRM_Utils_Array::value('required', $value)) {
+ if (!empty($value['required'])) {
$table[$value['name']] += self::DB_DAO_NOTNULL;
}
}
* execute a query and get the single result
*
* @param string $query query to be executed
+ * @param array $params
+ * @param bool $abort
+ * @param bool $i18nRewrite
+ * @return string|null the result of the query if any
*
- * @return string the result of the query
* @static
* @access public
*/
$fieldsToSuffix = array();
$fieldsToReplace = array();
}
- if (CRM_Utils_Array::value('prefix', $fieldsFix)) {
+ if (!empty($fieldsFix['prefix'])) {
$fieldsToPrefix = $fieldsFix['prefix'];
}
- if (CRM_Utils_Array::value('suffix', $fieldsFix)) {
+ if (!empty($fieldsFix['suffix'])) {
$fieldsToSuffix = $fieldsFix['suffix'];
}
- if (CRM_Utils_Array::value('replace', $fieldsFix)) {
+ if (!empty($fieldsFix['replace'])) {
$fieldsToReplace = $fieldsFix['replace'];
}
//skip the FK if it is not required
// if it's contact id we should create even if not required
// we'll have a go @ fetching first though
+ // we WILL create campaigns though for so tests with a campaign pseudoconstant will complete
+ if($FKClassName === 'CRM_Campaign_DAO_Campaign' && $daoName != $FKClassName) {
+ $required = TRUE;
+ }
if (!$required && $dbName != 'contact_id') {
$fkDAO = new $FKClassName;
if($fkDAO->find(TRUE)){
case CRM_Utils_Type::T_DATE:
case CRM_Utils_Type::T_TIMESTAMP:
+ case CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME:
$object->$dbName = '19700101';
+ if($dbName == 'end_date') {
+ // put this in the future
+ $object->$dbName = '20200101';
+ }
break;
case CRM_Utils_Type::T_TIME:
public function getOptionLabels() {
$fields = $this->fields();
if ($fields === NULL) {
- throw new exception ('Cannot call getOptionLabels on CRM_Core_DAO');
+ throw new Exception ('Cannot call getOptionLabels on CRM_Core_DAO');
}
foreach ($fields as $field) {
$name = CRM_Utils_Array::value('name', $field);
);
// Validation: enforce uniformity of this param
if ($context !== NULL && !isset($contexts[$context])) {
- throw new exception("'$context' is not a valid context for buildOptions.");
+ throw new Exception("'$context' is not a valid context for buildOptions.");
}
return $contexts;
}
+ /**
+ * @param $fieldName
+ * @return bool|array
+ */
+ function getFieldSpec($fieldName) {
+ $fields = $this->fields();
+ $fieldKeys = $this->fieldKeys();
+
+ // Support "unique names" as well as sql names
+ $fieldKey = $fieldName;
+ if (empty($fields[$fieldKey])) {
+ $fieldKey = CRM_Utils_Array::value($fieldName, $fieldKeys);
+ }
+ // If neither worked then this field doesn't exist. Return false.
+ if (empty($fields[$fieldKey])) {
+ return FALSE;
+ }
+ return $fields[$fieldKey];
+ }
+
/**
* SQL version of api function to assign filters to the DAO based on the syntax
* $field => array('IN' => array(4,6,9))
case 'BETWEEN':
case 'NOT BETWEEN':
if (empty($criteria[0]) || empty($criteria[1])) {
- throw new exception("invalid criteria for $operator");
+ throw new Exception("invalid criteria for $operator");
}
if(!$returnSanitisedArray) {
return (sprintf('%s ' . $operator . ' "%s" AND "%s"', $fieldName, CRM_Core_DAO::escapeString($criteria[0]), CRM_Core_DAO::escapeString($criteria[1])));
case 'IN':
case 'NOT IN':
if (empty($criteria)) {
- throw new exception("invalid criteria for $operator");
+ throw new Exception("invalid criteria for $operator");
}
$escapedCriteria = array_map(array(
'CRM_Core_DAO',