/** * @param Core_Dto_Entity * @throws Exception * */ public function arquivar(\Core_Dto_Entity $dto) { # persiste o arquivamento $this->getEntityManager()->persist($dto->getEntity()); # persiste o historico para o arquivamento $dtOperacao = \Zend_Date::now(); $sqTipoHistorico = \Core_Configuration::getSgdoceTipoHistoricoArquivoArquivado(); $this->_doInsertHistorico($dto->getEntity(), $dtOperacao, $sqTipoHistorico); # persiste o historico no artefato $serviceHA = $this->getServiceLocator()->getService('HistoricoArtefato'); $sqOcorrencia = \Core_Configuration::getSgdoceSqOcorrenciaArquivar(); $pessoaOperacao = $this->_getUserOperation()->getNoPessoa(); $strMessage = $serviceHA->getMessage('MH016', $dtOperacao->toString('dd/MM/YYYY HH:mm:ss'), $pessoaOperacao); $serviceHA->registrar($dto->getEntity()->getSqArtefato()->getSqArtefato(), $sqOcorrencia, $strMessage); $this->finish(); }
/** * Método que salva o historico do artefato * @param \Core_Dto_Entity $dto * @return boolean */ public function saveHistorico(\Core_Dto_Entity $dto) { $entity = $dto->getEntity(); $objStatus = $this->getEntityManager()->find('\\Sgdoce\\Model\\Entity\\StatusArtefato', $entity->getSqStatusArtefato()->getSqStatusArtefato()); $entity->setSqStatusArtefato($objStatus); $objUnidade = $this->getEntityManager()->find('\\Sgdoce\\Model\\Entity\\VwUnidadeOrg', $entity->getSqUnidadeOrg()->getSqUnidadeOrg()); $entity->setSqUnidadeOrg($objUnidade); $objArtefato = $this->getEntityManager()->find('\\Sgdoce\\Model\\Entity\\Artefato', $entity->getSqArtefato()->getSqArtefato()); $entity->setSqArtefato($objArtefato); $objPessoa = $this->getEntityManager()->find('\\Sgdoce\\Model\\Entity\\VwPessoa', $entity->getSqPessoa()->getSqPessoa()); $entity->setSqPessoa($objPessoa); $objOcorrencia = $this->getEntityManager()->find('\\Sgdoce\\Model\\Entity\\Ocorrencia', $entity->getSqOcorrencia()->getSqOcorrencia()); $entity->setSqOcorrencia($objOcorrencia); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush($entity); return TRUE; }
/** * @param array $data * @return string mensagem de sucesso */ public function save(Core_Dto_Entity $dto) { $entity = clone $dto->getEntity(); $entityName = Core_Util_Class::resolveNameEntity($this->_entityName, $this->getEntityManager()); if (!$entity instanceof $entityName) { throw new InvalidArgumentException('Tipo do Dto inválido'); } $isUpdate = FALSE; $metadata = $this->getEntityManager()->getClassMetadata(get_class($entity)); $ids = $metadata->getIdentifierValues($entity); $uow = $this->getEntityManager()->getUnitOfWork(); // @todo rever foreach ($metadata->associationMappings as $field => $prop) { $value = $metadata->reflFields[$field]->getValue($entity); if (is_object($value) && !$value instanceof \Doctrine\Common\Collections\Collection) { $metadataAssoc = $this->getEntityManager()->getClassMetadata(get_class($value)); $idsFk = $metadataAssoc->getIdentifierValues($value); if ($idsFk) { $uow->registerManaged($value, $idsFk, array()); $uow->removeFromIdentityMap($value); } else { // @todo $uow->registerManaged($value, array(0), array()); } } } $isUpdate = FALSE; if (count($ids)) { $uow->clear($metadata->name); $originalEntity = $entity; $entity = $this->find($ids); if (NULL !== $entity) { $isUpdate = TRUE; $entity->fromArray($originalEntity->toArrayIgnoreFields()); } else { $entity = $originalEntity; } } $args = func_get_args(); $args[0] = $entity; $this->_triggerPreSave($isUpdate, $args); $this->getEntityManager()->persist($entity); $this->_triggerPostSave($isUpdate, $args); return $entity; }
private function _save(\Core_Dto_Entity $dto) { $this->_getRepository()->save($dto->getEntity()); }