protected function traceEntity(Docgroupperso $cloneDocgroupperso, Docgroupperso $docgroupperso)
 {
     $curUser = $this->getSecurityTokenStorage()->getToken()->getUser();
     $trace = new Trace();
     $trace->setActionId($docgroupperso->getId());
     $trace->setActionType(Trace::AT_UPDATE);
     $trace->setUserId($curUser->getId());
     $trace->setCompanyId($docgroupperso->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_DOCGROUPPERSO);
     $trace->setActionId2($docgroupperso->getCompany()->getId());
     $trace->setActionEntity2(Trace::AE_COMPANY);
     $msg = '';
     if ($cloneDocgroupperso->getLabel() != $docgroupperso->getLabel()) {
         $msg .= '<tr><td>' . $this->translate('Docgroupperso.label.label') . '</td><td>';
         if ($cloneDocgroupperso->getLabel() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneDocgroupperso->getLabel();
         }
         $msg .= '</td><td>';
         if ($docgroupperso->getLabel() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $docgroupperso->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneDocgroupperso->getParent() != $docgroupperso->getParent() && ($cloneDocgroupperso->getParent() == null && $docgroupperso->getParent() != null || $cloneDocgroupperso->getParent() != null && $docgroupperso->getParent() == null || $docgroupperso->getParent() != null && $cloneDocgroupperso->getParent() != null && $cloneDocgroupperso->getParent()->getPageUrlFull() != $docgroupperso->getParent()->getPageUrlFull())) {
         $msg .= '<tr><td>' . $this->translate('Docgroupperso.parent.label') . '</td><td>';
         if ($cloneDocgroupperso->getParent() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneDocgroupperso->getParent()->getLabel();
         }
         $msg .= '</td><td>';
         if ($docgroupperso->getParent() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $docgroupperso->getParent()->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneDocgroupperso->getOtherInfos() != $docgroupperso->getOtherInfos()) {
         $msg .= '<tr><td>' . $this->translate('Docgroupperso.otherInfos.label') . '</td><td>';
         if ($cloneDocgroupperso->getOtherInfos() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneDocgroupperso->getOtherInfos();
         }
         $msg .= '</td><td>';
         if ($docgroupperso->getOtherInfos() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $docgroupperso->getOtherInfos();
         }
         $msg .= '</td></tr>';
     }
     if (\count(\array_diff($docgroupperso->getDocs()->toArray(), $cloneDocgroupperso->getDocs()->toArray())) != 0 || \count(\array_diff($cloneDocgroupperso->getDocs()->toArray(), $docgroupperso->getDocs()->toArray())) != 0) {
         $msg .= '<tr><td>' . $this->translate('Docgroupperso.docs.label') . '</td><td>';
         if (\count($cloneDocgroupperso->getDocs()) == 0) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= '<ul>';
             foreach ($cloneDocgroupperso->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($docgroupperso->getDocs()) == 0) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= '<ul>';
             foreach ($docgroupperso->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('Docgroupperso.traceEdit', array('%docgroupperso%' => $docgroupperso->getLabel(), '%company%' => $docgroupperso->getCompany()->getCorporateName())) . $msg);
         $trace->setDtCrea(new \DateTime('now'));
         $em = $this->getEntityManager();
         $em->persist($trace);
         $em->flush();
     }
 }
 /**
  * Get Query for All Entities
  *
  * @param Docgroupperso $dg
  *
  * @return \Doctrine\ORM\Query
  */
 public function getAllChildsQuery(Docgroupperso $dg)
 {
     $c = $dg->getCompany();
     $qb = $this->createQueryBuilder('d')->join('d.company', 'c')->where('c.id = :cid')->andWhere('d.pageUrlFull LIKE :url')->andWhere('d.id != :did')->orderBy('d.pageUrlFull', 'ASC')->setParameter('cid', $c->getId())->setParameter('url', $dg->getPageUrlFull() . '%')->setParameter('did', $dg->getId());
     $query = $qb->getQuery();
     return $query;
 }