Exemplo n.º 1
0
 /**
  *  pushing weekly scheduled campaigns to queue 
  * 
  */
 public function weeklycampToqueue($arr)
 {
     $arc = count($arr);
     $sendmessage = new Application_Model_Message();
     if ($arc != 0) {
         $sendtime = date('Y-m-d H:i:s');
         foreach ($arr as $cind => $cobj) {
             if ($cobj instanceof stdClass) {
                 // read the object
                 if (!$sendmessage->checkScheduled("msg", $cobj->campaignid)) {
                     echo $cobj->campaignid;
                     $folders = explode(',', $cobj->folder);
                     $totalfolders = count($folders);
                     $totalsubscribers = array();
                     for ($sbr = 0; $sbr < $totalfolders; $sbr++) {
                         $subscribers = $this->subscribersByFolderid($folders[$sbr]);
                         foreach ($subscribers as $usr_fid => $v) {
                             $totalsubscribers[$v['phonenumber']] = $v['phonenumber'];
                         }
                     }
                     $msg = $cobj->msghead ? "{$cobj->msghead}:" : '';
                     $msg .= "{$cobj->message}\n{$cobj->msgfoot}";
                     $msg = trim($msg);
                     //                    $sendmessage = new Application_Model_Message();
                     if (!empty($totalsubscribers)) {
                         $i_default = 0;
                         // Construct the message
                         $sendmessage->selectedfolders = $cobj->folder;
                         // Set the folderid this message is being sent to
                         $sendmessage->folderid = 1;
                         // Set the user description
                         $sendmessage->description = $cobj->name;
                         // Set a unique identifier for all messages that go out on this campaign
                         $sendmessage->campaignid = $cobj->campaignid;
                         //                     echo $sendtime = date('Y-m-d').' '.$cobj->sendtime;
                         $sendtime = date($cobj->sendtime);
                         $timezone = $cobj->timezone;
                         $userid = $cobj->createuser;
                         $shortcode = $cobj->shortcode;
                         $source = 404;
                         $totalmsg = count($totalsubscribers);
                         $status = $sendmessage->queue($msg, $totalsubscribers, $sendtime, $timezone, $i_default, $source, $userid, $shortcode);
                         /*api sms senders table*/
                         //                           $status = $sendmessage->api_msgsend($msg, $totalsubscribers, $sendtime, $timezone,$i_default,$source,$userid,$shortcode);
                         $sendmessage->weeklycampaignUpdate($cobj->id, $totalmsg, $cobj->createuser);
                     } else {
                         $error = 'There are no subscribers in the chosen folder(s).';
                     }
                 }
             }
             // end of object
             sleep(2);
         }
     }
 }