Merge pull request #17253 from mattwire/utf8convertblocksize
[civicrm-core.git] / CRM / Core / BAO / Query.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 * $Id$
17 *
18 */
19 class CRM_Core_BAO_Query {
20
21 /**
22 * @param CRM_Core_Form $form
23 * @param array $extends
24 */
25 public static function addCustomFormFields(&$form, $extends) {
26 $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends);
27 if ($groupDetails) {
28 $tplName = lcfirst($extends[0]) . 'GroupTree';
29 $form->assign($tplName, $groupDetails);
30 foreach ($groupDetails as $group) {
31 foreach ($group['fields'] as $field) {
32 $fieldId = $field['id'];
33 $elementName = 'custom_' . $fieldId;
34 if ($field['data_type'] === 'Date' && $field['is_search_range']) {
35 $form->addDatePickerRange($elementName, $field['label']);
36 }
37 else {
38 CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE);
39 }
40 }
41 }
42 }
43 }
44
45 /**
46 * Get legacy fields which we still maybe support.
47 *
48 * These are contribution specific but I think it's ok to have one list of legacy supported
49 * params in a central place.
50 *
51 * @return array
52 */
53 protected static function getLegacySupportedFields(): array {
54 // @todo enotices when these are hit so we can start to elimnate them.
55 $fieldAliases = [
56 'financial_type' => 'financial_type_id',
57 'contribution_page' => 'contribution_page_id',
58 'payment_instrument' => 'payment_instrument_id',
59 // or payment_instrument_id?
60 'contribution_payment_instrument' => 'contribution_payment_instrument_id',
61 'contribution_status' => 'contribution_status_id',
62 ];
63 return $fieldAliases;
64 }
65
66 /**
67 * Getter for the qill object.
68 *
69 * @return string
70 */
71 public function qill() {
72 return (isset($this->_qill)) ? $this->_qill : "";
73 }
74
75 /**
76 * Possibly unnecessary function.
77 *
78 * @param $row
79 * @param int $id
80 */
81 public static function searchAction(&$row, $id) {}
82
83 /**
84 * @param $tables
85 */
86 public static function tableNames(&$tables) {}
87
88 /**
89 * Get the name of the field.
90 *
91 * @param array $values
92 *
93 * @return string
94 */
95 protected static function getFieldName($values) {
96 $name = $values[0];
97 $fieldAliases = self::getLegacySupportedFields();
98 if (isset($fieldAliases[$name])) {
99 CRM_Core_Error::deprecatedFunctionWarning('These parameters should be standardised before we get here');
100 return $fieldAliases[$name];
101 }
102
103 return str_replace(['_high', '_low'], '', $name);
104 }
105
106 }