PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/com.bmn.memberships/memberships.civix.php

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