3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * This class generates form components for processing a survey
40 class CRM_Campaign_Form_Survey_Main
extends CRM_Campaign_Form_Survey
{
56 public function preProcess() {
59 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this);
61 $this->assign('context', $this->_context
);
63 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this);
65 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
66 CRM_Utils_System
::setTitle(ts('Configure Survey') . ' - ' . $this->_surveyTitle
);
69 $this->_cdType
= CRM_Utils_Array
::value('type', $_GET);
70 $this->assign('cdType', FALSE);
72 $this->assign('cdType', TRUE);
73 return CRM_Custom_Form_CustomData
::preProcess($this);
76 // when custom data is included in this page
77 if (!empty($_POST['hidden_custom'])) {
78 CRM_Custom_Form_CustomData
::preProcess($this);
79 CRM_Custom_Form_CustomData
::buildQuickForm($this);
82 if ($this->_name
!= 'Petition') {
83 $url = CRM_Utils_System
::url('civicrm/campaign', 'reset=1&subPage=survey');
84 CRM_Utils_System
::appendBreadCrumb(array(array('title' => ts('Survey Dashboard'), 'url' => $url)));
87 $this->_values
= $this->get('values');
88 if (!is_array($this->_values
)) {
89 $this->_values
= array();
90 if ($this->_surveyId
) {
91 $params = array('id' => $this->_surveyId
);
92 CRM_Campaign_BAO_Survey
::retrieve($params, $this->_values
);
94 $this->set('values', $this->_values
);
97 $this->assign('action', $this->_action
);
98 $this->assign('surveyId', $this->_surveyId
);
100 $this->assign('entityID', $this->_surveyId
);
104 * Set default values for the form. Note that in edit/view mode
105 * the default values are retrieved from the database
109 * @return array array of default values
111 public function setDefaultValues() {
112 if ($this->_cdType
) {
113 return CRM_Custom_Form_CustomData
::setDefaultValues($this);
116 $defaults = $this->_values
;
118 if ($this->_surveyId
) {
120 if (!empty($defaults['result_id']) && !empty($defaults['recontact_interval'])) {
122 $resultId = $defaults['result_id'];
123 $recontactInterval = unserialize($defaults['recontact_interval']);
125 unset($defaults['recontact_interval']);
126 $defaults['option_group_id'] = $resultId;
130 if (!isset($defaults['is_active'])) {
131 $defaults['is_active'] = 1;
134 $defaultSurveys = CRM_Campaign_BAO_Survey
::getSurveys(TRUE, TRUE);
135 if (!isset($defaults['is_default']) && empty($defaultSurveys)) {
136 $defaults['is_default'] = 1;
143 * Build the form object
149 public function buildQuickForm() {
150 if ($this->_cdType
) {
151 return CRM_Custom_Form_CustomData
::buildQuickForm($this);
154 $this->add('text', 'title', ts('Title'), CRM_Core_DAO
::getAttribute('CRM_Campaign_DAO_Survey', 'title'), TRUE);
156 $surveyActivityTypes = CRM_Campaign_BAO_Survey
::getSurveyActivityType();
158 $this->addSelect('activity_type_id', array('option_url' => 'civicrm/admin/campaign/surveyType'), TRUE);
161 $campaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(CRM_Utils_Array
::value('campaign_id', $this->_values
));
162 $this->add('select', 'campaign_id', ts('Campaign'), array('' => ts('- select -')) +
$campaigns);
164 // script / instructions
165 $this->addWysiwyg('instructions', ts('Instructions for interviewers'), array('rows' => 5, 'cols' => 40));
168 $this->add('text', 'release_frequency', ts('Release Frequency'), CRM_Core_DAO
::getAttribute('CRM_Campaign_DAO_Survey', 'release_frequency'));
170 $this->addRule('release_frequency', ts('Release Frequency interval should be a positive number.'), 'positiveInteger');
172 // max reserved contacts at a time
173 $this->add('text', 'default_number_of_contacts', ts('Maximum reserved at one time'), CRM_Core_DAO
::getAttribute('CRM_Campaign_DAO_Survey', 'default_number_of_contacts'));
174 $this->addRule('default_number_of_contacts', ts('Maximum reserved at one time should be a positive number'), 'positiveInteger');
176 // total reserved per interviewer
177 $this->add('text', 'max_number_of_contacts', ts('Total reserved per interviewer'), CRM_Core_DAO
::getAttribute('CRM_Campaign_DAO_Survey', 'max_number_of_contacts'));
178 $this->addRule('max_number_of_contacts', ts('Total reserved contacts should be a positive number'), 'positiveInteger');
181 $this->add('checkbox', 'is_active', ts('Active?'));
184 $this->add('checkbox', 'is_default', ts('Default?'));
186 parent
::buildQuickForm();
196 public function postProcess() {
197 // store the submitted values in an array
198 $params = $this->controller
->exportValues($this->_name
);
200 $session = CRM_Core_Session
::singleton();
202 $params['last_modified_id'] = $session->get('userID');
203 $params['last_modified_date'] = date('YmdHis');
205 if ($this->_surveyId
) {
206 $params['id'] = $this->_surveyId
;
209 $params['created_id'] = $session->get('userID');
210 $params['created_date'] = date('YmdHis');
213 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, 0);
214 $params['is_default'] = CRM_Utils_Array
::value('is_default', $params, 0);
216 $params['custom'] = CRM_Core_BAO_CustomField
::postProcess($params,
221 $survey = CRM_Campaign_BAO_Survey
::create($params);
222 $this->_surveyId
= $survey->id
;
224 if (!empty($this->_values
['result_id'])) {
225 $query = "SELECT COUNT(*) FROM civicrm_survey WHERE result_id = %1";
226 $countSurvey = (int)CRM_Core_DAO
::singleValueQuery($query,
228 1 => array($this->_values
['result_id'],
232 // delete option group if no any survey is using it.
234 CRM_Core_BAO_OptionGroup
::del($this->_values
['result_id']);
238 parent
::endPostProcess();