| 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 | */ |
| 17 | class CRM_Core_BAO_Query { |
| 18 | |
| 19 | /** |
| 20 | * @param CRM_Core_Form $form |
| 21 | * @param array $extends |
| 22 | */ |
| 23 | public static function addCustomFormFields(&$form, $extends) { |
| 24 | $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); |
| 25 | if ($groupDetails) { |
| 26 | foreach ($groupDetails as $group) { |
| 27 | foreach ($group['fields'] as $field) { |
| 28 | $fieldId = $field['id']; |
| 29 | $elementName = 'custom_' . $fieldId; |
| 30 | if ($field['data_type'] === 'Date' && $field['is_search_range']) { |
| 31 | $form->addDatePickerRange($elementName, $field['label']); |
| 32 | } |
| 33 | else { |
| 34 | CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE); |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | $tplName = lcfirst($extends[0]) . 'GroupTree'; |
| 40 | $form->assign($tplName, $groupDetails); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Get legacy fields which we still maybe support. |
| 45 | * |
| 46 | * These are contribution specific but I think it's ok to have one list of legacy supported |
| 47 | * params in a central place. |
| 48 | * |
| 49 | * @return array |
| 50 | */ |
| 51 | protected static function getLegacySupportedFields(): array { |
| 52 | // @todo enotices when these are hit so we can start to elimnate them. |
| 53 | $fieldAliases = [ |
| 54 | 'financial_type' => 'financial_type_id', |
| 55 | 'contribution_page' => 'contribution_page_id', |
| 56 | 'payment_instrument' => 'payment_instrument_id', |
| 57 | // or payment_instrument_id? |
| 58 | 'contribution_payment_instrument' => 'contribution_payment_instrument_id', |
| 59 | 'contribution_status' => 'contribution_status_id', |
| 60 | ]; |
| 61 | return $fieldAliases; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Getter for the qill object. |
| 66 | * |
| 67 | * @return string |
| 68 | */ |
| 69 | public function qill() { |
| 70 | return (isset($this->_qill)) ? $this->_qill : ""; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Possibly unnecessary function. |
| 75 | * |
| 76 | * @param $row |
| 77 | * @param int $id |
| 78 | */ |
| 79 | public static function searchAction(&$row, $id) {} |
| 80 | |
| 81 | /** |
| 82 | * @param $tables |
| 83 | */ |
| 84 | public static function tableNames(&$tables) {} |
| 85 | |
| 86 | /** |
| 87 | * Get the name of the field. |
| 88 | * |
| 89 | * @param array $values |
| 90 | * |
| 91 | * @return string |
| 92 | */ |
| 93 | protected static function getFieldName($values) { |
| 94 | $name = $values[0]; |
| 95 | $fieldAliases = self::getLegacySupportedFields(); |
| 96 | if (isset($fieldAliases[$name])) { |
| 97 | CRM_Core_Error::deprecatedFunctionWarning('These parameters should be standardised before we get here'); |
| 98 | return $fieldAliases[$name]; |
| 99 | } |
| 100 | |
| 101 | return str_replace(['_high', '_low'], '', $name); |
| 102 | } |
| 103 | |
| 104 | } |