src/Oss2/Doctrine2/WithPreferences.php
public function cleanExpiredPreferences( $asOf = null, $name = null )
    {
        $count = 0;

        if( $asOf === null )
            $asOf = new \DateTime();
        elseif( is_int( $asOf ) )
            $asOf = new \DateTime( date( 'Y-m-d H:i:s', $asOf ) );
        elseif( is_string( $asOf ) )
            $asOf = new \DateTime( $asOf );

        foreach( $this->getPreferences() as $pref )
        {
            if( $name && ( $pref->getName() != $name ) )
                continue;

            if( $pref->getExpiresAt() && ( $pref->getExpiresAt() < $asOf ) )
            {
                $count++;
                $this->getPreferences()->removeElement( $pref );
                \D2EM::remove( $pref );
            }
        }

        return $count;
    }
public function cleanExpiredPreferences( $asOf = null, $name = null )
    {
        $count = 0;

        if( $asOf === null )
            $asOf = new \DateTime();
        elseif( is_int( $asOf ) )
            $asOf = new \DateTime( date( 'Y-m-d H:i:s', $asOf ) );
        elseif( is_string( $asOf ) )
            $asOf = new \DateTime( $asOf );

        foreach( $this->getPreferences() as $pref )
        {
            if( $name && ( $pref->getName() != $name ) )
                continue;

            if( $pref->getExpiresAt() && ( $pref->getExpiresAt() < $asOf ) )
            {
                $count++;
                $this->getPreferences()->removeElement( $pref );
                \D2EM::remove( $pref );
            }
        }

        return $count;
    }
public function cleanExpiredPreferences ( $ asOf = null , $ name = null ) { $ count = 0 ; if ( $ asOf === null ) $ asOf = new \ DateTime ( ) ; elseif ( is_int ( $ asOf ) ) $ asOf = new \ DateTime ( date ( 'Y-m-d H:i:s' , $ asOf ) ) ; elseif ( is_string ( $ asOf ) ) $ asOf = new \ DateTime ( $ asOf ) ; foreach ( $ this -> getPreferences ( ) as $ pref ) { if ( $ name && ( $ pref -> getName ( ) != $ name ) ) continue ; if ( $ pref -> getExpiresAt ( ) && ( $ pref -> getExpiresAt ( ) < $ asOf ) ) { $ count ++ ; $ this -> getPreferences ( ) -> removeElement ( $ pref ) ; \ D2EM :: remove ( $ pref ) ; } } return $ count ; }
Clean expired preferences

Cleans preferences with an expiry date less than $asOf but not set to null (never expires).

WARNING: You need to EntityManager::flush() if the return > 0!

@param int|object|string $asOf default null A \DateTime object or date(time) string or Unix timestamp for the expriy, null means now
@param string $name default null Limit it to the specified attributes, null means all attributes
@return int The number of preferences deleted
Clean expired preferences