Skip to content
Snippets Groups Projects
Commit a5e1e9a3 authored by Pierre Fleutot's avatar Pierre Fleutot
Browse files

Réordonnement des blocs d'une entrée: ajout d'un log

parent b76dd2cf
No related branches found
No related tags found
No related merge requests found
...@@ -308,14 +308,14 @@ class EntryController extends AppBaseController ...@@ -308,14 +308,14 @@ class EntryController extends AppBaseController
return $this->redirectToRoute('app_entry_show', ['id' => $entry->getId()]); return $this->redirectToRoute('app_entry_show', ['id' => $entry->getId()]);
} }
public function addBlockLog(Entry $entry, $type, $blockCategory) public function addBlockLog(Entry $entry, $type, $blockCategory = null)
{ {
if (in_array($blockCategory, [ // if (in_array($blockCategory, [
Entry::ATTR_DEFINITION, // Entry::ATTR_DEFINITION,
Entry::ATTR_EXAMPLE, // Entry::ATTR_EXAMPLE,
Entry::ATTR_PRONUNCIATION, // Entry::ATTR_PRONUNCIATION,
Entry::ATTR_PART_OF_SPEECH, // Entry::ATTR_PART_OF_SPEECH,
])) { // ])) {
$log = new Log(); $log = new Log();
$log->setCreatedBy($this->getUser()); $log->setCreatedBy($this->getUser());
...@@ -324,7 +324,7 @@ class EntryController extends AppBaseController ...@@ -324,7 +324,7 @@ class EntryController extends AppBaseController
$log->setBlockCategory($blockCategory); $log->setBlockCategory($blockCategory);
$entry->addLog($log); $entry->addLog($log);
} // }
} }
/** /**
...@@ -334,36 +334,21 @@ class EntryController extends AppBaseController ...@@ -334,36 +334,21 @@ class EntryController extends AppBaseController
{ {
$movedId = $request->get('movedId'); $movedId = $request->get('movedId');
$position = $request->get('position'); $position = $request->get('position');
// dump($movedId, $position);die(); // dump($movedId, $position);die();
$oldAttributes = $entry->getAttributes();
$attributes = $entry->getAttributes(); $attributes = $entry->getAttributes();
$result = $this->moveBlock($attributes, $movedId, $position); $result = $this->moveBlock($attributes, $movedId, $position);
if ($oldAttributes != $attributes) {
$this->addBlockLog($entry, 'order');
}
$entry->setAttributes($attributes); $entry->setAttributes($attributes);
$this->em->flush(); $this->em->flush();
return $this->render('entry/show.html.twig', ['entry' => $entry]); return $this->render('entry/show.html.twig', ['entry' => $entry]);
} }
// public function getBlockByIdAndParent($attrArray, $id)
// {
// foreach ($attrArray as $item) {
// if (isset($item['id']) && $item['id'] == $id) {
// return [
// 'block' => $item,
// 'parent' => $attrArray,
// ];
// } elseif (is_array($item)) {
// $result = $this->getBlockByIdAndParent($item, $id);
// if ($result) {
// return $result;
// }
// }
// }
// return false;
// }
public function moveBlock(&$attrArray, $id, $newKey) public function moveBlock(&$attrArray, $id, $newKey)
{ {
foreach ($attrArray as $key => &$item) { foreach ($attrArray as $key => &$item) {
......
...@@ -168,7 +168,7 @@ class Log ...@@ -168,7 +168,7 @@ class Log
return $this->blockCategory; return $this->blockCategory;
} }
public function setBlockCategory(string $blockCategory): self public function setBlockCategory(?string $blockCategory): self
{ {
$this->blockCategory = $blockCategory; $this->blockCategory = $blockCategory;
......
...@@ -5,8 +5,12 @@ ...@@ -5,8 +5,12 @@
{% if log.content == 'add' %}{{ 'a ajouté'|trans }}{% endif %} {% if log.content == 'add' %}{{ 'a ajouté'|trans }}{% endif %}
{% if log.content == 'edit' %}{{ 'a modifié'|trans }}{% endif %} {% if log.content == 'edit' %}{{ 'a modifié'|trans }}{% endif %}
{% if log.content == 'delete' %}{{ 'a supprimé'|trans }}{% endif %} {% if log.content == 'delete' %}{{ 'a supprimé'|trans }}{% endif %}
{{ 'un bloc de type'|trans }} {% if log.content == 'order' %}
{{ log.blockCategory }} {{ 'a réordonné les blocs'|trans }}
{% else %}
{{ 'un bloc de type'|trans }}
{{ log.blockCategory }}
{% endif %}
{% elseif log.category in [constant('App\\Entity\\Log::CATEGORY_ADD_ENTRY'), constant('App\\Entity\\Log::CATEGORY_DELETE_ENTRY')] %} {% elseif log.category in [constant('App\\Entity\\Log::CATEGORY_ADD_ENTRY'), constant('App\\Entity\\Log::CATEGORY_DELETE_ENTRY')] %}
......
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