Пример #1
0
 public function executeResend()
 {
     $param = $this->getAllRequestParameter();
     $sendsCrit = new Criteria();
     $sendsCrit->add(SmsLogRecipientPeer::ID, $param['id'], Criteria::IN);
     $sends = SmsLogRecipientPeer::doSelect($sendsCrit);
     $logs = array();
     foreach ($sends as $send) {
         if (!array_key_exists($send->getSmsLog()->getId(), $logs)) {
             $log = new SmsLog();
             $log->setCreatorUserId($send->getSmsLog()->getCreatorUserId());
             $log->setCreatorType($send->getSmsLog()->getCreatorType());
             $log->setSubject('Resend : ' . $send->getSmsLog()->getSubject());
             $recipients = array(array('type' => $send->getRecipientType(), 'value' => $send->getRecipientId()));
             $log->setRecipient($this->jsonwrapper->json_encode($recipients));
             $log->setMessage($send->getSmsLog()->getMessage());
             $log->setCreated(date('Y-m-d H:i:s'));
             $log->setSenderId($send->getSmsLog()->getSenderId());
             $sendAt = date('Y-m-d H:i:s');
             $log->setSendAt($sendAt);
             $log->setSmsLong($send->getSmsLog()->getSmsLong());
             $log->setSmsCount(1);
             $log->save();
             $logs[$send->getSmsLog()->getId()]['object'] = $log;
             $logs[$send->getSmsLog()->getId()]['sms_count'] = 1;
         } else {
             $log = $logs[$send->getSmsLog()->getId()]['object'];
             $logs[$send->getSmsLog()->getId()]['sms_count']++;
             $recipients = $this->jsonwrapper->json_decode($log->getRecipient);
             $recipients[] = array(array('type' => $send->getRecipientType(), 'value' => $send->getRecipientId()));
             $log->setRecipient($this->jsonwrapper->json_encode($recipients));
             $log->setSmsCount($logs[$send->getSmsLog()->getId()]['sms_count']);
             $log->save();
         }
         $rec = new SmsLogRecipient();
         $rec->setLogId($log->getId());
         $rec->setRecipientId($send->getRecipientId());
         $rec->setRecipientType($send->getRecipientType());
         $rec->setRecipientNumber($send->getRecipientNumber());
         $rec->setStatus('pending');
         $rec->setLog(0);
         $rec->save();
         /* Saving to gammu Database */
         $save = $this->sms->send($rec->getId(), 1, 2, 3, $rec->getRecipientNumber(), $log->getMessage(), $log->getCreated(), $log->getSendAt());
         /* log send status to resend */
         $send->setStatus('resend');
         $send->save();
     }
     $this->jsonwrapper->print_json(array('success' => 1, 'message' => 'success'));
 }
Пример #2
0
 public function sendSmsToStudent($senderId, $employeeId, $userType, $sms, $students)
 {
     /* Mapping Recipients */
     $recipients = array();
     foreach ($students as $student) {
         $recipients[] = array('type' => 'student', 'value' => $student->getId());
     }
     /* ------------------ */
     /* Save SMS Log */
     /* ------------------ */
     $log = new SmsLog();
     $log->setCreatorUserId($employeeId);
     $log->setCreatorType($userType);
     $log->setSubject($sms['subject']);
     $log->setRecipient($this->jsonwrapper->json_encode($recipients));
     $log->setMessage($sms['message']);
     $log->setCreated(date('Y-m-d H:i:s'));
     $sendAt = date('Y-m-d H:i:s');
     $log->setSendAt('now');
     $log->setSenderId($senderId);
     $log->save();
     if (!$log) {
         $this->jsonwrapper->show_json_error('#send-02-save', 'Failed save log');
     }
     /* ------------------ */
     /* ------------------ */
     /* ------------------ */
     foreach ($students as $s) {
         if ($s->getStudentDetail()) {
             $recNumber = $s->getStudentDetail()->getCellphone();
             //echo $recNumber . '<br />';
             $rec = new SmsLogRecipient();
             $rec->setLogId($log->getId());
             $rec->setRecipientId($s->getId());
             $rec->setRecipientType('student');
             $rec->setRecipientNumber($recNumber);
             $rec->setStatus('pending');
             $rec->setLog(0);
             $rec->save();
             /* Saving to gammu Database */
             $save = $this->smsConn->send($rec->getId(), 1, 2, 3, $recNumber, $log->getMessage(), $log->getCreated(), $log->getSendAt());
         }
     }
     $rc = new Criteria();
     $rc->add(SmsLogRecipientPeer::LOG_ID, $log->getId(), Criteria::EQUAL);
     $recipientCount = SmsLogRecipientPeer::doCount($rc);
     $smsLong = ceil(strlen($sms['message']) / $this->smsConn->smsLong());
     $smsCount = $smsLong * $recipientCount;
     $log->setSmsLong($smsLong);
     $log->setSmsCount($smsCount);
     $log->save();
 }