Merge pull request #16879 from civicrm/5.24
[civicrm-core.git] / tools / extensions / org.civicrm.angularex / angularex.civix.php
1 <?php
2
3 // AUTO-GENERATED FILE -- Civix may overwrite any changes made to this file
4
5 /**
6 * (Delegated) Implementation of hook_civicrm_config
7 *
8 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
9 * @param null $config
10 */
11 function _angularex_civix_civicrm_config(&$config = NULL) {
12 static $configured = FALSE;
13 if ($configured) {
14 return;
15 }
16 $configured = TRUE;
17
18 $template =& CRM_Core_Smarty::singleton();
19
20 $extRoot = dirname(__FILE__) . DIRECTORY_SEPARATOR;
21 $extDir = $extRoot . 'templates';
22
23 if (is_array($template->template_dir)) {
24 array_unshift($template->template_dir, $extDir);
25 }
26 else {
27 $template->template_dir = [$extDir, $template->template_dir];
28 }
29
30 $include_path = $extRoot . PATH_SEPARATOR . get_include_path();
31 set_include_path($include_path);
32 }
33
34 /**
35 * (Delegated) Implementation of hook_civicrm_xmlMenu
36 *
37 * @param $files array(string)
38 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_xmlMenu
39 */
40 function _angularex_civix_civicrm_xmlMenu(&$files) {
41 foreach (_angularex_civix_glob(__DIR__ . '/xml/Menu/*.xml') as $file) {
42 $files[] = $file;
43 }
44 }
45
46 /**
47 * Implementation of hook_civicrm_install
48 *
49 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
50 */
51 function _angularex_civix_civicrm_install() {
52 _angularex_civix_civicrm_config();
53 if ($upgrader = _angularex_civix_upgrader()) {
54 return $upgrader->onInstall();
55 }
56 }
57
58 /**
59 * Implementation of hook_civicrm_uninstall
60 *
61 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall
62 */
63 function _angularex_civix_civicrm_uninstall() {
64 _angularex_civix_civicrm_config();
65 if ($upgrader = _angularex_civix_upgrader()) {
66 return $upgrader->onUninstall();
67 }
68 }
69
70 /**
71 * (Delegated) Implementation of hook_civicrm_enable
72 *
73 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable
74 */
75 function _angularex_civix_civicrm_enable() {
76 _angularex_civix_civicrm_config();
77 if ($upgrader = _angularex_civix_upgrader()) {
78 if (is_callable([$upgrader, 'onEnable'])) {
79 return $upgrader->onEnable();
80 }
81 }
82 }
83
84 /**
85 * (Delegated) Implementation of hook_civicrm_disable
86 *
87 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_disable
88 */
89 function _angularex_civix_civicrm_disable() {
90 _angularex_civix_civicrm_config();
91 if ($upgrader = _angularex_civix_upgrader()) {
92 if (is_callable([$upgrader, 'onDisable'])) {
93 return $upgrader->onDisable();
94 }
95 }
96 }
97
98 /**
99 * (Delegated) Implementation of hook_civicrm_upgrade
100 *
101 * @param $op string, the type of operation being performed; 'check' or 'enqueue'
102 * @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks
103 *
104 * @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending)
105 * for 'enqueue', returns void
106 *
107 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_upgrade
108 */
109 function _angularex_civix_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
110 if ($upgrader = _angularex_civix_upgrader()) {
111 return $upgrader->onUpgrade($op, $queue);
112 }
113 }
114
115 /**
116 * @return CRM_Angularex_Upgrader
117 */
118 function _angularex_civix_upgrader() {
119 if (!file_exists(__DIR__ . '/CRM/Angularex/Upgrader.php')) {
120 return NULL;
121 }
122 else {
123 return CRM_Angularex_Upgrader_Base::instance();
124 }
125 }
126
127 /**
128 * Search directory tree for files which match a glob pattern
129 *
130 * Note: Dot-directories (like "..", ".git", or ".svn") will be ignored.
131 * Note: In Civi 4.3+, delegate to CRM_Utils_File::findFiles()
132 *
133 * @param $dir string, base dir
134 * @param $pattern string, glob pattern, eg "*.txt"
135 * @return array(string)
136 */
137 function _angularex_civix_find_files($dir, $pattern) {
138 if (is_callable(['CRM_Utils_File', 'findFiles'])) {
139 return CRM_Utils_File::findFiles($dir, $pattern);
140 }
141
142 $todos = [$dir];
143 $result = [];
144 while (!empty($todos)) {
145 $subdir = array_shift($todos);
146 foreach (_angularex_civix_glob("$subdir/$pattern") as $match) {
147 if (!is_dir($match)) {
148 $result[] = $match;
149 }
150 }
151 if ($dh = opendir($subdir)) {
152 while (FALSE !== ($entry = readdir($dh))) {
153 $path = $subdir . DIRECTORY_SEPARATOR . $entry;
154 if ($entry{0} == '.') {
155 }
156 elseif (is_dir($path)) {
157 $todos[] = $path;
158 }
159 }
160 closedir($dh);
161 }
162 }
163 return $result;
164 }
165
166 /**
167 * (Delegated) Implementation of hook_civicrm_managed
168 *
169 * Find any *.mgd.php files, merge their content, and return.
170 *
171 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_managed
172 * @param $entities
173 */
174 function _angularex_civix_civicrm_managed(&$entities) {
175 $mgdFiles = _angularex_civix_find_files(__DIR__, '*.mgd.php');
176 foreach ($mgdFiles as $file) {
177 $es = include $file;
178 foreach ($es as $e) {
179 if (empty($e['module'])) {
180 $e['module'] = 'org.civicrm.angularex';
181 }
182 $entities[] = $e;
183 }
184 }
185 }
186
187 /**
188 * (Delegated) Implementation of hook_civicrm_caseTypes
189 *
190 * Find any and return any files matching "xml/case/*.xml"
191 *
192 * Note: This hook only runs in CiviCRM 4.4+.
193 *
194 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_caseTypes
195 * @param $caseTypes
196 * @throws \Exception
197 */
198 function _angularex_civix_civicrm_caseTypes(&$caseTypes) {
199 if (!is_dir(__DIR__ . '/xml/case')) {
200 return;
201 }
202
203 foreach (_angularex_civix_glob(__DIR__ . '/xml/case/*.xml') as $file) {
204 $name = preg_replace('/\.xml$/', '', basename($file));
205 if ($name != CRM_Case_XMLProcessor::mungeCaseType($name)) {
206 $errorMessage = sprintf("Case-type file name is malformed (%s vs %s)", $name, CRM_Case_XMLProcessor::mungeCaseType($name));
207 CRM_Core_Error::fatal($errorMessage);
208 // throw new CRM_Core_Exception($errorMessage);
209 }
210 $caseTypes[$name] = [
211 'module' => 'org.civicrm.angularex',
212 'name' => $name,
213 'file' => $file,
214 ];
215 }
216 }
217
218 /**
219 * Glob wrapper which is guaranteed to return an array.
220 *
221 * The documentation for glob() says, "On some systems it is impossible to
222 * distinguish between empty match and an error." Anecdotally, the return
223 * result for an empty match is sometimes array() and sometimes FALSE.
224 * This wrapper provides consistency.
225 *
226 * @link http://php.net/glob
227 * @param string $pattern
228 * @return array, possibly empty
229 */
230 function _angularex_civix_glob($pattern) {
231 $result = glob($pattern);
232 return is_array($result) ? $result : [];
233 }
234
235 /**
236 * Inserts a navigation menu item at a given place in the hierarchy
237 *
238 * $menu - menu hierarchy
239 * $path - path where insertion should happen (ie. Administer/System Settings)
240 * $item - menu you need to insert (parent/child attributes will be filled for you)
241 * $parentId - used internally to recurse in the menu structure
242 * @param $menu
243 * @param $path
244 * @param $item
245 * @param null $parentId
246 * @return bool
247 */
248 function _angularex_civix_insert_navigation_menu(&$menu, $path, $item, $parentId = NULL) {
249 static $navId;
250
251 // If we are done going down the path, insert menu
252 if (empty($path)) {
253 if (!$navId) {
254 $navId = CRM_Core_DAO::singleValueQuery("SELECT max(id) FROM civicrm_navigation");
255 }
256 $navId++;
257 $menu[$navId] = [
258 'attributes' => array_merge($item, [
259 'label' => $item['name'] ?? NULL,
260 'active' => 1,
261 'parentID' => $parentId,
262 'navID' => $navId,
263 ]),
264 ];
265 return TRUE;
266 }
267 else {
268 // Find an recurse into the next level down
269 $found = FALSE;
270 $path = explode('/', $path);
271 $first = array_shift($path);
272 foreach ($menu as $key => &$entry) {
273 if ($entry['attributes']['name'] == $first) {
274 if (!$entry['child']) {
275 $entry['child'] = [];
276 }
277 $found = _angularex_civix_insert_navigation_menu($entry['child'], implode('/', $path), $item, $key);
278 }
279 }
280 return $found;
281 }
282 }
283
284 /**
285 * (Delegated) Implementation of hook_civicrm_alterSettingsFolders
286 *
287 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterSettingsFolders
288 * @param null $metaDataFolders
289 */
290 function _angularex_civix_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
291 static $configured = FALSE;
292 if ($configured) {
293 return;
294 }
295 $configured = TRUE;
296
297 $settingsDir = __DIR__ . DIRECTORY_SEPARATOR . 'settings';
298 if (is_dir($settingsDir) && !in_array($settingsDir, $metaDataFolders)) {
299 $metaDataFolders[] = $settingsDir;
300 }
301 }