/** * @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); }
/** * @param int $id * @param int $userId * @param int $extraId The id of the module extra * @param string $locale * @param string $title * @param string $text * @param bool $isHidden * @param string $template * * @return self */ public static function create($id, $userId, $extraId, $locale, $title, $text, $isHidden, $template = self::DEFAULT_TEMPLATE) { return new self($id, $userId, $extraId, $template, $locale, $title, $text, $isHidden, ContentBlockStatus::active()); }
/** * @param int $id * @param Locale $locale * * @return ContentBlock|null */ public function findOneByIdAndLocale($id, Locale $locale) { return $this->findOneBy(['id' => $id, 'status' => ContentBlockStatus::active(), 'locale' => $locale]); }
/** * @param Locale $locale */ public function __construct(Locale $locale) { parent::__construct('SELECT i.id, i.title, i.hidden FROM content_blocks AS i WHERE i.status = :active AND i.language = :language', ['active' => ContentBlockStatus::active(), 'language' => $locale]); }