Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
347e061b | 19 | * Page for displaying list of Premiums. |
6a488035 TO |
20 | */ |
21 | class CRM_Contribute_Page_ManagePremiums extends CRM_Core_Page_Basic { | |
22 | ||
96f50de2 CW |
23 | public $useLivePageJS = TRUE; |
24 | ||
6a488035 | 25 | /** |
fe482240 | 26 | * The action links that we need to display for the browse screen. |
6a488035 TO |
27 | * |
28 | * @var array | |
6a488035 | 29 | */ |
1330f57a | 30 | public static $_links = NULL; |
6a488035 TO |
31 | |
32 | /** | |
fe482240 | 33 | * Get BAO Name. |
6a488035 | 34 | * |
a6c01b45 CW |
35 | * @return string |
36 | * Classname of BAO. | |
6a488035 | 37 | */ |
00be9182 | 38 | public function getBAOName() { |
37828d4f | 39 | return 'CRM_Contribute_BAO_Product'; |
6a488035 TO |
40 | } |
41 | ||
42 | /** | |
fe482240 | 43 | * Get action Links. |
6a488035 | 44 | * |
a6c01b45 CW |
45 | * @return array |
46 | * (reference) of action links | |
6a488035 | 47 | */ |
00be9182 | 48 | public function &links() { |
6a488035 | 49 | if (!(self::$_links)) { |
be2fb01f CW |
50 | self::$_links = [ |
51 | CRM_Core_Action::UPDATE => [ | |
6a488035 TO |
52 | 'name' => ts('Edit'), |
53 | 'url' => 'civicrm/admin/contribute/managePremiums', | |
54 | 'qs' => 'action=update&id=%%id%%&reset=1', | |
55 | 'title' => ts('Edit Premium'), | |
be2fb01f CW |
56 | ], |
57 | CRM_Core_Action::PREVIEW => [ | |
6a488035 TO |
58 | 'name' => ts('Preview'), |
59 | 'url' => 'civicrm/admin/contribute/managePremiums', | |
60 | 'qs' => 'action=preview&id=%%id%%', | |
61 | 'title' => ts('Preview Premium'), | |
be2fb01f CW |
62 | ], |
63 | CRM_Core_Action::DISABLE => [ | |
6a488035 | 64 | 'name' => ts('Disable'), |
4d17a233 | 65 | 'ref' => 'crm-enable-disable', |
6a488035 | 66 | 'title' => ts('Disable Premium'), |
be2fb01f CW |
67 | ], |
68 | CRM_Core_Action::ENABLE => [ | |
6a488035 | 69 | 'name' => ts('Enable'), |
4d17a233 | 70 | 'ref' => 'crm-enable-disable', |
6a488035 | 71 | 'title' => ts('Enable Premium'), |
be2fb01f CW |
72 | ], |
73 | CRM_Core_Action::DELETE => [ | |
6a488035 TO |
74 | 'name' => ts('Delete'), |
75 | 'url' => 'civicrm/admin/contribute/managePremiums', | |
76 | 'qs' => 'action=delete&id=%%id%%', | |
77 | 'title' => ts('Delete Premium'), | |
be2fb01f CW |
78 | ], |
79 | ]; | |
6a488035 TO |
80 | } |
81 | return self::$_links; | |
82 | } | |
83 | ||
84 | /** | |
85 | * Run the page. | |
86 | * | |
87 | * This method is called after the page is created. It checks for the | |
88 | * type of action and executes that action. | |
89 | * Finally it calls the parent's run method. | |
6a488035 | 90 | */ |
00be9182 | 91 | public function run() { |
5d6d0104 | 92 | $id = $this->getIdAndAction(); |
6a488035 TO |
93 | |
94 | // what action to take ? | |
cdbb3467 | 95 | if (!($this->_action & CRM_Core_Action::BROWSE)) { |
5d6d0104 | 96 | $this->edit($this->_action, $id, TRUE); |
6a488035 TO |
97 | } |
98 | // finally browse the custom groups | |
99 | $this->browse(); | |
100 | ||
101 | // parent run | |
5d6d0104 | 102 | return CRM_Core_Page::run(); |
6a488035 TO |
103 | } |
104 | ||
105 | /** | |
106 | * Browse all custom data groups. | |
6a488035 | 107 | */ |
00be9182 | 108 | public function browse() { |
6a488035 | 109 | // get all custom groups sorted by weight |
be2fb01f | 110 | $premiums = []; |
6a488035 TO |
111 | $dao = new CRM_Contribute_DAO_Product(); |
112 | $dao->orderBy('name'); | |
113 | $dao->find(); | |
114 | ||
115 | while ($dao->fetch()) { | |
be2fb01f | 116 | $premiums[$dao->id] = []; |
6a488035 TO |
117 | CRM_Core_DAO::storeValues($dao, $premiums[$dao->id]); |
118 | // form all action links | |
119 | $action = array_sum(array_keys($this->links())); | |
120 | ||
6a488035 TO |
121 | if ($dao->is_active) { |
122 | $action -= CRM_Core_Action::ENABLE; | |
123 | } | |
124 | else { | |
125 | $action -= CRM_Core_Action::DISABLE; | |
126 | } | |
127 | ||
128 | $premiums[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), | |
129 | $action, | |
be2fb01f | 130 | ['id' => $dao->id], |
87dab4a4 AH |
131 | ts('more'), |
132 | FALSE, | |
133 | 'premium.manage.row', | |
134 | 'Premium', | |
135 | $dao->id | |
6a488035 | 136 | ); |
da6b7c62 | 137 | // Financial Type |
353ffa53 | 138 | if (!empty($dao->financial_type_id)) { |
906c7498 | 139 | $premiums[$dao->id]['financial_type'] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Product', 'financial_type_id', $dao->financial_type_id); |
874c9be7 | 140 | } |
6a488035 | 141 | } |
6a488035 TO |
142 | $this->assign('rows', $premiums); |
143 | } | |
144 | ||
145 | /** | |
fe482240 | 146 | * Get name of edit form. |
6a488035 | 147 | * |
a6c01b45 CW |
148 | * @return string |
149 | * Classname of edit form. | |
6a488035 | 150 | */ |
00be9182 | 151 | public function editForm() { |
6a488035 TO |
152 | return 'CRM_Contribute_Form_ManagePremiums'; |
153 | } | |
154 | ||
155 | /** | |
fe482240 | 156 | * Get edit form name. |
6a488035 | 157 | * |
a6c01b45 CW |
158 | * @return string |
159 | * name of this page. | |
6a488035 | 160 | */ |
00be9182 | 161 | public function editName() { |
6a488035 TO |
162 | return 'Manage Premiums'; |
163 | } | |
164 | ||
165 | /** | |
166 | * Get user context. | |
167 | * | |
da6b46f4 EM |
168 | * @param null $mode |
169 | * | |
a6c01b45 CW |
170 | * @return string |
171 | * user context. | |
6a488035 | 172 | */ |
00be9182 | 173 | public function userContext($mode = NULL) { |
6a488035 TO |
174 | return 'civicrm/admin/contribute/managePremiums'; |
175 | } | |
96025800 | 176 | |
6a488035 | 177 | } |