Commit | Line | Data |
---|---|---|
c3e3dd65 DS |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
c3e3dd65 | 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 | | |
c3e3dd65 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
c3e3dd65 DS |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
c3e3dd65 DS |
16 | * $Id$ |
17 | * | |
18 | */ | |
19 | ||
20 | /** | |
21 | * Report hooks that allow extending a particular report. | |
74cf4551 | 22 | * Example: Adding new tables to log reports |
c3e3dd65 DS |
23 | */ |
24 | class CRM_Report_BAO_Hook { | |
25 | ||
26 | /** | |
51dda21e | 27 | * @var \CRM_Report_BAO_HookInterface[] |
c3e3dd65 DS |
28 | */ |
29 | protected $_queryObjects = NULL; | |
30 | ||
31 | /** | |
fe482240 | 32 | * Singleton function used to manage this object. |
c3e3dd65 DS |
33 | * |
34 | * @return object | |
c3e3dd65 DS |
35 | */ |
36 | public static function singleton() { | |
37 | static $singleton = NULL; | |
38 | if (!$singleton) { | |
39 | $singleton = new CRM_Report_BAO_Hook(); | |
40 | } | |
41 | return $singleton; | |
42 | } | |
43 | ||
353ffa53 TO |
44 | /** |
45 | * Get or build the list of search objects (via hook) | |
46 | * | |
47 | * @return array | |
16b10e64 | 48 | * Array of CRM_Report_BAO_Hook_Interface objects |
353ffa53 | 49 | */ |
c3e3dd65 DS |
50 | public function getSearchQueryObjects() { |
51 | if ($this->_queryObjects === NULL) { | |
be2fb01f | 52 | $this->_queryObjects = []; |
c3e3dd65 DS |
53 | CRM_Utils_Hook::queryObjects($this->_queryObjects, 'Report'); |
54 | } | |
c3e3dd65 DS |
55 | return $this->_queryObjects; |
56 | } | |
57 | ||
74cf4551 EM |
58 | /** |
59 | * @param $reportObj | |
60 | * @param $logTables | |
61 | */ | |
6b4b11c4 | 62 | public function alterLogTables(&$reportObj, &$logTables) { |
c3e3dd65 | 63 | foreach (self::getSearchQueryObjects() as $obj) { |
6b4b11c4 | 64 | $obj->alterLogTables($reportObj, $logTables); |
c3e3dd65 DS |
65 | } |
66 | } | |
6b4b11c4 | 67 | |
74cf4551 EM |
68 | /** |
69 | * @param $reportObj | |
70 | * @param $table | |
71 | * | |
72 | * @return array | |
73 | */ | |
6b4b11c4 DS |
74 | public function logDiffClause(&$reportObj, $table) { |
75 | $contactIdClause = $join = ''; | |
76 | foreach (self::getSearchQueryObjects() as $obj) { | |
77 | list($cidClause, $joinClause) = $obj->logDiffClause($reportObj, $table); | |
79d7553f | 78 | if ($joinClause) { |
6b4b11c4 | 79 | $join .= $joinClause; |
79d7553f | 80 | } |
81 | if ($cidClause) { | |
6b4b11c4 | 82 | $contactIdClause .= $cidClause; |
79d7553f | 83 | } |
6b4b11c4 | 84 | } |
be2fb01f | 85 | return [$contactIdClause, $join]; |
6b4b11c4 | 86 | } |
96025800 | 87 | |
232624b1 | 88 | } |