original_string: public function delete($idOrDocument) 
      {
  		$cache = $this->getServiceLocator()->get('ClassifiedCache');
  		$main = $this->getServiceLocator()->get('neobazaar.service.main');
  		$classifiedService = $this->getServiceLocator()->get('document.service.classified');
  		$entityManager = $main->getEntityManager();
  		$documentRepository = $main->getDocumentEntityRepository();
  		$entity = $documentRepository->getEntity($idOrDocument);
  		// It can NOT exists when add a NEW classified (parent still doesn't exists)
  		$parent = $entity->getParent(); 
  		
  		// checking for permission, only if we are in edit mode
  		if(null !== $parent && !$classifiedService->checkIfOwnerOrAdmin($parent)) {
  			throw new \Exception('Non possiedi i permessi per agire su questo documento');
  		}
  		
  		$cacheKey = $parent ? $documentRepository->getEncryptedId($parent->getDocumentId()) : 'noCache';
  		$imageModel = new ImageModel($entity, $this->getServiceLocator());
  
  		// 1) Delete the image
  		$phisical = $imageModel->deleteImages();
  		
  		// 3) Remove the document
  		$entityManager->remove($entity);
  		$entityManager->flush();
  		
  		// 4) Remove parent classified cache
  		if($cache->hasItem($cacheKey)) {
  			$cache->removeItem($cacheKey);
  		}
  		
  		return $phisical;
      }
code: public function delete($idOrDocument) 
      {
  		$cache = $this->getServiceLocator()->get('ClassifiedCache');
  		$main = $this->getServiceLocator()->get('neobazaar.service.main');
  		$classifiedService = $this->getServiceLocator()->get('document.service.classified');
  		$entityManager = $main->getEntityManager();
  		$documentRepository = $main->getDocumentEntityRepository();
  		$entity = $documentRepository->getEntity($idOrDocument);
  		// It can NOT exists when add a NEW classified (parent still doesn't exists)
  		$parent = $entity->getParent(); 
  		
  		// checking for permission, only if we are in edit mode
  		if(null !== $parent && !$classifiedService->checkIfOwnerOrAdmin($parent)) {
  			throw new \Exception('Non possiedi i permessi per agire su questo documento');
  		}
  		
  		$cacheKey = $parent ? $documentRepository->getEncryptedId($parent->getDocumentId()) : 'noCache';
  		$imageModel = new ImageModel($entity, $this->getServiceLocator());
  
  		// 1) Delete the image
  		$phisical = $imageModel->deleteImages();
  		
  		// 3) Remove the document
  		$entityManager->remove($entity);
  		$entityManager->flush();
  		
  		// 4) Remove parent classified cache
  		if($cache->hasItem($cacheKey)) {
  			$cache->removeItem($cacheKey);
  		}
  		
  		return $phisical;
      }
code_tokens: public function delete ( $ idOrDocument ) { $ cache = $ this -> getServiceLocator ( ) -> get ( 'ClassifiedCache' ) ; $ main = $ this -> getServiceLocator ( ) -> get ( 'neobazaar.service.main' ) ; $ classifiedService = $ this -> getServiceLocator ( ) -> get ( 'document.service.classified' ) ; $ entityManager = $ main -> getEntityManager ( ) ; $ documentRepository = $ main -> getDocumentEntityRepository ( ) ; $ entity = $ documentRepository -> getEntity ( $ idOrDocument ) ; // It can NOT exists when add a NEW classified (parent still doesn't exists) $ parent = $ entity -> getParent ( ) ; // checking for permission, only if we are in edit mode if ( null !== $ parent && ! $ classifiedService -> checkIfOwnerOrAdmin ( $ parent ) ) { throw new \ Exception ( 'Non possiedi i permessi per agire su questo documento' ) ; } $ cacheKey = $ parent ? $ documentRepository -> getEncryptedId ( $ parent -> getDocumentId ( ) ) : 'noCache' ; $ imageModel = new ImageModel ( $ entity , $ this -> getServiceLocator ( ) ) ; // 1) Delete the image $ phisical = $ imageModel -> deleteImages ( ) ; // 3) Remove the document $ entityManager -> remove ( $ entity ) ; $ entityManager -> flush ( ) ; // 4) Remove parent classified cache if ( $ cache -> hasItem ( $ cacheKey ) ) { $ cache -> removeItem ( $ cacheKey ) ; } return $ phisical ; }
docstring: Delete an image document and related images.
  If there is a parent delete its cache.
  
  @param unknown $idOrDocument
  @throws \Exception
  @return boolean
docstring_tokens: Delete an image document and related images . If there is a parent delete its cache .