Renaming log on user page. newLogin property deleted from UserRenameEvent entity. New migration.

This commit is contained in:
Alexey Skobkin 2016-03-29 03:58:33 +03:00
parent 13e35d939d
commit 9b052cc97e
6 changed files with 89 additions and 41 deletions

View File

@ -0,0 +1,34 @@
<?php
namespace Application\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20160329035248 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE users.rename_log DROP new_login');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE users.rename_log ADD new_login TEXT DEFAULT \'\'');
}
}

View File

@ -32,7 +32,8 @@ class UserController extends Controller
return $this->render('SkobkinPointToolsBundle:User:show.html.twig', [
'user' => $user,
'subscribers' => $em->getRepository('SkobkinPointToolsBundle:User')->findUserSubscribersById($user->getId()),
'log' => $em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->getUserLastSubscribersEventsById($user, 10),
'subscriptions_log' => $em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->getUserLastSubscribersEventsById($user, 10),
'rename_log' => $em->getRepository('SkobkinPointToolsBundle:UserRenameEvent')->findBy(['user' => $user], ['date' => 'DESC'], 10),
'avatar_url' => $userApi->getAvatarUrl($user, UserApi::AVATAR_SIZE_LARGE),
]);
}

View File

@ -47,19 +47,11 @@ class UserRenameEvent
*/
private $oldLogin;
/**
* @var string
*
* @ORM\Column(name="new_login", type="text")
*/
private $newLogin;
public function __construct(User $user, $old, $new)
public function __construct(User $user, $old)
{
$this->user = $user;
$this->oldLogin = $old;
$this->newLogin = $new;
}
/**
@ -126,29 +118,6 @@ class UserRenameEvent
return $this->oldLogin;
}
/**
* Set newLogin
*
* @param string $newLogin
* @return UserRenameEvent
*/
public function setNewLogin($newLogin)
{
$this->newLogin = $newLogin;
return $this;
}
/**
* Get newLogin
*
* @return string
*/
public function getNewLogin()
{
return $this->newLogin;
}
/**
* Set user
*

View File

@ -36,10 +36,7 @@ class UserRenameSubscriber implements EventSubscriber
}
if ($event->hasChangedField('login')) {
$old = $event->getOldValue('login');
$new = $event->getNewValue('login');
$this->items[] = new UserRenameEvent($entity, $old, $new);
$this->items[] = new UserRenameEvent($entity, $event->getOldValue('login'));
}
}

View File

@ -27,9 +27,13 @@ Subscriptions log: Лог подписок
User: Пользователь
Action: Действие
Date: Дата
Rename log: Лог переименований
Old login: Старый логин
New login: Новый логин
No subscribers data found: Информация о подписчиках отсутствует
No log data found: Лог отсутствует
No rename log data found: Лог переименований отсутствует
No subscribers log data found: Лог подписчиков отсутствует
# Топ пользователей
Top users: Популярные пользователи

View File

@ -35,8 +35,51 @@
{% endif %}
</div>
<div class="user-rename-log">
{% if rename_log|length > 0 %}
<div class="panel-group" id="accordion-log">
<div class="panel panel-default">
<div class="panel-heading" id="heading-subscriptions-log">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion-log" aria-expanded="true" href="#collapse-log">
<span class="glyphicon glyphicon-collapse-down"></span> {{ 'Rename log'|trans }}
</a>
</h4>
</div>
<div id="collapse-log" class="panel-collapse collapse in" aria-labelledby="heading-subscriptions-log">
<div class="panel-body">
<table class="table table-striped">
<thead>
<tr>
<td>{{ 'Date'|trans }}</td>
<td>{{ 'Old login'|trans }}</td>
</tr>
</thead>
<tbody>
{% for event in rename_log %}
<tr>
<td>
{# @todo Use DateTime helper: https://sonata-project.org/bundles/intl/master/doc/reference/datetime.html #}
{{ event.date|date('d F Y H:i:s') }}
</td>
<td>
{{ event.oldLogin }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
{% else %}
<div class="alert alert-warning" role="alert">{{ 'No rename log data found'|trans }}</div>
{% endif %}
</div>
<div class="user-subscriptions-log">
{% if log|length > 0 %}
{% if subscriptions_log|length > 0 %}
<div class="panel-group" id="accordion-log">
<div class="panel panel-default">
<div class="panel-heading" id="heading-subscriptions-log">
@ -57,7 +100,7 @@
</tr>
</thead>
<tbody>
{% for event in log %}
{% for event in subscriptions_log %}
<tr>
<td>
<a href="{{ url('user_show', {login: event.subscriber.login}) }}">@{{ event.subscriber.login }}</a>
@ -78,7 +121,7 @@
</div>
</div>
{% else %}
<div class="alert alert-warning" role="alert">{{ 'No log data found'|trans }}</div>
<div class="alert alert-warning" role="alert">{{ 'No subscribers log data found'|trans }}</div>
{% endif %}
</div>