/** * @param array $params * * @return array */ public static function getSurveySummary($params = array()) { $surveysData = array(); //get the survey. $config = CRM_Core_Config::singleton(); $surveys = CRM_Campaign_BAO_Survey::getSurveySummary($params); if (!empty($surveys)) { $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); $surveyType = CRM_Campaign_BAO_Survey::getSurveyActivityType(); foreach ($surveys as $sid => $survey) { $surveysData[$sid] = $survey; $campaignId = CRM_Utils_Array::value('campaign_id', $survey); $surveysData[$sid]['campaign'] = CRM_Utils_Array::value($campaignId, $campaigns); $surveysData[$sid]['activity_type'] = $surveyType[$survey['activity_type_id']]; if (!empty($survey['release_frequency'])) { $surveysData[$sid]['release_frequency'] = ts('1 Day', array('plural' => '%count Days', 'count' => $survey['release_frequency'])); } $action = array_sum(array_keys(self::surveyActionLinks($surveysData[$sid]['activity_type']))); if ($survey['is_active']) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } $isActive = ts('No'); if ($surveysData[$sid]['is_active']) { $isActive = ts('Yes'); } $surveysData[$sid]['isActive'] = $isActive; $isDefault = NULL; if ($surveysData[$sid]['is_default']) { $isDefault = '<img src="' . $config->resourceBase . 'i/check.gif" alt="' . ts('Default') . '" />'; } $surveysData[$sid]['is_default'] = $isDefault; if ($surveysData[$sid]['result_id']) { $resultSet = '<a href= "javascript:displayResultSet( ' . $sid . ',' . "'" . $surveysData[$sid]['title'] . "'" . ', ' . $surveysData[$sid]['result_id'] . ' )" title="' . ts('view result set') . '">' . ts('Result Set') . '</a>'; $surveysData[$sid]['result_id'] = $resultSet; } else { $resultUrl = CRM_Utils_System::url("civicrm/survey/configure/results", "action=update&id={$sid}&reset=1"); $surveysData[$sid]['result_id'] = "<a href='{$resultUrl}' class='status-warning'>(" . ts('Incomplete. Click to configure result set.') . ')</a>'; } $surveysData[$sid]['action'] = CRM_Core_Action::formLink(self::surveyActionLinks($surveysData[$sid]['activity_type']), $action, array('id' => $sid), ts('more'), FALSE, 'survey.dashboard.row', 'Survey', $sid); if (CRM_Utils_Array::value('activity_type', $surveysData[$sid]) != 'Petition') { $surveysData[$sid]['voterLinks'] = CRM_Campaign_BAO_Survey::buildPermissionLinks($sid, TRUE, ts('more')); } if ($reportID = CRM_Campaign_BAO_Survey::getReportID($sid)) { $url = CRM_Utils_System::url("civicrm/report/instance/{$reportID}", 'reset=1'); $surveysData[$sid]['title'] = "<a href='{$url}' title='View Survey Report'>{$surveysData[$sid]['title']}</a>"; } } } return $surveysData; }
/** * Delete the survey. * * @param int $id * Survey id. * * @return mixed|null */ public static function del($id) { if (!$id) { return NULL; } $reportId = CRM_Campaign_BAO_Survey::getReportID($id); if ($reportId) { CRM_Report_BAO_ReportInstance::del($reportId); } $dao = new CRM_Campaign_DAO_Survey(); $dao->id = $id; return $dao->delete(); }
/** * Build all the data structures needed to build the form. */ public function preProcess() { $this->_votingTab = $this->get('votingTab'); $this->_reserveToInterview = $this->get('reserveToInterview'); if ($this->_reserveToInterview || $this->_votingTab) { //user came from voting tab / reserve form. foreach (array('surveyId', 'contactIds', 'interviewerId') as $fld) { $this->{"_{$fld}"} = $this->get($fld); } //get the target voter ids. if ($this->_votingTab) { $this->getVoterIds(); } } else { parent::preProcess(); //get the survey id from user submitted values. $this->_surveyId = CRM_Utils_Array::value('campaign_survey_id', $this->get('formValues')); $this->_interviewerId = CRM_Utils_Array::value('survey_interviewer_id', $this->get('formValues')); } if ($this->_surveyId) { $params = array('id' => $this->_surveyId); CRM_Campaign_BAO_Survey::retrieve($params, $this->_surveyDetails); } $orderClause = FALSE; $buttonName = $this->controller->getButtonName(); if ($buttonName == '_qf_Interview_submit_orderBy' && !empty($_POST['order_bys'])) { $orderByParams = CRM_Utils_Array::value('order_bys', $_POST); } elseif (CRM_Core_OptionGroup::getValue('activity_type', 'WalkList') == $this->_surveyDetails['activity_type_id']) { $orderByParams = array(1 => array('column' => 'civicrm_address.street_name', 'order' => 'ASC'), 2 => array('column' => 'civicrm_address.street_number%2', 'order' => 'ASC'), 3 => array('column' => 'civicrm_address.street_number', 'order' => 'ASC'), 4 => array('column' => 'contact_a.sort_name', 'order' => 'ASC')); } $orderBy = array(); if (!empty($orderByParams)) { foreach ($orderByParams as $key => $val) { if (!empty($val['column'])) { $orderBy[] = "{$val['column']} {$val['order']}"; } } if (!empty($orderBy)) { $orderClause = "ORDER BY " . implode(', ', $orderBy); } } $this->_contactIds = array_unique($this->_contactIds); if (!empty($this->_contactIds) && $orderClause) { $clause = 'contact_a.id IN ( ' . implode(',', $this->_contactIds) . ' ) '; $sql = "\nSELECT contact_a.id\nFROM civicrm_contact contact_a\nLEFT JOIN civicrm_address ON contact_a.id = civicrm_address.contact_id\nWHERE {$clause}\n{$orderClause}"; $this->_contactIds = array(); $dao = CRM_Core_DAO::executeQuery($sql); while ($dao->fetch()) { $this->_contactIds[] = $dao->id; } } //get the contact read only fields to display. $readOnlyFields = array_merge(array('contact_type' => '', 'sort_name' => ts('Name'))); //get the read only field data. $returnProperties = array_fill_keys(array_keys($readOnlyFields), 1); $returnProperties['contact_sub_type'] = TRUE; //validate all voters for required activity. //get the survey activities for given voters. $this->_surveyActivityIds = CRM_Campaign_BAO_Survey::voterActivityDetails($this->_surveyId, $this->_contactIds, $this->_interviewerId); $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); $scheduledStatusId = array_search('Scheduled', $activityStatus); $activityIds = array(); foreach ($this->_contactIds as $key => $voterId) { $actVals = CRM_Utils_Array::value($voterId, $this->_surveyActivityIds); $statusId = CRM_Utils_Array::value('status_id', $actVals); $activityId = CRM_Utils_Array::value('activity_id', $actVals); if ($activityId && $statusId && $scheduledStatusId == $statusId) { $activityIds["activity_id_{$voterId}"] = $activityId; } else { unset($this->_contactIds[$key]); } } //retrieve the contact details. $voterDetails = CRM_Campaign_BAO_Survey::voterDetails($this->_contactIds, $returnProperties); $this->_allowAjaxReleaseButton = FALSE; if ($this->_votingTab && (CRM_Core_Permission::check('manage campaign') || CRM_Core_Permission::check('administer CiviCampaign') || CRM_Core_Permission::check('release campaign contacts'))) { $this->_allowAjaxReleaseButton = TRUE; } //validate voter ids across profile. $this->filterVoterIds(); $this->assign('votingTab', $this->_votingTab); $this->assign('componentIds', $this->_contactIds); $this->assign('componentIdsJson', json_encode($this->_contactIds)); $this->assign('voterDetails', $voterDetails); $this->assign('readOnlyFields', $readOnlyFields); $this->assign('interviewerId', $this->_interviewerId); $this->assign('surveyActivityIds', json_encode($activityIds)); $this->assign('allowAjaxReleaseButton', $this->_allowAjaxReleaseButton); //get the survey values. $this->_surveyValues = $this->get('surveyValues'); if (!is_array($this->_surveyValues)) { $this->_surveyValues = array(); if ($this->_surveyId) { $surveyParams = array('id' => $this->_surveyId); CRM_Campaign_BAO_Survey::retrieve($surveyParams, $this->_surveyValues); } $this->set('surveyValues', $this->_surveyValues); } $this->assign('surveyValues', $this->_surveyValues); $result = CRM_Campaign_BAO_Survey::getReportID($this->_surveyId); $this->assign("instanceId", $result); //get the survey result options. $this->_resultOptions = $this->get('resultOptions'); if (!is_array($this->_resultOptions)) { $this->_resultOptions = array(); if ($resultOptionId = CRM_Utils_Array::value('result_id', $this->_surveyValues)) { $this->_resultOptions = CRM_Core_OptionGroup::valuesByID($resultOptionId); } $this->set('resultOptions', $this->_resultOptions); } //validate the required ids. $this->validateIds(); //append breadcrumb to survey dashboard. if (CRM_Campaign_BAO_Campaign::accessCampaign()) { $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'); CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Survey(s)'), 'url' => $url))); } //set the title. $activityTypes = CRM_Core_PseudoConstant::activityType(FALSE, TRUE, FALSE, 'label', TRUE); $this->_surveyTypeId = CRM_Utils_Array::value('activity_type_id', $this->_surveyValues); CRM_Utils_System::setTitle(ts('Record %1 Responses', array(1 => $activityTypes[$this->_surveyTypeId]))); }