ninegate/src/cadolesuser-1.0/src/Cadoles/PortalBundle/Command/InitDataCommand.php

157 lines
6.6 KiB
PHP
Raw Normal View History

2019-03-12 14:50:57 +01:00
<?php
namespace Cadoles\PortalBundle\Command;
2019-03-13 17:30:41 +01:00
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
2019-03-12 14:50:57 +01:00
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\KernelInterface;
use Doctrine\DBAL\Connection as DBALConnection;
2019-03-21 17:15:06 +01:00
use Doctrine\ORM\em;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Id\AssignedGenerator;
2019-03-12 14:50:57 +01:00
2019-03-13 17:30:41 +01:00
use Cadoles\PortalBundle\Entity\Icon;
2019-03-21 17:15:06 +01:00
use Cadoles\PortalBundle\Entity\Pagecategory;
use Cadoles\PortalBundle\Entity\Widget;
2019-03-12 14:50:57 +01:00
2019-03-13 17:30:41 +01:00
class InitDataCommand extends ContainerAwareCommand
2019-03-12 14:50:57 +01:00
{
protected function configure()
{
$this
->setName('Portal:InitData')
->setDescription('Init Data for Portal')
->setHelp('This command Init Data for Portal')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
2019-03-13 17:30:41 +01:00
$em = $this->getContainer()->get('doctrine')->getEntityManager();
$output->writeln('PORTAL = Default Data');
// Creation des icons
2019-03-21 17:15:06 +01:00
$output->writeln(' > Creation Icons');
2019-03-13 17:30:41 +01:00
$finder = new Finder();
$finder->in('web/uploads/icon/');
$finder->name('icon_*');
foreach ($finder as $file) {
$image="uploads/icon/".$file->getRelativePathname();
$entityicon = $em->getRepository('CadolesPortalBundle:Icon')->findoneby(["label"=>$image]);
if(!$entityicon) {
$entityicon = new Icon;
$entityicon->setLabel($image);
$em->persist($entityicon);
}
}
2019-03-21 17:15:06 +01:00
// Creation des pagecategory
$output->writeln(' > Creation Pagecategory');
$entityPagecategory = $em->getRepository('CadolesPortalBundle:Pagecategory')->find(1);
if(!$entityPagecategory) {
$entityPagecategory = new Pagecategory();
$entityPagecategory->setId(1);
$entityPagecategory->setName('URL');
$em->persist($entityPagecategory);
}
$entityPagecategory = $em->getRepository('CadolesPortalBundle:Pagecategory')->find(2);
if(!$entityPagecategory) {
$entityPagecategory = new Pagecategory();
$entityPagecategory->setId(2);
$entityPagecategory->setName('Widget');
$em->persist($entityPagecategory);
}
$entityPagecategory = $em->getRepository('CadolesPortalBundle:Pagecategory')->find(3);
if(!$entityPagecategory) {
$entityPagecategory = new Pagecategory();
$entityPagecategory->setId(3);
$entityPagecategory->setName('Editeur');
$em->persist($entityPagecategory);
}
// Creation des Widgets
$output->writeln(' > Creation Widget');
$entityWidget = $em->getRepository('CadolesPortalBundle:Widget')->find(-2000);
if(!$entityWidget) {
$entityicon = $em->getRepository('CadolesPortalBundle:Icon')->findoneby(["label"=>"uploads/icon/icon_ribbon.png"]);
$entityWidget = new Widget();
$entityWidget->setId(-2000);
$entityWidget->setRoworder(1);
$entityWidget->setIcon($entityicon);
$entityWidget->setName('URL');
$entityWidget->setDescription("Affiche le contenu d'une url");
$entityWidget->setRouteview("cadoles_portal_config_panelwidget_view_url");
$entityWidget->setHeight("630");
$entityWidget->setAutoajust(false);
$entityWidget->setBorder(true);
$parameter = json_decode('{"fields": [{"id": "url", "loc": "col1", "type": "string", "label": "URL", "value": "", "mandatory": "true"}]}');
$entityWidget->setParameter($parameter);
$em->persist($entityWidget);
}
$entityWidget = $em->getRepository('CadolesPortalBundle:Widget')->find(-1990);
if(!$entityWidget) {
$entityicon = $em->getRepository('CadolesPortalBundle:Icon')->findoneby(["label"=>"uploads/icon/icon_computer.png"]);
$entityWidget = new Widget();
$entityWidget->setId(-1990);
$entityWidget->setRoworder(2);
$entityWidget->setIcon($entityicon);
$entityWidget->setName('Bureau');
$entityWidget->setDescription("Affiche vos items de bureau");
$entityWidget->setRouteview("cadoles_portal_config_panelwidget_view_item");
$entityWidget->setHeight("630");
$entityWidget->setAutoajust(true);
$entityWidget->setBorder(false);
$entityWidget->setColorbodyback("ffffff");
$parameter = json_decode('{"fields": [{"id": "modedesktop", "loc": "col1", "type": "desktopmode", "label": "Mode Affichage", "value": "0", "mandatory": "true"},{"id": "itemcategory", "loc": "col1", "type": "itemcategory", "label": "Catégorie Affichée", "value": "", "mandatory": "false"}]}');
$entityWidget->setParameter($parameter);
$em->persist($entityWidget);
}
$entityWidget = $em->getRepository('CadolesPortalBundle:Widget')->find(-1980);
if(!$entityWidget) {
$entityicon = $em->getRepository('CadolesPortalBundle:Icon')->findoneby(["label"=>"uploads/icon/icon_megaphone.png"]);
$entityWidget = new Widget();
$entityWidget->setId(-1980);
$entityWidget->setRoworder(3);
$entityWidget->setIcon($entityicon);
$entityWidget->setName('Annonces');
$entityWidget->setDescription("Affiche vos annonces");
$entityWidget->setRouteview("cadoles_portal_config_panelwidget_view_alert");
$entityWidget->setHeight("630");
$entityWidget->setAutoajust(true);
$entityWidget->setBorder(false);
$entityWidget->setColorbodyback("ffffff");
$parameter = json_decode('{"fields": [{"id": "alertcategory", "loc": "col1", "type": "alertcategory", "label": "Catégorie Affichée", "value": "", "mandatory": "false"}]}');
$entityWidget->setParameter($parameter);
$em->persist($entityWidget);
}
// afin de forcer les ID sur certaines entités
$metadata = $em->getClassMetaData(get_class($entityWidget));
$metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
$metadata->setIdGenerator(new AssignedGenerator());
$metadata = $em->getClassMetaData(get_class($entityPagecategory));
$metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
$metadata->setIdGenerator(new AssignedGenerator());
2019-03-13 17:30:41 +01:00
$em->flush();
$output->writeln('');
2019-03-12 14:50:57 +01:00
}
}