Merge pull request #24164 from herbdool/core-3783
[civicrm-core.git] / CRM / Event / Page / AJAX.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 */
17
18 /**
19 * This class contains all the function that are called using AJAX
20 */
21 class CRM_Event_Page_AJAX {
22
23 /**
24 * Building EventFee combo box.
25 * FIXME: This ajax callback could be eliminated in favor of an entityRef field but the priceFieldValue api doesn't currently support filtering on entity_table
26 */
27 public function eventFee() {
28 $name = trim(CRM_Utils_Type::escape($_GET['term'], 'String'));
29
30 if (!$name) {
31 $name = '%';
32 }
33
34 $whereClause = "cv.label LIKE '$name%' ";
35
36 $query = "SELECT DISTINCT (
37 cv.label
38 ), cv.id
39 FROM civicrm_price_field_value cv
40 LEFT JOIN civicrm_price_field cf ON cv.price_field_id = cf.id
41 LEFT JOIN civicrm_price_set_entity ce ON ce.price_set_id = cf.price_set_id
42 WHERE ce.entity_table = 'civicrm_event' AND {$whereClause}";
43
44 $dao = CRM_Core_DAO::executeQuery($query);
45 $results = [];
46 while ($dao->fetch()) {
47 $results[] = ['id' => $dao->id, 'text' => $dao->label];
48 }
49 CRM_Utils_JSON::output($results);
50 }
51
52 }