switch ($name) {
case 'activity_type_id':
- case 'activity_type':
case 'activity_status_id':
- case 'activity_status':
case 'activity_engagement_level':
case 'activity_subject':
case 'activity_id':
- if (!$value) {
- break;
- }
$qillName = $name;
- if (in_array($name, array('activity_type_id'))) {
- $name = $qillName = $name . '_id';
- }
if (in_array($name, array('activity_engagement_level', 'activity_id'))) {
$name = $qillName = str_replace('activity_', '', $name);
}
}
$dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String';
- if (in_array($name, array('activity_type', 'activity_status'))) {
- $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("$name.label", $op, $value, $dataType);
- }
- else {
- $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_activity.$name", $op, $value, $dataType);
- }
+ $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_activity.$name", $op, $value, $dataType);
list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Activity_DAO_Activity', $name, $value, $op);
$query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $op, 3 => $value));
break;
+ case 'activity_type':
+ case 'activity_status':
+ $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("$name.label", $op, $value, 'String');
+ list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Activity_DAO_Activity', $name, $value, $op);
+ $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$name]['title'], 2 => $op, 3 => $value));
+ $query->_tables[$name] = $query->_whereTables[$name] = 1;
+ break;
+
case 'activity_survey_id':
if (!$value) {
break;
if (
(substr($name, 0, 12) == 'participant_') ||
(substr($name, 0, 7) == 'pledge_') ||
- (substr($name, 0, 5) == 'case_')
+ (substr($name, 0, 5) == 'case_') ||
+ (substr($name, 0, 13) == 'contribution_') ||
+ (substr($name, 0, 8) == 'payment_')
) {
continue;
}
return $result;
}
- if ($apiEntity && substr($id, 0, strlen($apiEntity)) != $apiEntity) {
+ if ($apiEntity &&
+ (substr($id, 0, strlen($apiEntity)) != $apiEntity) &&
+ (substr($id, 0, 10) != 'financial_' && substr($id, 0, 8) != 'payment_')
+ ) {
$id = $apiEntity . '_' . $id;
}
(substr($values[0], 0, 7) == 'pledge_') ||
(substr($values[0], 0, 5) == 'case_') ||
(substr($values[0], 0, 10) == 'financial_') ||
+ (substr($values[0], 0, 8) == 'payment_') ||
(substr($values[0], 0, 11) == 'membership_')
) {
return;
static function buildQillForFieldValue($daoName, $fieldName, $fieldValue, $op, $pseduoExtraParam = array()) {
$pseduoOptions = CRM_Core_PseudoConstant::get($daoName, $fieldName, $pseduoExtraParam = array());
+ $qillOperators = CRM_Core_SelectValues::getSearchBuilderOperators();
if ($fieldName == 'activity_type_id') {
$pseduoOptions = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
}
$fieldValue = implode(', ', $fieldValue);
}
}
- return array($op, $fieldValue);
}
elseif (is_array($fieldValue)) {
$qillString = array();
foreach ((array)$fieldValue as $val) {
$qillString[] = $pseduoOptions[$val];
}
- return array($op, implode(', ', $qillString));
+ $fieldValue = implode(', ', $qillString);
}
else {
if (array_key_exists($fieldValue, $pseduoOptions)) {
$fieldValue = $pseduoOptions[$fieldValue];
}
- return array($op, $fieldValue);
}
+
+ return array(CRM_Utils_Array::value($op, $qillOperators, $op), $fieldValue);
}
}
}
}
- foreach (array('financial_type_id', 'contribution_soft_credit_type_id', 'contribution_status', 'contribution_source', 'contribution_trxn_id', 'activity_type_id', 'status_id', 'activity_subject', 'participant_status_id', 'participant_role_id') as $element) {
+ $specialParams = array(
+ 'financial_type_id',
+ 'contribution_soft_credit_type_id',
+ 'contribution_status',
+ 'contribution_source',
+ 'contribution_trxn_id',
+ 'activity_type_id',
+ 'status_id',
+ 'activity_subject',
+ 'participant_status_id',
+ 'participant_role_id'
+ );
+ foreach ($specialParams as $element) {
$value = CRM_Utils_Array::value($element, $this->_formValues);
if ($value) {
if (is_array($value)) {
}
// get payment instrument
- if (!empty($query->_returnProperties['contribution_payment_instrument'])) {
+ if (!empty($query->_returnProperties['payment_instrument'])) {
$query->_select['payment_instrument'] = "contribution_payment_instrument.label as payment_instrument";
$query->_element['payment_instrument'] = 1;
$query->_tables['civicrm_contribution'] = 1;
$query->_tables['contribution_payment_instrument'] = 1;
}
- // get payment instrument id
- if (!empty($query->_returnProperties['payment_instrument_id'])) {
- $query->_select['payment_instrument_id'] = "contribution_payment_instrument.value as payment_instrument_id";
- $query->_element['payment_instrument_id'] = 1;
- $query->_tables['civicrm_contribution'] = 1;
- $query->_tables['contribution_payment_instrument'] = 1;
- }
-
if (!empty($query->_returnProperties['check_number'])) {
$query->_select['contribution_check_number'] = "civicrm_contribution.check_number as contribution_check_number";
$query->_element['contribution_check_number'] = 1;
*/
public static function where(&$query) {
$grouping = NULL;
-
self::initializeAnySoftCreditClause($query);
foreach (array_keys($query->_params) as $id) {
if (empty($query->_params[$id][0])) {
continue;
}
- if (substr($query->_params[$id][0], 0, 13) == 'contribution_' || substr($query->_params[$id][0], 0, 10) == 'financial_') {
+ if (substr($query->_params[$id][0], 0, 13) == 'contribution_' || substr($query->_params[$id][0], 0, 10) == 'financial_' || substr($query->_params[$id][0], 0, 8) == 'payment_') {
if ($query->_mode == CRM_Contact_BAO_QUERY::MODE_CONTACTS) {
$query->_useDistinct = TRUE;
}
list($name, $op, $value, $grouping, $wildcard) = $values;
$quoteValue = NULL;
- $fields = self::getFields();
+ $fields = array_merge(CRM_Contribute_BAO_Contribution::fields(), self::getFields());
if (!empty($value) && !is_array($value)) {
$quoteValue = "\"$value\"";
return;
case 'financial_type_id':
- case 'financial_type':
case 'contribution_page_id':
case 'contribution_status_id':
case 'contribution_id':
case 'contribution_currency_type':
case 'contribution_currency':
case 'contribution_source':
- case 'contribution_payment_instrument_id':
case 'contribution_trxn_id':
case (strpos($name, '_amount') !== FALSE):
case (strpos($name, '_date') !== FALSE):
- if (!$value) {
- break;
- }
$qillName = $name;
$pseudoExtraParam = NULL;
- if (in_array($name, array('financial_type'))) {
- $name = $name . "_id";
- }
- if (in_array($name, array('financial_type_id', 'contribution_payment_instrument_id'))) {
- $qillName = str_replace('_id', '', $name);
- }
if ((strpos($name, '_amount') !== FALSE) || (strpos($name, '_date') !== FALSE) || in_array($name,
array(
'contribution_id',
'contribution_source',
'contribution_trxn_id',
'contribution_check_number',
- 'contribution_payment_instrument_id'
)
)
) {
$query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
return;
+ case 'financial_type':
+ $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fields[$name]['where'], $op, $value, 'String');
+ CRM_Core_Error::debug( '$query', $query->_where[$grouping] );
+ list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Contribute_DAO_Contribution', $name, $value, $op);
+ $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$name]['title'], 2 => $op, 3 => $value));
+ $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
+ $query->_tables['civicrm_financial_type'] = $query->_whereTables['civicrm_financial_type'] = 1;
+ return;
+
case 'contribution_page':
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fields[$name]['where'], $op, $value, 'String');
list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Contribute_DAO_Contribution', $name, $value, $op);
$query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
return;
+ case 'payment_instrument':
+ $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("contribution_payment_instrument.value", $op, $value, 'Int');
+ list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Contribute_DAO_Contribution', 'payment_instrument_id', $value, $op);
+ $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$name]['title'], 2 => $op, 3 => $value));
+ $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
+ $query->_tables['contribution_payment_instrument'] = $query->_whereTables['contribution_payment_instrument'] = 1;
+ return;
+
case 'contribution_status':
- case 'contribution_payment_instrument':
- if (!$value) {
- break;
- }
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("$name.label", $op, $value, 'String');
list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Contribute_DAO_Contribution', $name, $value, $op);
- if ($name == 'contribution_payment_instrument') {
- $name = 'payment_instrument';
- }
$query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$name]['title'], 2 => $op, 3 => $value));
$query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
+ $query->_tables[$name] = $query->_whereTables[$name] = 1;
break;
case 'contribution_pcp_made_through_id':
case 'contribution_soft_credit_type_id':
- if (!$value) {
- break;
- }
$qillName = $name;
if ($name == 'contribution_pcp_made_through_id') {
$qillName = $name = 'pcp_id';
'cancel_date' => 1,
'total_amount' => 1,
'accounting_code' => 1,
- 'contribution_payment_instrument' => 1,
- 'payment_instrument_id' => 1,
+ 'payment_instrument' => 1,
'check_number' => 1,
'non_deductible_amount' => 1,
'fee_amount' => 1,
FALSE, array('class' => 'crm-select2')
);
-
- $form->add('select', 'contribution_payment_instrument_id',
+ $form->add('select', 'payment_instrument',
ts('Payment Instrument'),
array(
'' => ts('- any -')
$config = CRM_Core_Config::singleton();
if (!empty($_POST)) {
- foreach (array('financial_type_id', 'contribution_soft_credit_type_id', 'contribution_status_id', 'contribution_source', 'contribution_trxn_id') as $element) {
+ $specialParams = array(
+ 'financial_type_id',
+ 'contribution_soft_credit_type_id',
+ 'contribution_status_id',
+ 'contribution_source',
+ 'contribution_trxn_id'
+ );
+ foreach ($specialParams as $element) {
$value = CRM_Utils_Array::value($element, $this->_formValues);
if ($value) {
if (is_array($value)) {
if ($v[0] == 'Contribution' && substr($fldName, 0, 7) != 'custom_'
&& substr($fldName, 0, 10) != 'financial_'
- ) {
+ && substr($fldName, 0, 8) != 'payment_') {
if (substr($fldName, 0, 13) != 'contribution_') {
$fldName = 'contribution_' . $fldName;
}
'>=' => '≥',
'<=' => '≤',
'IN' => ts('In'),
+ 'NOT IN' => ts('Not In'),
'LIKE' => ts('Like'),
+ 'NOT LIKE' => ts('Not Like'),
'RLIKE' => ts('Regex'),
'IS EMPTY' => ts('Is Empty'),
'IS NOT EMPTY' => ts('Not Empty'),
*/
public static function whereClauseSingle(&$values, &$query) {
list($name, $op, $value, $grouping, $wildcard) = $values;
- $fields = CRM_Event_BAO_Participant::exportableFields();
+ $fields = array_merge(self::fields(), CRM_Event_BAO_Event::fields(), CRM_Event_BAO_Participant::exportableFields());
switch ($name) {
case 'event_start_date_low':
$fields = array_intersect_key($fields, $params);
foreach ($fields as $fieldName => $fieldInfo) {
//In some case $params[$fieldName] holds Array value in this format Array([operator] => [value])
- $fieldValue = CRM_Utils_Array::value($fieldName, $params);
- $op = NULL;
- if (!empty($fieldValue) && is_array($fieldValue) && in_array(key($fieldValue), CRM_Core_DAO::acceptedSQLOperators())) {
- $op = key($fieldValue);
- $fieldValue = CRM_Utils_Array::value($op, $fieldValue);;
- }
+
switch (CRM_Utils_Array::value('type', $fieldInfo)) {
case CRM_Utils_Type::T_INT:
//field is of type integer
- _civicrm_api3_validate_integer($fieldValue, $fieldName, $fieldInfo, $entity);
+ _civicrm_api3_validate_integer($params, $fieldName, $fieldInfo, $entity);
break;
case 4:
case 12:
case CRM_Utils_Type::T_TIMESTAMP:
//field is of type date or datetime
- _civicrm_api3_validate_date($params, $fieldName, $fieldValue, $fieldInfo);
+ _civicrm_api3_validate_date($params, $fieldName, $fieldInfo);
break;
case 32://blob
- _civicrm_api3_validate_html($fieldValue, $fieldName, $fieldInfo);
+ _civicrm_api3_validate_html($params, $fieldName, $fieldInfo);
break;
case CRM_Utils_Type::T_STRING:
- _civicrm_api3_validate_string($fieldValue, $fieldName, $fieldInfo, $entity);
+ _civicrm_api3_validate_string($params, $fieldName, $fieldInfo, $entity);
break;
case CRM_Utils_Type::T_MONEY:
+ list($fieldValue, $op) = _civicrm_api3_field_value_check($params, $fieldName);
+ if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE) {
+ break;
+ }
if (!CRM_Utils_Rule::money($fieldValue) && !empty($fieldValue)) {
throw new Exception($fieldName . " is not a valid amount: " . $params[$fieldName]);
}
}
if (!empty($fieldInfo['api.unique'])) {
$params['entity'] = $entity;
- _civicrm_api3_validate_uniquekey($params, $fieldName, $fieldValue, $fieldInfo);
+ _civicrm_api3_validate_uniquekey($params, $fieldName, $fieldInfo);
}
}
-
- $params[$fieldName] = $fieldValue;
- if (!is_null($op)) {
- $params[$fieldName] = array($op => $fieldValue);
- }
}
}
* Array of fields from getfields function.
* @throws Exception
*/
-function _civicrm_api3_validate_date(&$params, &$fieldName, &$fieldValue, &$fieldInfo) {
+function _civicrm_api3_validate_date(&$params, &$fieldName, &$fieldInfo) {
+ list($fieldValue, $op) = _civicrm_api3_field_value_check($params, $fieldName);
+ if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE) {
+ return;
+ }
//should we check first to prevent it from being copied if they have passed in sql friendly format?
if (!empty($params[$fieldInfo['name']])) {
$fieldValue = _civicrm_api3_getValidDate($fieldValue, $fieldInfo['name'], $fieldInfo['type']);
if ((CRM_Utils_Array::value('name', $fieldInfo) != $fieldName) && !empty($fieldValue)) {
$fieldValue = _civicrm_api3_getValidDate($fieldValue, $fieldName, $fieldInfo['type']);
}
+
+ if (!empty($op)) {
+ $params[$fieldName][$op] = $fieldValue;
+ }
+ else {
+ $params[$fieldName] = $fieldValue;
+ }
}
/**
* Array of fields from getfields function.
* @throws Exception
*/
-function _civicrm_api3_validate_uniquekey(&$params, &$fieldName, &$fieldValue, &$fieldInfo) {
+function _civicrm_api3_validate_uniquekey(&$params, &$fieldName, &$fieldInfo) {
+ list($fieldValue, $op) = _civicrm_api3_field_value_check($params, $fieldName);
+ if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE) {
+ return;
+ }
$existing = civicrm_api($params['entity'], 'get', array(
'version' => $params['version'],
$fieldName => $fieldValue,
* @param string $entity
* @throws API_Exception
*/
-function _civicrm_api3_validate_integer(&$fieldValue, &$fieldName, &$fieldInfo, $entity) {
+function _civicrm_api3_validate_integer(&$params, &$fieldName, &$fieldInfo, $entity) {
+ list($fieldValue, $op) = _civicrm_api3_field_value_check($params, $fieldName);
+ if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE) {
+ return;
+ }
+
if (!empty($fieldValue)) {
// if value = 'user_contact_id' (or similar), replace value with contact id
if (!is_numeric($fieldValue) && is_scalar($fieldValue)) {
$realContactId = _civicrm_api3_resolve_contactID($fieldValue);
if ('unknown-user' === $realContactId) {
- throw new API_Exception("\"$fieldName\" \"{$params[$fieldName]}\" cannot be resolved to a contact ID", 2002, array('error_field' => $fieldName, "type" => "integer"));
+ throw new API_Exception("\"$fieldName\" \"{$fieldValue}\" cannot be resolved to a contact ID", 2002, array('error_field' => $fieldName,"type"=>"integer"));
} elseif (is_numeric($realContactId)) {
$fieldValue = $realContactId;
}
*
* @throws API_Exception
*/
-function _civicrm_api3_validate_html(&$fieldValue, &$fieldName, $fieldInfo) {
+function _civicrm_api3_validate_html(&$params, &$fieldName, $fieldInfo) {
+ list($fieldValue, $op) = _civicrm_api3_field_value_check($params, $fieldName);
+ if (strpos($op, 'NULL') || strpos($op, 'EMPTY')) {
+ return;
+ }
if ($fieldValue) {
if (!CRM_Utils_Rule::xssString($fieldValue)) {
throw new API_Exception('Illegal characters in input (potential scripting attack)', array("field"=>$fieldName,"error_code"=>"xss"));
* @throws API_Exception
* @throws Exception
*/
-function _civicrm_api3_validate_string(&$fieldValue, &$fieldName, &$fieldInfo, $entity) {
+function _civicrm_api3_validate_string(&$params, &$fieldName, &$fieldInfo, $entity) {
+ list($fieldValue, $op) = _civicrm_api3_field_value_check($params, $fieldName);
+ if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE) {
+ return;
+ }
// If fieldname exists in params
$fieldValue = !empty($fieldValue) ? $fieldValue : '';
if(!is_array($fieldValue)){
}
}
}
+
+/**
+ * In some case $params[$fieldName] holds Array value in this format Array([operator] => [value])
+ * So this function returns the actual field value
+ *
+ * @param array $params
+ * @param string $fieldName
+ * @return string|int|boolean|date|null
+ */
+function _civicrm_api3_field_value_check(&$params, $fieldName) {
+ $fieldValue = CRM_Utils_Array::value($fieldName, $params);
+ $op = NULL;
+
+ if (!empty($fieldValue) && is_array($fieldValue) && in_array(key($fieldValue), CRM_Core_DAO::acceptedSQLOperators())) {
+ $op = key($fieldValue);
+ $fieldValue = CRM_Utils_Array::value($op, $fieldValue);
+ }
+ return array($fieldValue, $op);
+}
<td>
<div class="float-left">
<label>{ts}Payment Method{/ts}</label> <br />
- {$form.contribution_payment_instrument_id.html|crmAddClass:twenty}
+ {$form.payment_instrument.html|crmAddClass:twenty}
</div>
<div class="float-left" id="contribution_check_number_wrapper">
{$form.contribution_check_number.label} <br />
</foreignKey>
<field>
<name>financial_type_id</name>
- <title>Financial Type</title>
+ <title>Financial Type ID</title>
<export>false</export>
<type>int unsigned</type>
<comment>FK to Financial Type for (total_amount - non_deductible_amount).</comment>
<uniqueName>event_type_id</uniqueName>
<title>Event Type</title>
<default>0</default>
- <export>true</export>
<pseudoconstant>
<optionGroupName>event_type</optionGroupName>
</pseudoconstant>
<import>true</import>
<type>varchar</type>
<length>128</length>
- <export>true</export>
+ <export>false</export>
<default>NULL</default>
<comment>Participant role ID. Implicit FK to civicrm_option_value where option_group = participant_role.</comment>
<add>1.7</add>