예제 #1
0
 public function send()
 {
     $sendMany = false;
     if ($this->sendingOptions == self::SEND_OPT_MULTI) {
         $contacts = Pbk::findAll(explode(',', $this->number));
         $sendMany = true;
     }
     if ($this->sendingOptions == self::SEND_OPT_GROUP) {
         $contacts = Pbk::find()->where(['GroupID' => $this->number])->all();
         $sendMany = true;
     }
     if ($this->timeOptions == self::TIME_OPT_NOW) {
         $time = new Expression('NOW()');
     } elseif ($this->timeOptions == self::TIME_OPT_DATETIME) {
         $time = $this->sendingDateTime;
     } else {
         $timeParts = explode(':', $this->sendingTime);
         $hours = intval($timeParts[0]);
         $minutes = intval($timeParts[1]);
         $now = new \DateTime();
         $now->add(new \DateInterval("PT{$hours}H{$minutes}M"));
         $time = $now->format('Y-m-d H:i:s');
     }
     if ($sendMany) {
         foreach ($contacts as $contact) {
             $this->insertIntoOutbox($contact->Number, $this->text, $time);
         }
     } else {
         $this->insertIntoOutbox(trim($this->number), $this->text, $time);
     }
 }