mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Prepare for moving into monorepo
This commit is contained in:
148
src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivity.php
Normal file
148
src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivity.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2015, 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\ActivityBundle\DataFixtures\ORM;
|
||||
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Faker\Factory as FakerFactory;
|
||||
use Chill\ActivityBundle\Entity\Activity;
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadUsers;
|
||||
use Chill\ActivityBundle\DataFixtures\ORM\LoadActivityReason;
|
||||
use Chill\ActivityBundle\DataFixtures\ORM\LoadActivityType;
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadScopes;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
|
||||
/**
|
||||
* Load reports into DB
|
||||
*
|
||||
* @author Champs-Libres Coop
|
||||
*/
|
||||
class LoadActivity extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
|
||||
{
|
||||
use \Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
|
||||
/**
|
||||
* @var \Faker\Generator
|
||||
*/
|
||||
private $faker;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->faker = FakerFactory::create('fr_FR');
|
||||
}
|
||||
|
||||
public function getOrder()
|
||||
{
|
||||
return 16400;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a random scope
|
||||
*
|
||||
* @return \Chill\MainBundle\Entity\Scope
|
||||
*/
|
||||
private function getRandomScope()
|
||||
{
|
||||
$scopeRef = LoadScopes::$references[array_rand(LoadScopes::$references)];
|
||||
return $this->getReference($scopeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a random activityType
|
||||
*
|
||||
* @return \Chill\ActivityBundle\Entity\ActivityType
|
||||
*/
|
||||
private function getRandomActivityType()
|
||||
{
|
||||
$typeRef = LoadActivityType::$references[array_rand(LoadActivityType::$references)];
|
||||
return $this->getReference($typeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a random activityReason
|
||||
*
|
||||
* @return \Chill\ActivityBundle\Entity\ActivityReason
|
||||
*/
|
||||
private function getRandomActivityReason(array $excludingIds)
|
||||
{
|
||||
$reasonRef = LoadActivityReason::$references[array_rand(LoadActivityReason::$references)];
|
||||
|
||||
if (in_array($this->getReference($reasonRef)->getId(), $excludingIds)) {
|
||||
// we have a reason which should be excluded. Find another...
|
||||
return $this->getRandomActivityReason($excludingIds);
|
||||
}
|
||||
|
||||
return $this->getReference($reasonRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a random user
|
||||
*
|
||||
* @return \Chill\MainBundle\Entity\User
|
||||
*/
|
||||
private function getRandomUser()
|
||||
{
|
||||
$userRef = array_rand(LoadUsers::$refs);
|
||||
return $this->getReference($userRef);
|
||||
}
|
||||
|
||||
public function newRandomActivity($person)
|
||||
{
|
||||
$activity = (new Activity())
|
||||
->setUser($this->getRandomUser())
|
||||
->setPerson($person)
|
||||
->setDate($this->faker->dateTimeThisYear())
|
||||
->setDurationTime($this->faker->dateTime(36000))
|
||||
->setType($this->getRandomActivityType())
|
||||
->setScope($this->getRandomScope())
|
||||
->setAttendee($this->faker->boolean())
|
||||
;
|
||||
|
||||
$usedId = array();
|
||||
for ($i = 0; $i < rand(0, 4); $i++) {
|
||||
$reason = $this->getRandomActivityReason($usedId);
|
||||
$usedId[] = $reason->getId();
|
||||
$activity->addReason($reason);
|
||||
}
|
||||
|
||||
return $activity;
|
||||
}
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
$persons = $this->container->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillPersonBundle:Person')
|
||||
->findAll();
|
||||
|
||||
foreach($persons as $person) {
|
||||
$activityNbr = rand(0,3);
|
||||
for($i = 0; $i < $activityNbr; $i ++) {
|
||||
print "Creating an activity type for : ".$person."\n";
|
||||
$activity = $this->newRandomActivity($person);
|
||||
$manager->persist($activity);
|
||||
}
|
||||
}
|
||||
$manager->flush();
|
||||
}
|
||||
}
|
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2015, 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\ActivityBundle\DataFixtures\ORM;
|
||||
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Chill\ActivityBundle\Entity\ActivityReason;
|
||||
|
||||
/**
|
||||
* Description of LoadActivityReason
|
||||
*
|
||||
* @author Champs-Libres Coop
|
||||
*/
|
||||
class LoadActivityReason extends AbstractFixture implements OrderedFixtureInterface
|
||||
{
|
||||
public function getOrder()
|
||||
{
|
||||
return 16300;
|
||||
}
|
||||
|
||||
public static $references = array();
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
$reasons = [
|
||||
[
|
||||
'name' => ['fr' => 'Recherche logement', 'en' => 'Housing research', 'nl' => 'Woning zoektoch'],
|
||||
'category' => 'cat_Housing'],
|
||||
[
|
||||
'name' => ['fr' => 'Problème avec propriétaire', 'en' => 'Landlord problems', 'nl' => 'Huisbaas problemen'],
|
||||
'category' => 'cat_Housing'],
|
||||
[
|
||||
'name' => ['fr' => 'Retard de payement', 'en' => 'Payement problems', 'nl' => 'Betalings vertragingen'],
|
||||
'category' => 'cat_Housing'],
|
||||
[
|
||||
'name' => ['fr' => 'Explication législation', 'en' => 'Legislation explanation', 'nl' => 'Legislative uitleg'],
|
||||
'category' => 'cat_Unemployment procedure'],
|
||||
[
|
||||
'name' => ['fr' => 'Coaching entretien d\'activation', 'en' => 'Interview coaching', 'nl' => 'Interview coaching'],
|
||||
'category' => 'cat_Unemployment procedure'],
|
||||
[
|
||||
'name' => ['fr' => 'Récupération des allocations', 'en' => 'Allowance recovery', 'nl' => 'Terugwinning van de uitkeringen'],
|
||||
'category' => 'cat_Unemployment procedure']
|
||||
];
|
||||
|
||||
foreach ($reasons as $r) {
|
||||
print "Creating activity reason : " . $r['name']['en'] . "\n";
|
||||
$activityReason = (new ActivityReason())
|
||||
->setName(($r['name']))
|
||||
->setActive(true)
|
||||
->setCategory($this->getReference($r['category']));
|
||||
$manager->persist($activityReason);
|
||||
$reference = 'activity_reason_'.$r['name']['en'];
|
||||
$this->addReference($reference, $activityReason);
|
||||
static::$references[] = $reference;
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2015, 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\ActivityBundle\DataFixtures\ORM;
|
||||
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Chill\ActivityBundle\Entity\ActivityReasonCategory;
|
||||
/**
|
||||
* Description of LoadActivityReasonCategory
|
||||
*
|
||||
* @author Champs-Libres Coop
|
||||
*/
|
||||
class LoadActivityReasonCategory extends AbstractFixture implements OrderedFixtureInterface
|
||||
{
|
||||
public function getOrder()
|
||||
{
|
||||
return 16200;
|
||||
}
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
$categs = [
|
||||
['name' =>
|
||||
['fr' => 'Logement', 'en' => 'Housing', 'nl' => 'Woning']],
|
||||
['name' =>
|
||||
['fr' => 'Démarches chômage', 'en' => 'Unemployment procedure', 'nl' => 'Werkloosheid werkwijze']],
|
||||
];
|
||||
|
||||
foreach ($categs as $c) {
|
||||
print "Creating activity reason category : " . $c['name']['en'] . "\n";
|
||||
$activityReasonCategory = (new ActivityReasonCategory())
|
||||
->setName(($c['name']))
|
||||
->setActive(true);
|
||||
$manager->persist($activityReasonCategory);
|
||||
$this->addReference(
|
||||
'cat_'.$c['name']['en'],
|
||||
$activityReasonCategory);
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2015, 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\ActivityBundle\DataFixtures\ORM;
|
||||
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Chill\ActivityBundle\Entity\ActivityType;
|
||||
|
||||
/**
|
||||
* Description of LoadActivityType
|
||||
*
|
||||
* @author Champs-Libres Coop
|
||||
*/
|
||||
class LoadActivityType extends AbstractFixture implements OrderedFixtureInterface
|
||||
{
|
||||
public function getOrder()
|
||||
{
|
||||
return 16100;
|
||||
}
|
||||
|
||||
public static $references = array();
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
$types = [
|
||||
[ 'name' =>
|
||||
['fr' => 'Appel téléphonique', 'en' => 'Telephone call', 'nl' => 'Telefoon appel']],
|
||||
[ 'name' =>
|
||||
['fr' => 'Entretien', 'en' => 'Interview', 'nl' => 'Vraaggesprek']],
|
||||
[ 'name' =>
|
||||
['fr' => 'Inspection', 'en' => 'Inspection', 'nl' => 'Inspectie']]
|
||||
];
|
||||
|
||||
foreach ($types as $t) {
|
||||
print "Creating activity type : " . $t['name']['en'] . "\n";
|
||||
$activityType = (new ActivityType())
|
||||
->setName(($t['name']));
|
||||
$manager->persist($activityType);
|
||||
$reference = 'activity_type_'.$t['name']['en'];
|
||||
$this->addReference($reference, $activityType);
|
||||
static::$references[] = $reference;
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
}
|
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Julien Fastré <julien.fastre@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\ActivityBundle\DataFixtures\ORM;
|
||||
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadPermissionsGroup;
|
||||
use Chill\MainBundle\Entity\RoleScope;
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadScopes;
|
||||
use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter;
|
||||
|
||||
/**
|
||||
* Add a role CHILL_ACTIVITY_UPDATE & CHILL_ACTIVITY_CREATE for all groups except administrative,
|
||||
* and a role CHILL_ACTIVITY_SEE for administrative
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class LoadActivitytACL extends AbstractFixture implements OrderedFixtureInterface
|
||||
{
|
||||
public function getOrder()
|
||||
{
|
||||
return 16000;
|
||||
}
|
||||
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
foreach (LoadPermissionsGroup::$refs as $permissionsGroupRef) {
|
||||
$permissionsGroup = $this->getReference($permissionsGroupRef);
|
||||
foreach (LoadScopes::$references as $scopeRef){
|
||||
$scope = $this->getReference($scopeRef);
|
||||
//create permission group
|
||||
switch ($permissionsGroup->getName()) {
|
||||
case 'social':
|
||||
if ($scope->getName()['en'] === 'administrative') {
|
||||
break 2; // we do not want any power on administrative
|
||||
}
|
||||
break;
|
||||
case 'administrative':
|
||||
case 'direction':
|
||||
if (in_array($scope->getName()['en'], array('administrative', 'social'))) {
|
||||
break 2; // we do not want any power on social or administrative
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
printf("Adding CHILL_ACTIVITY_UPDATE & CHILL_ACTIVITY_CREATE & CHILL_ACTIVITY_DELETE, and stats and list permissions to %s "
|
||||
. "permission group, scope '%s' \n",
|
||||
$permissionsGroup->getName(), $scope->getName()['en']);
|
||||
$roleScopeUpdate = (new RoleScope())
|
||||
->setRole('CHILL_ACTIVITY_UPDATE')
|
||||
->setScope($scope);
|
||||
$permissionsGroup->addRoleScope($roleScopeUpdate);
|
||||
$roleScopeCreate = (new RoleScope())
|
||||
->setRole('CHILL_ACTIVITY_CREATE')
|
||||
->setScope($scope);
|
||||
$permissionsGroup->addRoleScope($roleScopeCreate);
|
||||
$roleScopeDelete = (new RoleScope())
|
||||
->setRole('CHILL_ACTIVITY_DELETE')
|
||||
->setScope($scope);
|
||||
$permissionsGroup->addRoleScope($roleScopeDelete);
|
||||
$roleScopeList = (new RoleScope())
|
||||
->setRole(ActivityStatsVoter::LISTS)
|
||||
;
|
||||
$permissionsGroup->addRoleScope($roleScopeList);
|
||||
$roleScopeStat = (new RoleScope())
|
||||
->setRole(ActivityStatsVoter::STATS)
|
||||
;
|
||||
$permissionsGroup->addRoleScope($roleScopeStat);
|
||||
|
||||
$manager->persist($roleScopeUpdate);
|
||||
$manager->persist($roleScopeCreate);
|
||||
$manager->persist($roleScopeDelete);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user