Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
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 TO |
45 | */ |
46 | static $_links = NULL; | |
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() { |
6a488035 TO |
55 | return 'CRM_Contribute_BAO_ManagePremiums'; |
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 TO |
65 | if (!(self::$_links)) { |
66 | self::$_links = array( | |
67 | CRM_Core_Action::UPDATE => array( | |
68 | 'name' => ts('Edit'), | |
69 | 'url' => 'civicrm/admin/contribute/managePremiums', | |
70 | 'qs' => 'action=update&id=%%id%%&reset=1', | |
71 | 'title' => ts('Edit Premium'), | |
72 | ), | |
73 | CRM_Core_Action::PREVIEW => array( | |
74 | 'name' => ts('Preview'), | |
75 | 'url' => 'civicrm/admin/contribute/managePremiums', | |
76 | 'qs' => 'action=preview&id=%%id%%', | |
77 | 'title' => ts('Preview Premium'), | |
78 | ), | |
79 | CRM_Core_Action::DISABLE => array( | |
80 | 'name' => ts('Disable'), | |
4d17a233 | 81 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
82 | 'title' => ts('Disable Premium'), |
83 | ), | |
84 | CRM_Core_Action::ENABLE => array( | |
85 | 'name' => ts('Enable'), | |
4d17a233 | 86 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
87 | 'title' => ts('Enable Premium'), |
88 | ), | |
89 | CRM_Core_Action::DELETE => array( | |
90 | 'name' => ts('Delete'), | |
91 | 'url' => 'civicrm/admin/contribute/managePremiums', | |
92 | 'qs' => 'action=delete&id=%%id%%', | |
93 | 'title' => ts('Delete Premium'), | |
94 | ), | |
95 | ); | |
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() { |
6a488035 TO |
108 | |
109 | // get the requested action | |
110 | $action = CRM_Utils_Request::retrieve('action', 'String', | |
111 | // default to 'browse' | |
112 | $this, FALSE, 'browse' | |
113 | ); | |
114 | ||
115 | // assign vars to templates | |
116 | $this->assign('action', $action); | |
117 | $id = CRM_Utils_Request::retrieve('id', 'Positive', | |
118 | $this, FALSE, 0 | |
119 | ); | |
120 | ||
121 | // what action to take ? | |
122 | if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::PREVIEW)) { | |
123 | $this->edit($action, $id, TRUE); | |
124 | } | |
125 | // finally browse the custom groups | |
126 | $this->browse(); | |
127 | ||
128 | // parent run | |
129 | return parent::run(); | |
130 | } | |
131 | ||
132 | /** | |
133 | * Browse all custom data groups. | |
6a488035 | 134 | */ |
00be9182 | 135 | public function browse() { |
6a488035 TO |
136 | // get all custom groups sorted by weight |
137 | $premiums = array(); | |
138 | $dao = new CRM_Contribute_DAO_Product(); | |
139 | $dao->orderBy('name'); | |
140 | $dao->find(); | |
141 | ||
142 | while ($dao->fetch()) { | |
143 | $premiums[$dao->id] = array(); | |
144 | CRM_Core_DAO::storeValues($dao, $premiums[$dao->id]); | |
145 | // form all action links | |
146 | $action = array_sum(array_keys($this->links())); | |
147 | ||
6a488035 TO |
148 | if ($dao->is_active) { |
149 | $action -= CRM_Core_Action::ENABLE; | |
150 | } | |
151 | else { | |
152 | $action -= CRM_Core_Action::DISABLE; | |
153 | } | |
154 | ||
155 | $premiums[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), | |
156 | $action, | |
7d9f50a2 | 157 | array('id' => $dao->id), |
87dab4a4 AH |
158 | ts('more'), |
159 | FALSE, | |
160 | 'premium.manage.row', | |
161 | 'Premium', | |
162 | $dao->id | |
6a488035 | 163 | ); |
874c9be7 | 164 | //Financial Type |
353ffa53 | 165 | if (!empty($dao->financial_type_id)) { |
874c9be7 | 166 | require_once 'CRM/Core/DAO.php'; |
481a74f4 | 167 | $premiums[$dao->id]['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $dao->financial_type_id, 'name'); |
874c9be7 | 168 | } |
6a488035 | 169 | } |
6a488035 TO |
170 | $this->assign('rows', $premiums); |
171 | } | |
172 | ||
173 | /** | |
fe482240 | 174 | * Get name of edit form. |
6a488035 | 175 | * |
a6c01b45 CW |
176 | * @return string |
177 | * Classname of edit form. | |
6a488035 | 178 | */ |
00be9182 | 179 | public function editForm() { |
6a488035 TO |
180 | return 'CRM_Contribute_Form_ManagePremiums'; |
181 | } | |
182 | ||
183 | /** | |
fe482240 | 184 | * Get edit form name. |
6a488035 | 185 | * |
a6c01b45 CW |
186 | * @return string |
187 | * name of this page. | |
6a488035 | 188 | */ |
00be9182 | 189 | public function editName() { |
6a488035 TO |
190 | return 'Manage Premiums'; |
191 | } | |
192 | ||
193 | /** | |
194 | * Get user context. | |
195 | * | |
da6b46f4 EM |
196 | * @param null $mode |
197 | * | |
a6c01b45 CW |
198 | * @return string |
199 | * user context. | |
6a488035 | 200 | */ |
00be9182 | 201 | public function userContext($mode = NULL) { |
6a488035 TO |
202 | return 'civicrm/admin/contribute/managePremiums'; |
203 | } | |
96025800 | 204 | |
6a488035 | 205 | } |