Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class message extends model
- {
- public function create(
- $user_id,
- $campaign_id,
- $campaign_runs_id,
- $contactId_number,
- $message,
- $send_times,
- $is_sent,
- $priority,
- $try_count,
- $msg_in_parcel
- )
- {
- $row = array();
- $countContact = 0;
- $countParcel = 0;
- foreach ($contactId_number as $key => $value) {
- if (!($countContact < $msg_in_parcel)) {
- $countParcel += 1;
- $countContact = 0;
- }
- $send_time = "$send_times[$countParcel]";
- $row[] = "(
- $user_id,
- $campaign_id,
- $campaign_runs_id,
- $key,
- $value,
- '$send_time',
- '$message',
- $is_sent,
- $try_count,
- $priority
- )";
- $countContact += 1;
- }
- $rows = implode(',', $row);
- $sql = "INSERT INTO sms(
- user_id,
- campaign_id,
- campaign_runs_id,
- contact_id,
- number,
- send_time,
- message,
- is_sent,
- try_count,
- priority)
- VALUES $rows";
- $this->model->query($sql);
- }
- public static function getStartTimeForEveryParcel(
- $contactId_number,
- $msg_in_parcel,
- $chosenStartDate,
- $sendingInterval,
- $notSendAfter,
- $sendTo,
- $fromTimeArr)
- {
- $days = message::getNumberOfDays($chosenStartDate, $notSendAfter);
- $parcels_count = ceil(count($contactId_number) / $msg_in_parcel);
- $interval = 'PT' . $sendingInterval . 'M';
- $times = array();
- $startDate = new DateTime($chosenStartDate);
- //------------FIRST DAY-------------------------------------------//
- if ($days >= 1) {
- $send_time = $startDate;
- for ($i = 1; $i <= $parcels_count; $i++) {
- if (date_create(date_format($send_time, 'H:i:s'))
- <= date_create(date_format($sendTo, 'H:i:s'))
- ) {
- $times[] = date_format($send_time, 'Y-m-d H:i:s');
- $send_time->add(new DateInterval($interval));
- }
- }
- }
- //------------REGULAR DAY-------------------------------------------//
- if ($days > 2) {
- $send_time = $startDate;
- for ($d = 3; $d <= $days; $d++) {
- $send_time->setTime($fromTimeArr[0], $fromTimeArr[1], $fromTimeArr[2]);
- $send_time = $send_time->add(new DateInterval('P1D'));
- for ($i = (count($times) + 1); $i <= $parcels_count; $i++) {
- if (date_create(date_format($send_time, 'H:i:s'))
- <= date_create(date_format($sendTo, 'H:i:s'))
- ) {
- $times[] = date_format($send_time, 'Y-m-d H:i:s');
- $send_time->add(new DateInterval($interval));
- }
- }
- }
- }
- //------------LAST DAY-------------------------------------------//
- if ($days >= 1) {
- $startDate = new DateTime($chosenStartDate);
- $send_time = $startDate->add(new DateInterval('P' . ($days - 1) . 'D'));
- $send_time->setTime($fromTimeArr[0], $fromTimeArr[1], $fromTimeArr[2]);
- $notSendAfter = date_create($notSendAfter);
- for ($i = (count($times) + 1); $i <= $parcels_count; $i++) {
- if ((date_create(date_format($send_time, 'H:i:s'))
- <= date_create(date_format($notSendAfter, 'H:i:s'))) &&
- (date_create(date_format($send_time, 'H:i:s'))
- <= date_create(date_format($sendTo, 'H:i:s')))
- ) {
- $times[] = date_format($send_time, 'Y-m-d H:i:s');
- $send_time->add(new DateInterval($interval));
- }
- }
- }
- //------------FIRST_LAST DAY-------------------------------------------//
- if ($days == 1) {
- $notSendAfter = date_create($notSendAfter);
- $send_time = $startDate;
- for ($i = (count($times) + 1); $i <= $parcels_count; $i++) {
- if ((date_create(date_format($send_time, 'H:i:s'))
- <= date_create(date_format($notSendAfter, 'H:i:s'))) &&
- (date_create(date_format($send_time, 'H:i:s'))
- <= date_create(date_format($sendTo, 'H:i:s')))) {
- $times[] = date_format($send_time, 'Y-m-d H:i:s');
- $send_time->add(new DateInterval($interval));
- }
- }
- }
- return $times;
- }
- public static function getNumberOfDays($chosenStartDate, $notSendAfter)
- {
- $startDate = new DateTime($chosenStartDate);
- $startDate = $startDate->getTimestamp();
- $endDate = new DateTime($notSendAfter);
- $endDate = $endDate->getTimestamp();
- return ceil($endDate / 86400) - floor($startDate / 86400);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement