$Activityfields = array(
- 'activity_type' => array('title' => ts('Activity Type'), 'type' => CRM_Utils_Type::T_STRING),
- 'activity_status' => array('title' => ts('Activity Status'), 'type' => CRM_Utils_Type::T_STRING),
+ 'activity_type' => array('title' => ts('Activity Type'), 'name' => 'activity_type', 'type' => CRM_Utils_Type::T_STRING),
+ 'activity_status' => array('title' => ts('Activity Status'), 'name' => 'activity_status', 'type' => CRM_Utils_Type::T_STRING),
);
$fields = array_merge($Activityfields, $exportableFields);
}
public static function whereClauseSingle(&$values, &$query) {
list($name, $op, $value, $grouping, $wildcard) = $values;
+ $fields = CRM_Activity_BAO_Activity::exportableFields();
$strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
$query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
if ($query->_mode & CRM_Contact_BAO_Query::MODE_ACTIVITY) {
switch ($name) {
case 'activity_type_id':
case 'activity_type':
- $types = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
- //get the component activity types.
- $compActTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE, TRUE);
- $activityTypeIds = self::buildWhereAndQill($query, $value, $types, $op, $grouping, array(
- 'Activity Type',
- 'civicrm_activity.activity_type_id'
- ));
-
- foreach ($activityTypeIds as $activityTypeId) {
- if (array_key_exists($activityTypeId, $compActTypes)) {
- CRM_Contact_BAO_Query::$_considerCompActivities = TRUE;
- break;
- }
+ 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);
}
+ if (in_array($name, array('activity_status_id', 'activity_subject'))) {
+ $name = str_replace('activity_', '', $name);
+ $qillName = str_replace('_id', '', $qillName);
+ }
+ $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);
+ }
+ 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_survey_id':
$query->_qill[$grouping][] = ts('Survey') . ' - ' . CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $value, 'title');
break;
- case 'activity_engagement_level':
- if (!$value) {
- break;
- }
-
- $value = CRM_Utils_Type::escape($value, 'Integer');
- $query->_where[$grouping][] = " engagement_level = $value";
- $query->_qill[$grouping][] = ts('Engagement Index') . ' - ' . CRM_Core_OptionGroup::getLabel('engagement_index', $value);
- break;
-
case 'activity_role':
CRM_Contact_BAO_Query::$_activityRole = $values[2];
$activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
}
break;
- case 'activity_status':
- $status = CRM_Core_PseudoConstant::activityStatus();
-
- $activityTypeIds = self::buildWhereAndQill($query, $value, $status, $op, $grouping, array(
- 'Activity Status',
- 'civicrm_activity.status_id'
- ));
- break;
-
- case 'activity_subject':
- $n = trim($value);
- $value = strtolower(CRM_Core_DAO::escapeString($n));
- if ($wildcard) {
- if (strpos($value, '%') !== FALSE) {
- // only add wild card if not there
- $value = "'$value'";
- }
- else {
- $value = "'%$value%'";
- }
- $op = 'LIKE';
- }
- else {
- $value = "'$value'";
- }
- $wc = ($op != 'LIKE') ? "LOWER(civicrm_activity.subject)" : "civicrm_activity.subject";
- $query->_where[$grouping][] = " $wc $op $value";
- $query->_qill[$grouping][] = ts('Subject') . " $op - '$n'";
- break;
-
case 'activity_test':
// We dont want to include all tests for sql OR CRM-7827
if (!$value || $query->getOperator() != 'OR') {
);
break;
- case 'activity_id':
- if (empty($value)) {
- break;
- }
-
- if (is_array($value)) {
- foreach ($value as $k => $v) {
- $value[$k] = CRM_Utils_Type::escape($v, 'Integer');
- }
- }
- else {
- $value = array(CRM_Utils_Type::escape($value, 'Integer'));
- }
- $query->_where[$grouping][] = "civicrm_activity.id IN (" . implode(",", $value) . ")";
- $query->_qill[$grouping][] = ts('Activity Id(s) %1', array(1 => implode($value)));
- break;
-
case 'activity_taglist':
$taglist = $value;
$value = array();
*/
public static function buildSearchForm(&$form) {
$activityOptions = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
- asort($activityOptions);
- foreach ($activityOptions as $activityID => $activity) {
- $form->_activityElement =&
- $form->addElement(
- 'checkbox',
- "activity_type_id[$activityID]",
- NULL,
- $activity,
- array('onClick' => 'showCustomData( this.id );')
- );
- }
+ $form->addSelect('activity_type_id',
+ array('entity' => 'activity', 'label' => 'Activity Type(s)', 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))
+ );
CRM_Core_Form_Date::buildDateRange($form, 'activity_date', 1, '_low', '_high', ts('From'), FALSE, FALSE);
$followUpActivity = array(
);
$form->addRadio('activity_role', NULL, $activityRoles, array('allowClear' => TRUE));
$form->setDefaults(array('activity_role' => 3));
- $activityStatus = CRM_Core_PseudoConstant::activityStatus();
- foreach ($activityStatus as $activityStatusID => $activityStatusName) {
- $activity_status[] = $form->createElement('checkbox', $activityStatusID, NULL, $activityStatusName);
- }
- $form->addGroup($activity_status, 'activity_status', ts('Activity Status'));
- $form->setDefaults(array('activity_status[1]' => 1, 'activity_status[2]' => 1));
+ $activityStatus = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'status_id', array('flip' => 1, 'labelColumn' => 'name'));
+ $form->addSelect('status_id',
+ array('entity' => 'activity', 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))
+ );
+ $form->setDefaults(array('status_id' => array($activityStatus['Completed'], $activityStatus['Scheduled'])));
$form->addElement('text', 'activity_subject', ts('Subject'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
$form->addYesNo('activity_test', ts('Activity is a Test?'));
$activity_tags = CRM_Core_BAO_Tag::getTags('civicrm_activity');
return $properties;
}
-
- /**
- * @param $query
- * @param $value
- * @param $pseudoconstantType
- * @param $op
- * @param $grouping
- * @param array $params
- *
- * @return array
- */
- public static function buildWhereAndQill(&$query, $value, $pseudoconstantType, $op, $grouping, $params) {
- $matches = $val = $clause = array();
-
- if (is_array($value)) {
- foreach ($value as $k => $v) {
- if ($k) {
- $val[] = $k;
- }
- }
-
- if (count($val) > 0) {
- // Overwrite $op so it works with an IN where statement.
- $op = 'IN';
- }
- else {
- // If we somehow have an empty array, just return
- return;
- }
- $value = $matches[0] = $val;
- }
- else {
- preg_match_all('/\d+/', $value, $matches);
- }
- foreach ($matches[0] as $qill) {
- $clause[] = CRM_Utils_Array::value($qill, $pseudoconstantType);
- }
-
- $query->_qill[$grouping][] = ts($params[0] . ' %1 ', array(1 => $op)) . implode(' ' . ts('or') . ' ', $clause);
- $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($params[1],
- $op, $value, "Integer"
- );
- return $matches[0];
- }
}
if (!empty($_POST)) {
$this->_formValues = $this->controller->exportValues($this->_name);
+ foreach (array('activity_type_id', 'status_id', 'activity_subject') as $element) {
+ $value = CRM_Utils_Array::value($element, $this->_formValues);
+ if ($value) {
+ if (is_array($value)) {
+ if ($element == 'status_id') {
+ unset($this->_formValues[$element]);
+ $element = 'activity_' . $element;
+ }
+ $this->_formValues[$element] = array('IN' => $value);
+ }
+ else {
+ $this->_formValues[$element] = array('LIKE' => "%$value%");
+ }
+ }
+ }
}
$this->fixFormValues();
case 'activity_date_low':
case 'activity_date_high':
case 'activity_role':
+ case 'activity_status_id':
case 'activity_status':
case 'followup_parent_id':
case 'parent_id':
+ case 'source_contact_id':
case 'activity_subject':
case 'test_activities':
case 'activity_type_id':
return array($presentClause, $presentSimpleFromClause);
}
+
+ static function buildQillForFieldValue($daoName, $fieldName, $fieldValue, $op, $pseduoExtraParam = array()) {
+ $pseduoOptions = CRM_Core_PseudoConstant::get($daoName, $fieldName, $pseduoExtraParam = array());
+ if ($fieldName == 'activity_type_id') {
+ $pseduoOptions = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
+ }
+
+ //For those $fieldName which don't have any associated pseudoconstant defined
+ if (empty($pseduoOptions)) {
+ if (is_array($fieldValue)) {
+ $op = key($fieldValue);
+ $fieldValue = $fieldValue[$op];
+ }
+ return array($op, $fieldValue);
+ }
+ elseif (is_array($fieldValue)) {
+ $qillString = array();
+ if (in_array(key($fieldValue), CRM_Core_DAO::acceptedSQLOperators())) {
+ $op = key($fieldValue);
+ $fieldValue = $fieldValue[$op];
+ }
+ foreach ((array)$fieldValue as $val) {
+ $qillString[] = $pseduoOptions[$val];
+ }
+ return array($op, implode(', ', $qillString));
+ }
+ else {
+ if (array_key_exists($fieldValue, $pseduoOptions)) {
+ $fieldValue = $pseduoOptions[$fieldValue];
+ }
+ return array($op, $fieldValue);
+ }
+ }
}
}
}
- foreach (array('financial_type_id', 'contribution_soft_credit_type_id', 'contribution_status') as $element) {
+ foreach (array('financial_type_id', 'contribution_soft_credit_type_id', 'contribution_status', 'contribution_source', 'contribution_trxn_id', 'activity_type_id', 'status_id', 'activity_subject') as $element) {
$value = CRM_Utils_Array::value($element, $this->_formValues);
- if ($value && is_array($value)) {
- $this->_formValues[$element] = array('IN' => $value);
+ if ($value) {
+ if (is_array($value)) {
+ if ($element == 'status_id') {
+ unset($this->_formValues[$element]);
+ $element = 'activity_' . $element;
+ }
+ $this->_formValues[$element] = array('IN' => $value);
+ }
+ else {
+ $this->_formValues[$element] = array('LIKE' => "%$value%");
+ }
}
}
- foreach (array('contribution_source', 'contribution_trxn_id') as $element) {
- $value = CRM_Utils_Array::value($element, $this->_formValues);
- $this->_formValues[$element] = array('LIKE' => "%$value%");
- }
-
$taglist = CRM_Utils_Array::value('contact_taglist', $this->_formValues);
if ($taglist && is_array($taglist)) {
$dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String';
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution.$name", $op, $value, $dataType);
- list($op, $value) = self::buildQillForFieldValue('CRM_Contribute_DAO_Contribution', $name, $value, $op, $pseudoExtraParam);
+ list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Contribute_DAO_Contribution', $name, $value, $op, $pseudoExtraParam);
$query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $op, 3 => $value));
$query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
return;
case 'contribution_page':
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fields[$name]['where'], $op, $value, 'String');
- list($op, $value) = self::buildQillForFieldValue('CRM_Contribute_DAO_Contribution', $name, $value, $op);
+ 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_page'] = $query->_whereTables['civicrm_contribution_page'] = 1;
$query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution_soft.$name",
$op, $value, CRM_Utils_Type::typeToString($fields[$qillName]['type'])
);
- list($op, $value) = self::buildQillForFieldValue('CRM_Contribute_DAO_ContributionSoft', $name, $value, $op);
+ list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Contribute_DAO_ContributionSoft', $name, $value, $op);
$query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $op, 3 => $value));
$query->_tables['civicrm_contribution_soft'] = $query->_whereTables['civicrm_contribution_soft'] = 1;
return;
'contribution_recur_failure_retry_date' => ts('Failed Recurring Contribution Retry Date'),
);
}
-
- static function buildQillForFieldValue($daoName, $fieldName, $fieldValue, $op, $pseduoExtraParam = array()) {
- $pseduoOptions = CRM_Core_PseudoConstant::get($daoName, $fieldName, $pseduoExtraParam = array());
-
- //For those $fieldName which don't have any associated pseudoconstant defined
- if (empty($pseduoOptions)) {
- if (is_array($fieldValue)) {
- $op = key($fieldValue);
- $fieldValue = $fieldValue[$op];
- }
- return array($op, $fieldValue);
- }
- elseif (is_array($fieldValue)) {
- $qillString = array();
- if (in_array(key($fieldValue), CRM_Core_DAO::acceptedSQLOperators())) {
- $op = key($fieldValue);
- $fieldValue = $fieldValue[$op];
- }
- foreach ((array)$fieldValue as $val) {
- $qillString[] = $pseduoOptions[$val];
- }
- return array($op, implode(', ', $qillString));
- }
- else {
- if (array_key_exists($fieldValue, $pseduoOptions)) {
- $fieldValue = $pseduoOptions[$fieldValue];
- }
- return array($op, $fieldValue);
- }
- }
}
$config = CRM_Core_Config::singleton();
if (!empty($_POST)) {
- foreach (array('financial_type_id', 'contribution_soft_credit_type_id', 'contribution_status') as $element) {
- $value = CRM_Utils_Array::value($element, $this->_formValues);
- if ($value && is_array($value)) {
- $this->_formValues[$element] = array('IN' => $value);
- }
- }
-
- foreach (array('contribution_source', 'contribution_trxn_id') as $element) {
+ foreach (array('financial_type_id', 'contribution_soft_credit_type_id', 'contribution_status', 'contribution_source', 'contribution_trxn_id') as $element) {
$value = CRM_Utils_Array::value($element, $this->_formValues);
if ($value) {
+ if (is_array($value)) {
+ $this->_formValues[$element] = array('IN' => $value);
+ }
+ }
+ else {
$this->_formValues[$element] = array('LIKE' => "%$value%");
}
}
if (($mappingType == 'Search Builder') || ($exportMode == CRM_Export_Form_Select::CONTRIBUTE_EXPORT)) {
if (CRM_Core_Permission::access('CiviContribute')) {
$fields['Contribution'] = CRM_Contribute_BAO_Contribution::exportableFields();
- unset($fields['Contribution']['contribution_contact_id']);
+ foreach (array('contribution_contact_id', 'contribution_soft_credit_name', 'contribution_soft_credit_amount', 'contribution_soft_credit_type', 'contribution_soft_credit_contribution_id') as $element) {
+ unset($fields['Contribution'][$element]);
+ }
$compArray['Contribution'] = ts('Contribution');
}
}
</tr>
<tr>
{if $form.activity_type_id}
- <td><label>{ts}Activity Type(s){/ts}</label>
- <div id="Activity" class="listing-box">
- {foreach from=$form.activity_type_id item="activity_type_val"}
- <div class="{cycle values='odd-row,even-row'}">
- {$activity_type_val.html}
- </div>
- {/foreach}
- </div>
+ <td><label>{$form.activity_type_id.label}</label>
+ <br />
+ {$form.activity_type_id.html}
</td>
{else}
<td> </td>
{$form.activity_subject.html|crmAddClass:big}
</td>
<td colspan="2">
- {$form.activity_status.label}<br/>
- {$form.activity_status.html}
+ {$form.status_id.label}<br/>
+ {$form.status_id.html}
</td>
</tr>
<tr>
</index>
<field>
<name>activity_type_id</name>
- <title>Activity Type</title>
+ <title>Activity Type ID</title>
<import>true</import>
<type>int unsigned</type>
<required>true</required>
- <export>false</export>
+ <export>true</export>
<default>1</default>
<headerPattern>/(activity.)?type(.id$)/i</headerPattern>
<comment>FK to civicrm_option_value.id, that has to be valid, registered activity type.</comment>