Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
undelete actions in routing and controller
updates on twig

modified threads_list

 try to fix the formatting changes

try to fix the formatting changes

fixed an extra space

removed delete method

readded docs

hmm bad at english

cs

cs

cs

lol

added new  line to end of file

updated tabs in threads list

updates

added function

small updates
  • Loading branch information
michiel authored and Miliooo committed Oct 16, 2013
commit bfb64e98c3ccc24e3f8e97a869903faa5d924acd
20 changes: 19 additions & 1 deletion Controller/MessageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function inboxAction()
}

/**
* Displays the authenticated participant sent mails
* Displays the authenticated participant messages sent
*
* @return Response
*/
Expand Down Expand Up @@ -55,6 +55,7 @@ public function deletedAction()
* Displays a thread, also allows to reply to it
*
* @param string $threadId the thread id
*
* @return Response
*/
public function threadAction($threadId)
Expand Down Expand Up @@ -101,6 +102,7 @@ public function newThreadAction()
* Deletes a thread
*
* @param string $threadId the thread id
*
* @return RedirectResponse
*/
public function deleteAction($threadId)
Expand All @@ -111,6 +113,22 @@ public function deleteAction($threadId)

return new RedirectResponse($this->container->get('router')->generate('fos_message_inbox'));
}

/**
* Undeletes a thread
*
* @param string $threadId
*
* @return RedirectResponse
*/
public function undeleteAction($threadId)
{
$thread = $this->getProvider()->getThread($threadId);
$this->container->get('fos_message.deleter')->markAsUndeleted($thread);
$this->container->get('fos_message.thread_manager')->saveThread($thread);

return new RedirectResponse($this->container->get('router')->generate('fos_message_inbox'));
}

/**
* Searches for messages in the inbox and sentbox
Expand Down
1 change: 1 addition & 0 deletions Resources/config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<service id="fos_message.twig_extension.default" class="FOS\MessageBundle\Twig\Extension\MessageExtension" public="false">
<argument type="service" id="fos_message.participant_provider" />
<argument type="service" id="fos_message.provider" />
<argument type="service" id="fos_message.authorizer" />
<tag name="twig.extension" alias="fos_message" />
</service>

Expand Down
5 changes: 5 additions & 0 deletions Resources/config/routing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
<default key="_controller">FOSMessageBundle:Message:delete</default>
<requirement key="_method">POST|DELETE</requirement>
</route>

<route id="fos_message_thread_undelete" pattern="/{threadId}/undelete">
<default key="_controller">FOSMessageBundle:Message:undelete</default>
<requirement key="_method">POST</requirement>
</route>

<route id="fos_message_thread_view" pattern="/{threadId}">
<default key="_controller">FOSMessageBundle:Message:thread</default>
Expand Down
1 change: 1 addition & 0 deletions Resources/translations/FOSMessageBundle.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ on: On %date%
by: By %sender%
no_thread: There is no thread to show
delete: Delete
undelete: Undelete
15 changes: 12 additions & 3 deletions Resources/views/Message/threads_list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,18 @@
{% endif %}
</td>
<td>
<form action="{{ url('fos_message_thread_delete', {'threadId': thread.id}) }}" method="post">
<input type="submit" value="{% trans from 'FOSMessageBundle' %}delete{% endtrans %}" />
</form>
{% if fos_message_can_delete_thread(thread) %}
{% if fos_message_deleted_by_participant(thread) %}
{% set formAction %}{{ url('fos_message_thread_undelete', {'threadId': thread.id}) }}{% endset %}
{% set submitValue %}{% trans from 'FOSMessageBundle' %}undelete{% endtrans %}{% endset %}
{% else %}
{% set formAction %}{{ url('fos_message_thread_delete', {'threadId': thread.id}) }}{% endset %}
{% set submitValue %}{% trans from 'FOSMessageBundle' %}delete{% endtrans %}{% endset %}
{% endif %}
<form action="{{ formAction }}" method="post">
<input type="submit" value="{{ submitValue }}" />
</form>
{% endif %}
</td>
</tr>
{% endfor %}
Expand Down
35 changes: 33 additions & 2 deletions Twig/Extension/MessageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
use FOS\MessageBundle\Security\ParticipantProviderInterface;
use FOS\MessageBundle\Model\ReadableInterface;
use FOS\MessageBundle\Provider\ProviderInterface;
use FOS\MessageBundle\Model\ThreadInterface;
use FOS\MessageBundle\Security\AuthorizerInterface;

class MessageExtension extends \Twig_Extension
{
protected $participantProvider;
protected $provider;
protected $authorizer;

protected $nbUnreadMessagesCache;

public function __construct(ParticipantProviderInterface $participantProvider, ProviderInterface $provider)
public function __construct(ParticipantProviderInterface $participantProvider, ProviderInterface $provider, AuthorizerInterface $authorizer)
{
$this->participantProvider = $participantProvider;
$this->provider = $provider;
$this->authorizer = $authorizer;
}

/**
Expand All @@ -28,7 +32,9 @@ public function getFunctions()
{
return array(
'fos_message_is_read' => new \Twig_Function_Method($this, 'isRead'),
'fos_message_nb_unread' => new \Twig_Function_Method($this, 'getNbUnread')
'fos_message_nb_unread' => new \Twig_Function_Method($this, 'getNbUnread'),
'fos_message_can_delete_thread' => new \Twig_Function_Method($this, 'canDeleteThread'),
'fos_message_deleted_by_participant' => new \Twig_Function_Method($this, 'isThreadDeletedByParticipant')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably be a Twig test rather than a twig function

);
}

Expand All @@ -41,6 +47,31 @@ public function isRead(ReadableInterface $readable)
{
return $readable->isReadByParticipant($this->getAuthenticatedParticipant());
}


/**
* Checks if the participant can mark a thread as deleted
*
* @param ThreadInterface $thread
*
* @return boolean true if participant can mark a thread as deleted, false otherwise
*/
public function canDeleteThread(ThreadInterface $thread)
{
return $this->authorizer->canDeleteThread($thread);
}

/**
* Checks if the participant has marked the thread as deleted
*
* @param ThreadInterface $thread
*
* @return boolean true if participant has marked the thread as deleted, false otherwise
*/
public function isThreadDeletedByParticipant(ThreadInterface $thread)
{
return $thread->isDeletedByParticipant($this->getAuthenticatedParticipant());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect indenting

}

/**
* Gets the number of unread messages for the current user
Expand Down