From: monishdeb Date: Tue, 25 Nov 2014 12:45:05 +0000 (+0530) Subject: Activity cleanup X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=9ab341728aaea6f3acf12829e9166cd4850375d1;p=civicrm-core.git Activity cleanup --- diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index 02bda6fb35..d3f1a8441f 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -2180,8 +2180,8 @@ AND cl.modified_id = c.id $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); } diff --git a/CRM/Activity/BAO/Query.php b/CRM/Activity/BAO/Query.php index 243200697c..3007e30e8e 100644 --- a/CRM/Activity/BAO/Query.php +++ b/CRM/Activity/BAO/Query.php @@ -190,6 +190,7 @@ class CRM_Activity_BAO_Query { 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) { @@ -199,20 +200,35 @@ class CRM_Activity_BAO_Query { 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': @@ -224,16 +240,6 @@ class CRM_Activity_BAO_Query { $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'); @@ -258,36 +264,6 @@ class CRM_Activity_BAO_Query { } 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') { @@ -306,23 +282,6 @@ class CRM_Activity_BAO_Query { ); 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(); @@ -474,17 +433,9 @@ class CRM_Activity_BAO_Query { */ 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( @@ -500,12 +451,11 @@ class CRM_Activity_BAO_Query { ); $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'); @@ -626,48 +576,4 @@ class CRM_Activity_BAO_Query { 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]; - } } diff --git a/CRM/Activity/Form/Search.php b/CRM/Activity/Form/Search.php index f1b566bd38..9503298887 100644 --- a/CRM/Activity/Form/Search.php +++ b/CRM/Activity/Form/Search.php @@ -207,6 +207,21 @@ class CRM_Activity_Form_Search extends CRM_Core_Form_Search { 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(); diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 9b799de370..dfa13d4bf3 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -1735,9 +1735,11 @@ class CRM_Contact_BAO_Query { 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': @@ -5634,4 +5636,37 @@ AND displayRelType.is_active = 1 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); + } + } } diff --git a/CRM/Contact/Form/Search/Advanced.php b/CRM/Contact/Form/Search/Advanced.php index 1437662b39..963efef85a 100644 --- a/CRM/Contact/Form/Search/Advanced.php +++ b/CRM/Contact/Form/Search/Advanced.php @@ -364,18 +364,22 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search { } } - 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)) { diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index 9b8564d543..4948fff554 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -354,14 +354,14 @@ class CRM_Contribute_BAO_Query { $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; @@ -382,7 +382,7 @@ class CRM_Contribute_BAO_Query { $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; @@ -1028,34 +1028,4 @@ class CRM_Contribute_BAO_Query { '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); - } - } } diff --git a/CRM/Contribute/Form/Search.php b/CRM/Contribute/Form/Search.php index b8bafbf584..d70a2f8533 100644 --- a/CRM/Contribute/Form/Search.php +++ b/CRM/Contribute/Form/Search.php @@ -269,16 +269,14 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search { $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%"); } } diff --git a/CRM/Core/BAO/Mapping.php b/CRM/Core/BAO/Mapping.php index d44fee1f76..4d202a00ae 100644 --- a/CRM/Core/BAO/Mapping.php +++ b/CRM/Core/BAO/Mapping.php @@ -403,7 +403,9 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping { 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'); } } diff --git a/templates/CRM/Activity/Form/Search/Common.tpl b/templates/CRM/Activity/Form/Search/Common.tpl index 23ce31adfb..4b3813a6e3 100644 --- a/templates/CRM/Activity/Form/Search/Common.tpl +++ b/templates/CRM/Activity/Form/Search/Common.tpl @@ -31,14 +31,9 @@ {if $form.activity_type_id} - -
- {foreach from=$form.activity_type_id item="activity_type_val"} -
- {$activity_type_val.html} -
- {/foreach} -
+ +
+ {$form.activity_type_id.html} {else}   @@ -105,8 +100,8 @@ {$form.activity_subject.html|crmAddClass:big} - {$form.activity_status.label}
- {$form.activity_status.html} + {$form.status_id.label}
+ {$form.status_id.html} diff --git a/xml/schema/Activity/Activity.xml b/xml/schema/Activity/Activity.xml index 9fbc397894..4e742852a2 100644 --- a/xml/schema/Activity/Activity.xml +++ b/xml/schema/Activity/Activity.xml @@ -60,11 +60,11 @@ activity_type_id - Activity Type + Activity Type ID true int unsigned true - false + true 1 /(activity.)?type(.id$)/i FK to civicrm_option_value.id, that has to be valid, registered activity type.