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

Ajouts logs modifs blocs entrées. Ajout log approbation mot Agora

parent 3dd1c265
No related branches found
No related tags found
No related merge requests found
...@@ -507,7 +507,6 @@ class AppBaseController extends AbstractController ...@@ -507,7 +507,6 @@ class AppBaseController extends AbstractController
$log = new Log(); $log = new Log();
$log->setCategory($category); $log->setCategory($category);
$log->setCreatedBy($this->getUser()); $log->setCreatedBy($this->getUser());
$log->setContent((string) $entry);
$log->setLexicon($entry->getLexicon()); $log->setLexicon($entry->getLexicon());
$log->setEntry($entry); $log->setEntry($entry);
...@@ -528,8 +527,13 @@ class AppBaseController extends AbstractController ...@@ -528,8 +527,13 @@ class AppBaseController extends AbstractController
$log = new Log(); $log = new Log();
$log->setCategory($category); $log->setCategory($category);
$log->setCreatedBy($this->getUser()); $log->setCreatedBy($this->getUser());
$log->setContent((string) $label);
$log->setLabel($label); $log->setLabel($label);
$info = [];
$info['label_id'] = $label->getLexicon()->getId();
$info['label_name'] = $label->getName();
$log->setAdditionalInfo($info);
$this->em->persist($log); $this->em->persist($log);
} }
......
...@@ -204,7 +204,7 @@ class EntryController extends AppBaseController ...@@ -204,7 +204,7 @@ class EntryController extends AppBaseController
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$propertyAccessor->setValue($attributes, $blockId, $form->getData()); $propertyAccessor->setValue($attributes, $blockId, $form->getData());
$entry->setAttributes($attributes); $entry->setAttributes($attributes);
$this->addBlockLog($entry, 'edit', $blockCategory); $this->addBlockLog($entry, Log::CATEGORY_ENTRY_EDIT_BLOCK, $blockCategory, $form->getData());
$this->em->flush(); $this->em->flush();
return $this->render('closeModalAndReload.html.twig'); return $this->render('closeModalAndReload.html.twig');
...@@ -243,7 +243,7 @@ class EntryController extends AppBaseController ...@@ -243,7 +243,7 @@ class EntryController extends AppBaseController
$parentBlock[$blockCategory][] = $newBlock; $parentBlock[$blockCategory][] = $newBlock;
$propertyAccessor->setValue($attributes, $blockId, $parentBlock); $propertyAccessor->setValue($attributes, $blockId, $parentBlock);
$entry->setAttributes($attributes); $entry->setAttributes($attributes);
$this->addBlockLog($entry, 'add', $blockCategory); $this->addBlockLog($entry, Log::CATEGORY_ENTRY_ADD_BLOCK, $blockCategory, $form->getData());
$this->em->flush(); $this->em->flush();
return $this->render('closeModalAndReload.html.twig'); return $this->render('closeModalAndReload.html.twig');
...@@ -315,7 +315,7 @@ class EntryController extends AppBaseController ...@@ -315,7 +315,7 @@ class EntryController extends AppBaseController
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$newPos = $form->get('PartOfSpeech')->getData(); $newPos = $form->get('PartOfSpeech')->getData();
$newPosId = $entry->getLanguage(). '_' . $newPos . '_balex'; $newPosId = $entry->getLanguage(). '_' . $newPos . '_balex';
$attributes["Items"][] = [ $newItem = [
"id" => $newPosId, "id" => $newPosId,
"PartOfSpeech" => $newPos, "PartOfSpeech" => $newPos,
"Sense" => [ "Sense" => [
...@@ -327,8 +327,9 @@ class EntryController extends AppBaseController ...@@ -327,8 +327,9 @@ class EntryController extends AppBaseController
] ]
] ]
]; ];
$attributes["Items"][] = $newItem;
$entry->setAttributes($attributes); $entry->setAttributes($attributes);
$this->addBlockLog($entry, 'add', Entry::ATTR_PART_OF_SPEECH); $this->addBlockLog($entry, Log::CATEGORY_ENTRY_ADD_BLOCK, Entry::ATTR_PART_OF_SPEECH, $newItem);
$this->em->flush(); $this->em->flush();
return $this->render('closeModalAndReload.html.twig'); return $this->render('closeModalAndReload.html.twig');
...@@ -355,33 +356,36 @@ class EntryController extends AppBaseController ...@@ -355,33 +356,36 @@ class EntryController extends AppBaseController
$parentId = $matches[1]; $parentId = $matches[1];
$childId = $matches[2]; $childId = $matches[2];
$parentBlock = $propertyAccessor->getValue($attributes, $parentId); $parentBlock = $propertyAccessor->getValue($attributes, $parentId);
$content = $parentBlock[$childId];
unset($parentBlock[$childId]); unset($parentBlock[$childId]);
$propertyAccessor->setValue($attributes, $parentId, $parentBlock); $propertyAccessor->setValue($attributes, $parentId, $parentBlock);
$entry->setAttributes($attributes); $entry->setAttributes($attributes);
$this->addBlockLog($entry, 'delete', $blockCategory); $this->addBlockLog($entry, Log::CATEGORY_ENTRY_DELETE_BLOCK, $blockCategory, $content);
$this->em->flush(); $this->em->flush();
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 = null) public function addBlockLog(Entry $entry, $category, $blockCategory = null, $content = null)
{ {
// if (in_array($blockCategory, [ $log = new Log();
// Entry::ATTR_DEFINITION, $log->setCategory($category);
// Entry::ATTR_EXAMPLE, $log->setBlockCategory($blockCategory);
// Entry::ATTR_PRONUNCIATION, $log->setCreatedBy($this->getUser());
// Entry::ATTR_PART_OF_SPEECH, $log->setLexicon($entry->getLexicon());
// ])) { $log->setEntry($entry);
$log = new Log(); $info = [];
$log->setCreatedBy($this->getUser()); $info['blockCategory'] = $blockCategory;
$log->setContent($type); $info['entry_id'] = $entry->getId();
$log->setCategory(Log::CATEGORY_UPDATE_ENTRY); $info['graphy'] = (string) $entry;
$log->setBlockCategory($blockCategory); if ($content) {
$info['content'] = $content;
$entry->addLog($log); }
// } $log->setAdditionalInfo($info);
$this->em->persist($log);
} }
/** /**
...@@ -399,7 +403,7 @@ class EntryController extends AppBaseController ...@@ -399,7 +403,7 @@ class EntryController extends AppBaseController
$result = $this->moveBlock($attributes, $movedId, $position); $result = $this->moveBlock($attributes, $movedId, $position);
if ($oldAttributes != $attributes) { if ($oldAttributes != $attributes) {
$this->addBlockLog($entry, 'order'); $this->addBlockLog($entry, Log::CATEGORY_ENTRY_REORDER_BLOCK, null, ['movedId' => $movedId, 'position' => $position]);
} }
$entry->setAttributes($attributes); $entry->setAttributes($attributes);
$this->em->flush(); $this->em->flush();
...@@ -469,7 +473,7 @@ class EntryController extends AppBaseController ...@@ -469,7 +473,7 @@ class EntryController extends AppBaseController
] ]
]; ];
$entry->setAttributes($attributes); $entry->setAttributes($attributes);
$this->addBlockLog($entry, 'add', Entry::ATTR_PART_OF_SPEECH); $this->addBlockLog($entry, Log::CATEGORY_ENTRY_ADD_BLOCK, Entry::ATTR_PART_OF_SPEECH, $attributes);
$this->em->flush(); $this->em->flush();
return $this->render('closeModalAndReload.html.twig'); return $this->render('closeModalAndReload.html.twig');
......
...@@ -185,6 +185,13 @@ class UpdateRequestController extends AppBaseController ...@@ -185,6 +185,13 @@ class UpdateRequestController extends AppBaseController
$vote->setUser($this->getUser()); $vote->setUser($this->getUser());
$this->em->persist($vote); $this->em->persist($vote);
$updateRequest->addVote($vote); $updateRequest->addVote($vote);
$this->logManager->add([
'category' => Log::CATEGORY_ENTRY_APPROVE_NEW_WORD,
'entry' => $entry,
'additionalInfo' => ['entry_id' => $entry->getId(), 'graphy' => (string) $entry],
]);
$this->em->flush(); $this->em->flush();
if (count($updateRequest->getVotesFor()) >= $_ENV['ENTRY_APPROVAL_NB']) { if (count($updateRequest->getVotesFor()) >= $_ENV['ENTRY_APPROVAL_NB']) {
......
...@@ -64,19 +64,16 @@ class Log ...@@ -64,19 +64,16 @@ class Log
const CATEGORY_REMOVE_LABEL_FROM_WORD = 'remove_label_from_word'; const CATEGORY_REMOVE_LABEL_FROM_WORD = 'remove_label_from_word';
const CATEGORY_EDIT_LEXICON_DESCRIPTION = 'edit_lexicon_description'; const CATEGORY_EDIT_LEXICON_DESCRIPTION = 'edit_lexicon_description';
const CATEGORY_ADD_COMMENT = 'add_comment'; const CATEGORY_ADD_COMMENT = 'add_comment'; // On utilise plutôt CATEGORY_ENTRY_ADD_BLOCK avec $blockCategory = 'Comments'
const CATEGORY_DELETE_COMMENT = 'delete_comment'; const CATEGORY_DELETE_COMMENT = 'delete_comment'; // On utilise plutôt CATEGORY_ENTRY_DELETE_BLOCK avec $blockCategory = 'Comments
const CATEGORY_ENTRY_UPDATE_BLOCK = 'entry_update_block'; const CATEGORY_ENTRY_EDIT_BLOCK = 'entry_edit_block';
const CATEGORY_ENTRY_CREATE_BLOCK = 'entry_create_block'; const CATEGORY_ENTRY_ADD_BLOCK = 'entry_add_block';
const CATEGORY_ENTRY_DELETE_BLOCK = 'entry_delete_block'; const CATEGORY_ENTRY_DELETE_BLOCK = 'entry_delete_block';
const CATEGORY_SHOW_ENTRY_OTHER_LEXICON = 'show_entry_other_lexicon'; const CATEGORY_ENTRY_REORDER_BLOCK = 'entry_reorder_block';
const CATEGORY_SHOW_ENTRY_OTHER_LEXICON = 'show_entry_other_lexicon'; // Plutôt front pour ne pas loguer à chaque fois qu'on recharge la page
const CATEGORY_ENTRY_APPROVE_NEW_WORD = 'entry_approve_new_word'; const CATEGORY_ENTRY_APPROVE_NEW_WORD = 'entry_approve_new_word';
const CATEGORY_COPY_ENTRY = 'copy_entry';
const CATEGORY_COPY_ENTRY_OF_THE_DAY = 'copy_entry_of_the_day';
const CATEGORY_UPDATE_ENTRY = 'update_entry'; // TODO conservzer ?
const CATEGORY_COPY_ENTRY = 'copy_entry';
const CATEGORY_COPY_ENTRY_OF_THE_DAY = 'copy_entry_of_the_day';
// TODO supprimer // TODO supprimer
const CATEGORY_UPDATE_COMMENT = 'update_comment'; const CATEGORY_UPDATE_COMMENT = 'update_comment';
......
{% if log.category == constant('App\\Entity\\Log::CATEGORY_UPDATE_ENTRY') %} {{ log.createdAt|date('d/m/Y') }} :
{{ log.createdBy }}
{{ log.createdAt|date('d/m/Y') }} : {% if log.category == constant('App\\Entity\\Log::CATEGORY_ENTRY_ADD_BLOCK') %}
{{ log.createdBy }} {{ 'a ajouté'|trans }} {{ 'un bloc de type'|trans }} {{ log.blockCategory }}
{% if log.content == 'add' %}{{ 'a ajouté'|trans }}{% endif %}
{% if log.content == 'edit' %}{{ 'a modifié'|trans }}{% endif %}
{% if log.content == 'delete' %}{{ 'a supprimé'|trans }}{% endif %}
{% 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')] %} {% elseif log.category == constant('App\\Entity\\Log::CATEGORY_ENTRY_EDIT_BLOCK') %}
{{ 'a modifié'|trans }} {{ 'un bloc de type'|trans }} {{ log.blockCategory }}
{{ log.createdAt|date('d/m/Y') }} : {% elseif log.category == constant('App\\Entity\\Log::CATEGORY_ENTRY_DELETE_BLOCK') %}
{{ log.createdBy }} {{ 'a supprimé'|trans }} {{ 'un bloc de type'|trans }} {{ log.blockCategory }}
{% if log.category == constant('App\\Entity\\Log::CATEGORY_ADD_ENTRY') %}{{ "a ajouté l'entrée"|trans }}{% endif %}
{% if log.category == constant('App\\Entity\\Log::CATEGORY_DELETE_ENTRY') %}{{ "a supprimé l'entrée"|trans }}{% endif %} {% elseif log.category == constant('App\\Entity\\Log::CATEGORY_ENTRY_REORDER_BLOCK') %}
« {{ log.content }} » {{ "a réordonné les blocs de l'entrée"|trans }} « {{ log.additionalInfo['graphy'] }} »
{% elseif log.category == constant('App\\Entity\\Log::CATEGORY_ADD_ENTRY') %}
{{ "a ajouté l'entrée"|trans }} « {{ log.additionalInfo['graphy'] }} »
{% elseif log.category == constant('App\\Entity\\Log::CATEGORY_DELETE_ENTRY') %}
{{ "a supprimé l'entrée"|trans }} « {{ log.additionalInfo['graphy'] }} »
{% endif %} {% endif %}
\ No newline at end of file
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