Skip to content

Commit

Permalink
Merge pull request #9304 from colemanw/CRM-17869
Browse files Browse the repository at this point in the history
CRM-17869 - Revert custom field date search refactoring to support relative dates
  • Loading branch information
colemanw authored Oct 29, 2016
2 parents 35355c4 + 86a0d21 commit 1c0fed1
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 229 deletions.
25 changes: 2 additions & 23 deletions CRM/Activity/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,22 +394,12 @@ public static function from($name, $mode, $side) {
return $from;
}

/**
* Getter for the qill object.
*
* @return string
*/
public function qill() {
return (isset($this->_qill)) ? $this->_qill : "";
}

/**
* Add all the elements shared between case activity search and advanced search.
*
* @param CRM_Core_Form $form
*/
public static function buildSearchForm(&$form) {
$activityOptions = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
$form->addSelect('activity_type_id',
array('entity' => 'activity', 'label' => ts('Activity Type(s)'), 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))
);
Expand Down Expand Up @@ -457,18 +447,8 @@ public static function buildSearchForm(&$form) {
array('class' => 'crm-select2')
);
}
$extends = array('Activity');
$groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends);
if ($groupDetails) {
$form->assign('activityGroupTree', $groupDetails);
foreach ($groupDetails as $group) {
foreach ($group['fields'] as $field) {
$fieldId = $field['id'];
$elementName = 'custom_' . $fieldId;
CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE);
}
}
}

CRM_Core_BAO_Query::addCustomFormFields($form, array('Activity'));

CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'activity_campaign_id');

Expand All @@ -486,7 +466,6 @@ public static function buildSearchForm(&$form) {
$resultOptions = array();
foreach ($optionGroups as $gid => $name) {
if ($name) {
$value = array();
$value = CRM_Core_OptionGroup::values($name);
if (!empty($value)) {
while (list($k, $v) = each($value)) {
Expand Down
26 changes: 3 additions & 23 deletions CRM/Case/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2016
*/
class CRM_Case_BAO_Query {
class CRM_Case_BAO_Query extends CRM_Core_BAO_Query {

/**
* Get fields.
Expand Down Expand Up @@ -677,8 +677,6 @@ public static function tableNames(&$tables) {
* @param CRM_Core_Form $form
*/
public static function buildSearchForm(&$form) {
$config = CRM_Core_Config::singleton();

//validate case configuration.
$configured = CRM_Case_BAO_Case::isCaseConfigured();
$form->assign('notConfigured', !$configured['configured']);
Expand Down Expand Up @@ -718,27 +716,9 @@ public static function buildSearchForm(&$form) {
$form->addElement('checkbox', 'case_deleted', ts('Deleted Cases'));
}

// add all the custom searchable fields
$extends = array('Case');
$groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends);
if ($groupDetails) {
$form->assign('caseGroupTree', $groupDetails);
foreach ($groupDetails as $group) {
foreach ($group['fields'] as $field) {
$fieldId = $field['id'];
$elementName = 'custom_' . $fieldId;
CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE);
}
}
}
$form->setDefaults(array('case_owner' => 1));
}
self::addCustomFormFields($form, array('Case'));

/**
* @param $row
* @param int $id
*/
public static function searchAction(&$row, $id) {
$form->setDefaults(array('case_owner' => 1));
}

/**
Expand Down
34 changes: 9 additions & 25 deletions CRM/Contact/Form/Search/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,18 +371,8 @@ public static function location(&$form) {
'placeholder' => ts('Primary'),
));

// custom data extending addresses -
$extends = array('Address');
$groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends);
if ($groupDetails) {
$form->assign('addressGroupTree', $groupDetails);
foreach ($groupDetails as $group) {
foreach ($group['fields'] as $field) {
$elementName = 'custom_' . $field['id'];
CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $field['id'], FALSE, TRUE);
}
}
}
// custom data extending addresses
CRM_Core_BAO_Query::addCustomFormFields($form, array('Address'));
}

/**
Expand Down Expand Up @@ -447,18 +437,7 @@ public static function relationship(&$form) {
CRM_Core_Form_Date::buildDateRange($form, 'relation_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);

// add all the custom searchable fields
$relationship = array('Relationship');
$groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $relationship);
if ($groupDetails) {
$form->assign('relationshipGroupTree', $groupDetails);
foreach ($groupDetails as $group) {
foreach ($group['fields'] as $field) {
$fieldId = $field['id'];
$elementName = 'custom_' . $fieldId;
CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE);
}
}
}
CRM_Core_BAO_Query::addCustomFormFields($form, array('Relationship'));
}

/**
Expand Down Expand Up @@ -532,7 +511,12 @@ public static function custom(&$form) {
foreach ($group['fields'] as $field) {
$fieldId = $field['id'];
$elementName = 'custom_' . $fieldId;
CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE);
if ($field['data_type'] == 'Date' && $field['is_search_range']) {
CRM_Core_Form_Date::buildDateRange($form, $elementName, 1, '_from', '_to', ts('From:'), FALSE);
}
else {
CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE);
}
}
}
}
Expand Down
15 changes: 3 additions & 12 deletions CRM/Contribute/BAO/ContributionRecur.php
Original file line number Diff line number Diff line change
Expand Up @@ -783,18 +783,9 @@ public static function recurringContribution(&$form) {
CRM_Core_Form_Date::buildDateRange($form, 'contribution_recur_cancel_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth');
$form->addElement('text', 'contribution_recur_processor_id', ts('Processor ID'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionRecur', 'processor_id'));
$form->addElement('text', 'contribution_recur_trxn_id', ts('Transaction ID'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionRecur', 'trxn_id'));
$contributionRecur = array('ContributionRecur');
$groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $contributionRecur);
if ($groupDetails) {
$form->assign('contributeRecurGroupTree', $groupDetails);
foreach ($groupDetails as $group) {
foreach ($group['fields'] as $field) {
$fieldId = $field['id'];
$elementName = 'custom_' . $fieldId;
CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE);
}
}
}

CRM_Core_BAO_Query::addCustomFormFields($form, array('ContributionRecur'));

}

/**
Expand Down
25 changes: 2 additions & 23 deletions CRM/Contribute/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2016
*/
class CRM_Contribute_BAO_Query {
class CRM_Contribute_BAO_Query extends CRM_Core_BAO_Query {

/**
* Static field for all the export/import contribution fields.
Expand Down Expand Up @@ -1112,19 +1112,7 @@ public static function buildSearchForm(&$form) {
FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple', 'placeholder' => ts('- any -'))
);

// Add all the custom searchable fields
$contribution = array('Contribution');
$groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $contribution);
if ($groupDetails) {
$form->assign('contributeGroupTree', $groupDetails);
foreach ($groupDetails as $group) {
foreach ($group['fields'] as $field) {
$fieldId = $field['id'];
$elementName = 'custom_' . $fieldId;
CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE);
}
}
}
self::addCustomFormFields($form, array('Contribution'));

CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'contribution_campaign_id');

Expand All @@ -1145,15 +1133,6 @@ public static function buildSearchForm(&$form) {
CRM_Contribute_BAO_ContributionRecur::recurringContribution($form);
}

/**
* Function that may not be needed.
*
* @param array $row
* @param int $id
*/
public static function searchAction(&$row, $id) {
}

/**
* Get table names.
*
Expand Down
74 changes: 74 additions & 0 deletions CRM/Core/BAO/Query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2016 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2016
* $Id$
*
*/
class CRM_Core_BAO_Query {

/**
* @param CRM_Core_Form $form
* @param array $extends
*/
public static function addCustomFormFields(&$form, $extends) {
$groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends);
if ($groupDetails) {
$tplName = lcfirst($extends[0]) . 'GroupTree';
$form->assign($tplName, $groupDetails);
foreach ($groupDetails as $group) {
foreach ($group['fields'] as $field) {
$fieldId = $field['id'];
$elementName = 'custom_' . $fieldId;
if ($field['data_type'] == 'Date' && $field['is_search_range']) {
CRM_Core_Form_Date::buildDateRange($form, $elementName, 1, '_from', '_to', ts('From:'), FALSE);
}
else {
CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE);
}
}
}
}
}

/**
* Possibly unnecessary function.
*
* @param $row
* @param int $id
*/
public static function searchAction(&$row, $id) {}

/**
* @param $tables
*/
public static function tableNames(&$tables) {}

}
33 changes: 3 additions & 30 deletions CRM/Event/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* $Id$
*
*/
class CRM_Event_BAO_Query {
class CRM_Event_BAO_Query extends CRM_Core_BAO_Query {

/**
* Function get the import/export fields for contribution.
Expand Down Expand Up @@ -512,15 +512,6 @@ public static function from($name, $mode, $side) {
return $from;
}

/**
* Getter for the qill object.
*
* @return string
*/
public function qill() {
return (isset($this->_qill)) ? $this->_qill : "";
}

/**
* @param $mode
* @param bool $includeCustomFields
Expand Down Expand Up @@ -646,33 +637,15 @@ public static function buildSearchForm(&$form) {

$form->addRule('participant_fee_amount_low', ts('Please enter a valid money value.'), 'money');
$form->addRule('participant_fee_amount_high', ts('Please enter a valid money value.'), 'money');
// add all the custom searchable fields
$extends = array('Participant', 'Event');
$groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends);
if ($groupDetails) {
$form->assign('participantGroupTree', $groupDetails);
foreach ($groupDetails as $group) {
foreach ($group['fields'] as $field) {
$fieldId = $field['id'];
$elementName = 'custom_' . $fieldId;
CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE);
}
}
}

self::addCustomFormFields($form, array('Participant', 'Event'));

CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'participant_campaign_id');

$form->assign('validCiviEvent', TRUE);
$form->setDefaults(array('participant_test' => 0));
}

/**
* @param $row
* @param int $id
*/
public static function searchAction(&$row, $id) {
}

/**
* @param $tables
*/
Expand Down
Loading

0 comments on commit 1c0fed1

Please sign in to comment.