Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
fa938177 | 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
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 | |
fa938177 | 31 | * @copyright CiviCRM LLC (c) 2004-2016 |
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 TO |
43 | */ |
44 | static $_links = NULL; | |
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 | ||
67 | self::$_links = array( | |
68 | CRM_Core_Action::UPDATE => array( | |
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'), | |
73 | ), | |
74 | CRM_Core_Action::PREVIEW => array( | |
75 | 'name' => ts('Preview'), | |
76 | 'url' => 'civicrm/admin/contribute/addProductToPage', | |
77 | 'qs' => 'action=preview&id=%%id%%&pid=%%pid%%', | |
78 | 'title' => ts('Preview Premium'), | |
79 | ), | |
80 | CRM_Core_Action::DELETE => array( | |
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'), | |
86 | ), | |
87 | ); | |
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 TO |
128 | // get all custom groups sorted by weight |
129 | $premiums = array(); | |
130 | $pageID = CRM_Utils_Request::retrieve('id', 'Positive', | |
131 | $this, FALSE, 0 | |
132 | ); | |
353ffa53 | 133 | $dao = new CRM_Contribute_DAO_Premium(); |
6a488035 | 134 | $dao->entity_table = 'civicrm_contribution_page'; |
353ffa53 | 135 | $dao->entity_id = $pageID; |
6a488035 TO |
136 | $dao->find(TRUE); |
137 | $premiumID = $dao->id; | |
138 | $this->assign('products', FALSE); | |
139 | $this->assign('id', $pageID); | |
140 | if (!$premiumID) { | |
141 | return; | |
142 | } | |
143 | ||
144 | $dao = new CRM_Contribute_DAO_PremiumsProduct(); | |
145 | $dao->premiums_id = $premiumID; | |
146 | $dao->orderBy('weight'); | |
147 | $dao->find(); | |
148 | ||
149 | while ($dao->fetch()) { | |
150 | $productDAO = new CRM_Contribute_DAO_Product(); | |
151 | $productDAO->id = $dao->product_id; | |
152 | $productDAO->is_active = 1; | |
153 | ||
154 | if ($productDAO->find(TRUE)) { | |
155 | $premiums[$productDAO->id] = array(); | |
156 | $premiums[$productDAO->id]['weight'] = $dao->weight; | |
157 | CRM_Core_DAO::storeValues($productDAO, $premiums[$productDAO->id]); | |
158 | ||
159 | $action = array_sum(array_keys($this->links())); | |
160 | ||
161 | $premiums[$dao->product_id]['action'] = CRM_Core_Action::formLink(self::links(), $action, | |
87dab4a4 AH |
162 | array('id' => $pageID, 'pid' => $dao->id), |
163 | ts('more'), | |
164 | FALSE, | |
165 | 'premium.contributionpage.row', | |
166 | 'Premium', | |
167 | $dao->id | |
6a488035 TO |
168 | ); |
169 | //Financial Type | |
170 | if (!empty($dao->financial_type_id)) { | |
481a74f4 | 171 | $premiums[$productDAO->id]['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $dao->financial_type_id, 'name'); |
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 | } |