3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class generates form components for Tell A Friend
22 class CRM_Friend_Form_Event
extends CRM_Event_Form_ManageEvent
{
25 * Tell a friend id in db.
31 public function preProcess() {
33 $this->setSelectedChild('friend');
37 * Set default values for the form.
42 public function setDefaultValues() {
45 if (isset($this->_id
)) {
46 $defaults['entity_table'] = 'civicrm_event';
47 $defaults['entity_id'] = $this->_id
;
48 CRM_Friend_BAO_Friend
::getValues($defaults);
49 if (!empty($defaults['id'])) {
50 $defaults['tf_id'] = $defaults['id'] ??
NULL;
51 $this->_friendId
= $defaults['tf_id'];
52 // lets unset the 'id' since it conflicts with eventID (or contribID)
54 unset($defaults['id']);
56 $defaults['tf_title'] = $defaults['title'] ??
NULL;
57 $defaults['tf_is_active'] = $defaults['is_active'] ??
NULL;
58 $defaults['tf_thankyou_title'] = $defaults['thankyou_title'] ??
NULL;
59 $defaults['tf_thankyou_text'] = $defaults['thankyou_text'] ??
NULL;
62 if (!$this->_friendId
) {
63 $defaults['intro'] = ts('Help us spread the word about this event. Use the space below to personalize your email message - let your friends know why you\'re attending. Then fill in the name(s) and email address(es) and click \'Send Your Message\'.');
64 $defaults['suggested_message'] = ts('Thought you might be interested in checking out this event. I\'m planning on attending.');
65 $defaults['tf_thankyou_text'] = ts('Thanks for spreading the word about this event to your friends.');
66 $defaults['tf_title'] = ts('Tell a Friend');
67 $defaults['tf_thankyou_title'] = ts('Thanks for Spreading the Word');
74 * Build the form object.
78 public function buildQuickForm() {
79 if (isset($this->_id
)) {
80 $defaults['entity_table'] = 'civicrm_event';
81 $defaults['entity_id'] = $this->_id
;
82 CRM_Friend_BAO_Friend
::getValues($defaults);
83 $this->_friendId
= $defaults['id'] ??
NULL;
86 CRM_Friend_BAO_Friend
::buildFriendForm($this);
87 parent
::buildQuickForm();
91 * Process the form submission.
96 public function postProcess() {
97 // get the submitted form values.
98 $formValues = $this->controller
->exportValues($this->_name
);
100 // let's unset event id
101 unset($formValues['id']);
103 $formValues['entity_table'] = 'civicrm_event';
104 $formValues['entity_id'] = $this->_id
;
105 $formValues['title'] = $formValues['tf_title'];
106 $formValues['is_active'] = CRM_Utils_Array
::value('tf_is_active', $formValues, FALSE);
107 $formValues['thankyou_title'] = $formValues['tf_thankyou_title'] ??
NULL;
108 $formValues['thankyou_text'] = $formValues['tf_thankyou_text'] ??
NULL;
110 if (($this->_action
& CRM_Core_Action
::UPDATE
) && $this->_friendId
) {
111 $formValues['id'] = $this->_friendId
;
114 CRM_Friend_BAO_Friend
::addTellAFriend($formValues);
116 // Update tab "disabled" css class
117 $this->ajaxResponse
['tabValid'] = !empty($formValues['tf_is_active']);
119 parent
::endPostProcess();
123 * Return a descriptive name for the page, used in wizard header
127 public function getTitle() {
128 return ts('Tell a Friend');