/**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @param null
  *
  * @return array    array of default values
  * @access public
  */
 function setDefaultValues()
 {
     $defaults = parent::setDefaultValues();
     $ufJoinParams = array('entity_table' => 'civicrm_survey', 'entity_id' => $this->_surveyId, 'weight' => 2);
     if ($ufGroupId = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams)) {
         $defaults['contact_profile_id'] = $ufGroupId;
     }
     return $defaults;
 }
Esempio n. 2
0
 /**
  * Process the form
  *
  * @param null
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     // also update the ProfileModule tables
     $ufJoinParams = array('is_active' => 1, 'module' => 'CiviCampaign', 'entity_table' => 'civicrm_survey', 'entity_id' => $this->_surveyId);
     // first delete all past entries
     CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams);
     $uf = array();
     $wt = 2;
     if (!empty($params['contact_profile_id'])) {
         $uf[1] = $params['contact_profile_id'];
         $wt = 1;
     }
     if (!empty($params['activity_profile_id'])) {
         $uf[2] = $params['activity_profile_id'];
     }
     $uf = array_values($uf);
     if (!empty($uf)) {
         foreach ($uf as $weight => $ufGroupId) {
             $ufJoinParams['weight'] = $weight + $wt;
             $ufJoinParams['uf_group_id'] = $ufGroupId;
             CRM_Core_BAO_UFJoin::create($ufJoinParams);
             unset($ufJoinParams['id']);
         }
     }
     parent::endPostProcess();
 }
Esempio n. 3
0
 /**
  * Process the form
  *
  * @param null
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     $session = CRM_Core_Session::singleton();
     $params['last_modified_id'] = $session->get('userID');
     $params['last_modified_date'] = date('YmdHis');
     if ($this->_surveyId) {
         $params['id'] = $this->_surveyId;
     } else {
         $params['created_id'] = $session->get('userID');
         $params['created_date'] = date('YmdHis');
     }
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0);
     $params['is_default'] = CRM_Utils_Array::value('is_default', $params, 0);
     $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_surveyId, 'Survey');
     $survey = CRM_Campaign_BAO_Survey::create($params);
     $this->_surveyId = $survey->id;
     if (!empty($this->_values['result_id'])) {
         $query = "SELECT COUNT(*) FROM civicrm_survey WHERE result_id = %1";
         $countSurvey = (int) CRM_Core_DAO::singleValueQuery($query, array(1 => array($this->_values['result_id'], 'Positive')));
         // delete option group if no any survey is using it.
         if (!$countSurvey) {
             CRM_Core_BAO_OptionGroup::del($this->_values['result_id']);
         }
     }
     parent::endPostProcess();
 }
Esempio n. 4
0
 /**
  * Process the form.
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $status = '';
     $params = $this->controller->exportValues($this->_name);
     $params['id'] = $this->_surveyId;
     $updateResultSet = FALSE;
     $resultSetOptGrpId = NULL;
     if (CRM_Utils_Array::value('option_type', $params) == 2 && !empty($params['option_group_id'])) {
         $updateResultSet = TRUE;
         $resultSetOptGrpId = $params['option_group_id'];
     }
     $recontactInterval = array();
     if ($updateResultSet) {
         $optionValue = new CRM_Core_DAO_OptionValue();
         $optionValue->option_group_id = $resultSetOptGrpId;
         $optionValue->delete();
         $params['result_id'] = $resultSetOptGrpId;
     } else {
         $opGroupName = 'civicrm_survey_' . rand(10, 1000) . '_' . date('YmdHis');
         $optionGroup = new CRM_Core_DAO_OptionGroup();
         $optionGroup->name = $opGroupName;
         $optionGroup->title = $this->_values['title'] . ' Result Set';
         $optionGroup->is_active = 1;
         $optionGroup->save();
         $params['result_id'] = $optionGroup->id;
     }
     foreach ($params['option_value'] as $k => $v) {
         if (strlen(trim($v))) {
             $optionValue = new CRM_Core_DAO_OptionValue();
             $optionValue->option_group_id = $params['result_id'];
             $optionValue->label = $params['option_label'][$k];
             $optionValue->name = CRM_Utils_String::titleToVar($params['option_label'][$k]);
             $optionValue->value = trim($v);
             $optionValue->weight = $params['option_weight'][$k];
             $optionValue->is_active = 1;
             if (!empty($params['default_option']) && $params['default_option'] == $k) {
                 $optionValue->is_default = 1;
             }
             $optionValue->save();
             // using is_numeric since 0 is a valid value for option_interval
             if (is_numeric($params['option_interval'][$k])) {
                 $recontactInterval[$optionValue->label] = $params['option_interval'][$k];
             }
         }
     }
     $params['recontact_interval'] = serialize($recontactInterval);
     $survey = CRM_Campaign_BAO_Survey::create($params);
     // create report if required.
     if (!$this->_reportId && $survey->id && !empty($params['create_report'])) {
         $activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
         $activityStatus = array_flip($activityStatus);
         $this->_params = array('name' => "survey_{$survey->id}", 'title' => $params['report_title'] ? $params['report_title'] : $this->_values['title'], 'status_id_op' => 'eq', 'status_id_value' => $activityStatus['Scheduled'], 'survey_id_value' => array($survey->id), 'description' => ts('Detailed report for canvassing, phone-banking, walk lists or other surveys.'));
         //Default value of order by
         $this->_params['order_bys'] = array(1 => array('column' => 'sort_name', 'order' => 'ASC'));
         // for WalkList or default
         $displayFields = array('id', 'sort_name', 'result', 'street_number', 'street_name', 'street_unit', 'survey_response');
         if (CRM_Core_OptionGroup::getValue('activity_type', 'WalkList') == $this->_values['activity_type_id']) {
             $this->_params['order_bys'] = array(1 => array('column' => 'street_name', 'order' => 'ASC'), 2 => array('column' => 'street_number_odd_even', 'order' => 'ASC'), 3 => array('column' => 'street_number', 'order' => 'ASC'), 4 => array('column' => 'sort_name', 'order' => 'ASC'));
         } elseif (CRM_Core_OptionGroup::getValue('activity_type', 'PhoneBank') == $this->_values['activity_type_id']) {
             array_push($displayFields, 'phone');
         } elseif (CRM_Core_OptionGroup::getValue('activity_type', 'Survey') == $this->_values['activity_type_id'] || CRM_Core_OptionGroup::getValue('activity_type', 'Canvass') == $this->_values['activity_type_id']) {
             array_push($displayFields, 'phone', 'city', 'state_province_id', 'postal_code', 'email');
         }
         foreach ($displayFields as $key) {
             $this->_params['fields'][$key] = 1;
         }
         $this->_createNew = TRUE;
         $this->_id = CRM_Report_Utils_Report::getInstanceIDForValue('survey/detail');
         CRM_Report_Form_Instance::postProcess($this, FALSE);
         $query = "SELECT MAX(id) FROM civicrm_report_instance WHERE name = %1";
         $reportID = CRM_Core_DAO::singleValueQuery($query, array(1 => array("survey_{$survey->id}", 'String')));
         if ($reportID) {
             $url = CRM_Utils_System::url("civicrm/report/instance/{$reportID}", 'reset=1');
             $status = ts("A Survey Detail Report <a href='%1'>%2</a> has been created.", array(1 => $url, 2 => $this->_params['title']));
         }
     }
     if ($status) {
         // reset status as we don't want status set by Instance::postProcess
         $session = CRM_Core_Session::singleton();
         $session->getStatus(TRUE);
         // set new status
         CRM_Core_Session::setStatus($status, ts('Saved'), 'success');
     }
     parent::endPostProcess();
 }