Example #1
0
 /**
  * @param string $title
  * @param string $text
  * @param array $to
  * @param int $parentId
  * @param integer|null $from
  * @param bool $sendToAuthor
  * @return bool|int
  */
 public function sendMessage($title, $text, array $to, $parentId = 0, $from = null, $sendToAuthor = true)
 {
     if (empty($from)) {
         $from = null;
     }
     if (empty($to)) {
         return false;
     }
     if (!is_null($from) and $sendToAuthor) {
         $to[] = $from;
     }
     $to = array_unique($to);
     $message = $this->create(['from_user_id' => $from, 'message' => $text, 'title' => $title]);
     if (!$message->exists) {
         return false;
     }
     foreach ($to as $id) {
         MessageUsers::create(['status' => static::STATUS_NEW, 'user_id' => (int) $id, 'message_id' => $message->id, 'parent_id' => (int) $parentId]);
     }
     return $message->id;
 }