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