Browse Source

Save Post tags in the DB

pull/617/head
Timothée Jaussoin 8 years ago
parent
commit
5b70371936
  1. 53
      app/Post.php
  2. 15
      app/Tag.php
  3. 2
      app/widgets/ContactDisco/ContactDisco.php
  4. 11
      app/widgets/Menu/Menu.php
  5. 4
      database/migrations/20180402145603_create_tags_table.php

53
app/Post.php

@ -15,12 +15,18 @@ class Post extends Model
private $titleLimit = 200;
public $attachments = [];
public $tags = [];
public function contact()
{
return $this->hasOne('App\Contact', 'id', 'aid');
}
public function tags()
{
return $this->belongsToMany('App\Tag')->withTimestamps();
}
public function attachments()
{
return $this->hasMany('App\Attachment');
@ -29,8 +35,10 @@ class Post extends Model
public function save(array $options = [])
{
parent::save($options);
$this->attachments()->delete();
$this->attachments()->saveMany($this->attachments);
$this->tags()->sync($this->tags);
}
public function getOpenlinkAttribute()
@ -176,29 +184,28 @@ class Post extends Model
if ($delay) $this->delay = $delay;
// Tags parsing
/*if ($entry->entry->category) {
$td = new \Modl\TagDAO;
$td->delete($this->nodeid);
if ($entry->entry->category) {
if ($entry->entry->category->count() == 1
&& isset($entry->entry->category->attributes()->term)) {
$tag = new \Modl\Tag;
$tag->nodeid = $this->nodeid;
$tag->tag = strtolower((string)$entry->entry->category->attributes()->term);
$td->set($tag);
$tag = \App\Tag::firstOrCreate([
'name' => strtolower((string)$entry->entry->category->attributes()->term)
]);
$this->tags[] = $tag->id;
if ($tag->tag == 'nsfw') $this->nsfw = true;
if ($tag->name == 'nsfw') $this->nsfw = true;
} else {
foreach($entry->entry->category as $cat) {
$tag = new \Modl\Tag;
$tag->nodeid = $this->nodeid;
$tag->tag = strtolower((string)$cat->attributes()->term);
$td->set($tag);
$tag = \App\Tag::firstOrCreate([
'name' => strtolower((string)$cat->attributes()->term)
]);
$this->tags[] = $tag->id;
if ($tag->tag == 'nsfw') $this->nsfw = true;
}
}
}*/
}
if (current(explode('.', $this->server)) == 'nsfw') $this->nsfw = true;
@ -463,11 +470,6 @@ class Post extends Model
|| $this->server == \App\User::me()->id);
}
/*public function isPublic()
{
return ($this->open);
}*/
public function isMicroblog()
{
return ($this->node == "urn:xmpp:microblog:0");
@ -549,29 +551,27 @@ class Post extends Model
public function getComments()
{
/*$pd = new \Modl\PostnDAO;
/*
$comments = $pd->getComments($this);
return $comments ? $comments : [];*/
}
public function countComments()
{
/*$pd = new \Modl\PostnDAO;
/*
return $pd->countComments($this->commentserver, $this->commentnodeid);*/
return 0;
}
public function countLikes()
{
/*$pd = new \Modl\PostnDAO;
return $pd->countLikes($this->commentserver, $this->commentnodeid);*/
//return $pd->countLikes($this->commentserver, $this->commentnodeid);*/
return 0;
}
public function isLiked()
{
/*$pd = new \Modl\PostnDAO;
return $pd->isLiked($this->commentserver, $this->commentnodeid);*/
//return $pd->isLiked($this->commentserver, $this->commentnodeid);*/
return false;
}
@ -582,7 +582,6 @@ class Post extends Model
/*public function countReplies()
{
$pd = new \Modl\PostnDAO;
return $pd->countReplies([
'server' => $this->server,
'node' => $this->node,
@ -609,13 +608,11 @@ class Post extends Model
/*public function getNext()
{
$pd = new PostnDAO;
return $pd->getNext($this->server, $this->node, $this->nodeid);
}
public function getPrevious()
{
$pd = new PostnDAO;
return $pd->getPrevious($this->server, $this->node, $this->nodeid);
}*/
}

15
app/Tag.php

@ -0,0 +1,15 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Tag extends Model
{
protected $fillable = ['name'];
public function posts()
{
return $this->belongsToMany('App\Post')->withTimestamps();
}
}

2
app/widgets/ContactDisco/ContactDisco.php

@ -16,7 +16,7 @@ class ContactDisco extends \Movim\Widget\Base
{
$view = $this->tpl();
$users = App\Contact::where('id', function ($query) {
$users = \App\Contact::where('id', function ($query) {
$query->select('id')
->from('users')
->where('public', true);

11
app/widgets/Menu/Menu.php

@ -43,8 +43,14 @@ class Menu extends \Movim\Widget\Base
// We reload a fresh Post
$post = $pd->get($post->origin, $post->node, $post->nodeid);
if (is_object($post)
&& $post->isComment()
$post = \App\Post::where('server', $post->server)
->where('node', $post->node)
->where('nodeid', $post->nodeid)
->first();
if (!$post) return;
if ($post->isComment()
&& !$post->isMine()) {
$contact = \App\Contact::firstOrNew(['id' => $post->aid]);
Notification::append(
@ -55,7 +61,6 @@ class Menu extends \Movim\Widget\Base
2
);
} elseif ($count > 0
&& is_object($post)
&& (strtotime($post->published) > strtotime($since))) {
if ($post->isMicroblog()) {
$contact = \App\Contact::firstOrNew(['id' => $post->origin]);

4
database/migrations/20180402145603_create_tags_table.php

@ -9,9 +9,11 @@ class CreateTagsTable extends Migration
{
$this->schema->create('tags', function(Blueprint $table) {
$table->increments('id');
$table->string('title', 32);
$table->string('name', 64);
$table->timestamps();
$table->unique('name');
});
$this->schema->create('post_tag', function(Blueprint $table) {

Loading…
Cancel
Save