Here is my message object. This is a class that defines messages between users in my application.
class Message { protected $id; protected $title; protected $receiver; protected $sender; protected $content; protected $sentAt; protected $isSpam = false; protected $seenAt = null; protected $replyof; private $replies; public function __construct() { $this->replies = new ArrayCollection(); }
It is important to note the replyof variable, which tells which message is the parent of the message. If it is NULL, the message is not a response, it is the parent message (root).
And the messages variable, which is an array of messages that respond to a message. These answers may have the answers themselves. This array can also be NULL for leaf nodes because they have no answer.
All other variables contain only some fields that define the actual message between two users.
What I'm trying to do is show in Twig all my dungeon messages, for example:
message1 - root message, reply of none, but has replies reply1 - first reply of message 1 reply1 first reply of reply 1 of message 1, leaf with no further replies reply2 - second reply of message 1, leaf with no further replies message2 - root message, no replies and a reply of none
The problem is that Twig only supports foreach loops, and I'm not sure how to display this format when it has a higher depth, more than two.
{% for reply in message.replies %} <li> sent by: {{ reply.sender }} </li> <li> title: {{ reply.title }} </li> <li> content: {{ reply.content }} </li> <li> date: {{ reply.sentAt|date('dmY H:i:s') }} </li> <hr> {% endfor %}
Each message reply will be displayed, but how can I display the attached messages to the full depth?