示例#1
0
 public function toArray()
 {
     $props = parent::toArray();
     $props["messages"] = $this->messages();
     return $props;
 }
示例#2
0
 public function create()
 {
     /*
     if((!$this->author || !$this->author->existing) && $this->authorid) {
       $this->author = new SCUser($this->authorid);
     }
     */
     if (!$this->author() || !$this->author()->userid) {
         throw new MessageException("You need a valid userid to create a message");
     }
     if (!$this->threadid) {
         throw new MessageException("You need a valid threadid to create a message");
     }
     if (!$this->boardid) {
         throw new MessageException("You need a valid boardid to create a message");
     }
     if (!$this->text && !$this->media) {
         throw new MessageException("You need valid message content to create a message");
     }
     if ($this->type == "image") {
         $asset = new SCAsset($this->author()->userid, $this->media);
         $this->media = $asset->hash;
     }
     //$sql = "INSERT INTO messages (msg_date, msg_author, msg_subject, msg_text, msg_board_id" . ($source ? ", msg_source" : "") . ") VALUES('".SC::dbDate()."', $userid, '".SC::dbString($subject) ."', '" .SC::dbString($text) ."', " . $this->boardid  . ($source ? ", '" . SC::dbString($source) . "'" : "") . ")";
     $db = new SCDB();
     //$db->query($sql);
     $insert_array = array("msg_date" => SC::dbDate(), "msg_author" => SC::dbString($this->author()->userid, true), "msg_subject" => SC::dbString($this->subject, true), "msg_text" => SC::dbString($this->text, true), "msg_thread" => $this->threadid, "msg_board_id" => $this->boardid, "msg_source" => SC::dbString($this->source, true), "msg_type" => SC::dbString($this->type, true));
     if ($this->media) {
         $insert_array["msg_media"] = SC::dbString($this->media, true);
     }
     if ($this->caption) {
         $insert_array["msg_media_caption"] = SC::dbString($this->caption, true);
     }
     $db->insertFromArray($insert_array, "messages");
     $newmessage = mysql_insert_id($db->conn);
     if ($newmessage) {
         $message = new SCMessage($newmessage);
         $this->fromArray($message->toArray());
         try {
             $messageMail = SCEmail::newMessageEmail($message);
             $messageMail->sendEmail();
         } catch (Exception $ex) {
         }
         return $this;
     } else {
         throw new MessageException(mysql_error($db->conn));
     }
 }