mirror of
https://github.com/flarum/core.git
synced 2025-10-10 14:34:30 +02:00
Upgrade to JSON-API RC3 + latest version of tobscure/json-api
Note: npm source for ember-json-api changed to a fork, but I still had to apply a custom change to get polymorphic relationships to work (see https://github.com/kurko/ember-json-api/pull/71#issuecomment-85257281)
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
<?php namespace Flarum\Api\Serializers;
|
||||
|
||||
use Flarum\Core\Models\Activity;
|
||||
|
||||
class ActivitySerializer extends BaseSerializer
|
||||
{
|
||||
/**
|
||||
* The resource type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'activity';
|
||||
@@ -16,50 +15,30 @@ class ActivitySerializer extends BaseSerializer
|
||||
* @param Activity $activity The Activity model to serialize.
|
||||
* @return array
|
||||
*/
|
||||
protected function attributes(Activity $activity)
|
||||
protected function attributes($activity)
|
||||
{
|
||||
$attributes = [
|
||||
'id' => ((int) $activity->id) ?: str_random(5),
|
||||
'type' => $activity->type,
|
||||
'contentType' => $activity->type,
|
||||
'content' => json_encode($activity->data),
|
||||
'time' => $activity->time->toRFC3339String()
|
||||
];
|
||||
|
||||
return $this->attributesEvent($activity, $attributes);
|
||||
return $this->extendAttributes($activity, $attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a resource containing an activity's sender.
|
||||
*
|
||||
* @param Activity $activity
|
||||
* @return Tobscure\JsonApi\Resource
|
||||
*/
|
||||
public function linkUser(Activity $activity)
|
||||
public function user()
|
||||
{
|
||||
return (new UserBasicSerializer)->resource($activity->user_id);
|
||||
return $this->hasOne('Flarum\Api\Serializers\UserBasicSerializer');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a resource containing an activity's sender.
|
||||
*
|
||||
* @param Activity $activity
|
||||
* @param array $relations
|
||||
* @return Tobscure\JsonApi\Resource
|
||||
*/
|
||||
public function includeSender(Activity $activity, $relations)
|
||||
public function sender()
|
||||
{
|
||||
return (new UserBasicSerializer($relations))->resource($activity->sender);
|
||||
return $this->hasOne('Flarum\Api\Serializers\UserBasicSerializer');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a resource containing an activity's sender.
|
||||
*
|
||||
* @param Activity $activity
|
||||
* @param array $relations
|
||||
* @return Tobscure\JsonApi\Resource
|
||||
*/
|
||||
public function includePost(Activity $activity, $relations)
|
||||
public function post()
|
||||
{
|
||||
return (new PostSerializer($relations))->resource($activity->post);
|
||||
return $this->hasOne('Flarum\Api\Serializers\PostSerializer');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user