3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
30 * This file check and update the survey respondents.
34 require_once '../civicrm.config.php';
35 require_once 'CRM/Core/Config.php';
38 * Class CRM_RespondentProcessor
40 class CRM_RespondentProcessor
{
43 public function __construct() {
44 $config = CRM_Core_Config
::singleton();
46 //this does not return on failure
47 require_once 'CRM/Utils/System.php';
48 require_once 'CRM/Utils/Hook.php';
50 CRM_Utils_System
::authenticateScript(TRUE);
52 //log the execution time of script
53 CRM_Core_Error
::debug_log_message('RespondentProcessor.php');
56 public function releaseRespondent() {
57 require_once 'CRM/Core/PseudoConstant.php';
58 require_once 'CRM/Campaign/BAO/Survey.php';
59 $activityStatus = CRM_Core_PseudoConstant
::activityStatus('name');
60 $reserveStatusId = array_search('Scheduled', $activityStatus);
61 $surveyActivityTypes = CRM_Campaign_BAO_Survey
::getSurveyActivityType();
62 $surveyActivityTypesIds = array_keys($surveyActivityTypes);
64 //retrieve all survey activities related to reserve action.
66 if ($reserveStatusId && !empty($surveyActivityTypesIds)) {
68 SELECT activity.id as id,
69 activity.activity_date_time as activity_date_time,
70 survey.id as surveyId,
71 survey.release_frequency as release_frequency
72 FROM civicrm_activity activity
73 INNER JOIN civicrm_survey survey ON ( survey.id = activity.source_record_id )
74 WHERE activity.is_deleted = 0
75 AND activity.status_id = %1
76 AND activity.activity_type_id IN ( ' . implode(', ', $surveyActivityTypesIds) . ' )';
77 $activity = CRM_Core_DAO
::executeQuery($query, array(1 => array($reserveStatusId, 'Positive')));
78 $releasedIds = array();
79 while ($activity->fetch()) {
80 if (!$activity->release_frequency
) {
83 $reservedSeconds = CRM_Utils_Date
::unixTime($activity->activity_date_time
);
84 $releasedSeconds = $activity->release_frequency
* 24 * 3600;
85 $totalReservedSeconds = $reservedSeconds +
$releasedSeconds;
86 if ($totalReservedSeconds < time()) {
87 $releasedIds[$activity->id
] = $activity->id
;
91 //released respondent.
92 if (!empty($releasedIds)) {
94 UPDATE civicrm_activity
96 WHERE id IN ( ' . implode(', ', $releasedIds) . ' )';
97 CRM_Core_DAO
::executeQuery($query);
98 $releasedCount = count($releasedIds);
102 echo "<br /><br />Number of respondents released = {$releasedCount}";
107 $obj = new CRM_RespondentProcessor();
109 $obj->releaseRespondent();
110 echo "<br /><br />Respondent Release Done";