Example #1
0
 /**
  * Prepara uma entidade para ser salva
  * @param string $entityName Nome da entidade
  */
 public function setOperationalEntity($entityName = NULL)
 {
     $entityName = \Core_Util_Class::resolveNameEntity($this->options['entityName']);
     $this->_data['stMensagemAtiva'] = TRUE;
     // $sqAssunto e sqTipoDocumento = NULL == mensagem geral
     $sqAssunto = NULL;
     $sqTipoDocumento = NULL;
     if (!isset($this->_data['msgGeral'])) {
         $sqAssunto = $this->_createEntityManaged(array('sqAssunto' => $this->_data['sqAssunto']), 'app:Assunto');
         $sqTipoDocumento = $this->_createEntityManaged(array('sqTipoDocumento' => $this->_data['sqTipoDocumento']), 'app:TipoDocumento');
     }
     $this->_data['sqAssunto'] = $sqAssunto;
     $this->_data['sqTipoDocumento'] = $sqTipoDocumento;
     unset($this->_data['sqAssunto_autocomplete']);
 }
 public function savePerfilFuncionalidade($perfilEntity, $dto)
 {
     $this->deletePerfilFuncionalidadeByPerfil($perfilEntity->getSqPerfil());
     $entityName = \Core_Util_Class::resolveNameEntity($this->_entityName, $this->getEntityManager());
     unset($dto['perfilPadraoExterno']);
     foreach ($dto as $object) {
         $entity = new $entityName();
         $entity->setSqPerfil($perfilEntity);
         $funcionalidade = $object->getEntity();
         $this->getEntityManager()->getUnitOfWork()->registerManaged($funcionalidade, array('sqFuncionalidade' => $funcionalidade->getSqFuncionalidade()), array());
         $funcionalidade->setStRegistroAtivo(NULL);
         $funcionalidade->setInFuncionalidadePrincipal(NULL);
         $entity->setSqFuncionalidade($funcionalidade);
         $entity->setStRegistroAtivo(TRUE);
         $this->getEntityManager()->persist($entity);
     }
 }
Example #3
0
 /**
  * @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;
 }
Example #4
0
 /**
  * Cria uma entidade
  *
  * @param  string|null $entity
  * @return Entity
  */
 protected function _newEntity($entity = null)
 {
     if (null === $entity) {
         $entity = $this->_getEntityName();
     }
     $nameEntity = Core_Util_Class::resolveNameEntity($entity);
     return new $nameEntity();
 }