// communication Prefferance
$preffComm = $comm = [];
$comm = explode(CRM_Core_DAO::VALUE_SEPARATOR,
- $contact->preferred_communication_method
+ ($contact->preferred_communication_method ?? '')
);
foreach ($comm as $value) {
$preffComm[$value] = 1;
*/
public static function storeRequiredCustomDataInfo(&$form, $groupTree) {
if (in_array(CRM_Utils_System::getClassName($form), ['CRM_Contact_Form_Contact', 'CRM_Contact_Form_Inline_Address'])) {
- $requireOmission = NULL;
+ $requireOmission = '';
foreach ($groupTree as $csId => $csVal) {
// only process Address entity fields
if ($csVal['extends'] !== 'Address') {
// the DB to fatal
$fields = CRM_Core_BAO_Address::fields();
foreach ($fields as $fieldname => $field) {
- if (!empty($field['maxlength']) && strlen(CRM_Utils_Array::value($fieldname, $parseFields)) > $field['maxlength']) {
+ if (!empty($field['maxlength']) && strlen(($parseFields[$fieldname] ?? '')) > $field['maxlength']) {
return $emptyParseFields;
}
}
// In such cases we could just get intval($value) and fetch matching
// option again, but this would not work if key is float like 5.6.
// So we need to truncate trailing zeros to make it work as expected.
- if ($display === '' && strpos($value, '.') !== FALSE) {
+ if ($display === '' && strpos(($value ?? ''), '.') !== FALSE) {
// Use round() to truncate trailing zeros, e.g:
// 10.00 -> 10, 10.60 -> 10.6, 10.69 -> 10.69.
$value = (string) round($value, 5);
* @return string
*/
public static function getCanonicalClassName($baoName) {
- return str_replace('_BAO_', '_DAO_', $baoName);
+ return str_replace('_BAO_', '_DAO_', ($baoName ?? ''));
}
/**
}
$session = CRM_Core_Session::singleton();
- $searchFormName = strtolower($this->get('searchFormName'));
+ $searchFormName = strtolower($this->get('searchFormName') ?? '');
if ($searchFormName === 'search') {
$session->replaceUserContext(CRM_Utils_System::url('civicrm/' . $pathPart . '/search', $urlParams));
}
* For alternate decimal point and thousands separator, delimit values with single quotes in the template.
* EXAMPLE: {$number|crmNumberFormat:2:',':' '} for French notation - 1234.56 becomes 1 234,56
*/
-function smarty_modifier_crmNumberFormat($number, $decimals = NULL, $dec_point = NULL, $thousands_sep = NULL) {
+function smarty_modifier_crmNumberFormat($number, $decimals = 0, $dec_point = NULL, $thousands_sep = NULL) {
if (is_numeric($number)) {
// Both dec_point AND thousands_sep are required if one is not specified
// then use the config defaults
'is_email_receipt' => $params['is_send_contribution_notification'],
'trxn_date' => $params['trxn_date'],
'payment_instrument_id' => $paymentTrxnParams['payment_instrument_id'],
- 'payment_processor_id' => $paymentTrxnParams['payment_processor_id'] ?? NULL,
+ 'payment_processor_id' => $paymentTrxnParams['payment_processor_id'] ?? '',
]);
// Get the trxn
$trxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
$processor = new CRM_Financial_DAO_PaymentProcessor();
$processor->id = $paymentProcessorID;
$processor->find(TRUE);
- $cards = json_decode($processor->accepted_credit_cards, TRUE);
+ $cards = json_decode(($processor->accepted_credit_cards ?? ''), TRUE);
return $cards;
}
return [];
*/
protected function getFieldEntity(string $fieldName) {
if ($fieldName === 'do_not_import') {
- return NULL;
+ return '';
}
if (in_array($fieldName, ['email_greeting_id', 'postal_greeting_id', 'addressee_id'], TRUE)) {
return 'Contact';
}
// special-case for multiple values. Also works for CRM-7251: preferred_communication_method
- if ((substr($from, 0, 1) == CRM_Core_DAO::VALUE_SEPARATOR &&
- substr($from, -1, 1) == CRM_Core_DAO::VALUE_SEPARATOR) ||
- (substr($to, 0, 1) == CRM_Core_DAO::VALUE_SEPARATOR &&
- substr($to, -1, 1) == CRM_Core_DAO::VALUE_SEPARATOR)
+ if ((substr(($from ?? ''), 0, 1) == CRM_Core_DAO::VALUE_SEPARATOR &&
+ substr(($from ?? ''), -1, 1) == CRM_Core_DAO::VALUE_SEPARATOR) ||
+ (substr(($to ?? ''), 0, 1) == CRM_Core_DAO::VALUE_SEPARATOR &&
+ substr(($to ?? ''), -1, 1) == CRM_Core_DAO::VALUE_SEPARATOR)
) {
$froms = $tos = [];
foreach (explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($from, CRM_Core_DAO::VALUE_SEPARATOR)) as $val) {
$this->sqlArray[] = $sql;
foreach ($this->sqlArray as $sql) {
foreach (['LEFT JOIN'] as $term) {
- $sql = str_replace($term, '<br> ' . $term, $sql);
+ $sql = str_replace($term, '<br> ' . $term, ($sql ?? ''));
}
foreach (['FROM', 'WHERE', 'GROUP BY', 'ORDER BY', 'LIMIT', ';'] as $term) {
- $sql = str_replace($term, '<br><br>' . $term, $sql);
+ $sql = str_replace($term, '<br><br>' . $term, ($sql ?? ''));
}
$this->sqlFormattedArray[] = $sql;
$this->assign('sql', implode(';<br><br><br><br>', $this->sqlFormattedArray));
if (!empty($this->_params["{$fieldName}_relative"])) {
[$from, $to] = CRM_Utils_Date::getFromTo($this->_params["{$fieldName}_relative"], NULL, NULL);
}
- if (strlen($to) === 10) {
+ if (strlen($to ?? '') === 10) {
// If we just have the date we assume the end of that day.
$to .= ' 23:59:59';
}
public function buildPermissionClause() {
$ret = [];
foreach ($this->selectedTables() as $tableName) {
- $baoName = str_replace('_DAO_', '_BAO_', CRM_Core_DAO_AllCoreTables::getClassForTable($tableName));
+ $baoName = str_replace('_DAO_', '_BAO_', (CRM_Core_DAO_AllCoreTables::getClassForTable($tableName) ?? ''));
if ($baoName && class_exists($baoName) && !empty($this->_columns[$tableName]['alias'])) {
$tableAlias = $this->_columns[$tableName]['alias'];
$clauses = array_filter($baoName::getSelectWhereClause($tableAlias));
$day = (int) substr(($dateString ?? ''), 6, 2);
}
- if (strlen($dateString) > 10) {
+ if (strlen(($dateString ?? '')) > 10) {
$format = $config->dateformatDatetime;
}
elseif ($day > 0) {
* date/datetime in ISO format
*/
public static function mysqlToIso($mysql) {
- $year = substr($mysql, 0, 4);
- $month = substr($mysql, 4, 2);
- $day = substr($mysql, 6, 2);
- $hour = substr($mysql, 8, 2);
- $minute = substr($mysql, 10, 2);
- $second = substr($mysql, 12, 2);
+ $year = substr(($mysql ?? ''), 0, 4);
+ $month = substr(($mysql ?? ''), 4, 2);
+ $day = substr(($mysql ?? ''), 6, 2);
+ $hour = substr(($mysql ?? ''), 8, 2);
+ $minute = substr(($mysql ?? ''), 10, 2);
+ $second = substr(($mysql ?? ''), 12, 2);
$iso = '';
if ($year) {
$uniqID = md5(uniqid(rand(), TRUE));
$info = pathinfo($name);
$basename = substr($info['basename'],
- 0, -(strlen(CRM_Utils_Array::value('extension', $info)) + (CRM_Utils_Array::value('extension', $info) == '' ? 0 : 1))
+ 0, -(strlen(CRM_Utils_Array::value('extension', $info, '')) + (CRM_Utils_Array::value('extension', $info, '') == '' ? 0 : 1))
);
- if (!self::isExtensionSafe(CRM_Utils_Array::value('extension', $info))) {
+ if (!self::isExtensionSafe(CRM_Utils_Array::value('extension', $info, ''))) {
// munge extension so it cannot have an embbeded dot in it
// The maximum length of a filename for most filesystems is 255 chars.
// We'll truncate at 240 to give some room for the extension.
}
$iconClasses = Civi::$statics[__CLASS__]['mimeIcons'];
foreach ($iconClasses as $text => $icon) {
- if (strpos($mimeType, $text) === 0) {
+ if (strpos(($mimeType ?? ''), $text) === 0) {
return $icon;
}
}
* In php8 the return value from is_dir() is always bool but in php7 it can be null.
*/
public static function isDir(?string $dir) {
+ if ($dir === NULL) {
+ return FALSE;
+ }
set_error_handler(function($errno, $errstr) {
// If this is open_basedir-related, convert it to an exception so we
// can catch it.
public static function formatRFC822Email($name, $email, $useQuote = FALSE) {
$result = NULL;
- $name = trim($name);
+ $name = trim($name ?? '');
// strip out double quotes if present at the beginning AND end
if (substr($name, 0, 1) == '"' &&
if (is_array($query)) {
$buf = '';
foreach ($query as $key => $value) {
- $buf .= ($buf ? '&' : '') . urlencode($key) . '=' . urlencode($value);
+ $buf .= ($buf ? '&' : '') . urlencode($key ?? '') . '=' . urlencode($value ?? '');
}
$query = $buf;
}
// Convert multi-value strings to arrays
$sp = CRM_Core_DAO::VALUE_SEPARATOR;
foreach ($result as $id => $value) {
- if (strpos($value, $sp) !== FALSE) {
+ if (strpos(($value ?? ''), $sp) !== FALSE) {
$value = explode($sp, trim($value, $sp));
}
$job = civicrm_api3('MailingJob', 'create', $testEmailParams);
CRM_Mailing_BAO_Mailing::getRecipients($testEmailParams['mailing_id']);
$testEmailParams['job_id'] = $job['id'];
- $testEmailParams['emails'] = array_key_exists('test_email', $testEmailParams) ? explode(',', strtolower($testEmailParams['test_email'])) : NULL;
+ $testEmailParams['emails'] = array_key_exists('test_email', $testEmailParams) ? explode(',', strtolower($testEmailParams['test_email'] ?? '')) : NULL;
if (!empty($params['test_email'])) {
$query = CRM_Utils_SQL_Select::from('civicrm_email e')
->select(['e.id', 'e.contact_id', 'e.email'])
$contactEntities = ['contact', 'individual', 'organization', 'household'];
$locationEntities = ['email', 'address', 'phone', 'website', 'im'];
- $entity = strtolower(CRM_Utils_Array::value('entity', $field));
+ $entity = strtolower(CRM_Utils_Array::value('entity', $field, ''));
if ($entity && !in_array($entity, array_merge($contactEntities, $locationEntities))) {
switch ($entity) {
case 'note':
*/
function _civicrm_api3_validate_unique_key(&$params, &$fieldName) {
[$fieldValue, $op] = _civicrm_api3_field_value_check($params, $fieldName);
- if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE) {
+ if (strpos(($op ?? ''), 'NULL') !== FALSE || strpos(($op ?? ''), 'EMPTY') !== FALSE) {
return;
}
$existing = civicrm_api($params['entity'], 'get', [
*/
function _civicrm_api3_validate_html(&$params, &$fieldName, $fieldInfo) {
[$fieldValue, $op] = _civicrm_api3_field_value_check($params, $fieldName);
- if (strpos($op, 'NULL') || strpos($op, 'EMPTY')) {
+ if (strpos(($op ?? ''), 'NULL') || strpos(($op ?? ''), 'EMPTY')) {
return;
}
}