Skip to content

Commit

Permalink
Issue #44: Application texts moved to the separate bundle.
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxist committed Jan 22, 2017
1 parent 21ecda1 commit dae1aeb
Show file tree
Hide file tree
Showing 57 changed files with 1,516 additions and 308 deletions.
5 changes: 3 additions & 2 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* This file is part of Cantiga Project. Copyright 2016 Cantiga contributors.
* This file is part of Cantiga Project. Copyright 2016-2017 Cantiga contributors.
*
* Cantiga Project is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -13,7 +13,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar; if not, write to the Free Software
* along with Cantiga; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

Expand All @@ -34,6 +34,7 @@ public function registerBundles()
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Cantiga\CoreBundle\CantigaCoreBundle(),
new Cantiga\AppTextBundle\CantigaAppTextBundle(),
new Cantiga\UserBundle\CantigaUserBundle(),
new Cantiga\LinksBundle\CantigaLinksBundle(),
new Cantiga\MilestoneBundle\CantigaMilestoneBundle(),
Expand Down
3 changes: 3 additions & 0 deletions app/config/routing.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
cantiga_core_bundle:
resource: "@CantigaCoreBundle/Resources/config/routing.yml"
prefix: /
cantiga_apptext_bundle:
resource: "@CantigaAppTextBundle/Resources/config/routing.yml"
prefix: /
cantiga_user_bundle:
resource: "@CantigaUserBundle/Resources/config/routing.yml"
prefix: /
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,15 @@
* along with Foobar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
namespace Cantiga\Metamodel;
namespace Cantiga\AppTextBundle;

/**
* Keeps the information about the current locale, so that the services do not have
* to depend on requests, or be preloaded without any need just to set the locale.
*
* @author Tomasz Jędrzejewski
*/
class LocaleProvider
{
private $locale;

public function __construct($fallbackLocale)
{
$this->locale = $fallbackLocale;
}

public function getLocale()
{
return $this->locale;
}
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

public function setLocale($locale)
class CantigaAppTextBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
$this->locale = $locale;
return $this;
parent::build($container);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* This file is part of Cantiga Project. Copyright 2016 Cantiga contributors.
* This file is part of Cantiga Project. Copyright 2016-2017 Cantiga contributors.
*
* Cantiga Project is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -14,11 +14,11 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar; if not, write to the Free Software
* along with Cantiga; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

namespace Cantiga\CoreBundle\Controller;
namespace Cantiga\AppTextBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
Expand All @@ -31,8 +31,8 @@
use Cantiga\CoreBundle\Api\Actions\EditAction;
use Cantiga\CoreBundle\Api\Actions\InfoAction;
use Cantiga\CoreBundle\Api\Controller\AdminPageController;
use Cantiga\CoreBundle\Form\AppTextForm;
use Cantiga\CoreBundle\Entity\AppText;
use Cantiga\AppTextBundle\Form\AppTextForm;
use Cantiga\AppTextBundle\Entity\AppText;

/**
* @Route("/admin/app/text")
Expand All @@ -41,7 +41,7 @@
class AdminAppTextController extends AdminPageController
{

const REPOSITORY_NAME = 'cantiga.core.repo.text';
const REPOSITORY_NAME = 'cantiga.apptext.repo.text';

/**
* @var CRUDInfo
Expand All @@ -51,7 +51,7 @@ class AdminAppTextController extends AdminPageController
public function initialize(Request $request, AuthorizationCheckerInterface $authChecker)
{
$this->crudInfo = $this->newCrudInfo(self::REPOSITORY_NAME)
->setTemplateLocation('CantigaCoreBundle:AppText:')
->setTemplateLocation('CantigaAppTextBundle:AppText:')
->setItemNameProperty('title')
->setPageTitle('Application texts')
->setPageSubtitle('Manage texts displayed in various places of the application')
Expand All @@ -60,10 +60,10 @@ public function initialize(Request $request, AuthorizationCheckerInterface $auth
->setInsertPage('admin_app_text_insert')
->setEditPage('admin_app_text_edit')
->setRemovePage('admin_app_text_remove')
->setItemCreatedMessage('The text \'0\' has been created.')
->setItemUpdatedMessage('The text \'0\' has been updated.')
->setItemRemovedMessage('The text \'0\' has been removed.')
->setRemoveQuestion('Do you really want to remove \'0\' text?');
->setItemCreatedMessage('AppTextCreatedInfoMsg: 0')
->setItemUpdatedMessage('AppTextUpdatedInfoMsg: 0')
->setItemRemovedMessage('AppTextRemovedInfoMsg: 0')
->setRemoveQuestion('AppTextRemoveQuestion: 0');

$this->breadcrumbs()
->workgroup('settings')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* This file is part of Cantiga Project. Copyright 2016 Cantiga contributors.
* This file is part of Cantiga Project. Copyright 2016-2017 Cantiga contributors.
*
* Cantiga Project is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -14,20 +14,20 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar; if not, write to the Free Software
* along with Cantiga; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

namespace Cantiga\CoreBundle\Controller;
namespace Cantiga\AppTextBundle\Controller;

use Cantiga\CoreBundle\Api\Actions\CRUDInfo;
use Cantiga\CoreBundle\Api\Actions\EditAction;
use Cantiga\CoreBundle\Api\Actions\InfoAction;
use Cantiga\CoreBundle\Api\Actions\InsertAction;
use Cantiga\CoreBundle\Api\Actions\RemoveAction;
use Cantiga\CoreBundle\Api\Controller\ProjectPageController;
use Cantiga\CoreBundle\Entity\AppText;
use Cantiga\CoreBundle\Form\AppTextForm;
use Cantiga\AppTextBundle\Entity\AppText;
use Cantiga\AppTextBundle\Form\AppTextForm;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand All @@ -41,7 +41,7 @@
class ProjectAppTextController extends ProjectPageController
{

const REPOSITORY_NAME = 'cantiga.core.repo.text';
const REPOSITORY_NAME = 'cantiga.apptext.repo.text';

/**
* @var CRUDInfo
Expand All @@ -54,7 +54,7 @@ public function initialize(Request $request, AuthorizationCheckerInterface $auth
$repository->setProject($this->getActiveProject());

$this->crudInfo = $this->newCrudInfo(self::REPOSITORY_NAME)
->setTemplateLocation('CantigaCoreBundle:AppText:')
->setTemplateLocation('CantigaAppTextBundle:AppText:')
->setItemNameProperty('title')
->setPageTitle('Application texts')
->setPageSubtitle('Manage project-specific texts displayed in various places of the application')
Expand All @@ -63,10 +63,10 @@ public function initialize(Request $request, AuthorizationCheckerInterface $auth
->setInsertPage('project_app_text_insert')
->setEditPage('project_app_text_edit')
->setRemovePage('project_app_text_remove')
->setItemCreatedMessage('The text \'0\' has been created.')
->setItemUpdatedMessage('The text \'0\' has been updated.')
->setItemRemovedMessage('The text \'0\' has been removed.')
->setRemoveQuestion('Do you really want to remove \'0\' text?');
->setItemCreatedMessage('AppTextCreatedInfoMsg: 0')
->setItemUpdatedMessage('AppTextUpdatedInfoMsg: 0')
->setItemRemovedMessage('AppTextRemovedInfoMsg: 0')
->setRemoveQuestion('AppTextRemoveQuestion: 0');

$this->breadcrumbs()
->workgroup('manage')
Expand Down
47 changes: 47 additions & 0 deletions src/Cantiga/AppTextBundle/Database/AppTextAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/*
* This file is part of Cantiga Project. Copyright 2016-2017 Cantiga contributors.
*
* Cantiga Project is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Cantiga Project is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cantiga; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
namespace Cantiga\AppTextBundle\Database;

use Cantiga\CoreBundle\CoreTables;
use Doctrine\DBAL\Connection;

class AppTextAdapter
{
private $conn;

public function __construct(Connection $conn)
{
$this->conn = $conn;
}

public function selectGlobalText(string $place, string $locale)
{
return $this->conn->fetchAssoc('SELECT * FROM `'.CoreTables::APP_TEXT_TBL.'` '
. 'WHERE `place` = :place AND `locale` = :locale AND `projectId` IS NULL',
[':place' => $place, ':locale' => $locale]);
}

public function selectMatchingTexts(string $place, string $locale, int $projectId): array
{
return $this->conn->fetchAll('SELECT * FROM `'.CoreTables::APP_TEXT_TBL.'` '
. 'WHERE `place` = :place AND `locale` = :locale AND '
. '(`projectId` = :projectId OR `projectId` IS NULL)',
[':place' => $place, ':locale' => $locale, ':projectId' => $projectId]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/*
* This file is part of Cantiga Project. Copyright 2016 Cantiga contributors.
*
* Cantiga Project is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Cantiga Project is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
namespace Cantiga\AppTextBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

class CantigaAppTextExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
}
}
43 changes: 43 additions & 0 deletions src/Cantiga/AppTextBundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/*
* This file is part of Cantiga Project. Copyright 2016 Cantiga contributors.
*
* Cantiga Project is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Cantiga Project is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

namespace Cantiga\AppTextBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This is the class that validates and merges configuration from your app/config files
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/
class Configuration implements ConfigurationInterface
{

/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('cantiga_app_text');
return $treeBuilder;
}

}
Loading

0 comments on commit dae1aeb

Please sign in to comment.