public function delete($idOrUser, $forceLogout = true) 
    {
		// All the services we need
		$main = $this->getServiceLocator()->get('neobazaar.service.main');
		$em = $main->getEntityManager();
		$user = $this->getEntity($idOrUser);
		$classifiedService = $this->getServiceLocator()->get('document.service.classified');
		
		if(!$this->checkIfOwnerOrAdmin($user)) {
			throw new \Exception('Non possiedi i permessi per agire su questo documento');
		}

		$this->getEventManager()->trigger(__FUNCTION__, $this, array('user' => $user));
		$user->setState(UserEntity::USER_STATE_DELETED);
		$em->persist($user);
		$em->flush();
		
		$documents = $user->getDocument();
		foreach($documents as $document) {
			try {
				$classifiedService->delete($document);
			} catch(\Exception $e) { }
		}

		$this->getEventManager()->trigger(__FUNCTION__ . '.post', $this, array('user' => $user));
		
		if($forceLogout) {
			$this->logout();
		}
		
		return $user;
    }
public function delete($idOrUser, $forceLogout = true) 
    {
		// All the services we need
		$main = $this->getServiceLocator()->get('neobazaar.service.main');
		$em = $main->getEntityManager();
		$user = $this->getEntity($idOrUser);
		$classifiedService = $this->getServiceLocator()->get('document.service.classified');
		
		if(!$this->checkIfOwnerOrAdmin($user)) {
			throw new \Exception('Non possiedi i permessi per agire su questo documento');
		}

		$this->getEventManager()->trigger(__FUNCTION__, $this, array('user' => $user));
		$user->setState(UserEntity::USER_STATE_DELETED);
		$em->persist($user);
		$em->flush();
		
		$documents = $user->getDocument();
		foreach($documents as $document) {
			try {
				$classifiedService->delete($document);
			} catch(\Exception $e) { }
		}

		$this->getEventManager()->trigger(__FUNCTION__ . '.post', $this, array('user' => $user));
		
		if($forceLogout) {
			$this->logout();
		}
		
		return $user;
    }
public function delete ( $ idOrUser , $ forceLogout = true ) { // All the services we need $ main = $ this -> getServiceLocator ( ) -> get ( 'neobazaar.service.main' ) ; $ em = $ main -> getEntityManager ( ) ; $ user = $ this -> getEntity ( $ idOrUser ) ; $ classifiedService = $ this -> getServiceLocator ( ) -> get ( 'document.service.classified' ) ; if ( ! $ this -> checkIfOwnerOrAdmin ( $ user ) ) { throw new \ Exception ( 'Non possiedi i permessi per agire su questo documento' ) ; } $ this -> getEventManager ( ) -> trigger ( __FUNCTION__ , $ this , array ( 'user' => $ user ) ) ; $ user -> setState ( UserEntity :: USER_STATE_DELETED ) ; $ em -> persist ( $ user ) ; $ em -> flush ( ) ; $ documents = $ user -> getDocument ( ) ; foreach ( $ documents as $ document ) { try { $ classifiedService -> delete ( $ document ) ; } catch ( \ Exception $ e ) { } } $ this -> getEventManager ( ) -> trigger ( __FUNCTION__ . '.post' , $ this , array ( 'user' => $ user ) ) ; if ( $ forceLogout ) { $ this -> logout ( ) ; } return $ user ; }
Save a document

@param array $data
@param bool $forceLogout
@throws \Exception
@return \Neobazaar\Entity\User
Save a document