Added the UserDataSpan Twig extension

This Twig extension can filter User entities, creating a HTML <span>
element from them with the class userdata, which can later be converted
to an AJAX tooltip with jquery.cluetip

Signed-off-by: Gergely Polonkai <polesz@w00d5t0ck.info>
This commit is contained in:
Polonkai Gergely 2012-08-01 01:15:10 +02:00
parent fe41e755f7
commit ac6467f649
16 changed files with 85 additions and 14 deletions

View File

@ -21,7 +21,7 @@
{% for request in group.members %} {% for request in group.members %}
{% if not group.isMember(request.user) %} {% if not group.isMember(request.user) %}
<tr> <tr>
<td colspan="2">{{ request.user.displayName }}</td> <td colspan="2">{{ request.user|userdataspan }}</td>
<td> <td>
<form method="post" action="{{ path('KekRozsakAdminBundle_groupJoinRequests') }}"> <form method="post" action="{{ path('KekRozsakAdminBundle_groupJoinRequests') }}">
<input type="hidden" name="user" value="{{ request.user.id }}" /> <input type="hidden" name="user" value="{{ request.user.id }}" />

View File

@ -19,7 +19,7 @@
<tr> <tr>
<td>{{ user.username }}</td> <td>{{ user.username }}</td>
<td>{{ user.email }}</td> <td>{{ user.email }}</td>
<td>{{ user.displayName }}</td> <td>{{ user|userdataspan }}</td>
<td>{{ user.registeredAt|date('Y-m-d H:i') }}</td> <td>{{ user.registeredAt|date('Y-m-d H:i') }}</td>
<td> <td>
<form method="post" action=""> <form method="post" action="">

View File

@ -8,6 +8,6 @@
<p class="forras">Forrás: {{ article.source }}</p> <p class="forras">Forrás: {{ article.source }}</p>
{% endif %} {% endif %}
{% if app.user %} {% if app.user %}
<p class="szerzo">{{ article.createdBy.displayName }}</p> <p class="szerzo">{{ article.createdBy|userdataspan }}</p>
{% endif %} {% endif %}
{% endblock content %} {% endblock content %}

View File

@ -7,5 +7,5 @@
{{ document.title }}{% if document.createdBy == app.user %} [ <a href="{{ path('KekRozsakFrontBundle_documentEdit', {slug: document.slug}) }}">Szerkesztés</a> ] {% endif %} {{ document.title }}{% if document.createdBy == app.user %} [ <a href="{{ path('KekRozsakFrontBundle_documentEdit', {slug: document.slug}) }}">Szerkesztés</a> ] {% endif %}
</h3> </h3>
{{ document.content|raw }} {{ document.content|raw }}
<div class="szerzo">{{ document.createdBy.displayName }}</div> <div class="szerzo">{{ document.createdBy|userdataspan }}</div>
{% endblock content %} {% endblock content %}

View File

@ -5,14 +5,14 @@
{% block content %} {% block content %}
<h3>Esemény - {{ event.title }}</h3> <h3>Esemény - {{ event.title }}</h3>
<p class="esemeny-idopont">{{ event.startDate|date('Y-m-d') }} {{ event.startTime|date('H:i') }}{% if event.endDate or event.endTime %} - {% endif %}{% if event.endDate is not null %} {{ event.endDate|date('Y-m-d') }}{% endif %}{% if event.endTime is not null %} {{ event.endTime|date('H:i') }}{% endif %}</p> <p class="esemeny-idopont">{{ event.startDate|date('Y-m-d') }} {{ event.startTime|date('H:i') }}{% if event.endDate or event.endTime %} - {% endif %}{% if event.endDate is not null %} {{ event.endDate|date('Y-m-d') }}{% endif %}{% if event.endTime is not null %} {{ event.endTime|date('H:i') }}{% endif %}</p>
<p class="esemeny-szervezo">Az eseményt szervezi: {{ event.createdBy.displayName }}</p> <p class="esemeny-szervezo">Az eseményt szervezi: {{ event.createdBy|userdataspan }}</p>
<p> <p>
{{ event.description }} {{ event.description }}
</p> </p>
<h4>Eddigi résztvevők</h4> <h4>Eddigi résztvevők</h4>
<ul> <ul>
{% for attendee in event.attendees %} {% for attendee in event.attendees %}
<li>{{ attendee.displayName }}</li> <li>{{ attendee|userdataspan }}</li>
{% endfor %} {% endfor %}
</ul> </ul>
{% if not event.isAttending(app.user) %} {% if not event.isAttending(app.user) %}

View File

@ -33,7 +33,7 @@
{{ post.createdAt|date('Y-m-d') }}<br /> {{ post.createdAt|date('Y-m-d') }}<br />
{{ post.createdAt|date('H:i') }}<br /> {{ post.createdAt|date('H:i') }}<br />
[avatar]<br /> [avatar]<br />
{{ post.createdBy.displayName }}<br /> {{ post.createdBy|userdataspan }}<br />
Szint<br /> Szint<br />
<br /> <br />
Tagság kezdete:<br /> Tagság kezdete:<br />

View File

@ -22,7 +22,7 @@
<td></td> <td></td>
<td> <td>
{% if topic.lastPost %} {% if topic.lastPost %}
{{ topic.lastPost.createdBy.displayName }}<br /> {{ topic.lastPost.createdBy|userdataspan }}<br />
{{ topic.lastPost.createdAt|date('Y-m-d H:i') }} {{ topic.lastPost.createdAt|date('Y-m-d H:i') }}
{% else %} {% else %}
&nbsp;<br />&nbsp; &nbsp;<br />&nbsp;

View File

@ -20,7 +20,7 @@
<td></td> <td></td>
<td> <td>
{% if topic.lastPost %} {% if topic.lastPost %}
{{ topic.lastPost.createdBy.displayName }}<br /> {{ topic.lastPost.createdBy|userdataspan }}<br />
{{ topic.lastPost.createdAt|date('Y-m-d H:i') }} {{ topic.lastPost.createdAt|date('Y-m-d H:i') }}
{% else %} {% else %}
&nbsp;<br />&nbsp; &nbsp;<br />&nbsp;

View File

@ -23,7 +23,7 @@
<td>[ikon]</td> <td>[ikon]</td>
<td><a href="{{ path('KekRozsakFrontBundle_documentView', {slug: document.slug}) }}">{{ document.title }}</a></td> <td><a href="{{ path('KekRozsakFrontBundle_documentView', {slug: document.slug}) }}">{{ document.title }}</a></td>
<td> <td>
{{ document.createdBy.displayName }}<br /> {{ document.createdBy|userdataspan }}<br />
{{ document.createdAt|date('Y-m-d H:i') }} {{ document.createdAt|date('Y-m-d H:i') }}
</td> </td>
</tr> </tr>

View File

@ -5,9 +5,9 @@
{% block content %} {% block content %}
<h3>Jelentkezés</h3> <h3>Jelentkezés</h3>
{% if isRequested %} {% if isRequested %}
Már jelentkeztél ebbe a csoportba ({{ group.name }}), de {{ group.leader.displayName }} még nem hagyta jóvá a belépésedet. Már jelentkeztél ebbe a csoportba ({{ group.name }}), de {{ group.leader|userdataspan }} még nem hagyta jóvá a belépésedet.
{% endif %} {% endif %}
{% if needApproval %} {% if needApproval %}
A csoportba való jelentkezésedről a csoport vezetőjét ({{ group.leader.displayName }}) értesítettük. A csoportba való jelentkezésedről a csoport vezetőjét ({{ group.leader|userdataspan }}) értesítettük.
{% endif %} {% endif %}
{% endblock content %} {% endblock content %}

View File

@ -34,7 +34,7 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
</td> </td>
<td>{% if group.leader %}{{ group.leader.displayName }}{% else %}Nincs{% endif %}</td> <td>{% if group.leader %}{{ group.leader|userdataspan }}{% else %}Nincs{% endif %}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>

View File

@ -14,7 +14,7 @@
<ul> <ul>
{% for user in group.members %} {% for user in group.members %}
{% if group.isMember(user.user) %} {% if group.isMember(user.user) %}
<li>{{ user.user.displayName }}</li> <li>{{ user.user|userdataspan }}</li>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</ul> </ul>

View File

@ -4,7 +4,9 @@ namespace KekRozsak\SecurityBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\Security\Core\SecurityContext; use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserInterface;
@ -121,4 +123,17 @@ class DefaultController extends Controller
return array( return array(
); );
} }
/**
* @Route("/profil/{id}/ajax-felhasznalo-info.{_format}", name="KekRozsakSecurityBundle_ajaxUserdata", requirements={"_format": "html"})
* @Method({"GET"})
* @Template()
* @ParamConverter("user")
*/
public function ajaxUserdataAction(User $user)
{
return array(
'user' => $user,
);
}
} }

View File

@ -8,5 +8,10 @@
<argument type="service" id="doctrine" /> <argument type="service" id="doctrine" />
<tag name="kernel.event_listener" event="security.authentication.success" /> <tag name="kernel.event_listener" event="security.authentication.success" />
</service> </service>
<service id="kek_rozsak_security.twig_extension.userdataspan" class="KekRozsak\SecurityBundle\Twig\UserDataSpanExtension">
<argument type="service" id="service_container" />
<argument type="service" id="security.context" />
<tag name="twig.extension" />
</service>
</services> </services>
</container> </container>

View File

@ -0,0 +1,10 @@
{# vim: ft=htmljinja
#}
<html>
<head>
<title>{{ user.displayName }}</title>
</head>
<body>
Tagság kezdete: {{ user.registeredAt|date('Y-m-d') }}
</body>
</html>

View File

@ -0,0 +1,41 @@
<?php
namespace KekRozsak\SecurityBundle\Twig;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use KekRozsak\SecurityBundle\Entity\User;
class UserDataSpanExtension extends \Twig_Extension
{
protected $_securityContext;
protected $_serviceContainer;
public function __construct(ContainerInterface $container, SecurityContextInterface $security)
{
$this->_serviceContainer = $container;
$this->_securityContext = $security;
}
public function getFilters()
{
return array(
'userdataspan' => new \Twig_Filter_Method($this, 'getUserDataSpan', array('is_safe' => array('html'))),
);
}
public function getUserDataSpan(User $user)
{
if (!is_object($this->_securityContext->getToken()) || !is_object($this->_securityContext->getToken()->getUser()))
return '<span class="userdata-secret" title="|Felhasználó|A felhasználóink kiléte szigorúan bizalmas, csak a tagok számára elérhető.">[nem jelenhet meg]</span>';
return '<span class="userdata" rel="' . $this->_serviceContainer->get('router')->generate('KekRozsakSecurityBundle_ajaxUserdata', array('id' => $user->getId(), '_format' => 'html')) . '">' . $user->getDisplayName() . '</span>';
}
public function getName()
{
return 'twig_userdataspan';
}
}