Merge pull request #2540 from eileenmcnaughton/CRM-14235
[civicrm-core.git] / CRM / Friend / Form / Contribute.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
32 * $Id$
33 *
34 */
35
36 /**
37 * This class generates form components for Tell A Friend
38 *
39 */
40 class CRM_Friend_Form_Contribute extends CRM_Contribute_Form_ContributionPage {
41
42 /**
43 * tell a friend id in db
44 *
45 * @var int
46 */
47 public $_friendId;
48
49 public function preProcess() {
50 parent::preProcess();
51 }
52
53 /**
54 * This function sets the default values for the form. Note that in edit/view mode
55 * the default values are retrieved from the database
56 *
57 * @access public
58 *
59 * @return void
60 */
61 public function setDefaultValues() {
62 $title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'title');
63 CRM_Utils_System::setTitle(ts('Tell a Friend') . " ($title)");
64
65 $defaults = array();
66
67 if (isset($this->_id)) {
68 $defaults['entity_table'] = 'civicrm_contribution_page';
69 $defaults['entity_id'] = $this->_id;
70 CRM_Friend_BAO_Friend::getValues($defaults);
71 $this->_friendId = CRM_Utils_Array::value('id', $defaults);
72 $defaults['tf_title'] = CRM_Utils_Array::value('title', $defaults);
73 $defaults['tf_is_active'] = CRM_Utils_Array::value('is_active', $defaults);
74 $defaults['tf_thankyou_title'] = CRM_Utils_Array::value('thankyou_title', $defaults);
75 $defaults['tf_thankyou_text'] = CRM_Utils_Array::value('thankyou_text', $defaults);
76 }
77
78 if (!$this->_friendId) {
79 $defaults['intro'] = ts('Help us spread the word and leverage the power of your contribution by telling your friends. Use the space below to personalize your email message - let your friends know why you support us. Then fill in the name(s) and email address(es) and click \'Send Your Message\'.');
80 $defaults['suggested_message'] = ts('Thought you might be interested in learning about and helping this organization. I think they do important work.');
81 $defaults['tf_thankyou_text'] = ts('Thanks for telling your friends about us and supporting our efforts. Together we can make a difference.');
82 $defaults['tf_title'] = ts('Tell a Friend');
83 $defaults['tf_thankyou_title'] = ts('Thanks for Spreading the Word');
84 }
85
86 return $defaults;
87 }
88
89 /**
90 * Function to build the form
91 *
92 * @return void
93 * @access public
94 */
95 public function buildQuickForm() {
96 if (isset($this->_id)) {
97 $defaults['entity_table'] = 'civicrm_contribution_page';
98 $defaults['entity_id'] = $this->_id;
99 CRM_Friend_BAO_Friend::getValues($defaults);
100 $this->_friendId = CRM_Utils_Array::value('id', $defaults);
101 }
102
103 CRM_Friend_BAO_Friend::buildFriendForm($this);
104 parent::buildQuickForm();
105 }
106
107 /**
108 * Function to process the form
109 *
110 * @access public
111 *
112 * @return void
113 */
114 public function postProcess() {
115 // get the submitted form values.
116 $formValues = $this->controller->exportValues($this->_name);
117
118 $formValues['entity_table'] = 'civicrm_contribution_page';
119 $formValues['entity_id'] = $this->_id;
120 $formValues['title'] = $formValues['tf_title'];
121 $formValues['is_active'] = CRM_Utils_Array::value('tf_is_active', $formValues, FALSE);
122 $formValues['thankyou_title'] = CRM_Utils_Array::value('tf_thankyou_title', $formValues);
123 $formValues['thankyou_text'] = CRM_Utils_Array::value('tf_thankyou_text', $formValues);
124
125 if (($this->_action & CRM_Core_Action::UPDATE) && $this->_friendId) {
126 $formValues['id'] = $this->_friendId;
127 }
128
129 CRM_Friend_BAO_Friend::addTellAFriend($formValues);
130 parent::endPostProcess();
131 }
132
133 /**
134 * Return a descriptive name for the page, used in wizard header
135 *
136 * @return string
137 * @access public
138 */
139 public function getTitle() {
140 return ts('Tell a Friend');
141 }
142 }
143