Skip to content
Snippets Groups Projects
Commit bfaf8083 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

add attachment relationship and is-answered attribute

parent b76a5187
No related branches found
No related tags found
1 merge request!8Vueify messages
......@@ -13,7 +13,7 @@ use JsonApi\JsonApiController;
*/
abstract class BoxController extends JsonApiController
{
protected $allowedIncludePaths = ['sender', 'recipients'];
protected $allowedIncludePaths = ['sender', 'recipients', 'attachments'];
protected $allowedPagingParameters = ['offset', 'limit'];
......
......@@ -10,6 +10,7 @@ class Message extends SchemaProvider
const TYPE = 'messages';
const REL_SENDER = 'sender';
const REL_RECIPIENTS = 'recipients';
const REL_ATTACHMENTS = 'attachments';
public function getId($message): ?string
{
......@@ -25,6 +26,7 @@ class Message extends SchemaProvider
'message' => $message->message,
'mkdate' => date('c', $message->mkdate),
'is-read' => (bool) $message->isRead($user->id),
'is-answered' => (bool) $message->isAnswered($user->id),
'priority' => $message->priority,
'tags' => $message->getTags(),
];
......@@ -38,6 +40,7 @@ class Message extends SchemaProvider
if ($isPrimary) {
$relationships = $this->getSenderRelationship($relationships, $message, $this->shouldInclude($context, self::REL_SENDER));
$relationships = $this->getRecipientsRelationship($relationships, $message, $this->shouldInclude($context, self::REL_RECIPIENTS));
$relationships = $this->getAttachmentsRelationship($relationships, $message, $this->shouldInclude($context, self::REL_ATTACHMENTS));
}
return $relationships;
......@@ -75,4 +78,16 @@ class Message extends SchemaProvider
return $relationships;
}
private function getAttachmentsRelationship(array $relationships, \Message $message, bool $shouldInclude)
{
$attachments = $message->attachment_folder->file_refs;
$relationships[self::REL_ATTACHMENTS] = [
// self::RELATIONSHIP_LINKS_SELF => true,
self::RELATIONSHIP_DATA => $attachments ? $attachments->map(function ($a) { return \FileRef::build(['id' => $a->id], false); }) : [],
];
return $relationships;
}
}
......@@ -21,7 +21,7 @@
* @property string readed database column
* @property string priority database column
* @property SimpleORMapCollection receivers has_many MessageUser
* @property SimpleORMapCollection attachment_folder has_one Folder
* @property Folder $attachment_folder has_one Folder
* @property User author has_one User
* @property MessageUser originator has_one MessageUser
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment