Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
3819f101 | 35 | * This class generates form components for processing a survey. |
6a488035 TO |
36 | */ |
37 | class CRM_Campaign_Form_Survey_Questions extends CRM_Campaign_Form_Survey { | |
38 | ||
39 | /** | |
3819f101 | 40 | * Set default values for the form. |
41 | * | |
42 | * Note that in edit/view mode the default values are retrieved from the database. | |
6a488035 | 43 | * |
a6c01b45 CW |
44 | * @return array |
45 | * array of default values | |
6a488035 | 46 | */ |
00be9182 | 47 | public function setDefaultValues() { |
6a488035 TO |
48 | $defaults = array(); |
49 | ||
50 | $ufJoinParams = array( | |
51 | 'entity_table' => 'civicrm_survey', | |
52 | 'module' => 'CiviCampaign', | |
53 | 'entity_id' => $this->_surveyId, | |
54 | ); | |
55 | ||
79d7553f | 56 | list($defaults['contact_profile_id'], $second) |
57 | = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); | |
6a488035 TO |
58 | $defaults['activity_profile_id'] = $second ? array_shift($second) : ''; |
59 | ||
60 | return $defaults; | |
61 | } | |
62 | ||
63 | /** | |
fe482240 | 64 | * Build the form object. |
6a488035 TO |
65 | */ |
66 | public function buildQuickForm() { | |
67 | $subTypeId = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $this->_surveyId, 'activity_type_id'); | |
68 | if (!CRM_Core_BAO_CustomGroup::autoCreateByActivityType($subTypeId)) { | |
69 | $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE, FALSE); // everything | |
70 | // FIXME: Displays weird "/\ Array" message; doesn't work with tabs | |
342936e2 DL |
71 | CRM_Core_Session::setStatus( |
72 | ts( | |
73 | 'There are no custom data sets for activity type "%1". To create one, <a href="%2" target="%3">click here</a>.', | |
74 | array( | |
75 | 1 => $activityTypes[$subTypeId], | |
76 | 2 => CRM_Utils_System::url('civicrm/admin/custom/group', 'action=add&reset=1'), | |
21dfd5f5 | 77 | 3 => '_blank', |
342936e2 DL |
78 | ) |
79 | ) | |
80 | ); | |
6a488035 TO |
81 | } |
82 | ||
83 | $allowCoreTypes = CRM_Campaign_BAO_Survey::surveyProfileTypes(); | |
84 | $allowSubTypes = array( | |
85 | 'ActivityType' => array($subTypeId), | |
86 | ); | |
87 | $entities = array( | |
88 | array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel'), | |
89 | array('entity_name' => 'activity_1', 'entity_type' => 'ActivityModel', 'entity_sub_type' => $subTypeId), | |
90 | ); | |
91 | $this->addProfileSelector('contact_profile_id', ts('Contact Info'), $allowCoreTypes, $allowSubTypes, $entities); | |
92 | $this->addProfileSelector('activity_profile_id', ts('Questions'), $allowCoreTypes, $allowSubTypes, $entities); | |
93 | // Note: Because this is in a tab, we also preload the schema via CRM_Campaign_Form_Survey::preProcess | |
94 | ||
95 | parent::buildQuickForm(); | |
96 | } | |
97 | ||
98 | ||
99 | /** | |
fe482240 | 100 | * Process the form. |
6a488035 TO |
101 | */ |
102 | public function postProcess() { | |
103 | // store the submitted values in an array | |
104 | $params = $this->controller->exportValues($this->_name); | |
105 | ||
106 | // also update the ProfileModule tables | |
107 | $ufJoinParams = array( | |
108 | 'is_active' => 1, | |
353ffa53 | 109 | 'module' => 'CiviCampaign', |
6a488035 | 110 | 'entity_table' => 'civicrm_survey', |
353ffa53 | 111 | 'entity_id' => $this->_surveyId, |
6a488035 TO |
112 | ); |
113 | ||
114 | // first delete all past entries | |
115 | CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams); | |
116 | ||
117 | $uf = array(); | |
118 | $wt = 2; | |
119 | if (!empty($params['contact_profile_id'])) { | |
120 | $uf[1] = $params['contact_profile_id']; | |
121 | $wt = 1; | |
122 | } | |
123 | if (!empty($params['activity_profile_id'])) { | |
124 | $uf[2] = $params['activity_profile_id']; | |
125 | } | |
126 | ||
127 | $uf = array_values($uf); | |
128 | if (!empty($uf)) { | |
129 | foreach ($uf as $weight => $ufGroupId) { | |
130 | $ufJoinParams['weight'] = $weight + $wt; | |
131 | $ufJoinParams['uf_group_id'] = $ufGroupId; | |
132 | CRM_Core_BAO_UFJoin::create($ufJoinParams); | |
133 | unset($ufJoinParams['id']); | |
134 | } | |
135 | } | |
136 | ||
137 | parent::endPostProcess(); | |
138 | } | |
96025800 | 139 | |
6a488035 | 140 | } |