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