Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

管理側のメールテンプレートも修正できるように対応 #5

Open
wants to merge 2 commits into
base: 3.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 59 additions & 16 deletions Controller/MailTemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MailTemplateController extends AbstractController
* メールファイル管理一覧画面.
*
* @param Application $app
* @param Request $request
* @param Request $request
*
* @return \Symfony\Component\HttpFoundation\Response
*/
Expand All @@ -36,16 +36,37 @@ public function index(Application $app, Request $request)

$files = array();
foreach ($finder->in($mailDir) as $file) {
$files[$file->getFilename()] = $file->getFilename();
$fileName = '[front]'.$file->getFilename();
$files[$fileName] = $fileName;
}

$mailDir = $app['config']['template_realdir'].'/Mail';
if (file_exists($mailDir)) {
foreach ($finder->in($mailDir) as $file) {
$files[$file->getFilename()] = $file->getFilename();
$fileName = '[front]'.$file->getFilename();
$files[$fileName] = $fileName;
}
}

$finder = Finder::create()->depth(0);
$mailDir = $app['config']['template_admin_realdir'].'/Mail';
if (file_exists($mailDir)) {
foreach ($finder->in($mailDir) as $file) {
$fileName = '[admin]'.$file->getFilename();
$files[$fileName] = $fileName;
}
}

$mailDir = $app['config']['template_realdir'].'/../admin/Mail';
if (file_exists($mailDir)) {
foreach ($finder->in($mailDir) as $file) {
$fileName = '[admin]'.$file->getFilename();
$files[$fileName] = $fileName;
}
}

asort($files);

return $app->render('MailTemplateEditor/Resource/template/admin/mail.twig', array(
'files' => $files,
));
Expand All @@ -55,22 +76,34 @@ public function index(Application $app, Request $request)
* メール編集画面.
*
* @param Application $app
* @param Request $request
* @param Request $request
* @param $name
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function edit(Application $app, Request $request, $name)
{
$readPaths = array(
$app['config']['template_realdir'],
$app['config']['template_default_realdir'],
);

if (strpos($name, '[front]') !== false) {
$readPaths = array(
$app['config']['template_realdir'],
$app['config']['template_default_realdir'],
);
$targetName = str_replace('[front]', '', $name);
$targetDir = $app['config']['template_realdir'];
} elseif (strpos($name, '[admin]') !== false) {
$readPaths = array(
$app['config']['template_realdir'].'/../admin',
$app['config']['template_admin_realdir'],
);
$targetName = str_replace('[admin]', '', $name);
$targetDir = $app['config']['template_realdir'].'/../admin';
}

$fs = new Filesystem();
$tplData = null;
foreach ($readPaths as $readPath) {
$filePath = $readPath.'/Mail/'.$name;
$filePath = $readPath.'/Mail/'.$targetName;
if ($fs->exists($filePath)) {
$tplData = file_get_contents($filePath);
break;
Expand All @@ -94,7 +127,7 @@ public function edit(Application $app, Request $request, $name)
if ($form->isSubmitted() && $form->isValid()) {

// ファイル生成・更新
$filePath = $app['config']['template_realdir'].'/Mail/'.$name;
$filePath = $targetDir.'/Mail/'.$targetName;

$fs = new Filesystem();
$pageData = $form->get('tpl_data')->getData();
Expand All @@ -121,7 +154,7 @@ public function edit(Application $app, Request $request, $name)
* メールファイル初期化処理.
*
* @param Application $app
* @param Request $request
* @param Request $request
* @param $name
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
Expand All @@ -130,14 +163,24 @@ public function reedit(Application $app, Request $request, $name)
{
$this->isTokenValid($app);

$readPaths = array(
$app['config']['template_default_realdir'],
);
if (strpos($name, '[front]') !== false) {
$readPaths = array(
$app['config']['template_default_realdir'],
);
$targetName = str_replace('[front]', '', $name);
$targetDir = $app['config']['template_realdir'];
} elseif (strpos($name, '[admin]') !== false) {
$readPaths = array(
$app['config']['template_admin_realdir'],
);
$targetName = str_replace('[admin]', '', $name);
$targetDir = $app['config']['template_realdir'].'/../admin';
}

$fs = new Filesystem();
$tplData = null;
foreach ($readPaths as $readPath) {
$filePath = $readPath.'/Mail/'.$name;
$filePath = $readPath.'/Mail/'.$targetName;
if ($fs->exists($filePath)) {
$tplData = file_get_contents($filePath);
break;
Expand All @@ -157,7 +200,7 @@ public function reedit(Application $app, Request $request, $name)
$form->get('tpl_data')->setData($tplData);

// ファイル生成・更新
$filePath = $app['config']['template_realdir'].'/Mail/'.$name;
$filePath = $targetDir.'/Mail/'.$targetName;

$fs = new Filesystem();
$fs->dumpFile($filePath, $tplData);
Expand Down
14 changes: 13 additions & 1 deletion ServiceProvider/MailTemplateEditorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,19 @@ public function register(BaseApplication $app)

// 管理画面メニュー追加
$app['config'] = $app->share($app->extend('config', function ($config) {
$config['nav'][3]['child'][] = array(

$navs = $config['nav'];
$targetId = 3;
$i = 0;
foreach ($navs as $nav) {
if ($nav['id'] === 'content') {
$targetId = $i;
break;
}
$i++;
}

$config['nav'][$targetId]['child'][] = array(
'id' => 'mail',
'name' => 'メール管理',
'url' => 'plugin_MailTemplateEditor_mail',
Expand Down