mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
fix folder name
This commit is contained in:
68
src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadCenters.php
Normal file
68
src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadCenters.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a suite of a modules, Chill is a software for social workers
|
||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DataFixtures\ORM;
|
||||
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class LoadCenters extends AbstractFixture implements OrderedFixtureInterface
|
||||
{
|
||||
public function getOrder()
|
||||
{
|
||||
return 100;
|
||||
}
|
||||
|
||||
public static $centers = array(
|
||||
array(
|
||||
'name' => 'Center A',
|
||||
'ref' => 'centerA'
|
||||
),
|
||||
array(
|
||||
'name' => 'Center B',
|
||||
'ref' => 'centerB'
|
||||
)
|
||||
);
|
||||
|
||||
public static $refs = array();
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
foreach (static::$centers as $new) {
|
||||
$centerA = new Center();
|
||||
$centerA->setName($new['name']);
|
||||
|
||||
$manager->persist($centerA);
|
||||
$this->addReference($new['ref'], $centerA);
|
||||
static::$refs[] = $new['ref'];
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\DataFixtures\ORM;
|
||||
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Chill\MainBundle\Command\LoadCountriesCommand;
|
||||
|
||||
/**
|
||||
* Load countries into database
|
||||
*
|
||||
* @author Julien Fastré <julien arobase fastre point info>
|
||||
*/
|
||||
class LoadCountries extends AbstractFixture implements ContainerAwareInterface, OrderedFixtureInterface {
|
||||
|
||||
/**
|
||||
*
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
private $container;
|
||||
|
||||
public function setContainer(ContainerInterface $container = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function getOrder() {
|
||||
return 20;
|
||||
}
|
||||
|
||||
public function load(ObjectManager $manager) {
|
||||
|
||||
echo "loading countries... \n";
|
||||
|
||||
$languages = $this->container->getParameter('chill_main.available_languages');
|
||||
|
||||
foreach (LoadCountriesCommand::prepareCountryList($languages) as $country){
|
||||
$manager->persist($country);
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a suite of a modules, Chill is a software for social workers
|
||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DataFixtures\ORM;
|
||||
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Chill\MainBundle\Entity\GroupCenter;
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadCenters;
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadPermissionsGroup;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class LoadGroupCenters extends AbstractFixture implements OrderedFixtureInterface
|
||||
{
|
||||
public function getOrder()
|
||||
{
|
||||
return 500;
|
||||
}
|
||||
|
||||
public static $refs = array();
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
foreach (LoadCenters::$refs as $centerRef) {
|
||||
foreach (LoadPermissionsGroup::$refs as $permissionGroupRef) {
|
||||
$GroupCenter = new GroupCenter();
|
||||
$GroupCenter->setCenter($this->getReference($centerRef));
|
||||
$GroupCenter->setPermissionsGroup($this->getReference($permissionGroupRef));
|
||||
|
||||
$manager->persist($GroupCenter);
|
||||
|
||||
$reference = $centerRef.'_'.$permissionGroupRef;
|
||||
$this->addReference($reference, $GroupCenter);
|
||||
static::$refs[] = $reference;
|
||||
echo "Creating $reference... \n";
|
||||
}
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
}
|
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\DataFixtures\ORM;
|
||||
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
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>
|
||||
*/
|
||||
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"];
|
||||
|
||||
/**
|
||||
*
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
private $container;
|
||||
|
||||
public function setContainer(ContainerInterface $container = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function getOrder() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
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)
|
||||
) {
|
||||
|
||||
$lang = (new Language())
|
||||
->setId($code)
|
||||
->setName($this->prepareName($code))
|
||||
;
|
||||
$manager->persist($lang);
|
||||
}
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* prepare names for languages
|
||||
*
|
||||
* @param string $languageCode
|
||||
* @return string[] languages name indexed by available language code
|
||||
*/
|
||||
private function prepareName($languageCode) {
|
||||
foreach ($this->container->getParameter('chill_main.available_languages') as $lang) {
|
||||
$names[$lang] = Intl::getLanguageBundle()->getLanguageName($languageCode);
|
||||
}
|
||||
|
||||
return $names;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a suite of a modules, Chill is a software for social workers
|
||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DataFixtures\ORM;
|
||||
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Chill\MainBundle\Entity\PermissionsGroup;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class LoadPermissionsGroup extends AbstractFixture implements OrderedFixtureInterface
|
||||
{
|
||||
public function getOrder()
|
||||
{
|
||||
return 400;
|
||||
}
|
||||
|
||||
public static $permissionGroup = array(
|
||||
array(
|
||||
'name' => 'social',
|
||||
'role_scopes' => array(
|
||||
'role_scope_CHILL_FOO_EDIT_social',
|
||||
'role_scope_CHILL_FOO_SEE_administrative',
|
||||
"role_scope_CHILL_FOO_EDIT_all"
|
||||
)
|
||||
),
|
||||
array(
|
||||
'name' => 'administrative',
|
||||
'role_scopes' => array(
|
||||
"role_scope_CHILL_FOO_SEE_social",
|
||||
"role_scope_CHILL_FOO_EDIT_administrative",
|
||||
"role_scope_CHILL_FOO_EDIT_all"
|
||||
)
|
||||
),
|
||||
array(
|
||||
'name' => 'direction',
|
||||
'role_scopes' => array(
|
||||
"role_scope_CHILL_FOO_EDIT_all",
|
||||
"role_scope_CHILL_FOO_SEE_DETAILS_social",
|
||||
"role_scope_CHILL_FOO_SEE_DETAILS_administrative"
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
public static $refs = array();
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
foreach (static::$permissionGroup as $new) {
|
||||
$permissionGroup = new PermissionsGroup();
|
||||
$permissionGroup->setName($new['name']);
|
||||
foreach ($new['role_scopes'] as $roleScopeRef) {
|
||||
$permissionGroup->addRoleScope($this->getReference($roleScopeRef));
|
||||
}
|
||||
|
||||
$manager->persist($permissionGroup);
|
||||
$reference = 'permission_group_'.$new['name'];
|
||||
echo "Creating $reference \n";
|
||||
$this->setReference($reference, $permissionGroup);
|
||||
static::$refs[] = $reference;
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
}
|
105
src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadPostalCodes.php
Normal file
105
src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadPostalCodes.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2016, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DataFixtures\ORM;
|
||||
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Chill\MainBundle\Entity\PostalCode;
|
||||
|
||||
/**
|
||||
* Description of LoadPostalCodes
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @author Champs Libres <info@champs-libres.coop>
|
||||
*/
|
||||
class LoadPostalCodes extends AbstractFixture implements OrderedFixtureInterface
|
||||
{
|
||||
public function getOrder()
|
||||
{
|
||||
return 50;
|
||||
}
|
||||
|
||||
public static $refs = array();
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
$lines = str_getcsv(self::$codes, "\n");
|
||||
$belgium = $manager->getRepository('ChillMainBundle:Country')
|
||||
->findOneBy(array('countryCode' => 'BE'));
|
||||
|
||||
foreach($lines as $line) {
|
||||
$code = str_getcsv($line);
|
||||
$c = new PostalCode();
|
||||
$c->setCountry($belgium)
|
||||
->setCode($code[0])
|
||||
->setName(\ucwords(\strtolower($code[2])))
|
||||
;
|
||||
$manager->persist($c);
|
||||
$ref = 'postal_code_'.$code[0];
|
||||
|
||||
if (! $this->hasReference($ref)) {
|
||||
$this->addReference($ref, $c);
|
||||
self::$refs[] = $ref;
|
||||
}
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
private static $codes = <<<EOF
|
||||
1000,BRUXELLES,BRUXELLES,Bruxelles
|
||||
1020,Laeken,BRUXELLES,Bruxelles
|
||||
1030,SCHAERBEEK,SCHAERBEEK,Bruxelles
|
||||
1040,ETTERBEEK,ETTERBEEK,Bruxelles
|
||||
1050,IXELLES,IXELLES,Bruxelles
|
||||
1060,SAINT-GILLES,SAINT-GILLES,Bruxelles
|
||||
1070,ANDERLECHT,ANDERLECHT,Bruxelles
|
||||
1080,MOLENBEEK-SAINT-JEAN,MOLENBEEK-SAINT-JEAN,Bruxelles
|
||||
1081,KOEKELBERG,KOEKELBERG,Bruxelles
|
||||
1082,BERCHEM-SAINTE-AGATHE,BERCHEM-SAINTE-AGATHE,Bruxelles
|
||||
1083,GANSHOREN,GANSHOREN,Bruxelles
|
||||
1090,JETTE,JETTE,Bruxelles
|
||||
1120,Neder-Over-Heembeek,BRUXELLES,Bruxelles
|
||||
1130,Haren,BRUXELLES,Bruxelles
|
||||
1140,EVERE,EVERE,Bruxelles
|
||||
1150,WOLUWE-SAINT-PIERRE,WOLUWE-SAINT-PIERRE,Bruxelles
|
||||
1160,AUDERGHEM,AUDERGHEM,Bruxelles
|
||||
1170,WATERMAEL-BOITSFORT,WATERMAEL-BOITSFORT,Bruxelles
|
||||
1180,UCCLE,UCCLE,Bruxelles
|
||||
1190,FOREST,FOREST,Bruxelles
|
||||
1200,WOLUWE-SAINT-LAMBERT,WOLUWE-SAINT-LAMBERT,Bruxelles
|
||||
1210,SAINT-JOSSE-TEN-NOODE,SAINT-JOSSE-TEN-NOODE,Bruxelles
|
||||
1300,Limal,WAVRE,Brabant-Wallon
|
||||
1300,WAVRE,WAVRE,Brabant-Wallon
|
||||
1301,Bierges,WAVRE,Brabant-Wallon
|
||||
1310,LA HULPE,LA HULPE,Brabant-Wallon
|
||||
1315,Glimes,INCOURT,Brabant-Wallon
|
||||
1315,INCOURT,INCOURT,Brabant-Wallon
|
||||
1315,Opprebais,INCOURT,Brabant-Wallon
|
||||
1315,Piètrebais,INCOURT,Brabant-Wallon
|
||||
1315,Roux-Miroir,INCOURT,Brabant-Wallon
|
||||
1320,BEAUVECHAIN,BEAUVECHAIN,Brabant-Wallon
|
||||
EOF;
|
||||
|
||||
}
|
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a suite of a modules, Chill is a software for social workers
|
||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DataFixtures\ORM;
|
||||
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Chill\MainBundle\Entity\RoleScope;
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadScopes;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class LoadRoleScopes extends AbstractFixture implements OrderedFixtureInterface
|
||||
{
|
||||
public function getOrder()
|
||||
{
|
||||
return 300;
|
||||
}
|
||||
|
||||
public static $permissions = array(
|
||||
'CHILL_FOO_SEE' => array(
|
||||
'names' => array(
|
||||
'fr' => 'voir foo',
|
||||
'en' => 'see foo',
|
||||
'nl' => 'zie foo'
|
||||
)
|
||||
),
|
||||
'CHILL_FOO_SEE_DETAILS' => array(
|
||||
'names' => array(
|
||||
'fr' => 'voir foo avec détails',
|
||||
'en' => 'see foo with details',
|
||||
'nl' => 'zie foo in details'
|
||||
)
|
||||
),
|
||||
'CHILL_FOO_EDIT' => array(
|
||||
'names' => array(
|
||||
'fr' => 'modifier foo',
|
||||
'en' => 'edit foo',
|
||||
'nl' => 'editie foo'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
public static $references = array();
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
foreach (static::$permissions as $key => $permission) {
|
||||
foreach(LoadScopes::$references as $scopeReference) {
|
||||
$roleScope = new RoleScope();
|
||||
$roleScope->setRole($key)
|
||||
->setScope($this->getReference($scopeReference))
|
||||
;
|
||||
$reference = 'role_scope_'.$key.'_'.$this->getReference($scopeReference)->getName()['en'];
|
||||
echo "Creating $reference \n";
|
||||
$this->addReference($reference, $roleScope);
|
||||
$manager->persist($roleScope);
|
||||
static::$references[] = $reference;
|
||||
}
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
}
|
79
src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadScopes.php
Normal file
79
src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadScopes.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a suite of a modules, Chill is a software for social workers
|
||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DataFixtures\ORM;
|
||||
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
|
||||
/**
|
||||
* Create scopes
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class LoadScopes extends AbstractFixture implements OrderedFixtureInterface
|
||||
{
|
||||
public function getOrder()
|
||||
{
|
||||
return 200;
|
||||
}
|
||||
|
||||
public $scopes = array(
|
||||
array(
|
||||
'names' => array(
|
||||
'fr' => 'tous',
|
||||
'en' => 'all',
|
||||
'nl' => 'algemeen'
|
||||
),
|
||||
),
|
||||
array(
|
||||
'names' => array(
|
||||
'fr' => 'social',
|
||||
'en' => 'social',
|
||||
'nl' => 'sociaal'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'names' => array(
|
||||
'fr' => 'administratif',
|
||||
'en' => 'administrative',
|
||||
'nl' => 'administratief'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
public static $references = array();
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
foreach ($this->scopes as $new) {
|
||||
$scope = new \Chill\MainBundle\Entity\Scope();
|
||||
$scope->setName($new['names']);
|
||||
|
||||
$manager->persist($scope);
|
||||
$reference = 'scope_'.$new['names']['en'];
|
||||
$this->addReference($reference, $scope);
|
||||
static::$references[] = $reference;
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
}
|
105
src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadUsers.php
Normal file
105
src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadUsers.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\DataFixtures\ORM;
|
||||
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadCenters;
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadPermissionsGroup;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Symfony\Component\Security\Core\Encoder\EncoderFactory;
|
||||
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
|
||||
|
||||
/**
|
||||
* Load fixtures users into database
|
||||
*
|
||||
* create a user for each permission_group and center.
|
||||
* username and password are identicals.
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class LoadUsers extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
private $container;
|
||||
|
||||
public function getOrder()
|
||||
{
|
||||
return 1000;
|
||||
}
|
||||
|
||||
public static $refs = array(
|
||||
'center a_social' => array(
|
||||
'groupCenterRefs' => ['centerA_permission_group_social']
|
||||
),
|
||||
'center a_administrative' => array(
|
||||
'groupCenterRefs' => ['centerA_permission_group_administrative']
|
||||
),
|
||||
'center a_direction' => array(
|
||||
'groupCenterRefs' => ['centerA_permission_group_direction']
|
||||
),
|
||||
'center b_social' => array(
|
||||
'groupCenterRefs' => ['centerB_permission_group_social']
|
||||
),
|
||||
'center b_administrative' => array(
|
||||
'groupCenterRefs' => ['centerB_permission_group_administrative']
|
||||
),
|
||||
'center b_direction' => array(
|
||||
'groupCenterRefs' => ['centerB_permission_group_direction']
|
||||
),
|
||||
'multi_center' => array(
|
||||
'groupCenterRefs' => ['centerA_permission_group_social',
|
||||
'centerB_permission_group_social']
|
||||
)
|
||||
|
||||
);
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
foreach (self::$refs as $username => $params) {
|
||||
|
||||
$user = new User();
|
||||
|
||||
$defaultEncoder = new MessageDigestPasswordEncoder('sha512', true, 5000);
|
||||
|
||||
$encoderFactory = new EncoderFactory([
|
||||
User::class => $defaultEncoder
|
||||
]);
|
||||
|
||||
$user
|
||||
->setUsername($username)
|
||||
->setPassword($encoderFactory
|
||||
->getEncoder($user)
|
||||
->encodePassword('password', $user->getSalt())
|
||||
)
|
||||
->setEmail(sprintf("%s@chill.social", \str_replace(' ', '', $username)))
|
||||
;
|
||||
|
||||
foreach ($params['groupCenterRefs'] as $groupCenterRef) {
|
||||
$user->addGroupCenter($this->getReference($groupCenterRef));
|
||||
}
|
||||
|
||||
echo 'Creating user ' . $username ."... \n";
|
||||
$manager->persist($user);
|
||||
$this->addReference($username, $user);
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
public function setContainer(ContainerInterface $container = null)
|
||||
{
|
||||
if (NULL === $container) {
|
||||
throw new \LogicException('$container should not be null');
|
||||
}
|
||||
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user