Merge pull request #15986 from civicrm/5.20
[civicrm-core.git] / CRM / Event / Page / AJAX.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 * $Id$
17 *
18 */
19
20/**
21 * This class contains all the function that are called using AJAX
22 */
23class CRM_Event_Page_AJAX {
24
6a488035 25 /**
fe482240 26 * Building EventFee combo box.
93793e86 27 * 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
6a488035 28 */
00be9182 29 public function eventFee() {
93793e86 30 $name = trim(CRM_Utils_Type::escape($_GET['term'], 'String'));
6a488035
TO
31
32 if (!$name) {
33 $name = '%';
34 }
35
36 $whereClause = "cv.label LIKE '$name%' ";
03e04002 37
6a488035
TO
38 $query = "SELECT DISTINCT (
39cv.label
40), cv.id
41FROM civicrm_price_field_value cv
42LEFT JOIN civicrm_price_field cf ON cv.price_field_id = cf.id
43LEFT JOIN civicrm_price_set_entity ce ON ce.price_set_id = cf.price_set_id
0ee5581e 44WHERE ce.entity_table = 'civicrm_event' AND {$whereClause}";
45
6a488035 46 $dao = CRM_Core_DAO::executeQuery($query);
be2fb01f 47 $results = [];
6a488035 48 while ($dao->fetch()) {
be2fb01f 49 $results[] = ['id' => $dao->id, 'text' => $dao->label];
6a488035 50 }
ecdef330 51 CRM_Utils_JSON::output($results);
6a488035 52 }
96025800 53
6a488035 54}