diff --git a/src/Controller/EntryController.php b/src/Controller/EntryController.php index 5be32ee4301efaef13cd42fc99177b7b7951b801..36f464c2d024146d744d1a8d9095e5661b2adbaa 100644 --- a/src/Controller/EntryController.php +++ b/src/Controller/EntryController.php @@ -308,14 +308,14 @@ class EntryController extends AppBaseController 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, [ - Entry::ATTR_DEFINITION, - Entry::ATTR_EXAMPLE, - Entry::ATTR_PRONUNCIATION, - Entry::ATTR_PART_OF_SPEECH, - ])) { +// if (in_array($blockCategory, [ +// Entry::ATTR_DEFINITION, +// Entry::ATTR_EXAMPLE, +// Entry::ATTR_PRONUNCIATION, +// Entry::ATTR_PART_OF_SPEECH, +// ])) { $log = new Log(); $log->setCreatedBy($this->getUser()); @@ -324,7 +324,7 @@ class EntryController extends AppBaseController $log->setBlockCategory($blockCategory); $entry->addLog($log); - } +// } } /** @@ -334,36 +334,21 @@ class EntryController extends AppBaseController { $movedId = $request->get('movedId'); $position = $request->get('position'); - // dump($movedId, $position);die(); + + $oldAttributes = $entry->getAttributes(); $attributes = $entry->getAttributes(); $result = $this->moveBlock($attributes, $movedId, $position); - + if ($oldAttributes != $attributes) { + $this->addBlockLog($entry, 'order'); + } $entry->setAttributes($attributes); $this->em->flush(); 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) { foreach ($attrArray as $key => &$item) { diff --git a/src/Entity/Log.php b/src/Entity/Log.php index f8aa3eea9915fef3234f4ab9ec12028f3bedf57c..615829ad9dc4080640a029c43ae939070767c713 100644 --- a/src/Entity/Log.php +++ b/src/Entity/Log.php @@ -168,7 +168,7 @@ class Log return $this->blockCategory; } - public function setBlockCategory(string $blockCategory): self + public function setBlockCategory(?string $blockCategory): self { $this->blockCategory = $blockCategory; diff --git a/templates/log/_formattedLog.html.twig b/templates/log/_formattedLog.html.twig index 593ccaff232783afbc184de51ab731c6494d9425..c72cf31f0b26830ab455ae1087520f5bef9a1ae9 100644 --- a/templates/log/_formattedLog.html.twig +++ b/templates/log/_formattedLog.html.twig @@ -5,8 +5,12 @@ {% if log.content == 'add' %}{{ 'a ajouté'|trans }}{% endif %} {% if log.content == 'edit' %}{{ 'a modifié'|trans }}{% endif %} {% if log.content == 'delete' %}{{ 'a supprimé'|trans }}{% endif %} - {{ 'un bloc de type'|trans }} - {{ log.blockCategory }} + {% if log.content == 'order' %} + {{ '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')] %}