Merge pull request #21876 from mariav0/patch-14
[civicrm-core.git] / CRM / Pledge / Page / Payment.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 class CRM_Pledge_Page_Payment extends CRM_Core_Page {
18
19 /**
20 * the main function that is called when the page loads, it decides the which action has to be taken for the page.
21 *
22 * @return null
23 */
24 public function run() {
25 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
26 $this->_context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this);
27
28 $this->assign('action', $this->_action);
29 $this->assign('context', $this->_context);
30
31 $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
32
33 CRM_Pledge_Page_Tab::setContext($this);
34
35 if ($this->_action & CRM_Core_Action::UPDATE) {
36 $this->edit();
37 }
38 else {
39 $pledgeId = CRM_Utils_Request::retrieve('pledgeId', 'Positive', $this);
40
41 $paymentDetails = CRM_Pledge_BAO_PledgePayment::getPledgePayments($pledgeId);
42
43 $this->assign('rows', $paymentDetails);
44 $this->assign('pledgeId', $pledgeId);
45 $this->assign('contactId', $this->_contactId);
46
47 // check if we can process credit card contributions
48 $this->assign('newCredit', CRM_Core_Config::isEnabledBackOfficeCreditCardPayments());
49
50 // check is the user has view/edit signer permission
51 $permission = 'view';
52 if (CRM_Core_Permission::check('edit pledges')) {
53 $permission = 'edit';
54 }
55 $this->assign('permission', $permission);
56 }
57
58 return parent::run();
59 }
60
61 /**
62 * called when action is update or new.
63 *
64 * @return null
65 */
66 public function edit() {
67 $controller = new CRM_Core_Controller_Simple('CRM_Pledge_Form_Payment',
68 'Update Pledge Payment',
69 $this->_action
70 );
71
72 $pledgePaymentId = CRM_Utils_Request::retrieve('ppId', 'Positive', $this);
73
74 $controller->setEmbedded(TRUE);
75 $controller->set('id', $pledgePaymentId);
76
77 return $controller->run();
78 }
79
80 }