Exemplo n.º 1
0
 /**
  * ブロックを登録
  *
  * @param $app
  * @throws \Exception
  */
 private function copyBlock($app)
 {
     // ファイルコピー
     $file = new Filesystem();
     // ブロックファイルをコピー
     $file->copy($this->originBlock, $app['config']['block_realdir'] . '/' . $this->blockFileName . '.twig');
     $em = $app['orm.em'];
     $em->getConnection()->beginTransaction();
     try {
         $DeviceType = $app['eccube.repository.master.device_type']->find(DeviceType::DEVICE_TYPE_PC);
         /** @var \Eccube\Entity\Block $Block */
         $Block = $app['eccube.repository.block']->findOrCreate(null, $DeviceType);
         // Blockの登録
         $Block->setName($this->blockName);
         $Block->setFileName($this->blockFileName);
         $Block->setDeletableFlg(Constant::DISABLED);
         $Block->setLogicFlg(1);
         $em->persist($Block);
         $em->flush($Block);
         // BlockPositionの登録
         $blockPos = $em->getRepository('Eccube\\Entity\\BlockPosition')->findOneBy(array('page_id' => 1, 'target_id' => PageLayout::TARGET_ID_MAIN_BOTTOM), array('block_row' => 'DESC'));
         $BlockPosition = new BlockPosition();
         // ブロックの順序を変更
         if ($blockPos) {
             $blockRow = $blockPos->getBlockRow() + 1;
             $BlockPosition->setBlockRow($blockRow);
         } else {
             // 1番目にセット
             $BlockPosition->setBlockRow(1);
         }
         $PageLayout = $app['eccube.repository.page_layout']->find(1);
         $BlockPosition->setPageLayout($PageLayout);
         $BlockPosition->setPageId($PageLayout->getId());
         $BlockPosition->setTargetId(PageLayout::TARGET_ID_MAIN_BOTTOM);
         $BlockPosition->setBlock($Block);
         $BlockPosition->setBlockId($Block->getId());
         $BlockPosition->setAnywhere(Constant::ENABLED);
         $em->persist($BlockPosition);
         $em->flush($BlockPosition);
         $em->getConnection()->commit();
     } catch (\Exception $e) {
         $em->getConnection()->rollback();
         throw $e;
     }
 }
Exemplo n.º 2
0
 /**
  * ブロックを登録.
  *
  * @param \Eccube\Application $app
  *
  * @throws \Exception
  */
 private function createDataBlock($app)
 {
     $em = $app['orm.em'];
     try {
         $DeviceType = $app['eccube.repository.master.device_type']->find(DeviceType::DEVICE_TYPE_PC);
         // check exists block
         /** @var Block $Block */
         $Block = $app['eccube.repository.block']->findOneBy(array('DeviceType' => $DeviceType, 'file_name' => $this->blockFileName));
         if (!$Block) {
             /** @var Block $Block */
             $Block = $app['eccube.repository.block']->findOrCreate(null, $DeviceType);
             // Blockの登録
             $Block->setName($this->blockName)->setFileName($this->blockFileName)->setDeletableFlg(Constant::DISABLED)->setLogicFlg(1);
             $em->persist($Block);
             $em->flush($Block);
         }
         // check exists block position
         $blockPos = $em->getRepository('Eccube\\Entity\\BlockPosition')->findOneBy(array('block_id' => $Block->getId()));
         if ($blockPos) {
             return;
         }
         // BlockPositionの登録
         $blockPos = $em->getRepository('Eccube\\Entity\\BlockPosition')->findOneBy(array('page_id' => 1, 'target_id' => PageLayout::TARGET_ID_MAIN_BOTTOM), array('block_row' => 'DESC'));
         $BlockPosition = new BlockPosition();
         // ブロックの順序を変更
         $BlockPosition->setBlockRow(1);
         if ($blockPos) {
             $blockRow = $blockPos->getBlockRow() + 1;
             $BlockPosition->setBlockRow($blockRow);
         }
         $PageLayout = $app['eccube.repository.page_layout']->find(1);
         $BlockPosition->setPageLayout($PageLayout)->setPageId($PageLayout->getId())->setTargetId(PageLayout::TARGET_ID_MAIN_BOTTOM)->setBlock($Block)->setBlockId($Block->getId())->setAnywhere(Constant::ENABLED);
         $em->persist($BlockPosition);
         $em->flush($BlockPosition);
     } catch (\Exception $e) {
         throw $e;
     }
 }