public function executeSentReport() { $param = $this->getAllRequestParameter(); $this->userInit(); $user_id = $this->user->getAttribute('user_id', null, 'bo'); $senderIdAvailable = $this->senderIdAvailable(); $senderId = array(); foreach ($senderIdAvailable as $s) { $senderId[] = $s->getId(); } $this->pageLimit = $limit = !empty($param['limit']) ? $param['limit'] : 20; $this->pageOffset = $offset = !empty($param['offset']) ? $param['offset'] : 1; $offset = ($offset - 1) * $limit; $criteria = new Criteria(); $join = array(); $criteria->addJoin(SmsLogRecipientPeer::LOG_ID, SmsLogPeer::ID); $join[] = 'SmsLogRecipient'; $criteria->addDescendingOrderByColumn(SmsLogPeer::ID); /* ADD FILTER SEARCH */ /* Sender Id */ if (!in_array('SmsLogRecipient', $join)) { $criteria->addJoin(SmsLogRecipientPeer::LOG_ID, SmsLogPeer::ID); $join[] = 'SmsLogRecipient'; } if (!empty($param['filter']['sender_id'])) { $criteria->add(SmsLogPeer::SENDER_ID, $this->getSenderIdByInitial($param['filter']['sender_id']), Criteria::EQUAL); } else { $criteria->add(SmsLogPeer::SENDER_ID, $senderId, Criteria::IN); } /* Start Date */ if (!empty($param['filter']['start_date'])) { if (!in_array('SmsLogRecipient', $join)) { $criteria->addJoin(SmsLogRecipientPeer::LOG_ID, SmsLogPeer::ID); $join[] = 'SmsLogRecipient'; } $hour = !empty($param['filter']['start_hour']) ? !empty($param['filter']['start_hour']) : '0'; $minute = !empty($param['filter']['start_minute']) ? !empty($param['filter']['start_minute']) : '0'; $start_time = $param['filter']['start_date'] . ', ' . $hour . ':' . $minute; $start_time = date('Y-m-d H:i:s', strtotime($start_time)); if (!in_array('criterionDate', $join)) { $criterionDate = $criteria->getNewCriterion(SmsLogPeer::SEND_AT, $start_time, Criteria::GREATER_EQUAL); $join[] = 'criterionDate'; } else { $criterionDate->addAnd($criteria->getNewCriterion(SmsLogPeer::SEND_AT, $start_time, Criteria::GREATER_EQUAL)); } } /* End Date */ if (!empty($param['filter']['end_date'])) { if (!in_array('SmsLogRecipient', $join)) { $criteria->addJoin(SmsLogRecipientPeer::LOG_ID, SmsLogPeer::ID); $join[] = 'SmsLogRecipient'; } $hour = !empty($param['filter']['end_hour']) ? !empty($param['filter']['end_hour']) : '0'; $minute = !empty($param['filter']['end_minute']) ? !empty($param['filter']['end_minute']) : '0'; $end_time = $param['filter']['end_date'] . ', ' . $hour . ':' . $minute; $end_time = date('Y-m-d H:i:s', strtotime($end_time)); if (!in_array('criterionDate', $join)) { $criterionDate = $criteria->getNewCriterion(SmsLogPeer::SEND_AT, $end_time, Criteria::LESS_EQUAL); $join[] = 'criterionDate'; } else { $criterionDate->addAnd($criteria->getNewCriterion(SmsLogPeer::SEND_AT, $end_time, Criteria::LESS_EQUAL)); } } if (in_array('criterionDate', $join)) { $criteria->add($criterionDate); } /* Sender Name */ if (!empty($param['filter']['sender_name']) && !empty($param['filter']['sender_type']) && ($param['filter']['sender_type'] == 'common' || $param['filter']['sender_type'] == 'lector')) { //echo $param['filter']['sender_type']; if ($param['filter']['sender_type'] == 'common') { $senderId = $this->getUserByName($param['filter']['sender_name']); } else { if ($param['filter']['sender_type'] == 'lector') { $senderId = $this->getEmployeeByName($param['filter']['sender_name']); } } if (!in_array('SmsLogRecipient', $join)) { $criteria->addJoin(SmsLogRecipientPeer::LOG_ID, SmsLogPeer::ID); $join[] = 'SmsLogRecipient'; } $criteria->add(SmsLogPeer::CREATOR_USER_ID, $senderId, Criteria::IN); $criteria->add(SmsLogPeer::CREATOR_TYPE, $param['filter']['sender_type'], Criteria::EQUAL); } /* Recipient Name */ if (!empty($param['filter']['recipient_name']) || !empty($param['filter']['recipient_class'])) { $recipientName = !empty($param['filter']['recipient_name']) ? $param['filter']['recipient_name'] : ''; $recipientClass = !empty($param['filter']['recipient_class']) ? $param['filter']['recipient_class'] : ''; $recipientId = $this->getStudentByNameAndClass($recipientName, $recipientClass); $criteria->add(SmsLogRecipientPeer::RECIPIENT_ID, $recipientId, Criteria::IN); } /* Status */ if (!empty($param['filter']['status'])) { $criteria->add(SmsLogRecipientPeer::STATUS, $param['filter']['status'], Criteria::EQUAL); } $allcount = SmsLogRecipientPeer::doCount($criteria); $criteria->setLimit($limit); $criteria->setOffset($offset); $result = SmsLogRecipientPeer::doSelect($criteria); /* if(!$result){ $this->jsonwrapper->show_json_error('Not Found', 'Data Not Found'); } */ $output = array('success' => true, 'data' => array(), 'count' => count($result), 'allcount' => $allcount); $lectorSender = array(); $commonSender = array(); $studentRec = array(); foreach ($result as $r) { $temp = $r->toArray(); $temp['sender_type'] = $r->getSmsLog()->getCreatorType(); $temp['detail'] = $r->getSmsLog()->toArray(); $sender = array(); if ($r->getSmsLog()->getCreatorType() == 'common') { $sender = $this->smsContact->getCommon($r->getSmsLog()->getCreatorUserId()); $sender = $sender->toArray(); } if ($r->getSmsLog()->getCreatorType() == 'lector') { $sender = $this->smsContact->getLector($r->getSmsLog()->getCreatorUserId()); $sender = $sender->toArray(); } $recipient = array(); if ($r->getRecipientType() == 'student' || $r->getRecipientType() == 'student_class') { $recipientRes = $this->smsContact->getStudent($r->getRecipientId()); $recipient = $recipientRes->toArray(); $recipient['detail'] = $recipientRes->getStudentDetail()->toArray(); $recipient['class_group'] = $recipientRes->getClassGroup()->toArray(); } else { if ($r->getRecipientType() == 'employee') { $recipientRes = $this->smsContactEmployee->getEmployee($r->getRecipientId()); if ($recipientRes) { $recipient = $recipientRes->toArray(); $detail = $this->smsContactEmployee->getEmployeeDetail($recipientRes->getId()); $recipient['detail'] = $detail ? $detail->toArray() : ''; $recipient['department'] = $recipientRes->getDepartment()->toArray(); } else { $recipient = array('Name' => 'unknown'); } } } $temp['sender'] = $sender; $temp['recipient'] = $recipient; $output['data'][] = $temp; } if (!empty($param['export'])) { $export = empty($param['export']) ? '' : $param['export']; switch ($export) { case 'xls': header("Content-type: application/vnd-ms-excel"); header("Content-Disposition: attachment; filename=export.xls"); $this->output = $output; break; case 'doc': header("Content-Type: application/vnd.ms-word"); header("Content-Disposition: attachment; filename=export.doc"); $this->output = $output; break; default: $this->jsonwrapper->print_json($output); //die(); break; } } else { $this->jsonwrapper->print_json($output); die; } }
public function executeTest() { $log = SmsLogPeer::doSelect(new Criteria()); foreach ($log as $l) { $jsonwrapper = new jsonwrapper(); $rc = new Criteria(); $rc->add(SmsLogRecipientPeer::LOG_ID, $l->getId(), Criteria::EQUAL); $recipientCount = SmsLogRecipientPeer::doCount($rc); $count = $recipientCount * $l->getSmsLong(); $l->setSmsCount($count); $l->save(); //$count = ceil(strlen($l->getMessage()) / 140); //$l->setSmsCount($count); //$l->save(); } die; }
public function countSmsLogRecipients($criteria = null, $distinct = false, $con = null) { include_once 'lib/model/om/BaseSmsLogRecipientPeer.php'; if ($criteria === null) { $criteria = new Criteria(); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } $criteria->add(SmsLogRecipientPeer::LOG_ID, $this->getId()); return SmsLogRecipientPeer::doCount($criteria, $distinct, $con); }
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(); }