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 processing a survey.
21 class CRM_Campaign_Form_Survey_Questions
extends CRM_Campaign_Form_Survey
{
24 * Set default values for the form.
26 * Note that in edit/view mode the default values are retrieved from the database.
29 * array of default values
31 public function setDefaultValues() {
35 'entity_table' => 'civicrm_survey',
36 'module' => 'CiviCampaign',
37 'entity_id' => $this->_surveyId
,
40 list($defaults['contact_profile_id'], $second)
41 = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
42 $defaults['activity_profile_id'] = $second ?
array_shift($second) : '';
48 * Build the form object.
50 public function buildQuickForm() {
51 $subTypeId = CRM_Core_DAO
::getFieldValue('CRM_Campaign_DAO_Survey', $this->_surveyId
, 'activity_type_id');
52 if (!CRM_Core_BAO_CustomGroup
::autoCreateByActivityType($subTypeId)) {
54 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, FALSE, 'label', TRUE, FALSE);
55 // FIXME: Displays weird "/\ Array" message; doesn't work with tabs
56 CRM_Core_Session
::setStatus(
58 'There are no custom data sets for activity type "%1". To create one, <a href="%2" target="%3">click here</a>.',
60 1 => $activityTypes[$subTypeId],
61 2 => CRM_Utils_System
::url('civicrm/admin/custom/group', 'action=add&reset=1'),
68 $allowCoreTypes = CRM_Campaign_BAO_Survey
::surveyProfileTypes();
70 'ActivityType' => [$subTypeId],
73 ['entity_name' => 'contact_1', 'entity_type' => 'IndividualModel'],
74 ['entity_name' => 'activity_1', 'entity_type' => 'ActivityModel', 'entity_sub_type' => $subTypeId],
76 $this->addProfileSelector('contact_profile_id', ts('Contact Info'), $allowCoreTypes, $allowSubTypes, $entities);
77 $this->addProfileSelector('activity_profile_id', ts('Questions'), $allowCoreTypes, $allowSubTypes, $entities);
78 // Note: Because this is in a tab, we also preload the schema via CRM_Campaign_Form_Survey::preProcess
80 parent
::buildQuickForm();
86 public function postProcess() {
87 // store the submitted values in an array
88 $params = $this->controller
->exportValues($this->_name
);
90 // also update the ProfileModule tables
93 'module' => 'CiviCampaign',
94 'entity_table' => 'civicrm_survey',
95 'entity_id' => $this->_surveyId
,
98 // first delete all past entries
99 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParams);
103 if (!empty($params['contact_profile_id'])) {
104 $uf[1] = $params['contact_profile_id'];
107 if (!empty($params['activity_profile_id'])) {
108 $uf[2] = $params['activity_profile_id'];
111 $uf = array_values($uf);
113 foreach ($uf as $weight => $ufGroupId) {
114 $ufJoinParams['weight'] = $weight +
$wt;
115 $ufJoinParams['uf_group_id'] = $ufGroupId;
116 CRM_Core_BAO_UFJoin
::create($ufJoinParams);
117 unset($ufJoinParams['id']);
121 parent
::endPostProcess();