/**
  * Get Query for All Entities
  *
  * @param Docgroupfiscal $dg
  *
  * @return \Doctrine\ORM\Query
  */
 public function getAllChildsQuery(Docgroupfiscal $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;
 }
 protected function traceEntity(Docgroupfiscal $cloneDocgroupfiscal, Docgroupfiscal $docgroupfiscal)
 {
     $curUser = $this->getSecurityTokenStorage()->getToken()->getUser();
     $trace = new Trace();
     $trace->setActionId($docgroupfiscal->getId());
     $trace->setActionType(Trace::AT_UPDATE);
     $trace->setUserId($curUser->getId());
     $trace->setCompanyId($docgroupfiscal->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_DOCGROUPFISCAL);
     $trace->setActionId2($docgroupfiscal->getCompany()->getId());
     $trace->setActionEntity2(Trace::AE_COMPANY);
     $msg = '';
     if ($cloneDocgroupfiscal->getLabel() != $docgroupfiscal->getLabel()) {
         $msg .= '<tr><td>' . $this->translate('Docgroupfiscal.label.label') . '</td><td>';
         if ($cloneDocgroupfiscal->getLabel() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneDocgroupfiscal->getLabel();
         }
         $msg .= '</td><td>';
         if ($docgroupfiscal->getLabel() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $docgroupfiscal->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneDocgroupfiscal->getParent() != $docgroupfiscal->getParent() && ($cloneDocgroupfiscal->getParent() == null && $docgroupfiscal->getParent() != null || $cloneDocgroupfiscal->getParent() != null && $docgroupfiscal->getParent() == null || $docgroupfiscal->getParent() != null && $cloneDocgroupfiscal->getParent() != null && $cloneDocgroupfiscal->getParent()->getPageUrlFull() != $docgroupfiscal->getParent()->getPageUrlFull())) {
         $msg .= '<tr><td>' . $this->translate('Docgroupfiscal.parent.label') . '</td><td>';
         if ($cloneDocgroupfiscal->getParent() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneDocgroupfiscal->getParent()->getLabel();
         }
         $msg .= '</td><td>';
         if ($docgroupfiscal->getParent() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $docgroupfiscal->getParent()->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneDocgroupfiscal->getOtherInfos() != $docgroupfiscal->getOtherInfos()) {
         $msg .= '<tr><td>' . $this->translate('Docgroupfiscal.otherInfos.label') . '</td><td>';
         if ($cloneDocgroupfiscal->getOtherInfos() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneDocgroupfiscal->getOtherInfos();
         }
         $msg .= '</td><td>';
         if ($docgroupfiscal->getOtherInfos() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $docgroupfiscal->getOtherInfos();
         }
         $msg .= '</td></tr>';
     }
     if (\count(\array_diff($docgroupfiscal->getDocs()->toArray(), $cloneDocgroupfiscal->getDocs()->toArray())) != 0 || \count(\array_diff($cloneDocgroupfiscal->getDocs()->toArray(), $docgroupfiscal->getDocs()->toArray())) != 0) {
         $msg .= '<tr><td>' . $this->translate('Docgroupfiscal.docs.label') . '</td><td>';
         if (\count($cloneDocgroupfiscal->getDocs()) == 0) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= '<ul>';
             foreach ($cloneDocgroupfiscal->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($docgroupfiscal->getDocs()) == 0) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= '<ul>';
             foreach ($docgroupfiscal->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('Docgroupfiscal.traceEdit', array('%docgroupfiscal%' => $docgroupfiscal->getLabel(), '%company%' => $docgroupfiscal->getCompany()->getCorporateName())) . $msg);
         $trace->setDtCrea(new \DateTime('now'));
         $em = $this->getEntityManager();
         $em->persist($trace);
         $em->flush();
     }
 }