/** * RPC Routine to send reminder for participants in a survey * Returns array of results of sending * * @access public * @param string $sSessionKey Auth credentials * @param int $iSurveyID ID of the survey that participants belong * @param int $iMinDaysBetween Optional parameter days from last reminder * @param int $iMaxReminders Optional parameter Maximum reminders count * @return array Result of the action */ public function remind_participants($sSessionKey, $iSurveyID, $iMinDaysBetween = null, $iMaxReminders = null) { Yii::app()->loadHelper('admin/token'); if (!$this->_checkSessionKey($sSessionKey)) { return array('status' => 'Invalid session key'); } $oSurvey = Survey::model()->findByPk($iSurveyID); if (!isset($oSurvey)) { return array('status' => 'Error: Invalid survey ID'); } if (Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'update')) { $timeadjust = Yii::app()->getConfig("timeadjust"); if (!tableExists("{{tokens_{$iSurveyID}}}")) { return array('status' => 'Error: No token table'); } if (getEmailFormat($iSurveyID) == 'html') { $bHtml = true; } else { $bHtml = false; } $SQLemailstatuscondition = "emailstatus = 'OK'"; $SQLremindercountcondition = ''; $SQLreminderdelaycondition = ''; $iMaxEmails = (int) Yii::app()->getConfig("maxemails"); if (!is_null($iMinDaysBetween)) { $compareddate = dateShift(date("Y-m-d H:i:s", time() - 86400 * $iMinDaysBetween), "Y-m-d H:i", $timeadjust); $SQLreminderdelaycondition = " ((remindersent = 'N' AND sent < '" . $compareddate . "') OR (remindersent < '" . $compareddate . "'))"; } if (!is_null($iMaxReminders)) { $SQLremindercountcondition = "remindercount < " . $iMaxReminders; } $oTokens = TokenDynamic::model($iSurveyID); $aAllTokens = $oTokens->findUninvitedIDs(false, 0, false, $SQLemailstatuscondition, $SQLremindercountcondition, $SQLreminderdelaycondition); $iAllTokensCount = count($aAllTokens); unset($aAllTokens); // save some memory before the next query $aResultTokens = $oTokens->findUninvited(false, $iMaxEmails, false, $SQLemailstatuscondition, $SQLremindercountcondition, $SQLreminderdelaycondition); if (empty($aResultTokens)) { return array('status' => 'Error: No candidate tokens'); } $aResult = emailTokens($iSurveyID, $aResultTokens, 'remind'); $iLeft = $iAllTokensCount - count($aResultTokens); $aResult['status'] = $iLeft . " left to send"; return $aResult; } else { return array('status' => 'No permission'); } }
/** * RPC Routine to send reminder for participants in a survey * Returns array of results of sending * * @access public * @param string $sSessionKey Auth credentials * @param int $iSurveyID ID of the survey that participants belong * @param int $iTokenID ID of the participant to send the reminder to * @return array Result of the action */ public function remind_participant($sSessionKey, $iSurveyID, $iTokenID) { Yii::app()->loadHelper('admin/token'); if (!$this->_checkSessionKey($sSessionKey)) { return array('status' => 'Invalid session key'); } $oSurvey = Survey::model()->findByPk($iSurveyID); if (!isset($oSurvey)) { return array('status' => 'Error: Invalid survey ID'); } if (Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'update')) { $timeadjust = Yii::app()->getConfig("timeadjust"); if (!tableExists("{{tokens_{$iSurveyID}}}")) { return array('status' => 'Error: No token table'); } $SQLemailstatuscondition = "emailstatus = 'OK'"; $oTokens = TokenDynamic::model($iSurveyID); $aResultTokens = $oTokens->findUninvited(false, $iMaxEmails, false, $SQLemailstatuscondition, '', ''); if (empty($aResultTokens)) { return array('status' => 'Error: No candidate tokens'); } // find our token $token = null; foreach ($aResultTokens as $key => $value) { if ($value['tid'] == $iTokenID) { $token = $value; } } if ($token) { emailTokens($iSurveyID, array($token), 'remind'); return $iTokenID; } else { return 'Error: Can not find token in token table'; } } else { return array('status' => 'No permission'); } }