Example #1
0
 /**
  * build all the data structures needed to build the form
  *
  * @return void
  * @access public
  */
 function preProcess()
 {
     $this->_interviewToRelease = $this->get('interviewToRelease');
     if ($this->_interviewToRelease) {
         //user came from interview form.
         foreach (array('surveyId', 'contactIds', 'interviewerId') as $fld) {
             $this->{"_{$fld}"} = $this->get($fld);
         }
         if (!empty($this->_contactIds)) {
             $this->assign('totalSelectedContacts', count($this->_contactIds));
         }
     } 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'));
     }
     $activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
     $surveyActType = CRM_Campaign_BAO_Survey::getSurveyActivityType();
     if (!$this->_surveyId) {
         CRM_Core_Error::statusBounce(ts("Please search with 'Survey', to apply this action."));
     }
     if (!$this->_interviewerId) {
         CRM_Core_Error::statusBounce(ts('Missing Interviewer contact.'));
     }
     if (!is_array($this->_contactIds) || empty($this->_contactIds)) {
         CRM_Core_Error::statusBounce(ts('Could not find respondents to release.'));
     }
     $surveyDetails = array();
     $params = array('id' => $this->_surveyId);
     $this->_surveyDetails = CRM_Campaign_BAO_Survey::retrieve($params, $surveyDetails);
     require_once 'CRM/Core/PseudoConstant.php';
     $activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
     $statusIds = array();
     foreach (array('Scheduled') as $name) {
         if ($statusId = array_search($name, $activityStatus)) {
             $statusIds[] = $statusId;
         }
     }
     //fetch the target survey activities.
     $this->_surveyActivities = CRM_Campaign_BAO_Survey::voterActivityDetails($this->_surveyId, $this->_contactIds, $this->_interviewerId, $statusIds);
     if (count($this->_surveyActivities) < 1) {
         CRM_Core_Error::statusBounce(ts('We could not found respondent for this survey to release.'));
     }
     $this->assign('surveyTitle', $surveyDetails['title']);
     //append breadcrumb to survey dashboard.
     require_once 'CRM/Campaign/BAO/Campaign.php';
     if (CRM_Campaign_BAO_Campaign::accessCampaignDashboard()) {
         $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.
     CRM_Utils_System::setTitle(ts('Release Respondents'));
 }
Example #2
0
 /**
  * Build all the data structures needed to build the form.
  */
 public function preProcess()
 {
     parent::preprocess();
     // set print view, so that print templates are called
     $this->controller->setPrint(1);
     // get the formatted params
     $queryParams = $this->get('queryParams');
     $sortID = NULL;
     if ($this->get(CRM_Utils_Sort::SORT_ID)) {
         $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), $this->get(CRM_Utils_Sort::SORT_DIRECTION));
     }
     $selector = new CRM_Campaign_Selector_Search($queryParams, $this->_action, $this->_componentClause);
     $controller = new CRM_Core_Selector_Controller($selector, NULL, $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SCREEN);
     $controller->setEmbedded(TRUE);
     $controller->run();
 }
Example #3
0
 /**
  * Build all the data structures needed to build the form.
  */
 public function preProcess()
 {
     parent::preProcess();
     //get the survey id from user submitted values.
     $this->_surveyId = $this->get('surveyId');
     $this->_interviewerId = $this->get('interviewerId');
     if (!$this->_surveyId) {
         CRM_Core_Error::statusBounce(ts("Could not find Survey Id."));
     }
     if (!$this->_interviewerId) {
         CRM_Core_Error::statusBounce(ts("Missing Interviewer contact."));
     }
     if (!is_array($this->_contactIds) || empty($this->_contactIds)) {
         CRM_Core_Error::statusBounce(ts("Could not find contacts for reservation."));
     }
     $params = array('id' => $this->_surveyId);
     CRM_Campaign_BAO_Survey::retrieve($params, $this->_surveyDetails);
     //get the survey activities.
     $activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
     $statusIds = array();
     foreach (array('Scheduled') as $name) {
         if ($statusId = array_search($name, $activityStatus)) {
             $statusIds[] = $statusId;
         }
     }
     // these are the activities count that are linked to the current
     // interviewer and current survey and not the list of ALL survey activities
     $this->_numVoters = CRM_Campaign_BAO_Survey::getSurveyActivities($this->_surveyId, $this->_interviewerId, $statusIds, NULL, TRUE);
     //validate the selected survey.
     $this->validateSurvey();
     $this->assign('surveyTitle', $this->_surveyDetails['title']);
     $this->assign('activityType', $this->_surveyDetails['activity_type_id']);
     $this->assign('surveyId', $this->_surveyId);
     //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.
     CRM_Utils_System::setTitle(ts('Reserve Respondents'));
 }
Example #4
0
 /**
  * build all the data structures needed to build the form
  *
  * @return void
  * @access 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'));
     }
     //get the contact read only fields to display.
     require_once 'CRM/Core/BAO/Preferences.php';
     $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;
     //get the profile id.
     require_once 'CRM/Core/BAO/UFJoin.php';
     $ufJoinParams = array('entity_id' => $this->_surveyId, 'entity_table' => 'civicrm_survey', 'module' => 'CiviCampaign');
     $this->_ufGroupId = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams);
     $this->assign('ufGroupId', $this->_ufGroupId);
     //validate all voters for required activity.
     //get the survey activities for given voters.
     require_once 'CRM/Campaign/BAO/Survey.php';
     $this->_surveyActivityIds = CRM_Campaign_BAO_Survey::voterActivityDetails($this->_surveyId, $this->_contactIds, $this->_interviewerId);
     require_once 'CRM/Core/PseudoConstant.php';
     $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;
     }
     $this->assign('votingTab', $this->_votingTab);
     $this->assign('componentIds', $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) {
             require_once 'CRM/Campaign/BAO/Survey.php';
             $surveyParams = array('id' => $this->_surveyId);
             CRM_Campaign_BAO_Survey::retrieve($surveyParams, $this->_surveyValues);
         }
         $this->set('surveyValues', $this->_surveyValues);
     }
     $this->assign('surveyValues', $this->_surveyValues);
     //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)) {
             require_once 'CRM/Core/OptionGroup.php';
             $this->_resultOptions = CRM_Core_OptionGroup::valuesByID($resultOptionId);
         }
         $this->set('resultOptions', $this->_resultOptions);
     }
     //validate the required ids.
     $this->validateIds();
     //append breadcrumb to survey dashboard.
     require_once 'CRM/Campaign/BAO/Campaign.php';
     if (CRM_Campaign_BAO_Campaign::accessCampaignDashboard()) {
         $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.
     require_once 'CRM/Core/PseudoConstant.php';
     $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])));
 }
 /**
  * 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])));
 }