Пример #1
0
 protected function traceEntity(Shareholder $cloneShareholder, Shareholder $shareholder)
 {
     $curUser = $this->getSecurityTokenStorage()->getToken()->getUser();
     $trace = new Trace();
     $trace->setActionId($shareholder->getId());
     $trace->setActionType(Trace::AT_UPDATE);
     $trace->setUserId($curUser->getId());
     $trace->setCompanyId($shareholder->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_WHITHHOLDING);
     $trace->setActionId2($shareholder->getCompany()->getId());
     $trace->setActionEntity2(Trace::AE_COMPANY);
     $msg = '';
     if ($cloneShareholder->getName() != $shareholder->getName()) {
         $msg .= '<tr><td>' . $this->translate('Shareholder.name.label') . '</td><td>';
         if ($cloneShareholder->getName() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneShareholder->getName();
         }
         $msg .= '</td><td>';
         if ($shareholder->getName() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $shareholder->getName();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneShareholder->getCin() != $shareholder->getCin()) {
         $msg .= '<tr><td>' . $this->translate('Shareholder.cin.label') . '</td><td>';
         if ($cloneShareholder->getCin() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneShareholder->getCin();
         }
         $msg .= '</td><td>';
         if ($shareholder->getCin() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $shareholder->getCin();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneShareholder->getQuality() != $shareholder->getQuality()) {
         $msg .= '<tr><td>' . $this->translate('Shareholder.quality.label') . '</td><td>';
         if ($cloneShareholder->getQuality() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneShareholder->getQuality();
         }
         $msg .= '</td><td>';
         if ($shareholder->getQuality() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $shareholder->getQuality();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneShareholder->getAddress() != $shareholder->getAddress()) {
         $msg .= '<tr><td>' . $this->translate('Shareholder.address.label') . '</td><td>';
         if ($cloneShareholder->getAddress() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneShareholder->getAddress();
         }
         $msg .= '</td><td>';
         if ($shareholder->getAddress() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $shareholder->getAddress();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneShareholder->getTrades() != $shareholder->getTrades()) {
         $msg .= '<tr><td>' . $this->translate('Shareholder.trades.label') . '</td><td>';
         if ($cloneShareholder->getTrades() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneShareholder->getTrades();
         }
         $msg .= '</td><td>';
         if ($shareholder->getTrades() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $shareholder->getTrades();
         }
         $msg .= '</td></tr>';
     }
     if ($msg != '') {
         $msg = $tableBegin . $msg . $tableEnd;
         $trace->setMsg($this->translate('Shareholder.traceEdit', array('%shareholder%' => $shareholder->getName(), '%company%' => $shareholder->getCompany()->getCorporateName())) . $msg);
         $trace->setDtCrea(new \DateTime('now'));
         $em = $this->getEntityManager();
         $em->persist($trace);
         $em->flush();
     }
 }