BxDonationsConfig.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Donations Donations
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxDonationsConfig extends BxBaseModGeneralConfig
  12. {
  13. protected $_oDb;
  14. protected $_aHtmlIds;
  15. protected $_iOwner;
  16. protected $_bShowTitle;
  17. protected $_bEnableOther;
  18. protected $_aBillingTypes;
  19. protected $_aPeriodUnits;
  20. public function __construct($aModule)
  21. {
  22. parent::__construct($aModule);
  23. $this->CNF = array (
  24. // module icon
  25. 'ICON' => 'donate',
  26. // database tables
  27. 'TABLE_ENTRIES' => $aModule['db_prefix'] . 'entries',
  28. 'TABLE_ENTRIES_DELETED' => $aModule['db_prefix'] . 'entries_deleted',
  29. 'TABLE_TYPES' => $aModule['db_prefix'] . 'types',
  30. // database fields
  31. 'FIELD_ID' => 'id',
  32. 'FIELD_NAME' => 'name',
  33. 'FIELD_TITLE' => 'title',
  34. 'FIELD_PERIOD' => 'period',
  35. 'FIELD_PERIOD_UNIT' => 'period_unit',
  36. 'FIELD_AMOUNT' => 'amount',
  37. 'FIELD_CUSTOM' => 'custom',
  38. // page URIs
  39. 'URL_MAKE' => 'page.php?i=donations-make',
  40. 'URL_LIST' => 'page.php?i=donations-list',
  41. 'URL_LIST_ALL' => 'page.php?i=donations-list-all',
  42. // some params
  43. 'PARAM_SHOW_TITLE' => 'bx_donations_show_title',
  44. 'PARAM_ENABLE_OTHER' => 'bx_donations_enable_other',
  45. 'PARAM_AMOUNT_PRECISION' => 'bx_donations_amount_precision',
  46. 'PARAM_OTHER_NAME' => 'other',
  47. 'PARAM_OTHER_PERIOD' => 1,
  48. 'PARAM_OTHER_PERIOD_UNIT' => 'month',
  49. 'PARAM_OTHER_PRICE_MIN' => 5,
  50. // objects
  51. 'OBJECT_GRID_LIST' => 'bx_donations_list',
  52. 'OBJECT_GRID_LIST_ALL' => 'bx_donations_list_all',
  53. 'OBJECT_GRID_TYPES' => 'bx_donations_types',
  54. 'OBJECT_FORM_TYPE' => 'bx_donations_type',
  55. 'OBJECT_FORM_TYPE_DISPLAY_ADD' => 'bx_donations_type_add',
  56. 'OBJECT_FORM_TYPE_DISPLAY_EDIT' => 'bx_donations_type_edit',
  57. 'OBJECT_FORM_PRELISTS_PERIOD_UNITS' => 'bx_donations_period_units',
  58. 'OBJECT_MENU_LIST_SUBMENU' => 'bx_donations_list_submenu',
  59. // email templates
  60. 'ETEMPLATE_DONATED' => 'bx_donations_donated',
  61. );
  62. $this->_aJsClasses = array(
  63. 'main' => 'BxDonationsMain',
  64. 'form' => 'BxDonationsForm',
  65. );
  66. $this->_aJsObjects = array(
  67. 'main' => 'oBxDonationsMain',
  68. 'form' => 'oBxDonationsForm',
  69. );
  70. $sHtmlPrefix = str_replace('_', '-', $this->_sName);
  71. $this->_aHtmlIds = array(
  72. 'popup_type' => $sHtmlPrefix . '-popup-type',
  73. 'menu_billing_types' => $sHtmlPrefix . '-menu-billing_types',
  74. 'link_billing_type' => $sHtmlPrefix . '-link-billing-',
  75. );
  76. $oPayments = BxDolPayments::getInstance();
  77. $this->_iOwner = (int)$oPayments->getOption('site_admin');
  78. $this->_aBillingTypes = array(
  79. BX_DONATIONS_BTYPE_SINGLE,
  80. BX_DONATIONS_BTYPE_RECURRING
  81. );
  82. $this->_aPeriodUnits = BxDolForm::getDataItems($this->CNF['OBJECT_FORM_PRELISTS_PERIOD_UNITS']);
  83. }
  84. public function init(&$oDb)
  85. {
  86. $this->_oDb = &$oDb;
  87. $this->_bShowTitle = $this->_oDb->getParam($this->CNF['PARAM_SHOW_TITLE']) == 'on';
  88. $this->_bEnableOther = $this->_oDb->getParam($this->CNF['PARAM_ENABLE_OTHER']) == 'on';
  89. }
  90. public function getHtmlIds($sKey = '')
  91. {
  92. if(empty($sKey))
  93. return $this->_aHtmlIds;
  94. return isset($this->_aHtmlIds[$sKey]) ? $this->_aHtmlIds[$sKey] : '';
  95. }
  96. public function getOwner()
  97. {
  98. return $this->_iOwner;
  99. }
  100. public function isShowTitle()
  101. {
  102. return $this->_bShowTitle;
  103. }
  104. public function isEnableOther()
  105. {
  106. return $this->_bEnableOther;
  107. }
  108. public function getBillingTypes()
  109. {
  110. return $this->_aBillingTypes;
  111. }
  112. public function getPeriodUnits()
  113. {
  114. return $this->_aPeriodUnits;
  115. }
  116. public function getTypeName($sName)
  117. {
  118. return uriGenerate($sName, $this->CNF['TABLE_TYPES'], $this->CNF['FIELD_NAME'], ['lowercase' => false]);
  119. }
  120. public function getTypeNameCustom()
  121. {
  122. return $this->getTypeName($this->CNF['PARAM_OTHER_NAME'] . '_' . bx_get_logged_profile_id());
  123. }
  124. }
  125. /** @} */