X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FDAO.php;h=02b3d3d1587f72fb0edf5c094bc30a726caa6f89;hb=ac7a239e2050ecd8e7b48ed43138be046b073de0;hp=eb24e0ed285b7607348f0105f8b9d5fc81e3924b;hpb=9bda6b7a507b0c43cd1062296c334e7e464cf3ff;p=civicrm-core.git diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index eb24e0ed28..02b3d3d158 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -1669,6 +1669,9 @@ FROM civicrm_domain } } $newObject->save(); + if (!empty($newData['custom'])) { + CRM_Core_BAO_CustomValueTable::store($newData['custom'], $newObject::getTableName(), $newObject->id); + } CRM_Utils_Hook::post('create', CRM_Core_DAO_AllCoreTables::getBriefName($daoName), $newObject->id, $newObject); } @@ -2362,19 +2365,47 @@ SELECT contact_id * This is relevant where we want to offer both the ID field and the label field * as an option, e.g. search builder. * - * It is currently limited for optionGroupName for purposes keeping the scope of the + * It is currently limited for optionGroupName & id+ name+ FK combos for purposes keeping the scope of the * change small, but is appropriate for other sorts of pseudoconstants. * * @param array $fields */ - protected static function appendPseudoConstantsToFields(&$fields) { + public static function appendPseudoConstantsToFields(&$fields) { foreach ($fields as $field) { - if (!empty($field['pseudoconstant']) && !empty($field['pseudoconstant']['optionGroupName'])) { - $fields[$field['pseudoconstant']['optionGroupName']] = array( - 'title' => CRM_Core_BAO_OptionGroup::getTitleByName($field['pseudoconstant']['optionGroupName']), - 'name' => $field['pseudoconstant']['optionGroupName'], - 'data_type' => CRM_Utils_Type::T_STRING, - ); + if (!empty($field['pseudoconstant'])) { + $pseudoConstant = $field['pseudoconstant']; + if (!empty($pseudoConstant['optionGroupName'])) { + $fields[$pseudoConstant['optionGroupName']] = [ + 'title' => CRM_Core_BAO_OptionGroup::getTitleByName($pseudoConstant['optionGroupName']), + 'name' => $pseudoConstant['optionGroupName'], + 'data_type' => CRM_Utils_Type::T_STRING, + 'is_pseudofield_for' => $field['name'], + ]; + } + // We restrict to id + name + FK as we are extending this a bit, but cautiously. + elseif ( + !empty($field['FKClassName']) + && CRM_Utils_Array::value('keyColumn', $pseudoConstant) === 'id' + && CRM_Utils_Array::value('labelColumn', $pseudoConstant) === 'name' + ) { + $pseudoFieldName = str_replace('_' . $pseudoConstant['keyColumn'], '', $field['name']); + // This if is just an extra caution when adding change. + if (!isset($fields[$pseudoFieldName])) { + $daoName = $field['FKClassName']; + $fkFields = $daoName::fields(); + foreach ($fkFields as $fkField) { + if ($fkField['name'] === $pseudoConstant['labelColumn']) { + $fields[$pseudoFieldName] = [ + 'name' => $pseudoFieldName, + 'is_pseudofield_for' => $field['name'], + 'title' => $fkField['title'], + 'data_type' => $fkField['type'], + 'where' => $field['where'], + ]; + } + } + } + } } } } @@ -2511,7 +2542,7 @@ SELECT contact_id // ternary operators case 'BETWEEN': case 'NOT BETWEEN': - if (empty($criteria[0]) || empty($criteria[1])) { + if ((empty($criteria[0]) && !in_array($criteria[0], ['0', 0]))|| (empty($criteria[1]) && !in_array($criteria[1], ['0', 0]))) { throw new Exception("invalid criteria for $operator"); } if (!$returnSanitisedArray) {