Backend\Modules\ContentBlocks\Repository\ContentBlockRepository::getNextIdForLanguage PHP Method

getNextIdForLanguage() public method

public getNextIdForLanguage ( Locale $locale ) : integer
$locale common\Locale
return integer
    public function getNextIdForLanguage(Locale $locale)
    {
        return (int) $this->getEntityManager()->createQueryBuilder()->select('MAX(cb.id) as id')->from(ContentBlock::class, 'cb')->where('cb.locale = :locale')->setParameter('locale', $locale)->getQuery()->getSingleScalarResult() + 1;
    }

Usage Example

 /**
  * @param CopyContentBlocksToOtherLocale $copyContentBlocksToOtherLocale
  *
  * @return ContentBlock
  */
 public function handle(CopyContentBlocksToOtherLocale $copyContentBlocksToOtherLocale)
 {
     $fromLocaleContentBlocks = (array) $this->contentBlockRepository->findBy(['locale' => $copyContentBlocksToOtherLocale->fromLocale, 'status' => ContentBlockStatus::active()]);
     $id = $this->contentBlockRepository->getNextIdForLanguage($copyContentBlocksToOtherLocale->toLocale);
     array_map(function (ContentBlock $contentBlock) use($copyContentBlocksToOtherLocale, &$id) {
         $copyContentBlocksToOtherLocale->extraIdMap[$contentBlock->getExtraId()] = $this->getNewExtraId();
         $otherLocaleContentBlock = ContentBlock::create($id++, $contentBlock->getUserId(), $copyContentBlocksToOtherLocale->extraIdMap[$contentBlock->getExtraId()], $copyContentBlocksToOtherLocale->toLocale, $contentBlock->getTitle(), $contentBlock->getText(), $contentBlock->isHidden(), $contentBlock->getTemplate());
         $this->contentBlockRepository->add($otherLocaleContentBlock);
     }, $fromLocaleContentBlocks);
 }
All Usage Examples Of Backend\Modules\ContentBlocks\Repository\ContentBlockRepository::getNextIdForLanguage