Ian province abbreviation patch - issue 724
[civicrm-core.git] / CRM / Contribute / Page / ManagePremiums.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2015
32 */
33
34 /**
35 * Page for displaying list of Premiums.
36 */
37 class CRM_Contribute_Page_ManagePremiums extends CRM_Core_Page_Basic {
38
39 public $useLivePageJS = TRUE;
40
41 /**
42 * The action links that we need to display for the browse screen.
43 *
44 * @var array
45 */
46 static $_links = NULL;
47
48 /**
49 * Get BAO Name.
50 *
51 * @return string
52 * Classname of BAO.
53 */
54 public function getBAOName() {
55 return 'CRM_Contribute_BAO_ManagePremiums';
56 }
57
58 /**
59 * Get action Links.
60 *
61 * @return array
62 * (reference) of action links
63 */
64 public function &links() {
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'),
81 'ref' => 'crm-enable-disable',
82 'title' => ts('Disable Premium'),
83 ),
84 CRM_Core_Action::ENABLE => array(
85 'name' => ts('Enable'),
86 'ref' => 'crm-enable-disable',
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.
106 */
107 public function run() {
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.
134 */
135 public function browse() {
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
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,
157 array('id' => $dao->id),
158 ts('more'),
159 FALSE,
160 'premium.manage.row',
161 'Premium',
162 $dao->id
163 );
164 //Financial Type
165 if (!empty($dao->financial_type_id)) {
166 require_once 'CRM/Core/DAO.php';
167 $premiums[$dao->id]['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $dao->financial_type_id, 'name');
168 }
169 }
170 $this->assign('rows', $premiums);
171 }
172
173 /**
174 * Get name of edit form.
175 *
176 * @return string
177 * Classname of edit form.
178 */
179 public function editForm() {
180 return 'CRM_Contribute_Form_ManagePremiums';
181 }
182
183 /**
184 * Get edit form name.
185 *
186 * @return string
187 * name of this page.
188 */
189 public function editName() {
190 return 'Manage Premiums';
191 }
192
193 /**
194 * Get user context.
195 *
196 * @param null $mode
197 *
198 * @return string
199 * user context.
200 */
201 public function userContext($mode = NULL) {
202 return 'civicrm/admin/contribute/managePremiums';
203 }
204
205 }