Merge pull request #21905 from braders/feature/add-to-group-translatable-errors
[civicrm-core.git] / CRM / Report / BAO / Hook.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 * Report hooks that allow extending a particular report.
20 * Example: Adding new tables to log reports
21 */
22 class CRM_Report_BAO_Hook {
23
24 /**
25 * @var \CRM_Report_BAO_HookInterface[]
26 */
27 protected $_queryObjects = NULL;
28
29 /**
30 * Singleton function used to manage this object.
31 *
32 * @return object
33 */
34 public static function singleton() {
35 static $singleton = NULL;
36 if (!$singleton) {
37 $singleton = new CRM_Report_BAO_Hook();
38 }
39 return $singleton;
40 }
41
42 /**
43 * Get or build the list of search objects (via hook)
44 *
45 * @return array
46 * Array of CRM_Report_BAO_Hook_Interface objects
47 */
48 public function getSearchQueryObjects() {
49 if ($this->_queryObjects === NULL) {
50 $this->_queryObjects = [];
51 CRM_Utils_Hook::queryObjects($this->_queryObjects, 'Report');
52 }
53 return $this->_queryObjects;
54 }
55
56 /**
57 * @param $reportObj
58 * @param $logTables
59 */
60 public function alterLogTables(&$reportObj, &$logTables) {
61 foreach (self::getSearchQueryObjects() as $obj) {
62 $obj->alterLogTables($reportObj, $logTables);
63 }
64 }
65
66 /**
67 * @param $reportObj
68 * @param $table
69 *
70 * @return array
71 */
72 public function logDiffClause(&$reportObj, $table) {
73 $contactIdClause = $join = '';
74 foreach (self::getSearchQueryObjects() as $obj) {
75 list($cidClause, $joinClause) = $obj->logDiffClause($reportObj, $table);
76 if ($joinClause) {
77 $join .= $joinClause;
78 }
79 if ($cidClause) {
80 $contactIdClause .= $cidClause;
81 }
82 }
83 return [$contactIdClause, $join];
84 }
85
86 }