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