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_Premium extends CRM_Core_Page_Basic { | |
38 | ||
39 | /** | |
fe482240 | 40 | * The action links that we need to display for the browse screen. |
6a488035 TO |
41 | * |
42 | * @var array | |
6a488035 | 43 | */ |
683bf891 | 44 | public static $_links = NULL; |
6a488035 TO |
45 | |
46 | /** | |
fe482240 | 47 | * Get BAO Name. |
6a488035 | 48 | * |
a6c01b45 CW |
49 | * @return string |
50 | * Classname of BAO. | |
6a488035 | 51 | */ |
00be9182 | 52 | public function getBAOName() { |
6a488035 TO |
53 | return 'CRM_Contribute_BAO_Premium'; |
54 | } | |
55 | ||
56 | /** | |
fe482240 | 57 | * Get action Links. |
6a488035 | 58 | * |
a6c01b45 CW |
59 | * @return array |
60 | * (reference) of action links | |
6a488035 | 61 | */ |
00be9182 | 62 | public function &links() { |
6a488035 TO |
63 | if (!(self::$_links)) { |
64 | // helper variable for nicer formatting | |
65 | $deleteExtra = ts('Are you sure you want to remove this product form this page?'); | |
66 | ||
be2fb01f CW |
67 | self::$_links = [ |
68 | CRM_Core_Action::UPDATE => [ | |
6a488035 TO |
69 | 'name' => ts('Edit'), |
70 | 'url' => 'civicrm/admin/contribute/addProductToPage', | |
71 | 'qs' => 'action=update&id=%%id%%&pid=%%pid%%&reset=1', | |
72 | 'title' => ts('Edit Premium'), | |
be2fb01f CW |
73 | ], |
74 | CRM_Core_Action::PREVIEW => [ | |
6a488035 TO |
75 | 'name' => ts('Preview'), |
76 | 'url' => 'civicrm/admin/contribute/addProductToPage', | |
77 | 'qs' => 'action=preview&id=%%id%%&pid=%%pid%%', | |
78 | 'title' => ts('Preview Premium'), | |
be2fb01f CW |
79 | ], |
80 | CRM_Core_Action::DELETE => [ | |
6a488035 TO |
81 | 'name' => ts('Remove'), |
82 | 'url' => 'civicrm/admin/contribute/addProductToPage', | |
83 | 'qs' => 'action=delete&id=%%id%%&pid=%%pid%%', | |
84 | 'extra' => 'onclick = "if (confirm(\'' . $deleteExtra . '\') ) this.href+=\'&confirmed=1\'; else return false;"', | |
85 | 'title' => ts('Disable Premium'), | |
be2fb01f CW |
86 | ], |
87 | ]; | |
6a488035 TO |
88 | } |
89 | return self::$_links; | |
90 | } | |
91 | ||
92 | /** | |
93 | * Run the page. | |
94 | * | |
95 | * This method is called after the page is created. It checks for the | |
96 | * type of action and executes that action. | |
97 | * Finally it calls the parent's run method. | |
6a488035 | 98 | */ |
00be9182 | 99 | public function run() { |
6a488035 TO |
100 | // get the requested action |
101 | $action = CRM_Utils_Request::retrieve('action', 'String', | |
102 | // default to 'browse' | |
103 | $this, FALSE, 'browse' | |
104 | ); | |
105 | ||
106 | // assign vars to templates | |
107 | $this->assign('action', $action); | |
108 | $id = CRM_Utils_Request::retrieve('id', 'Positive', | |
109 | $this, FALSE, 0 | |
110 | ); | |
111 | $this->assign('id', $id); | |
112 | ||
113 | $this->edit($action, $id, FALSE, FALSE); | |
114 | ||
115 | // this is special case where we need to call browse to list premium | |
116 | if ($action == CRM_Core_Action::UPDATE) { | |
117 | $this->browse(); | |
118 | } | |
119 | ||
120 | // parent run | |
121 | return parent::run(); | |
122 | } | |
123 | ||
124 | /** | |
347e061b | 125 | * Browse function. |
6a488035 | 126 | */ |
00be9182 | 127 | public function browse() { |
6a488035 | 128 | // get all custom groups sorted by weight |
be2fb01f | 129 | $premiums = []; |
6a488035 TO |
130 | $pageID = CRM_Utils_Request::retrieve('id', 'Positive', |
131 | $this, FALSE, 0 | |
132 | ); | |
da6b7c62 MW |
133 | $premiumDao = new CRM_Contribute_DAO_Premium(); |
134 | $premiumDao->entity_table = 'civicrm_contribution_page'; | |
135 | $premiumDao->entity_id = $pageID; | |
136 | $premiumDao->find(TRUE); | |
137 | $premiumID = $premiumDao->id; | |
6a488035 TO |
138 | $this->assign('products', FALSE); |
139 | $this->assign('id', $pageID); | |
140 | if (!$premiumID) { | |
141 | return; | |
142 | } | |
143 | ||
da6b7c62 MW |
144 | $premiumsProductDao = new CRM_Contribute_DAO_PremiumsProduct(); |
145 | $premiumsProductDao->premiums_id = $premiumID; | |
146 | $premiumsProductDao->orderBy('weight'); | |
147 | $premiumsProductDao->find(); | |
6a488035 | 148 | |
da6b7c62 | 149 | while ($premiumsProductDao->fetch()) { |
6a488035 | 150 | $productDAO = new CRM_Contribute_DAO_Product(); |
da6b7c62 | 151 | $productDAO->id = $premiumsProductDao->product_id; |
6a488035 TO |
152 | $productDAO->is_active = 1; |
153 | ||
154 | if ($productDAO->find(TRUE)) { | |
be2fb01f | 155 | $premiums[$productDAO->id] = []; |
da6b7c62 | 156 | $premiums[$productDAO->id]['weight'] = $premiumsProductDao->weight; |
6a488035 TO |
157 | CRM_Core_DAO::storeValues($productDAO, $premiums[$productDAO->id]); |
158 | ||
159 | $action = array_sum(array_keys($this->links())); | |
160 | ||
da6b7c62 | 161 | $premiums[$premiumsProductDao->product_id]['action'] = CRM_Core_Action::formLink(self::links(), $action, |
be2fb01f | 162 | ['id' => $pageID, 'pid' => $premiumsProductDao->id], |
87dab4a4 AH |
163 | ts('more'), |
164 | FALSE, | |
165 | 'premium.contributionpage.row', | |
166 | 'Premium', | |
da6b7c62 | 167 | $premiumsProductDao->id |
6a488035 | 168 | ); |
da6b7c62 MW |
169 | // Financial Type |
170 | if (!empty($premiumsProductDao->financial_type_id)) { | |
906c7498 | 171 | $premiums[$productDAO->id]['financial_type'] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Product', 'financial_type_id', $premiumsProductDao->financial_type_id); |
6a488035 TO |
172 | } |
173 | } | |
174 | } | |
175 | ||
176 | if (count(CRM_Contribute_PseudoConstant::products($pageID)) == 0) { | |
177 | $this->assign('products', FALSE); | |
178 | } | |
179 | else { | |
180 | $this->assign('products', TRUE); | |
181 | } | |
182 | ||
183 | // Add order changing widget to selector | |
184 | $returnURL = CRM_Utils_System::url('civicrm/admin/contribute/premium', "reset=1&action=update&id={$pageID}"); | |
185 | $filter = "premiums_id = {$premiumID}"; | |
186 | CRM_Utils_Weight::addOrder($premiums, 'CRM_Contribute_DAO_PremiumsProduct', | |
187 | 'id', $returnURL, $filter | |
188 | ); | |
189 | $this->assign('rows', $premiums); | |
190 | } | |
191 | ||
192 | /** | |
fe482240 | 193 | * Get name of edit form. |
6a488035 | 194 | * |
a6c01b45 CW |
195 | * @return string |
196 | * Classname of edit form. | |
6a488035 | 197 | */ |
00be9182 | 198 | public function editForm() { |
6a488035 TO |
199 | return 'CRM_Contribute_Form_ContributionPage_Premium'; |
200 | } | |
201 | ||
202 | /** | |
fe482240 | 203 | * Get edit form name. |
6a488035 | 204 | * |
a6c01b45 CW |
205 | * @return string |
206 | * name of this page. | |
6a488035 | 207 | */ |
00be9182 | 208 | public function editName() { |
6a488035 TO |
209 | return 'Configure Premiums'; |
210 | } | |
211 | ||
212 | /** | |
213 | * Get user context. | |
214 | * | |
dd244018 EM |
215 | * @param null $mode |
216 | * | |
a6c01b45 CW |
217 | * @return string |
218 | * user context. | |
6a488035 | 219 | */ |
00be9182 | 220 | public function userContext($mode = NULL) { |
6a488035 TO |
221 | return CRM_Utils_System::currentPath(); |
222 | } | |
96025800 | 223 | |
6a488035 | 224 | } |