Merge pull request #16016 from seamuslee001/master
[civicrm-core.git] / CRM / Contribute / Page / ManagePremiums.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * Page for displaying list of Premiums.
20 */
21 class CRM_Contribute_Page_ManagePremiums extends CRM_Core_Page_Basic {
22
23 public $useLivePageJS = TRUE;
24
25 /**
26 * The action links that we need to display for the browse screen.
27 *
28 * @var array
29 */
30 public static $_links = NULL;
31
32 /**
33 * Get BAO Name.
34 *
35 * @return string
36 * Classname of BAO.
37 */
38 public function getBAOName() {
39 return 'CRM_Contribute_BAO_Product';
40 }
41
42 /**
43 * Get action Links.
44 *
45 * @return array
46 * (reference) of action links
47 */
48 public function &links() {
49 if (!(self::$_links)) {
50 self::$_links = [
51 CRM_Core_Action::UPDATE => [
52 'name' => ts('Edit'),
53 'url' => 'civicrm/admin/contribute/managePremiums',
54 'qs' => 'action=update&id=%%id%%&reset=1',
55 'title' => ts('Edit Premium'),
56 ],
57 CRM_Core_Action::PREVIEW => [
58 'name' => ts('Preview'),
59 'url' => 'civicrm/admin/contribute/managePremiums',
60 'qs' => 'action=preview&id=%%id%%',
61 'title' => ts('Preview Premium'),
62 ],
63 CRM_Core_Action::DISABLE => [
64 'name' => ts('Disable'),
65 'ref' => 'crm-enable-disable',
66 'title' => ts('Disable Premium'),
67 ],
68 CRM_Core_Action::ENABLE => [
69 'name' => ts('Enable'),
70 'ref' => 'crm-enable-disable',
71 'title' => ts('Enable Premium'),
72 ],
73 CRM_Core_Action::DELETE => [
74 'name' => ts('Delete'),
75 'url' => 'civicrm/admin/contribute/managePremiums',
76 'qs' => 'action=delete&id=%%id%%',
77 'title' => ts('Delete Premium'),
78 ],
79 ];
80 }
81 return self::$_links;
82 }
83
84 /**
85 * Run the page.
86 *
87 * This method is called after the page is created. It checks for the
88 * type of action and executes that action.
89 * Finally it calls the parent's run method.
90 */
91 public function run() {
92 $id = $this->getIdAndAction();
93
94 // what action to take ?
95 if (!($this->_action & CRM_Core_Action::BROWSE)) {
96 $this->edit($this->_action, $id, TRUE);
97 }
98 // finally browse the custom groups
99 $this->browse();
100
101 // parent run
102 return CRM_Core_Page::run();
103 }
104
105 /**
106 * Browse all custom data groups.
107 */
108 public function browse() {
109 // get all custom groups sorted by weight
110 $premiums = [];
111 $dao = new CRM_Contribute_DAO_Product();
112 $dao->orderBy('name');
113 $dao->find();
114
115 while ($dao->fetch()) {
116 $premiums[$dao->id] = [];
117 CRM_Core_DAO::storeValues($dao, $premiums[$dao->id]);
118 // form all action links
119 $action = array_sum(array_keys($this->links()));
120
121 if ($dao->is_active) {
122 $action -= CRM_Core_Action::ENABLE;
123 }
124 else {
125 $action -= CRM_Core_Action::DISABLE;
126 }
127
128 $premiums[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(),
129 $action,
130 ['id' => $dao->id],
131 ts('more'),
132 FALSE,
133 'premium.manage.row',
134 'Premium',
135 $dao->id
136 );
137 // Financial Type
138 if (!empty($dao->financial_type_id)) {
139 $premiums[$dao->id]['financial_type'] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Product', 'financial_type_id', $dao->financial_type_id);
140 }
141 }
142 $this->assign('rows', $premiums);
143 }
144
145 /**
146 * Get name of edit form.
147 *
148 * @return string
149 * Classname of edit form.
150 */
151 public function editForm() {
152 return 'CRM_Contribute_Form_ManagePremiums';
153 }
154
155 /**
156 * Get edit form name.
157 *
158 * @return string
159 * name of this page.
160 */
161 public function editName() {
162 return 'Manage Premiums';
163 }
164
165 /**
166 * Get user context.
167 *
168 * @param null $mode
169 *
170 * @return string
171 * user context.
172 */
173 public function userContext($mode = NULL) {
174 return 'civicrm/admin/contribute/managePremiums';
175 }
176
177 }