mirror of https://github.com/movim/movim
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.4 KiB
62 lines
1.4 KiB
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Draft extends Model
|
|
{
|
|
protected $with = ['reply'];
|
|
private $embeds = [];
|
|
|
|
public function save(array $options = [])
|
|
{
|
|
parent::save($options);
|
|
$this->embeds()->saveMany($this->embeds);
|
|
}
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo('App\User');
|
|
}
|
|
|
|
public function embeds()
|
|
{
|
|
return $this->hasMany('App\DraftEmbed');
|
|
}
|
|
|
|
public function reply()
|
|
{
|
|
return $this->hasOne('App\Post', 'id', 'reply_id');
|
|
}
|
|
|
|
public function isNotEmpty()
|
|
{
|
|
return !empty($this->title);
|
|
}
|
|
|
|
public function tryFillPost()
|
|
{
|
|
$post = Post::where('server', $this->server)
|
|
->where('node', $this->node)
|
|
->where('nodeid', $this->nodeid)
|
|
->first();
|
|
|
|
if ($post) {
|
|
$this->title = $post->title;
|
|
$this->content = $post->contentraw;
|
|
$this->open = $post->open;
|
|
|
|
$reply = $post->getReply();
|
|
if ($reply) {
|
|
$this->reply_id = $reply->id;
|
|
}
|
|
|
|
foreach ($post->attachments()->whereIn('rel', ['enclosure', 'related'])->get() as $attachment) {
|
|
$embed = new DraftEmbed;
|
|
$embed->url = $attachment->href;
|
|
array_push($this->embeds, $embed);
|
|
}
|
|
}
|
|
}
|
|
}
|