private function getTipTransUnit($locale, $domain, $identifier)
    {
        $storage = $this->get('lexik_translation.translation_storage');
        try {
            // Note that getAllByLocaleAndDomain return arrays rather than entities; presumably for performance reasons
            $transUnits = $storage->getTransUnitsByLocaleAndDomain($locale, $domain);
        } catch (QueryException $e) {
            throw new \RuntimeException('Tips database not configured');
        }

        // Throw exception if not tips
        if (!$total = count($transUnits)) {
            throw new \RuntimeException('No tips in database');
        }

        // Get a random tip from the array
        $random = random_int(0, $total-1);

        // Now retrieve a single TransUnit entity
        $transUnitId = $transUnits[$random]['id'];
        $transUnit = $storage->getTransUnitById($transUnitId);

        // Retrieve meta data
        $om = $this->getObjectManager();
        $tipMetaDataRepository = $om->getRepository('TamagoTipsManagerBundle:TamagoTransUnitMeta');
        $tipMetaData = $tipMetaDataRepository->singleton($transUnit, $locale, $identifier);

        // Increment view count
        $tipMetaData->setViewCount($tipMetaData->getViewCount() + 1);
        $om->flush();

        return $transUnit;
    }
private function getTipTransUnit($locale, $domain, $identifier)
    {
        $storage = $this->get('lexik_translation.translation_storage');
        try {
            // Note that getAllByLocaleAndDomain return arrays rather than entities; presumably for performance reasons
            $transUnits = $storage->getTransUnitsByLocaleAndDomain($locale, $domain);
        } catch (QueryException $e) {
            throw new \RuntimeException('Tips database not configured');
        }

        // Throw exception if not tips
        if (!$total = count($transUnits)) {
            throw new \RuntimeException('No tips in database');
        }

        // Get a random tip from the array
        $random = random_int(0, $total-1);

        // Now retrieve a single TransUnit entity
        $transUnitId = $transUnits[$random]['id'];
        $transUnit = $storage->getTransUnitById($transUnitId);

        // Retrieve meta data
        $om = $this->getObjectManager();
        $tipMetaDataRepository = $om->getRepository('TamagoTipsManagerBundle:TamagoTransUnitMeta');
        $tipMetaData = $tipMetaDataRepository->singleton($transUnit, $locale, $identifier);

        // Increment view count
        $tipMetaData->setViewCount($tipMetaData->getViewCount() + 1);
        $om->flush();

        return $transUnit;
    }
private function getTipTransUnit ( $ locale , $ domain , $ identifier ) { $ storage = $ this -> get ( 'lexik_translation.translation_storage' ) ; try { // Note that getAllByLocaleAndDomain return arrays rather than entities; presumably for performance reasons $ transUnits = $ storage -> getTransUnitsByLocaleAndDomain ( $ locale , $ domain ) ; } catch ( QueryException $ e ) { throw new \ RuntimeException ( 'Tips database not configured' ) ; } // Throw exception if not tips if ( ! $ total = count ( $ transUnits ) ) { throw new \ RuntimeException ( 'No tips in database' ) ; } // Get a random tip from the array $ random = random_int ( 0 , $ total - 1 ) ; // Now retrieve a single TransUnit entity $ transUnitId = $ transUnits [ $ random ] [ 'id' ] ; $ transUnit = $ storage -> getTransUnitById ( $ transUnitId ) ; // Retrieve meta data $ om = $ this -> getObjectManager ( ) ; $ tipMetaDataRepository = $ om -> getRepository ( 'TamagoTipsManagerBundle:TamagoTransUnitMeta' ) ; $ tipMetaData = $ tipMetaDataRepository -> singleton ( $ transUnit , $ locale , $ identifier ) ; // Increment view count $ tipMetaData -> setViewCount ( $ tipMetaData -> getViewCount ( ) + 1 ) ; $ om -> flush ( ) ; return $ transUnit ; }
Retrieve a random tip from the Lexik translations.  Increment view count.

@param Request $request
@param $domain
@param $identifier
@return TransUnit
Retrieve a random tip from the Lexik translations . Increment view count .