3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2016
35 * Page for displaying list of Premiums.
37 class CRM_Contribute_Page_Premium
extends CRM_Core_Page_Basic
{
40 * The action links that we need to display for the browse screen.
44 static $_links = NULL;
52 public function getBAOName() {
53 return 'CRM_Contribute_BAO_Premium';
60 * (reference) of action links
62 public function &links() {
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?');
67 self
::$_links = array(
68 CRM_Core_Action
::UPDATE
=> array(
70 'url' => 'civicrm/admin/contribute/addProductToPage',
71 'qs' => 'action=update&id=%%id%%&pid=%%pid%%&reset=1',
72 'title' => ts('Edit Premium'),
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'),
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'),
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.
99 public function run() {
100 // get the requested action
101 $action = CRM_Utils_Request
::retrieve('action', 'String',
102 // default to 'browse'
103 $this, FALSE, 'browse'
106 // assign vars to templates
107 $this->assign('action', $action);
108 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
111 $this->assign('id', $id);
113 $this->edit($action, $id, FALSE, FALSE);
115 // this is special case where we need to call browse to list premium
116 if ($action == CRM_Core_Action
::UPDATE
) {
121 return parent
::run();
127 public function browse() {
128 // get all custom groups sorted by weight
130 $pageID = CRM_Utils_Request
::retrieve('id', 'Positive',
133 $dao = new CRM_Contribute_DAO_Premium();
134 $dao->entity_table
= 'civicrm_contribution_page';
135 $dao->entity_id
= $pageID;
137 $premiumID = $dao->id
;
138 $this->assign('products', FALSE);
139 $this->assign('id', $pageID);
144 $dao = new CRM_Contribute_DAO_PremiumsProduct();
145 $dao->premiums_id
= $premiumID;
146 $dao->orderBy('weight');
149 while ($dao->fetch()) {
150 $productDAO = new CRM_Contribute_DAO_Product();
151 $productDAO->id
= $dao->product_id
;
152 $productDAO->is_active
= 1;
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
]);
159 $action = array_sum(array_keys($this->links()));
161 $premiums[$dao->product_id
]['action'] = CRM_Core_Action
::formLink(self
::links(), $action,
162 array('id' => $pageID, 'pid' => $dao->id
),
165 'premium.contributionpage.row',
170 if (!empty($dao->financial_type_id
)) {
171 $premiums[$productDAO->id
]['financial_type_id'] = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType', $dao->financial_type_id
, 'name');
176 if (count(CRM_Contribute_PseudoConstant
::products($pageID)) == 0) {
177 $this->assign('products', FALSE);
180 $this->assign('products', TRUE);
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
189 $this->assign('rows', $premiums);
193 * Get name of edit form.
196 * Classname of edit form.
198 public function editForm() {
199 return 'CRM_Contribute_Form_ContributionPage_Premium';
203 * Get edit form name.
208 public function editName() {
209 return 'Configure Premiums';
220 public function userContext($mode = NULL) {
221 return CRM_Utils_System
::currentPath();