protected function traceEntity(Docgroup $cloneDocgroup, Docgroup $docgroup) { $curUser = $this->getSecurityTokenStorage()->getToken()->getUser(); $trace = new Trace(); $trace->setActionId($docgroup->getId()); $trace->setActionType(Trace::AT_UPDATE); $trace->setUserId($curUser->getId()); $trace->setCompanyId($docgroup->getCompany()->getId()); $trace->setUserFullname($curUser->getFullName()); if (!$this->hasRole('ROLE_SUPERADMIN')) { if (!$this->hasRole('ROLE_ADMIN')) { $trace->setUserType(Trace::UT_CLIENT); } else { $trace->setUserType(Trace::UT_ADMIN); } } else { $trace->setUserType(Trace::UT_SUPERADMIN); } $tableBegin = ': <br><table class="table table-bordered table-condensed table-hover table-striped">'; $tableBegin .= '<thead><tr><th class="text-left">' . $this->translate('Entity.field') . '</th>'; $tableBegin .= '<th class="text-left">' . $this->translate('Entity.oldVal') . '</th>'; $tableBegin .= '<th class="text-left">' . $this->translate('Entity.newVal') . '</th></tr></thead><tbody>'; $tableEnd = '</tbody></table>'; $trace->setActionEntity(Trace::AE_DOCGROUP); $trace->setActionId2($docgroup->getCompany()->getId()); $trace->setActionEntity2(Trace::AE_COMPANY); $msg = ''; if ($cloneDocgroup->getLabel() != $docgroup->getLabel()) { $msg .= '<tr><td>' . $this->translate('Docgroup.label.label') . '</td><td>'; if ($cloneDocgroup->getLabel() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $cloneDocgroup->getLabel(); } $msg .= '</td><td>'; if ($docgroup->getLabel() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $docgroup->getLabel(); } $msg .= '</td></tr>'; } if ($cloneDocgroup->getParent() != $docgroup->getParent() && ($cloneDocgroup->getParent() == null && $docgroup->getParent() != null || $cloneDocgroup->getParent() != null && $docgroup->getParent() == null || $docgroup->getParent() != null && $cloneDocgroup->getParent() != null && $cloneDocgroup->getParent()->getPageUrlFull() != $docgroup->getParent()->getPageUrlFull())) { $msg .= '<tr><td>' . $this->translate('Docgroup.parent.label') . '</td><td>'; if ($cloneDocgroup->getParent() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $cloneDocgroup->getParent()->getLabel(); } $msg .= '</td><td>'; if ($docgroup->getParent() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $docgroup->getParent()->getLabel(); } $msg .= '</td></tr>'; } if ($cloneDocgroup->getOtherInfos() != $docgroup->getOtherInfos()) { $msg .= '<tr><td>' . $this->translate('Docgroup.otherInfos.label') . '</td><td>'; if ($cloneDocgroup->getOtherInfos() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $cloneDocgroup->getOtherInfos(); } $msg .= '</td><td>'; if ($docgroup->getOtherInfos() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $docgroup->getOtherInfos(); } $msg .= '</td></tr>'; } if (\count(\array_diff($docgroup->getDocs()->toArray(), $cloneDocgroup->getDocs()->toArray())) != 0 || \count(\array_diff($cloneDocgroup->getDocs()->toArray(), $docgroup->getDocs()->toArray())) != 0) { $msg .= '<tr><td>' . $this->translate('Docgroup.docs.label') . '</td><td>'; if (\count($cloneDocgroup->getDocs()) == 0) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= '<ul>'; foreach ($cloneDocgroup->getDocs() as $doc) { $msg .= '<li><a href="' . $this->generateUrl('_admin_doc_editGet', array('uid' => $doc->getId())) . '">' . $doc->getOriginalName() . '</a></li>'; } $msg .= '<ul>'; } $msg .= '</td><td>'; if (\count($docgroup->getDocs()) == 0) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= '<ul>'; foreach ($docgroup->getDocs() as $doc) { $msg .= '<li><a href="' . $this->generateUrl('_admin_doc_editGet', array('uid' => $doc->getId())) . '">' . $doc->getOriginalName() . '</a></li>'; } $msg .= '<ul>'; } $msg .= '</td></tr>'; } if ($msg != '') { $msg = $tableBegin . $msg . $tableEnd; $trace->setMsg($this->translate('Docgroup.traceEdit', array('%docgroup%' => $docgroup->getLabel(), '%company%' => $docgroup->getCompany()->getCorporateName())) . $msg); $trace->setDtCrea(new \DateTime('now')); $em = $this->getEntityManager(); $em->persist($trace); $em->flush(); } }