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