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
21 * This class generates form components for Tell A Friend
24 class CRM_Friend_Form_Event
extends CRM_Event_Form_ManageEvent
{
27 * Tell a friend id in db.
33 public function preProcess() {
35 $this->setSelectedChild('friend');
39 * Set default values for the form.
44 public function setDefaultValues() {
47 if (isset($this->_id
)) {
48 $defaults['entity_table'] = 'civicrm_event';
49 $defaults['entity_id'] = $this->_id
;
50 CRM_Friend_BAO_Friend
::getValues($defaults);
51 if (!empty($defaults['id'])) {
52 $defaults['tf_id'] = $defaults['id'] ??
NULL;
53 $this->_friendId
= $defaults['tf_id'];
54 // lets unset the 'id' since it conflicts with eventID (or contribID)
56 unset($defaults['id']);
58 $defaults['tf_title'] = $defaults['title'] ??
NULL;
59 $defaults['tf_is_active'] = $defaults['is_active'] ??
NULL;
60 $defaults['tf_thankyou_title'] = $defaults['thankyou_title'] ??
NULL;
61 $defaults['tf_thankyou_text'] = $defaults['thankyou_text'] ??
NULL;
64 if (!$this->_friendId
) {
65 $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\'.');
66 $defaults['suggested_message'] = ts('Thought you might be interested in checking out this event. I\'m planning on attending.');
67 $defaults['tf_thankyou_text'] = ts('Thanks for spreading the word about this event to your friends.');
68 $defaults['tf_title'] = ts('Tell a Friend');
69 $defaults['tf_thankyou_title'] = ts('Thanks for Spreading the Word');
76 * Build the form object.
80 public function buildQuickForm() {
81 if (isset($this->_id
)) {
82 $defaults['entity_table'] = 'civicrm_event';
83 $defaults['entity_id'] = $this->_id
;
84 CRM_Friend_BAO_Friend
::getValues($defaults);
85 $this->_friendId
= $defaults['id'] ??
NULL;
88 CRM_Friend_BAO_Friend
::buildFriendForm($this);
89 parent
::buildQuickForm();
93 * Process the form submission.
98 public function postProcess() {
99 // get the submitted form values.
100 $formValues = $this->controller
->exportValues($this->_name
);
102 // let's unset event id
103 unset($formValues['id']);
105 $formValues['entity_table'] = 'civicrm_event';
106 $formValues['entity_id'] = $this->_id
;
107 $formValues['title'] = $formValues['tf_title'];
108 $formValues['is_active'] = CRM_Utils_Array
::value('tf_is_active', $formValues, FALSE);
109 $formValues['thankyou_title'] = $formValues['tf_thankyou_title'] ??
NULL;
110 $formValues['thankyou_text'] = $formValues['tf_thankyou_text'] ??
NULL;
112 if (($this->_action
& CRM_Core_Action
::UPDATE
) && $this->_friendId
) {
113 $formValues['id'] = $this->_friendId
;
116 CRM_Friend_BAO_Friend
::addTellAFriend($formValues);
118 // Update tab "disabled" css class
119 $this->ajaxResponse
['tabValid'] = !empty($formValues['tf_is_active']);
121 parent
::endPostProcess();
125 * Return a descriptive name for the page, used in wizard header
129 public function getTitle() {
130 return ts('Tell a Friend');