本文整理匯總了PHP中CRM_Campaign_BAO_Survey::create方法的典型用法代碼示例。如果您正苦於以下問題:PHP CRM_Campaign_BAO_Survey::create方法的具體用法?PHP CRM_Campaign_BAO_Survey::create怎麽用?PHP CRM_Campaign_BAO_Survey::create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CRM_Campaign_BAO_Survey
的用法示例。
在下文中一共展示了CRM_Campaign_BAO_Survey::create方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: postProcess
/**
* 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();
}
示例2: postProcess
/**
* 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();
}
示例3: postProcess
/**
* 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');
require_once 'CRM/Core/BAO/OptionValue.php';
require_once 'CRM/Core/BAO/OptionGroup.php';
$updateResultSet = false;
if (CRM_Utils_Array::value('option_type', $params) == 2 && CRM_Utils_Array::value('option_group_id', $params)) {
if ($params['option_group_id'] == CRM_Utils_Array::value('result_id', $this->_values)) {
$updateResultSet = true;
}
}
if ($this->_surveyId) {
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Campaign_BAO_Survey::del($this->_surveyId);
CRM_Core_Session::setStatus(ts(' Survey has been deleted.'));
$session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'));
return;
}
$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);
$recontactInterval = array();
if ($updateResultSet) {
$optionValue = new CRM_Core_DAO_OptionValue();
$optionValue->option_group_id = $this->_values['result_id'];
$optionValue->delete();
$params['result_id'] = $this->_values['result_id'];
} else {
$opGroupName = 'civicrm_survey_' . rand(10, 1000) . '_' . date('YmdHis');
$optionGroup = new CRM_Core_DAO_OptionGroup();
$optionGroup->name = $opGroupName;
$optionGroup->label = $params['title'] . ' Response 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 (CRM_Utils_Array::value('default_option', $params) && $params['default_option'] == $k) {
$optionValue->is_default = 1;
}
$optionValue->save();
if (CRM_Utils_Array::value($k, $params['option_interval'])) {
$recontactInterval[$optionValue->label] = $params['option_interval'][$k];
}
}
}
$params['recontact_interval'] = serialize($recontactInterval);
$surveyId = CRM_Campaign_BAO_Survey::create($params);
if (CRM_Utils_Array::value('result_id', $this->_values) && !$updateResultSet) {
$query = "SELECT COUNT(*) FROM civicrm_survey WHERE result_id = %1";
$countSurvey = CRM_Core_DAO::singleValueQuery($query, array(1 => array($this->_values['result_id'], 'Integer')));
// delete option group if no any survey is using it.
if (!($countSurvey >= 1)) {
CRM_Core_BAO_OptionGroup::del($this->_values['result_id']);
}
}
require_once 'CRM/Core/BAO/UFJoin.php';
// also update the ProfileModule tables
$ufJoinParams = array('is_active' => 1, 'module' => 'CiviCampaign', 'entity_table' => 'civicrm_survey', 'entity_id' => $surveyId->id);
// first delete all past entries
if ($this->_surveyId) {
CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams);
}
if (CRM_Utils_Array::value('profile_id', $params)) {
$ufJoinParams['weight'] = 1;
$ufJoinParams['uf_group_id'] = $params['profile_id'];
CRM_Core_BAO_UFJoin::create($ufJoinParams);
}
if (!is_a($surveyId, 'CRM_Core_Error')) {
CRM_Core_Session::setStatus(ts('Survey %1 has been saved.', array(1 => $params['title'])));
}
if ($this->_context == 'dialog') {
$returnArray = array('returnSuccess' => true);
echo json_encode($returnArray);
CRM_Utils_System::civiExit();
}
//.........這裏部分代碼省略.........
示例4: postProcess
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');
$params['is_share'] = CRM_Utils_Array::value('is_share', $params, FALSE);
if ($this->_surveyId) {
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Campaign_BAO_Survey::del($this->_surveyId);
CRM_Core_Session::setStatus(ts(' Petition has been deleted.'), ts('Record Deleted'), 'success');
$session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=petition'));
return;
}
$params['id'] = $this->_surveyId;
} else {
$params['created_id'] = $session->get('userID');
$params['created_date'] = date('YmdHis');
}
$params['bypass_confirm'] = CRM_Utils_Array::value('bypass_confirm', $params, 0);
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0);
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, 0);
$surveyId = CRM_Campaign_BAO_Survey::create($params);
// also update the ProfileModule tables
$ufJoinParams = array('is_active' => 1, 'module' => 'CiviCampaign', 'entity_table' => 'civicrm_survey', 'entity_id' => $surveyId->id);
// first delete all past entries
if ($this->_surveyId) {
CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams);
}
if (!empty($params['profile_id'])) {
$ufJoinParams['weight'] = 1;
$ufJoinParams['uf_group_id'] = $params['profile_id'];
CRM_Core_BAO_UFJoin::create($ufJoinParams);
}
if (!empty($params['contact_profile_id'])) {
$ufJoinParams['weight'] = 2;
$ufJoinParams['uf_group_id'] = $params['contact_profile_id'];
CRM_Core_BAO_UFJoin::create($ufJoinParams);
}
if (!is_a($surveyId, 'CRM_Core_Error')) {
CRM_Core_Session::setStatus(ts('Petition has been saved.'), ts('Saved'), 'success');
}
$buttonName = $this->controller->getButtonName();
if ($buttonName == $this->getButtonName('next', 'new')) {
CRM_Core_Session::setStatus(ts(' You can add another Petition.'), '', 'info');
$session->replaceUserContext(CRM_Utils_System::url('civicrm/petition/add', 'reset=1&action=add'));
} else {
$session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=petition'));
}
}