public function expired($limit = 10) 
    {
		$main = $this->getServiceLocator()->get('neobazaar.service.main');
		$em = $main->getEntityManager();
		$cache = $this->getServiceLocator()->get('ClassifiedCache');
		$documentRepository = $main->getDocumentEntityRepository();
		$documents = $documentRepository->getExpiredElegibleToMailSend($limit); 
        $url = $this->getServiceLocator()->get('ControllerPluginManager')->get('Url');

		$ids = array();
		foreach ($documents as $document) {
    	    $classifiedModel = $this->getServiceLocator()->get('document.model.classifiedAdminListing');
    	    $classifiedModel->init($document, $this->getServiceLocator());
		    $event = new ClassifiedExpiredEvent(__FUNCTION__, null, array(
    		    'to' => $classifiedModel->email, 
    		    'siteurl' => $url->fromRoute('home', array(), array('force_canonical' => true)),
    		    'fullname' => $classifiedModel->fullname,
		        'title' => $classifiedModel->title, 
		        'hash' => $classifiedModel->hashId, 
		        'content' => $classifiedModel->content,
		        'hits' => $classifiedModel->visited
    		));
		    
		    $this->getEventManager()->trigger(ClassifiedExpiredEvent::EVENT_CLASSIFIED_EXPIRED_PRE, $this, $event);
			
			$document->setState(Document::DOCUMENT_STATE_DEACTIVE);
			$document->setVisited($document->getVisited() + 1); // this is a trick to make it not update edit date
			$em->persist($document);
			$em->flush();
			$ids[] = $document->getDocumentId();		
			$key = $documentRepository->getEncryptedId($document->getDocumentId());
			if ($cache->hasItem($key)) {
				$cache->removeItem($key);
			}
			
		    $this->getEventManager()->trigger(ClassifiedExpiredEvent::EVENT_CLASSIFIED_EXPIRED_POST, $this, $event);
		}
		
		return $ids;
    }
public function expired($limit = 10) 
    {
		$main = $this->getServiceLocator()->get('neobazaar.service.main');
		$em = $main->getEntityManager();
		$cache = $this->getServiceLocator()->get('ClassifiedCache');
		$documentRepository = $main->getDocumentEntityRepository();
		$documents = $documentRepository->getExpiredElegibleToMailSend($limit); 
        $url = $this->getServiceLocator()->get('ControllerPluginManager')->get('Url');

		$ids = array();
		foreach ($documents as $document) {
    	    $classifiedModel = $this->getServiceLocator()->get('document.model.classifiedAdminListing');
    	    $classifiedModel->init($document, $this->getServiceLocator());
		    $event = new ClassifiedExpiredEvent(__FUNCTION__, null, array(
    		    'to' => $classifiedModel->email, 
    		    'siteurl' => $url->fromRoute('home', array(), array('force_canonical' => true)),
    		    'fullname' => $classifiedModel->fullname,
		        'title' => $classifiedModel->title, 
		        'hash' => $classifiedModel->hashId, 
		        'content' => $classifiedModel->content,
		        'hits' => $classifiedModel->visited
    		));
		    
		    $this->getEventManager()->trigger(ClassifiedExpiredEvent::EVENT_CLASSIFIED_EXPIRED_PRE, $this, $event);
			
			$document->setState(Document::DOCUMENT_STATE_DEACTIVE);
			$document->setVisited($document->getVisited() + 1); // this is a trick to make it not update edit date
			$em->persist($document);
			$em->flush();
			$ids[] = $document->getDocumentId();		
			$key = $documentRepository->getEncryptedId($document->getDocumentId());
			if ($cache->hasItem($key)) {
				$cache->removeItem($key);
			}
			
		    $this->getEventManager()->trigger(ClassifiedExpiredEvent::EVENT_CLASSIFIED_EXPIRED_POST, $this, $event);
		}
		
		return $ids;
    }
public function expired ( $ limit = 10 ) { $ main = $ this -> getServiceLocator ( ) -> get ( 'neobazaar.service.main' ) ; $ em = $ main -> getEntityManager ( ) ; $ cache = $ this -> getServiceLocator ( ) -> get ( 'ClassifiedCache' ) ; $ documentRepository = $ main -> getDocumentEntityRepository ( ) ; $ documents = $ documentRepository -> getExpiredElegibleToMailSend ( $ limit ) ; $ url = $ this -> getServiceLocator ( ) -> get ( 'ControllerPluginManager' ) -> get ( 'Url' ) ; $ ids = array ( ) ; foreach ( $ documents as $ document ) { $ classifiedModel = $ this -> getServiceLocator ( ) -> get ( 'document.model.classifiedAdminListing' ) ; $ classifiedModel -> init ( $ document , $ this -> getServiceLocator ( ) ) ; $ event = new ClassifiedExpiredEvent ( __FUNCTION__ , null , array ( 'to' => $ classifiedModel -> email , 'siteurl' => $ url -> fromRoute ( 'home' , array ( ) , array ( 'force_canonical' => true ) ) , 'fullname' => $ classifiedModel -> fullname , 'title' => $ classifiedModel -> title , 'hash' => $ classifiedModel -> hashId , 'content' => $ classifiedModel -> content , 'hits' => $ classifiedModel -> visited ) ) ; $ this -> getEventManager ( ) -> trigger ( ClassifiedExpiredEvent :: EVENT_CLASSIFIED_EXPIRED_PRE , $ this , $ event ) ; $ document -> setState ( Document :: DOCUMENT_STATE_DEACTIVE ) ; $ document -> setVisited ( $ document -> getVisited ( ) + 1 ) ; // this is a trick to make it not update edit date $ em -> persist ( $ document ) ; $ em -> flush ( ) ; $ ids [ ] = $ document -> getDocumentId ( ) ; $ key = $ documentRepository -> getEncryptedId ( $ document -> getDocumentId ( ) ) ; if ( $ cache -> hasItem ( $ key ) ) { $ cache -> removeItem ( $ key ) ; } $ this -> getEventManager ( ) -> trigger ( ClassifiedExpiredEvent :: EVENT_CLASSIFIED_EXPIRED_POST , $ this , $ event ) ; } return $ ids ; }
This service will trigger event with expired classifieds.
anything binded with these events will run

@param int $limit
@return array with document ids
This service will trigger event with expired classifieds . anything binded with these events will run