Ejemplo n.º 1
0
 public function updateStatus($logId)
 {
     $criteria = new Criteria();
     $criteria->add(SmsLogRecipientPeer::LOG_ID, $logId, Criteria::EQUAL);
     $criteria->add(SmsLogRecipientPeer::STATUS, 'queue', Criteria::EQUAL);
     $criteria->addAscendingOrderByColumn(SmsLogRecipientPeer::RECIPIENT_ID);
     $criteria->setLimit(100);
     $log = SmsLogRecipientPeer::doSelect($criteria);
     $logString = '(';
     $logCount = count($log);
     if ($logCount < 1) {
         return false;
     }
     $n = 1;
     foreach ($log as $l) {
         $logString .= $l->getId();
         if ($n != $logCount) {
             $logString .= ', ';
         }
         $n++;
     }
     $logString .= ')';
     $result = $this->conn->get_results("SELECT sms_outbox.id as id, sms_outbox.log_id as log_id, sentitems.Status as status FROM sms_outbox, sentitems WHERE sms_outbox.id = sentitems.Id AND sms_outbox.log_id IN {$logString} ORDER BY sms_outbox.id ASC");
     if (!$result) {
         return false;
     }
     $status = array();
     $statusString = array('SendingOK' => 'sent', 'SendingError' => 'error');
     foreach ($result as $r) {
         $status[$r->log_id] = $statusString[$r->status];
     }
     foreach ($log as $l) {
         if (!empty($status[$l->getId()])) {
             $l->setStatus($status[$l->getId()]);
             $l->save();
         }
     }
 }
Ejemplo n.º 2
0
 public static function retrieveByPKs($pks, $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(self::DATABASE_NAME);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria();
         $criteria->add(SmsLogRecipientPeer::ID, $pks, Criteria::IN);
         $objs = SmsLogRecipientPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Ejemplo n.º 3
0
 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;
     }
 }
Ejemplo n.º 4
0
 public function getSmsLogRecipients($criteria = null, $con = null)
 {
     include_once 'lib/model/om/BaseSmsLogRecipientPeer.php';
     if ($criteria === null) {
         $criteria = new Criteria();
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collSmsLogRecipients === null) {
         if ($this->isNew()) {
             $this->collSmsLogRecipients = array();
         } else {
             $criteria->add(SmsLogRecipientPeer::LOG_ID, $this->getId());
             SmsLogRecipientPeer::addSelectColumns($criteria);
             $this->collSmsLogRecipients = SmsLogRecipientPeer::doSelect($criteria, $con);
         }
     } else {
         if (!$this->isNew()) {
             $criteria->add(SmsLogRecipientPeer::LOG_ID, $this->getId());
             SmsLogRecipientPeer::addSelectColumns($criteria);
             if (!isset($this->lastSmsLogRecipientCriteria) || !$this->lastSmsLogRecipientCriteria->equals($criteria)) {
                 $this->collSmsLogRecipients = SmsLogRecipientPeer::doSelect($criteria, $con);
             }
         }
     }
     $this->lastSmsLogRecipientCriteria = $criteria;
     return $this->collSmsLogRecipients;
 }