1 | <?php |
||
34 | class BlockController extends AbstractController |
||
|
|||
35 | { |
||
36 | 1 | public function index(Application $app) |
|
48 | |||
49 | 2 | public function edit(Application $app, $id = null) |
|
50 | { |
||
51 | $DeviceType = $app['eccube.repository.master.device_type'] |
||
52 | ->find(DeviceType::DEVICE_TYPE_PC); |
||
53 | |||
54 | $Block = $app['eccube.repository.block'] |
||
55 | ->findOrCreate($id, $DeviceType); |
||
56 | |||
57 | 2 | if (!$Block) { |
|
58 | throw new NotFoundHttpException(); |
||
59 | } |
||
60 | |||
61 | $form = $app['form.factory'] |
||
62 | ->createBuilder('block', $Block) |
||
63 | ->getForm(); |
||
64 | |||
65 | 2 | $html = ''; |
|
66 | 2 | $previous_filename = null; |
|
67 | $deletable = $Block->getDeletableFlg(); |
||
68 | |||
69 | 2 | if ($id) { |
|
70 | // テンプレートファイルの取得 |
||
71 | $previous_filename = $Block->getFileName(); |
||
72 | $file = $app['eccube.repository.block'] |
||
73 | ->getReadTemplateFile($previous_filename, $deletable); |
||
74 | 2 | $html = $file['tpl_data']; |
|
75 | } |
||
76 | |||
77 | $form->get('block_html')->setData($html); |
||
78 | |||
79 | if ($app['request']->getMethod() === 'POST') { |
||
80 | $form->handleRequest($app['request']); |
||
81 | if ($form->isValid()) { |
||
82 | $Block = $form->getData(); |
||
83 | |||
84 | // DB登録 |
||
85 | $app['orm.em']->persist($Block); |
||
86 | $app['orm.em']->flush(); |
||
87 | |||
88 | // ファイル生成・更新 |
||
89 | $tplDir = $app['config']['block_realdir']; |
||
90 | |||
91 | $filePath = $tplDir . '/' . $Block->getFileName() . '.twig'; |
||
92 | |||
93 | $fs = new Filesystem(); |
||
94 | $fs->dumpFile($filePath, $form->get('block_html')->getData()); |
||
95 | // 更新でファイル名を変更した場合、以前のファイルを削除 |
||
96 | if ($Block->getFileName() != $previous_filename && !is_null($previous_filename)) { |
||
97 | 1 | $oldFilePath = $tplDir . $previous_filename; |
|
98 | if ($fs->exists($oldFilePath)) { |
||
99 | $fs->remove($oldFilePath); |
||
100 | } |
||
101 | } |
||
102 | |||
103 | \Eccube\Util\Cache::clear($app,false); |
||
104 | |||
105 | $app->addSuccess('admin.register.complete', 'admin'); |
||
106 | |||
107 | return $app->redirect($app->url('admin_content_block_edit', array('id' => $Block->getId()))); |
||
108 | } |
||
109 | } |
||
110 | |||
111 | |||
112 | 1 | return $app->render('Content/block_edit.twig', array( |
|
113 | 1 | 'form' => $form->createView(), |
|
114 | 'block_id' => $id, |
||
115 | 'deletable' => $deletable, |
||
116 | )); |
||
117 | 2 | } |
|
118 | |||
119 | 1 | public function delete(Application $app, $id) |
|
155 | } |
||
156 |