Clean up post type API

This commit is contained in:
Toby Zerner 2015-05-05 14:28:40 +09:30
parent ee1302c9ef
commit 2e2617e5b0
4 changed files with 20 additions and 7 deletions

View File

@ -113,8 +113,8 @@ class CoreServiceProvider extends ServiceProvider
public function registerPostTypes()
{
Post::addType('comment', 'Flarum\Core\Models\CommentPost');
Post::addType('discussionRenamed', 'Flarum\Core\Models\DiscussionRenamedPost');
Post::addType('Flarum\Core\Models\CommentPost');
Post::addType('Flarum\Core\Models\DiscussionRenamedPost');
CommentPost::setFormatter($this->app['flarum.formatter']);
}

View File

@ -8,6 +8,13 @@ use Flarum\Core\Events\PostWasRestored;
class CommentPost extends Post
{
/**
* The type of post this is, to be stored in the posts table.
*
* @var string
*/
public static $type = 'comment';
/**
* The text formatter instance.
*

View File

@ -2,6 +2,13 @@
class DiscussionRenamedPost extends ActivityPost
{
/**
* The type of post this is, to be stored in the posts table.
*
* @var string
*/
public static $type = 'discussionRenamed';
/**
* Merge the post into another post of the same type.
*
@ -35,7 +42,6 @@ class DiscussionRenamedPost extends ActivityPost
$post->time = time();
$post->discussion_id = $discussionId;
$post->user_id = $userId;
$post->type = 'discussionRenamed';
return $post;
}

View File

@ -58,6 +58,7 @@ class Post extends Model
parent::boot();
static::creating(function ($post) {
$post->type = $post::$type;
$post->number = ++$post->discussion->number_index;
$post->discussion->save();
});
@ -161,13 +162,12 @@ class Post extends Model
/**
* Register a post type and its model class.
*
* @param string $type
* @param string $class
* @return void
*/
public static function addType($type, $class)
public static function addType($class)
{
static::$types[$type] = $class;
static::$types[$class::$type] = $class;
}
public static function getTypes()