mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,60 +1,57 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DataFixtures\ORM;
|
||||
|
||||
use Chill\MainBundle\Entity\Language;
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Symfony\Component\Intl\Intl;
|
||||
use Chill\MainBundle\Entity\Language;
|
||||
|
||||
/**
|
||||
* Load languages into database
|
||||
*
|
||||
* @author Julien Fastré <julien arobase fastre point info>
|
||||
* Load languages into database.
|
||||
*/
|
||||
class LoadLanguages extends AbstractFixture implements ContainerAwareInterface, OrderedFixtureInterface
|
||||
{
|
||||
// The regional version of language are language with _ in the code
|
||||
// This array contains regional code to not exclude
|
||||
private $regionalVersionToInclude = ["ro_MD"];
|
||||
|
||||
// Array of ancien languages (to exclude)
|
||||
private $ancientToExclude = ["ang", "egy", "fro", "goh", "grc", "la", "non", "peo", "pro", "sga",
|
||||
"dum", "enm", "frm", "gmh", "mga", "akk", "phn", "zxx", "got", "und"];
|
||||
private $ancientToExclude = ['ang', 'egy', 'fro', 'goh', 'grc', 'la', 'non', 'peo', 'pro', 'sga',
|
||||
'dum', 'enm', 'frm', 'gmh', 'mga', 'akk', 'phn', 'zxx', 'got', 'und', ];
|
||||
|
||||
/**
|
||||
*
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
private $container;
|
||||
|
||||
public function setContainer(ContainerInterface $container = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
// The regional version of language are language with _ in the code
|
||||
// This array contains regional code to not exclude
|
||||
private $regionalVersionToInclude = ['ro_MD'];
|
||||
|
||||
public function getOrder() {
|
||||
public function getOrder()
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
|
||||
public function load(ObjectManager $manager) {
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
echo "loading languages... \n";
|
||||
|
||||
foreach (Intl::getLanguageBundle()->getLanguageNames() as $code => $language) {
|
||||
if (
|
||||
!in_array($code, $this->regionalVersionToInclude)
|
||||
&&
|
||||
!in_array($code, $this->ancientToExclude)
|
||||
&& !in_array($code, $this->ancientToExclude)
|
||||
) {
|
||||
|
||||
$lang = (new Language())
|
||||
->setId($code)
|
||||
->setName($this->prepareName($code))
|
||||
;
|
||||
->setId($code)
|
||||
->setName($this->prepareName($code));
|
||||
$manager->persist($lang);
|
||||
}
|
||||
}
|
||||
@@ -62,12 +59,18 @@ class LoadLanguages extends AbstractFixture implements ContainerAwareInterface,
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
public function setContainer(?ContainerInterface $container = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare names for languages.
|
||||
*
|
||||
* @return string[] languages name indexed by available language code
|
||||
*/
|
||||
private function prepareName(string $languageCode): array {
|
||||
private function prepareName(string $languageCode): array
|
||||
{
|
||||
$names = [];
|
||||
|
||||
foreach ($this->container->getParameter('chill_main.available_languages') as $lang) {
|
||||
@@ -76,6 +79,4 @@ class LoadLanguages extends AbstractFixture implements ContainerAwareInterface,
|
||||
|
||||
return $names;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user