init
This commit is contained in:
621
src/Command/AppInitCommand.php
Normal file
621
src/Command/AppInitCommand.php
Normal file
@ -0,0 +1,621 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Id\AssignedGenerator;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\Category;
|
||||
use App\Entity\Config;
|
||||
|
||||
class AppInitCommand extends Command
|
||||
{
|
||||
|
||||
private $container;
|
||||
private $em;
|
||||
private $output;
|
||||
private $filesystem;
|
||||
private $rootlog;
|
||||
private $appname;
|
||||
private $appmailnoreply;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('app:AppInit')
|
||||
->setDescription('Init Data for App')
|
||||
->setHelp('This command Init Data App')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
$this->appname = $this->container->getParameter('appName');
|
||||
$this->appmailnoreply = $this->container->getParameter('appMailnoreply');
|
||||
|
||||
$output->writeln('APP = Default Data');
|
||||
|
||||
// Création du compte admin si non existant
|
||||
$this->insertUser("admin","admin");
|
||||
|
||||
// Création d'une catégory par défaut
|
||||
$this->insertCategory(-100,1,"Illustrations");
|
||||
|
||||
// colorbgbody = Couleur des fonds de page
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"site", // category
|
||||
"appname", // id
|
||||
"Titre de votre site", // title
|
||||
"", // value
|
||||
"string", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Titre de votre site"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
2, // order
|
||||
"site", // category
|
||||
"appsubname", // id
|
||||
"Sous-titre de votre site", // title
|
||||
"", // value
|
||||
"string", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Sous-titre de votre site"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
3, // order
|
||||
"site", // category
|
||||
"appdescription", // id
|
||||
"Description de votre site", // title
|
||||
"", // value
|
||||
"editor", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Description de votre site"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
4, // order
|
||||
"site", // category
|
||||
"appthumbwidth", // id
|
||||
"Largeur des miniatures", // title
|
||||
"0", // value
|
||||
"thumbwidth", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"" , // grouped
|
||||
"Largeur des miniatures"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
5, // order
|
||||
"site", // category
|
||||
"appthumbheight", // id
|
||||
"Hauteur des miniatures", // title
|
||||
"0", // value
|
||||
"thumbheight", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"" , // grouped
|
||||
"Largeur des miniatures"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
6, // order
|
||||
"site", // category
|
||||
"appthumbfilter", // id
|
||||
"Filtre sur les miniatures", // title
|
||||
"0", // value
|
||||
"boolean", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"" , // grouped
|
||||
"Filtre sur les miniatures"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
7, // order
|
||||
"site", // category
|
||||
"appthumbfiltergrayscale", // id
|
||||
"Filtre grayscale sur les miniatures", // title
|
||||
"100", // value
|
||||
"pourcentage", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"appthumbfilter" , // grouped
|
||||
"Filtre grayscale sur les miniatures"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
8, // order
|
||||
"site", // category
|
||||
"appthumbfilteropacity", // id
|
||||
"Filtre opacity sur les miniatures", // title
|
||||
"100", // value
|
||||
"pourcentage", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"appthumbfilter" , // grouped
|
||||
"Filtre opacity sur les miniatures"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
9, // order
|
||||
"site", // category
|
||||
"appthumbfiltersepia", // id
|
||||
"Filtre sepia sur les miniatures", // title
|
||||
"0", // value
|
||||
"pourcentage", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"appthumbfilter" , // grouped
|
||||
"Filtre sepia sur les miniatures"
|
||||
);
|
||||
|
||||
|
||||
$this->insertConfig(
|
||||
10, // order
|
||||
"site", // category
|
||||
"appmaxthumbwidth", // id
|
||||
"Largeur maximum de la grille des thumbs", // title
|
||||
"0", // value
|
||||
"integer", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"" , // grouped
|
||||
"Largeur maximum de la grille des thumbs\n0 pour indiquer qu'il n'y a pas de taille maximum"
|
||||
);
|
||||
|
||||
// colorbgbody = Couleur des fonds de page
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"colorbgbody", // category
|
||||
"colorbgbodydark", // id
|
||||
"Couleur de fond fonçée", // title
|
||||
"#343a40", // value
|
||||
"color", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"", // grouped
|
||||
"La couleur de fond quand le site a besoin d'avoir une couleur de fond foncée"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
2, // order
|
||||
"colorbgbody", // category
|
||||
"colorbgbodylight", // id
|
||||
"Couleur de fond claire", // title
|
||||
"#ffffff", // value
|
||||
"color", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"", // grouped
|
||||
"La couleur de fond quand le site a besoin d'avoir une couleur de fond claire"
|
||||
);
|
||||
|
||||
// colorfttitle = Couleur des fontes titre
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"colorfttitle", // category
|
||||
"colorfttitledark", // id
|
||||
"Couleur des titres sur fond fonçé", // title
|
||||
"#ffffff", // value
|
||||
"color", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"", // grouped
|
||||
"La couleur des titres sur fond fonçé"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
2, // order
|
||||
"colorfttitle", // category
|
||||
"colorfttitlelight", // id
|
||||
"Couleur des titres sur fond claire", // title
|
||||
"#343a40", // value
|
||||
"color", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"", // grouped
|
||||
"La couleur des titres sur fond claire"
|
||||
);
|
||||
|
||||
// colorftbody = Couleur des fontes titre
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"colorftbody", // category
|
||||
"colorftbodydark", // id
|
||||
"Couleur de la police sur fond fonçé", // title
|
||||
"#ffffff", // value
|
||||
"color", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"", // grouped
|
||||
"La couleur de la police sur fond fonçé"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
2, // order
|
||||
"colorftbody", // category
|
||||
"colorftbodylight", // id
|
||||
"Couleur de la police sur fond claire", // title
|
||||
"#343a40", // value
|
||||
"color", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"", // grouped
|
||||
"La couleur de la police sur fond claire"
|
||||
);
|
||||
|
||||
// font = nom des polices
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"font", // category
|
||||
"fonttitle", // id
|
||||
"Police pour les titres", // title
|
||||
"FredokaOne-Regular", // value
|
||||
"font", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"", // grouped
|
||||
"La couleur de la police de votre site"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
2, // order
|
||||
"font", // category
|
||||
"fontbody", // id
|
||||
"Police principale", // title
|
||||
"Roboto-Regular", // value
|
||||
"font", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"", // grouped
|
||||
"Nom de la police principale"
|
||||
);
|
||||
|
||||
// logo =
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"logo", // category
|
||||
"logodark", // id
|
||||
"Logo sur fond fonçé", // title
|
||||
"", // value
|
||||
"logo", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Logo sur fond fonçé"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
2, // order
|
||||
"logo", // category
|
||||
"logolight", // id
|
||||
"Logo sur fond clair", // title
|
||||
"", // value
|
||||
"logo", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Logo sur fond clair"
|
||||
);
|
||||
|
||||
// image =
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"image", // category
|
||||
"imgcontact", // id
|
||||
"Image Contact", // title
|
||||
"", // value
|
||||
"image", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Image associée à la section contact"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"image", // category
|
||||
"imglink", // id
|
||||
"Image Liens", // title
|
||||
"", // value
|
||||
"image", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Image associée à la section liens"
|
||||
);
|
||||
|
||||
// hero =
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"hero", // category
|
||||
"hero01", // id
|
||||
"Carrousel 01", // title
|
||||
"", // value
|
||||
"hero", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Image 01 de votre carrousel"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
2, // order
|
||||
"hero", // category
|
||||
"hero02", // id
|
||||
"Carrousel 02", // title
|
||||
"", // value
|
||||
"hero", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Image 02 de votre carrousel"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
3, // order
|
||||
"hero", // category
|
||||
"hero03", // id
|
||||
"Carrousel 03", // title
|
||||
"", // value
|
||||
"hero", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Image 03 de votre carrousel"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
4, // order
|
||||
"hero", // category
|
||||
"hero04", // id
|
||||
"Carrousel 04", // title
|
||||
"", // value
|
||||
"hero", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Image 04 de votre carrousel"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
5, // order
|
||||
"hero", // category
|
||||
"hero05", // id
|
||||
"Carrousel 05", // title
|
||||
"", // value
|
||||
"hero", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Image 05 de votre carrousel"
|
||||
);
|
||||
|
||||
// Social =
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"social", // category
|
||||
"email", // id
|
||||
"Email", // title
|
||||
"", // value
|
||||
"string", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"L'email du site"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
2, // order
|
||||
"social", // category
|
||||
"facebook", // id
|
||||
"Facebook", // title
|
||||
"", // value
|
||||
"string", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Le Facebook du site"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
3, // order
|
||||
"social", // category
|
||||
"instagram", // id
|
||||
"Instagram", // title
|
||||
"", // value
|
||||
"string", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Le Instagram du site"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
4, // order
|
||||
"social", // category
|
||||
"twitter", // id
|
||||
"Twitter", // title
|
||||
"", // value
|
||||
"string", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Le Twitter du site"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
5, // order
|
||||
"social", // category
|
||||
"google", // id
|
||||
"Google", // title
|
||||
"", // value
|
||||
"string", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Le Google du site"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
6, // order
|
||||
"social", // category
|
||||
"youtube", // id
|
||||
"Youtube", // title
|
||||
"", // value
|
||||
"string", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Le Youtube du site"
|
||||
);
|
||||
|
||||
$output->writeln('');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
protected function insertUser() {
|
||||
$metadata = $this->em->getClassMetaData('App:User');
|
||||
$metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
|
||||
$metadata->setIdGenerator(new AssignedGenerator());
|
||||
|
||||
// Création du compte admin par défaut
|
||||
$entity = $this->em->getRepository('App:User')->findOneBy(["username"=>"admin"]);
|
||||
if(!$entity) {
|
||||
$this->writelnred('Création du compte admin par défaut avec password admin - Veuillez modifier votre password admin après connexion');
|
||||
$entity = new User;
|
||||
$entity->setId(-100);
|
||||
$entity->setUsername("admin");
|
||||
$entity->setPassword("admin");
|
||||
$entity->setFirstname($this->appname);
|
||||
$entity->setLastname("Admin");
|
||||
$entity->setEmail($this->appmailnoreply);
|
||||
$entity->setRoles(["ROLE_ADMIN"]);
|
||||
$entity->setAvatar("admin.jpg");
|
||||
$this->em->persist($entity);
|
||||
}
|
||||
|
||||
// On flush
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
protected function insertCategory($id,$order,$name) {
|
||||
$metadata = $this->em->getClassMetaData('App:Category');
|
||||
$metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
|
||||
$metadata->setIdGenerator(new AssignedGenerator());
|
||||
|
||||
// Création du compte admin par défaut
|
||||
$entity = $this->em->getRepository('App:Category')->find($id);
|
||||
if(!$entity) {
|
||||
$entity = new Category;
|
||||
$entity->setId($id);
|
||||
$entity->setOrder($order);
|
||||
$entity->setName($name);
|
||||
$entity->setUsecategoryconfig(false);
|
||||
$entity->setAppthumbfilter(false);
|
||||
$entity->setAppthumbheight(0);
|
||||
$entity->setAppthumbwidth(0);
|
||||
$entity->setAppthumbfilter(false);
|
||||
$entity->setAppthumbfiltergrayscale(100);
|
||||
$entity->setAppthumbfilteropacity(100);
|
||||
$entity->setAppthumbfiltersepia(0);
|
||||
$this->em->persist($entity);
|
||||
}
|
||||
|
||||
// On flush
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
protected function insertConfig($order,$category,$id,$title,$value,$type,$visible,$changeable,$required,$grouped,$help) {
|
||||
$entity=$this->em->getRepository("App:Config")->find($id);
|
||||
if(!$entity) {
|
||||
$entity= new Config();
|
||||
$entity->setId($id);
|
||||
$entity->setValue($value);
|
||||
}
|
||||
|
||||
$entity->setCategory($category);
|
||||
$entity->setOrder($order);
|
||||
$entity->setTitle($title);
|
||||
$entity->setType($type);
|
||||
$entity->setVisible($visible);
|
||||
$entity->setChangeable($changeable);
|
||||
$entity->setRequired($required);
|
||||
$entity->setGrouped($grouped);
|
||||
$entity->setHelp($help);
|
||||
|
||||
$this->em->persist($entity);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
private function writelnred($string) {
|
||||
$this->output->writeln('<fg=red>'.$string.'</>');
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
private function writeln($string) {
|
||||
$this->output->writeln($string);
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
}
|
165
src/Command/CronCommand.php
Normal file
165
src/Command/CronCommand.php
Normal file
@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Command\LockableTrait;
|
||||
|
||||
use App\Entity\Cron;
|
||||
|
||||
class CronCommand extends Command
|
||||
{
|
||||
private $container;
|
||||
private $em;
|
||||
private $output;
|
||||
private $filesystem;
|
||||
private $rootlog;
|
||||
use LockableTrait;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('app:Cron')
|
||||
->setDescription('Execution of the cron command')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
|
||||
$appCron = $this->container->getParameter('appCron');
|
||||
if(!$appCron)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!$this->lock()) {
|
||||
$this->output->writeln("CRON LOCK");
|
||||
return 0;
|
||||
}
|
||||
|
||||
$crons = $this->em->getRepository('App:Cron')->toexec();
|
||||
$i=0;
|
||||
|
||||
if($crons) {
|
||||
$now=new \DateTime();
|
||||
$this->writelnred('');
|
||||
$this->writelnred('');
|
||||
$this->writelnred('');
|
||||
$this->writelnred('');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
$this->writelnred('== CRON ==================================================================================================');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
$this->writeln ('Date = '.$now->format('Y-m-d H:i:s'));
|
||||
$this->writeln ('Application = '.$this->container->getParameter("appName"));
|
||||
}
|
||||
|
||||
foreach($crons as $cron) {
|
||||
$i++;
|
||||
|
||||
// Id du cron
|
||||
$idcron = $cron->getId();
|
||||
|
||||
// Flag d'execution en cours
|
||||
$now=new \DateTime();
|
||||
$cron->setStartexecdate($now);
|
||||
//$cron->setStatut(1);
|
||||
$this->em->persist($cron);
|
||||
$this->em->flush();
|
||||
|
||||
// Récupération de la commande
|
||||
$command = $this->getApplication()->find($cron->getCommand());
|
||||
|
||||
// Réccuépration des parametres
|
||||
$jsonparameter=json_decode($cron->getJsonargument(),true);
|
||||
|
||||
// Parametre id du cron actuel
|
||||
$jsonparameter["cronid"]=$cron->getId();
|
||||
|
||||
// Parametre si dernière execution
|
||||
$lastchance=false;
|
||||
if($cron->getRepeatcall()>0)
|
||||
$lastchance=($cron->getRepeatexec()+1==$cron->getRepeatcall());
|
||||
$jsonparameter["lastchance"]=$lastchance;
|
||||
|
||||
// Formater la chaine de parametre
|
||||
$parameter = new ArrayInput($jsonparameter);
|
||||
|
||||
// Executer la commande
|
||||
$returnCode=false;
|
||||
try{
|
||||
$returnCode = $command->run($parameter, $output);
|
||||
|
||||
// Revenir sur le cron encours à cause du clear du manager présent dans la synchro
|
||||
// Sinon le manager se pomme et génère des nouveaux enregistrement plutot que mettre à jour celui en cours
|
||||
$cron=$this->em->getRepository('App:Cron')->find($idcron);
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
$this->writelnred("JOB EN ERREUR");
|
||||
}
|
||||
|
||||
// Flag de fin d'execution
|
||||
$now=new \DateTime();
|
||||
$cron->setEndexecdate($now);
|
||||
|
||||
// Date prochaine execution
|
||||
if($cron->getrepeatinterval()>=0) {
|
||||
// Si interval par heure
|
||||
if(fmod($cron->getRepeatinterval(),3600)==0)
|
||||
$next=clone $cron->getNextexecdate();
|
||||
else
|
||||
$next=new \DateTime();
|
||||
|
||||
$next->add(new \DateInterval('PT'.$cron->getRepeatinterval().'S'));
|
||||
$cron->setNextexecdate($next);
|
||||
}
|
||||
|
||||
// Statut OK/KO/Retry
|
||||
if($returnCode!="retry"||!$returnCode) {
|
||||
$cron->setStatut(2);
|
||||
if($returnCode!=1) {
|
||||
$cron->setStatut(3);
|
||||
if($cron->getRepeatcall()>0) $cron->setRepeatexec($cron->getRepeatexec()+1);
|
||||
}
|
||||
}
|
||||
|
||||
$this->em->persist($cron);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
if($crons) {
|
||||
$this->writelnred("==");
|
||||
$this->writelnred("FIN CRON");
|
||||
$this->writelnred("==");
|
||||
$this->writelnred("");
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
private function writelnred($string) {
|
||||
$this->output->writeln('<fg=red>'.$string.'</>');
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
private function writeln($string) {
|
||||
$this->output->writeln($string);
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
}
|
119
src/Command/CronInitCommand.php
Normal file
119
src/Command/CronInitCommand.php
Normal file
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Id\AssignedGenerator;
|
||||
|
||||
use App\Entity\Cron;
|
||||
|
||||
|
||||
class CronInitCommand extends Command
|
||||
{
|
||||
|
||||
private $container;
|
||||
private $em;
|
||||
private $output;
|
||||
private $filesystem;
|
||||
private $rootlog;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('app:CronInit')
|
||||
->setDescription('Init Data for Cron')
|
||||
->setHelp('This command Init Data Cron')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$appCron = $this->container->getParameter('appCron');
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
|
||||
if(!$appCron)
|
||||
return false;
|
||||
|
||||
$output->writeln('CRON = Default Data');
|
||||
|
||||
$this->insertCron();
|
||||
|
||||
$output->writeln('');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
protected function insertCron() {
|
||||
|
||||
$metadata = $this->em->getClassMetaData('App:Cron');
|
||||
|
||||
// Job Mail
|
||||
// Toute les minutes
|
||||
$entity = $this->em->getRepository('App:Cron')->findOneBy(["command"=>"app:sendMail"]);
|
||||
if(!$entity) {
|
||||
$entity = new Cron;
|
||||
$entity->setCommand("app:sendMail");
|
||||
$entity->setDescription("Execution du spool de mail en attente");
|
||||
$entity->setStatut(2);
|
||||
$entity->setRepeatcall(0);
|
||||
$entity->setRepeatexec(0);
|
||||
$entity->setRepeatinterval(60);
|
||||
$entity->setNextexecdate($entity->getSubmitdate());
|
||||
$entity->setJsonargument('{"message-limit":"100","env":"prod"}');
|
||||
$this->em->persist($entity);
|
||||
}
|
||||
|
||||
// Job de purge des fichiers obsolète
|
||||
// Toute les 24h à 3h00
|
||||
$entity = $this->em->getRepository('App:Cron')->findOneBy(["command"=>"app:purgeFile"]);
|
||||
if(!$entity) {
|
||||
$entity = new Cron;
|
||||
$nextdate=$entity->getSubmitdate();
|
||||
$nextdate->setTime(3,0);
|
||||
$entity->setCommand("app:purgeFile");
|
||||
$entity->setDescription("Suppression des fichiers obsolètes");
|
||||
$entity->setStatut(2);
|
||||
$entity->setRepeatcall(0);
|
||||
$entity->setRepeatexec(0);
|
||||
$entity->setRepeatinterval(86400);
|
||||
$entity->setNextexecdate($nextdate);
|
||||
$this->em->persist($entity);
|
||||
}
|
||||
|
||||
// Job Dump
|
||||
// Toute les 24h à 2h00
|
||||
$entity = $this->em->getRepository('App:Cron')->findOneBy(["command"=>"app:dumpBdd"]);
|
||||
if(!$entity) {
|
||||
$entity = new Cron;
|
||||
$nextdate=$entity->getSubmitdate();
|
||||
$nextdate->setTime(2,0);
|
||||
$entity->setCommand("app:dumpBdd");
|
||||
$entity->setDescription("Sauvegarde de la BDD");
|
||||
$entity->setStatut(2);
|
||||
$entity->setRepeatcall(0);
|
||||
$entity->setRepeatexec(0);
|
||||
$entity->setRepeatinterval(86400);
|
||||
$entity->setNextexecdate($nextdate);
|
||||
$this->em->persist($entity);
|
||||
}
|
||||
|
||||
// On flush
|
||||
$this->em->flush();
|
||||
|
||||
}
|
||||
}
|
92
src/Command/DumpBddCommand.php
Normal file
92
src/Command/DumpBddCommand.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Security\Core\Encoder\EncoderFactory;
|
||||
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
class DumpBddCommand extends Command
|
||||
{
|
||||
private $container;
|
||||
private $em;
|
||||
private $output;
|
||||
private $filesystem;
|
||||
private $rootlog;
|
||||
private $byexec;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('app:dumpBdd')
|
||||
->setDescription('Sauvegarde de la BDD')
|
||||
->setHelp('Sauvegarde de la BDD')
|
||||
->addArgument('cronid', InputArgument::OPTIONAL, 'ID Cron Job')
|
||||
->addArgument('lastchance', InputArgument::OPTIONAL, 'Lastchance to run the cron')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
$alias = $this->container->getParameter('appAlias');
|
||||
|
||||
$this->writelnred('');
|
||||
$this->writelnred('== app:dumpBdd');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
|
||||
$this->datahost = $this->container->getParameter('databaseHost');
|
||||
$this->database = $this->container->getParameter('databaseName') ;
|
||||
$this->username = $this->container->getParameter('databaseUser') ;
|
||||
$this->password = $this->container->getParameter('databasePassword') ;
|
||||
|
||||
$cmd = sprintf('mysqldump -h %s -B %s -u %s --password=%s'
|
||||
, $this->datahost
|
||||
, $this->database
|
||||
, $this->username
|
||||
, $this->password
|
||||
);
|
||||
|
||||
$result = $this->runCommand($cmd);
|
||||
if($result['exit_status'] == 0) {
|
||||
$this->filesystem->dumpFile($this->rootlog.$alias.".sql", implode('', $result['output']));
|
||||
}
|
||||
|
||||
$this->writeln('');
|
||||
return 1;
|
||||
}
|
||||
|
||||
protected function runCommand($command)
|
||||
{
|
||||
$command .=" >&1";
|
||||
exec($command, $output, $exit_status);
|
||||
return array(
|
||||
"output" => $output
|
||||
, "exit_status" => $exit_status
|
||||
);
|
||||
}
|
||||
|
||||
private function writelnred($string) {
|
||||
$this->output->writeln('<fg=red>'.$string.'</>');
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
private function writeln($string) {
|
||||
$this->output->writeln($string);
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
}
|
105
src/Command/PurgeFileCommand.php
Normal file
105
src/Command/PurgeFileCommand.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Security\Core\Encoder\EncoderFactory;
|
||||
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
class PurgeFileCommand extends Command
|
||||
{
|
||||
private $container;
|
||||
private $em;
|
||||
private $output;
|
||||
private $filesystem;
|
||||
private $rootlog;
|
||||
private $byexec;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('app:purgeFile')
|
||||
->setDescription('Suppression des fichier obsolètes')
|
||||
->setHelp('Suppression des fichier obsolètes')
|
||||
->addArgument('cronid', InputArgument::OPTIONAL, 'ID Cron Job')
|
||||
->addArgument('lastchance', InputArgument::OPTIONAL, 'Lastchance to run the cron')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
$alias = $this->container->getParameter('appAlias');
|
||||
|
||||
$this->writelnred('');
|
||||
$this->writelnred('== app:purgeFile');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
|
||||
$now=new \DateTime('now');
|
||||
|
||||
$directory=$this->container->get('kernel')->getProjectDir()."/public/uploads/avatar";
|
||||
$this->writeln($directory);
|
||||
|
||||
$files=[];
|
||||
$fs = new Filesystem();
|
||||
|
||||
if($fs->exists($directory)) {
|
||||
$finder = new Finder();
|
||||
$finder->in($directory)->files();
|
||||
|
||||
foreach (iterator_to_array($finder) as $file) {
|
||||
$name = $file->getRelativePathname();
|
||||
if($name!="admin.jpg"&&$name!="noavatar.png"&&$name!="system.jpg") {
|
||||
$entity=$this->em->getRepository("App:User")->findBy(["avatar"=>$name]);
|
||||
if(!$entity) {
|
||||
$this->writeln($name);
|
||||
$url=$directory."/".$name;
|
||||
if($fs->exists($url)) {
|
||||
$fs->remove($url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$fs = new Filesystem();
|
||||
$users=$this->em->getRepository("App:User")->findAll();
|
||||
foreach($users as $user) {
|
||||
if(!$fs->exists($directory."/".$user->getAvatar())) {
|
||||
$this->writeln($user->getUsername());
|
||||
$user->setAvatar("noavatar.png");
|
||||
$this->em->persist($user);
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
|
||||
$this->writeln('');
|
||||
return 1;
|
||||
}
|
||||
|
||||
private function writelnred($string) {
|
||||
$this->output->writeln('<fg=red>'.$string.'</>');
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
if($this->byexec) $this->filesystem->appendToFile($this->rootlog.'exec.log', $string."\n");
|
||||
}
|
||||
private function writeln($string) {
|
||||
$this->output->writeln($string);
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
if($this->byexec) $this->filesystem->appendToFile($this->rootlog.'exec.log', $string."\n");
|
||||
}
|
||||
}
|
157
src/Command/RegenThumbCommand.php
Normal file
157
src/Command/RegenThumbCommand.php
Normal file
@ -0,0 +1,157 @@
|
||||
<?php
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Security\Core\Encoder\EncoderFactory;
|
||||
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
class RegenThumbCommand extends Command
|
||||
{
|
||||
private $container;
|
||||
private $em;
|
||||
private $output;
|
||||
private $filesystem;
|
||||
private $rootlog;
|
||||
private $byexec;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('app:regenthumb')
|
||||
->setDescription('Regénère les thumbs des illustrations')
|
||||
->setHelp('Regénère les thumbs des illustrations')
|
||||
->addArgument('cronid', InputArgument::OPTIONAL, 'ID Cron Job')
|
||||
->addArgument('lastchance', InputArgument::OPTIONAL, 'Lastchance to run the cron')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
$alias = $this->container->getParameter('appAlias');
|
||||
|
||||
$this->writelnred('');
|
||||
$this->writelnred('== app:regenthumb');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
|
||||
$now=new \DateTime('now');
|
||||
|
||||
$directory=$this->container->get('kernel')->getProjectDir()."/public/uploads/illustration";
|
||||
$this->writeln($directory);
|
||||
|
||||
$files=[];
|
||||
$fs = new Filesystem();
|
||||
|
||||
if($fs->exists($directory)) {
|
||||
$finder = new Finder();
|
||||
$finder->in($directory)->files();
|
||||
|
||||
foreach (iterator_to_array($finder) as $file) {
|
||||
$name = $file->getRelativePathname();
|
||||
if(stripos($name,"thumb_")===false&&stripos($name,"thumbori_")===false) {
|
||||
$width = $this->getWidth($directory.'/'.$name);
|
||||
$height = $this->getHeight($directory.'/'.$name);
|
||||
|
||||
// Création des miniatures proportionnelle
|
||||
$fs->remove($directory.'/thumbori_'.$name);
|
||||
$fs->copy($directory.'/'.$name,$directory.'/thumbori_'.$name);
|
||||
$max_width=500;
|
||||
$scale = $max_width/$width;
|
||||
$this->resizeImage($directory.'/thumbori_'.$name,$width,$height,$scale);
|
||||
|
||||
$this->writeln($name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->writeln('');
|
||||
return 1;
|
||||
}
|
||||
|
||||
private function writelnred($string) {
|
||||
$this->output->writeln('<fg=red>'.$string.'</>');
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
if($this->byexec) $this->filesystem->appendToFile($this->rootlog.'exec.log', $string."\n");
|
||||
}
|
||||
private function writeln($string) {
|
||||
$this->output->writeln($string);
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
if($this->byexec) $this->filesystem->appendToFile($this->rootlog.'exec.log', $string."\n");
|
||||
}
|
||||
|
||||
|
||||
protected function getHeight($image) {
|
||||
$size = getimagesize($image);
|
||||
$height = $size[1];
|
||||
return $height;
|
||||
}
|
||||
|
||||
// Cacul de la largeur
|
||||
protected function getWidth($image) {
|
||||
$size = getimagesize($image);
|
||||
$width = $size[0];
|
||||
return $width;
|
||||
}
|
||||
|
||||
protected function resizeImage($image,$width,$height,$scale) {
|
||||
list($imagewidth, $imageheight, $imageType) = getimagesize($image);
|
||||
$imageType = image_type_to_mime_type($imageType);
|
||||
$newImageWidth = ceil($width * $scale);
|
||||
$newImageHeight = ceil($height * $scale);
|
||||
$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
|
||||
switch($imageType) {
|
||||
case "image/gif":
|
||||
$source=imagecreatefromgif($image);
|
||||
break;
|
||||
case "image/pjpeg":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
$source=imagecreatefromjpeg($image);
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/x-png":
|
||||
$source=imagecreatefrompng($image);
|
||||
break;
|
||||
}
|
||||
|
||||
$newImage = imagecreatetruecolor( $newImageWidth, $newImageHeight );
|
||||
imagealphablending( $newImage, false );
|
||||
imagesavealpha( $newImage, true );
|
||||
imagecopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$width,$height);
|
||||
|
||||
switch($imageType) {
|
||||
case "image/gif":
|
||||
imagegif($newImage,$image);
|
||||
break;
|
||||
case "image/pjpeg":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
imagejpeg($newImage,$image,90);
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/x-png":
|
||||
imagepng($newImage,$image);
|
||||
break;
|
||||
}
|
||||
|
||||
chmod($image, 0640);
|
||||
chown($image, 'www-data');
|
||||
return $image;
|
||||
}
|
||||
}
|
89
src/Command/ScriptCommand.php
Normal file
89
src/Command/ScriptCommand.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Id\AssignedGenerator;
|
||||
|
||||
use App\Entity\Script;
|
||||
|
||||
class ScriptCommand extends Command
|
||||
{
|
||||
|
||||
private $container;
|
||||
private $em;
|
||||
private $output;
|
||||
private $filesystem;
|
||||
private $rootlog;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('app:Script')
|
||||
->setDescription('Script to call')
|
||||
->setHelp('Script to call')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
|
||||
$output->writeln('APP = Scripts');
|
||||
|
||||
//$this->callscript("test");
|
||||
|
||||
$output->writeln('');
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
private function callscript($name) {
|
||||
$script=$this->em->getRepository("App:Script")->findOneBy(["name"=>$name]);
|
||||
if(!$script) {
|
||||
$this->writelnred("== SCRIPT = ".$name);
|
||||
$this->$name();
|
||||
|
||||
$script=new Script();
|
||||
$script->setName($name);
|
||||
$this->em->persist($script);
|
||||
$this->em->flush();
|
||||
$this->writeln("");
|
||||
}
|
||||
}
|
||||
|
||||
private function test() {
|
||||
$this->writeln("TEST");
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function writelnred($string) {
|
||||
$this->output->writeln('<fg=red>'.$string.'</>');
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
private function writeln($string) {
|
||||
$this->output->writeln($string);
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
}
|
87
src/Command/SendMailCommand.php
Normal file
87
src/Command/SendMailCommand.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Security\Core\Encoder\EncoderFactory;
|
||||
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
|
||||
|
||||
class SendMailCommand extends Command
|
||||
{
|
||||
private $container;
|
||||
private $em;
|
||||
private $output;
|
||||
private $filesystem;
|
||||
private $rootlog;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('app:sendMail')
|
||||
->setDescription('Envoi des mails')
|
||||
->setHelp('Envoi des mails')
|
||||
->addArgument('message-limit', InputArgument::OPTIONAL, 'limit message Mail')
|
||||
->addArgument('env', InputArgument::OPTIONAL, 'env Mail')
|
||||
->addArgument('cronid', InputArgument::OPTIONAL, 'ID Cron Job')
|
||||
->addArgument('lastchance', InputArgument::OPTIONAL, 'Lastchance to run the cron')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
|
||||
$this->writelnred('');
|
||||
$this->writelnred('== app:sendMail');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
|
||||
$appMailmethod=$this->container->getParameter("appMailmethod");
|
||||
|
||||
$command = $this->getApplication()->find("swiftmailer:spool:send");
|
||||
$tbparameter["--message-limit"]=100;
|
||||
$tbparameter["--env"]="prod";
|
||||
$tbparameter["--time-limit"]=5;
|
||||
if($appMailmethod=="sendmail") $tbparameter["--transport"]="app.sendmail.transport";
|
||||
|
||||
|
||||
$parameter = new ArrayInput($tbparameter);
|
||||
try{
|
||||
$returnCode = $command->run($parameter, $output);
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
$this->writeln("");
|
||||
$this->writelnred("Impossible d'envoyer des mails");
|
||||
$this->writeln("");
|
||||
return 0;
|
||||
}
|
||||
$this->writeln("");
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
private function writelnred($string) {
|
||||
$this->output->writeln('<fg=red>'.$string.'</>');
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
private function writeln($string) {
|
||||
$this->output->writeln($string);
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
|
||||
}
|
81
src/Command/SetPasswordCommand.php
Normal file
81
src/Command/SetPasswordCommand.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Security\Core\Encoder\EncoderFactory;
|
||||
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
|
||||
|
||||
class SetPasswordCommand extends Command
|
||||
{
|
||||
private $container;
|
||||
private $em;
|
||||
private $output;
|
||||
private $filesystem;
|
||||
private $rootlog;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('app:setPassword')
|
||||
->setDescription("Modifier le password d'un utilisateur")
|
||||
->setHelp("Modifier le password d'un utilisateur")
|
||||
->addArgument('username', InputArgument::OPTIONAL, 'username')
|
||||
->addArgument('password', InputArgument::OPTIONAL, 'password')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
|
||||
|
||||
|
||||
$this->writelnred('');
|
||||
$this->writelnred('== app:SetPasword');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
|
||||
$username = $input->getArgument('username');
|
||||
$this->writeln($username);
|
||||
|
||||
$password = $input->getArgument('password');
|
||||
$this->writeln($password);
|
||||
|
||||
$user = $this->em->getRepository('App:User')->findOneBy(array('username' => $username));
|
||||
if($user) {
|
||||
// Set Password
|
||||
$user->setPassword($password);
|
||||
$this->em->persist($user);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
$this->writeln('');
|
||||
return 1;
|
||||
}
|
||||
|
||||
private function writelnred($string) {
|
||||
$this->output->writeln('<fg=red>'.$string.'</>');
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
private function writeln($string) {
|
||||
$this->output->writeln($string);
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
81
src/Command/SetRolesCommand.php
Normal file
81
src/Command/SetRolesCommand.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Security\Core\Encoder\EncoderFactory;
|
||||
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
|
||||
|
||||
class SetRolesCommand extends Command
|
||||
{
|
||||
private $container;
|
||||
private $em;
|
||||
private $output;
|
||||
private $filesystem;
|
||||
private $rootlog;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('app:setRoles')
|
||||
->setDescription("Modifier le rôle d'un utilisateur")
|
||||
->setHelp("Modifier le rôle d'un utilisateur")
|
||||
->addArgument('username', InputArgument::OPTIONAL, 'username')
|
||||
->addArgument('roles', InputArgument::OPTIONAL, 'roles')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
|
||||
|
||||
$this->writelnred('');
|
||||
$this->writelnred('== app:setRoles');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
|
||||
$username = $input->getArgument('username');
|
||||
$this->writeln($username);
|
||||
|
||||
$this->writeln($input->getArgument('roles'));
|
||||
$roles = explode(",",$input->getArgument('roles'));
|
||||
//$this->writeln($roles);
|
||||
|
||||
$user = $this->em->getRepository('App:User')->findOneBy(array('username' => $username));
|
||||
if($user) {
|
||||
// Set Password
|
||||
$user->setRoles($roles);
|
||||
$this->em->persist($user);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
$this->writeln('');
|
||||
return 1;
|
||||
}
|
||||
|
||||
private function writelnred($string) {
|
||||
$this->output->writeln('<fg=red>'.$string.'</>');
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
private function writeln($string) {
|
||||
$this->output->writeln($string);
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
77
src/Command/UpdateDateCommand.php
Normal file
77
src/Command/UpdateDateCommand.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Security\Core\Encoder\EncoderFactory;
|
||||
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
class UpdateDateCommand extends Command
|
||||
{
|
||||
private $container;
|
||||
private $em;
|
||||
private $output;
|
||||
private $filesystem;
|
||||
private $rootlog;
|
||||
private $byexec;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('app:updatedate')
|
||||
->setDescription('Regnère les dates de création')
|
||||
->setHelp('Regnère les dates de création dans le même ordre mais à la date du jour afin que les illustrations soient vu par le moteur sociale comme nouveau')
|
||||
->addArgument('cronid', InputArgument::OPTIONAL, 'ID Cron Job')
|
||||
->addArgument('lastchance', InputArgument::OPTIONAL, 'Lastchance to run the cron')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
$alias = $this->container->getParameter('appAlias');
|
||||
|
||||
$this->writelnred('');
|
||||
$this->writelnred('== app:updatedate');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
|
||||
$now=new \DateTime('now');
|
||||
$illustrations=$this->em->getRepository("App:Illustration")->findAll();
|
||||
foreach($illustrations as $illustration) {
|
||||
$now->add(new \DateInterval('PT1M'));
|
||||
$illustration->setSubmittime($now);
|
||||
$this->em->persist($illustration);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
|
||||
$this->writeln('');
|
||||
return 1;
|
||||
}
|
||||
|
||||
private function writelnred($string) {
|
||||
$this->output->writeln('<fg=red>'.$string.'</>');
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
if($this->byexec) $this->filesystem->appendToFile($this->rootlog.'exec.log', $string."\n");
|
||||
}
|
||||
private function writeln($string) {
|
||||
$this->output->writeln($string);
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
if($this->byexec) $this->filesystem->appendToFile($this->rootlog.'exec.log', $string."\n");
|
||||
}
|
||||
}
|
0
src/Controller/.gitignore
vendored
Normal file
0
src/Controller/.gitignore
vendored
Normal file
151
src/Controller/CategoryController.php
Executable file
151
src/Controller/CategoryController.php
Executable file
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Form\FormError;
|
||||
|
||||
use App\Entity\Category as Entity;
|
||||
use App\Form\CategoryType as Form;
|
||||
|
||||
class CategoryController extends AbstractController
|
||||
{
|
||||
private $data = "category";
|
||||
private $route = "app_category";
|
||||
private $render = "Category/";
|
||||
private $entity = "App:Category";
|
||||
|
||||
public function list(Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$datas = $em->getRepository($this->entity)->findAll();
|
||||
|
||||
return $this->render($this->render.'list.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
"useheader" => true,
|
||||
"usesidebar" => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function submit(Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data = new Entity();
|
||||
$data->setUsecategoryconfig(false);
|
||||
$data->setAppthumbfilter(false);
|
||||
$data->setAppthumbheight(0);
|
||||
$data->setAppthumbwidth(0);
|
||||
$data->setAppthumbfilter(false);
|
||||
$data->setAppthumbfiltergrayscale(100);
|
||||
$data->setAppthumbfilteropacity(100);
|
||||
$data->setAppthumbfiltersepia(0);
|
||||
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"submit"));
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm(null,$form,$request,$data,"submit");
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'submit',
|
||||
'form' => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
public function update($id,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"update"));
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm($id,$form,$request,$data,"update");
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete($id,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
|
||||
// Controle avant suppression
|
||||
$error=false;
|
||||
if($id<0) $error=true;
|
||||
|
||||
if($error)
|
||||
return $this->redirectToRoute($this->route."_update",["id"=>$id]);
|
||||
else {
|
||||
$em->remove($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getErrorForm($id,$form,$request,$data,$mode) {
|
||||
if ($form->get('submit')->isClicked()&&$mode=="delete") {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && $mode=="submit") {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && ($mode=="submit" || $mode=="update")) {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && !$form->isValid()) {
|
||||
$this->get('session')->getFlashBag()->clear();
|
||||
|
||||
$errors = $form->getErrors();
|
||||
foreach( $errors as $error ) {
|
||||
$request->getSession()->getFlashBag()->add("error", $error->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
113
src/Controller/ConfigController.php
Executable file
113
src/Controller/ConfigController.php
Executable file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Form\FormError;
|
||||
|
||||
use App\Entity\Config as Entity;
|
||||
use App\Form\ConfigType as Form;
|
||||
|
||||
class ConfigController extends AbstractController
|
||||
{
|
||||
private $data = "config";
|
||||
private $route = "app_config";
|
||||
private $render = "Config/";
|
||||
private $entity = "App:Config";
|
||||
|
||||
public function list()
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$datas = $em->getRepository($this->entity)->findBy(["visible"=>true]);
|
||||
|
||||
return $this->render($this->render.'list.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
"useheader" => true,
|
||||
"usesidebar" => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function listrender($category)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$datas = $em->getRepository($this->entity)->findBy(["visible"=>true,"category"=>$category]);
|
||||
|
||||
return $this->render($this->render.'render.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
"useheader" => true,
|
||||
"usesidebar" => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update($id,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"update","id"=>$data->getId(),"type"=>$data->getType(),"required"=>$data->getRequired()));
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm($id,$form,$request,$data,"update");
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete($id,Request $request)
|
||||
{
|
||||
// Récupération de l'enregistrement courant
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$config=$em->getRepository($this->entity)->find($id);
|
||||
if(!$config->getRequired()) {
|
||||
$config->setValue("");
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($config);
|
||||
$em->flush();
|
||||
}
|
||||
return $this->redirectToRoute('app_config');
|
||||
}
|
||||
|
||||
public function logo()
|
||||
{
|
||||
return $this->render($this->render.'logo.html.twig');
|
||||
}
|
||||
|
||||
protected function getErrorForm($id,$form,$request,$data) {
|
||||
if ($form->get('submit')->isClicked() && !$form->isValid()) {
|
||||
$this->get('session')->getFlashBag()->clear();
|
||||
$validator = $this->get('validator');
|
||||
$errors = $validator->validate($data);
|
||||
foreach( $errors as $error ) {
|
||||
$request->getSession()->getFlashBag()->add("error", $error->getMessage());
|
||||
}
|
||||
|
||||
$errors = $form->getErrors();
|
||||
foreach( $errors as $error ) {
|
||||
$request->getSession()->getFlashBag()->add("error", $error->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
114
src/Controller/CronController.php
Normal file
114
src/Controller/CronController.php
Normal file
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Form\FormError;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
|
||||
use App\Entity\Cron as Entity;
|
||||
use App\Form\CronType as Form;
|
||||
|
||||
class CronController extends AbstractController
|
||||
{
|
||||
private $data = "cron";
|
||||
private $route = "app_cron";
|
||||
private $render = "Cron/";
|
||||
private $entity = "App:Cron";
|
||||
|
||||
public function list()
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$datas = $em->getRepository($this->entity)->findAll();
|
||||
|
||||
return $this->render($this->render.'list.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
"useheader" => true,
|
||||
"usesidebar" => true,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function update($id,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"update"));
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm(null,$form,$request,$data,"update");
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
public function log()
|
||||
{
|
||||
return $this->render($this->render.'logs.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getlog(Request $request, $id)
|
||||
{
|
||||
|
||||
$path = $this->getParameter('kernel.project_dir');
|
||||
if($id=="dump")
|
||||
$file = $path . '/var/log/' . $this->getParameter("appAlias") . '.sql';
|
||||
else
|
||||
$file = $path . '/var/log/'.$id.'.log';
|
||||
|
||||
$response = new BinaryFileResponse($file);
|
||||
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
protected function getErrorForm($id,$form,$request,$data,$mode) {
|
||||
if ($form->get('submit')->isClicked()&&$mode=="delete") {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && $mode=="submit") {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && !$form->isValid()) {
|
||||
$this->get('session')->getFlashBag()->clear();
|
||||
|
||||
$errors = $form->getErrors();
|
||||
foreach( $errors as $error ) {
|
||||
$request->getSession()->getFlashBag()->add("error", $error->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
206
src/Controller/CropController.php
Normal file
206
src/Controller/CropController.php
Normal file
@ -0,0 +1,206 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
class CropController extends AbstractController
|
||||
{
|
||||
// Etape 01 - Téléchargement de l'image
|
||||
public function crop01($type,$reportinput)
|
||||
{
|
||||
return $this->render('Crop/crop01.html.twig',[
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
'type' => $type,
|
||||
'reportinput' => $reportinput
|
||||
]);
|
||||
}
|
||||
|
||||
// Etape 02 - Couper votre l'image
|
||||
public function crop02($type,$reportinput,Request $request)
|
||||
{
|
||||
// Récupération de l'image à cropper
|
||||
$file=$request->query->get('file');
|
||||
$large_image_location = "uploads/$type/$file";
|
||||
|
||||
// Récupérer les tailles de l'image
|
||||
$width = $this->getWidth($large_image_location);
|
||||
$height = $this->getHeight($large_image_location);
|
||||
|
||||
// Définir le pourcentage de réduction de l'image
|
||||
switch ($type) {
|
||||
case "illustration":
|
||||
$max_height=0;
|
||||
$ratio="1:1";
|
||||
break;
|
||||
|
||||
case "avatar":
|
||||
$max_height=900;
|
||||
$max_width=900;
|
||||
$ratio="1:1";
|
||||
break;
|
||||
|
||||
case "hero":
|
||||
$max_height=1600;
|
||||
$max_width=1600;
|
||||
$ratio="16:9";
|
||||
break;
|
||||
|
||||
case "image":
|
||||
$max_height=1600;
|
||||
$max_width=1600;
|
||||
$ratio="1:1";
|
||||
break;
|
||||
}
|
||||
|
||||
if($max_height>0) {
|
||||
$scale = $max_height/$height;
|
||||
if(($width*$scale)>$max_width) {
|
||||
$scale = $max_width/$width;
|
||||
}
|
||||
$this->resizeImage($large_image_location,$width,$height,$scale);
|
||||
}
|
||||
else $scale=1;
|
||||
|
||||
// Construction du formulaire
|
||||
$submited=false;
|
||||
$form = $this->createFormBuilder()
|
||||
->add('submit',SubmitType::class,array("label" => "Valider","attr" => array("class" => "btn btn-success","onclick" => "reportThumb()")))
|
||||
->add('x',HiddenType::class)
|
||||
->add('y',HiddenType::class)
|
||||
->add('w',HiddenType::class)
|
||||
->add('h',HiddenType::class)
|
||||
->add('xs',HiddenType::class)
|
||||
->add('ys',HiddenType::class)
|
||||
->add('ws',HiddenType::class)
|
||||
->add('hs',HiddenType::class)
|
||||
->getForm();
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur validation on généère la miniature croppée
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
// Récupération des valeurs du formulaire
|
||||
$data = $form->getData();
|
||||
$thumb_image_location = "uploads/$type/thumb_".$file;
|
||||
$cropped = $this->resizeThumbnailImage($thumb_image_location, $large_image_location,$data["ws"],$data["hs"],$data["xs"],$data["ys"],$scale);
|
||||
$submited=true;
|
||||
}
|
||||
|
||||
return $this->render('Crop/crop02.html.twig', [
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
'form' => $form->createView(),
|
||||
'type' => $type,
|
||||
'file' => $file,
|
||||
'ratio' => $ratio,
|
||||
"reportinput" => $reportinput,
|
||||
"submited" => $submited
|
||||
]);
|
||||
}
|
||||
|
||||
// Calcul de la hauteur
|
||||
protected function getHeight($image) {
|
||||
$size = getimagesize($image);
|
||||
$height = $size[1];
|
||||
return $height;
|
||||
}
|
||||
|
||||
// Cacul de la largeur
|
||||
protected function getWidth($image) {
|
||||
$size = getimagesize($image);
|
||||
$width = $size[0];
|
||||
return $width;
|
||||
}
|
||||
|
||||
protected function resizeImage($image,$width,$height,$scale) {
|
||||
list($imagewidth, $imageheight, $imageType) = getimagesize($image);
|
||||
$imageType = image_type_to_mime_type($imageType);
|
||||
$newImageWidth = ceil($width * $scale);
|
||||
$newImageHeight = ceil($height * $scale);
|
||||
$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
|
||||
switch($imageType) {
|
||||
case "image/gif":
|
||||
$source=imagecreatefromgif($image);
|
||||
break;
|
||||
case "image/pjpeg":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
$source=imagecreatefromjpeg($image);
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/x-png":
|
||||
$source=imagecreatefrompng($image);
|
||||
break;
|
||||
}
|
||||
imagecopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$width,$height);
|
||||
|
||||
switch($imageType) {
|
||||
case "image/gif":
|
||||
imagegif($newImage,$image);
|
||||
break;
|
||||
case "image/pjpeg":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
imagejpeg($newImage,$image,90);
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/x-png":
|
||||
imagepng($newImage,$image);
|
||||
break;
|
||||
}
|
||||
|
||||
chmod($image, 0640);
|
||||
return $image;
|
||||
}
|
||||
|
||||
protected function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale){
|
||||
$fs = new Filesystem();
|
||||
$fs->remove($thumb_image_name);
|
||||
|
||||
list($imagewidth, $imageheight, $imageType) = getimagesize($image);
|
||||
$imageType = image_type_to_mime_type($imageType);
|
||||
|
||||
$newImageWidth = ceil($width * $scale);
|
||||
$newImageHeight = ceil($height * $scale);
|
||||
$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
|
||||
switch($imageType) {
|
||||
case "image/gif":
|
||||
$source=imagecreatefromgif($image);
|
||||
break;
|
||||
case "image/pjpeg":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
$source=imagecreatefromjpeg($image);
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/x-png":
|
||||
$source=imagecreatefrompng($image);
|
||||
break;
|
||||
}
|
||||
imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height);
|
||||
switch($imageType) {
|
||||
case "image/gif":
|
||||
imagegif($newImage,$thumb_image_name);
|
||||
break;
|
||||
case "image/pjpeg":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
imagejpeg($newImage,$thumb_image_name,90);
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/x-png":
|
||||
imagepng($newImage,$thumb_image_name);
|
||||
break;
|
||||
}
|
||||
chmod($thumb_image_name, 0640);
|
||||
return $thumb_image_name;
|
||||
}
|
||||
|
||||
}
|
220
src/Controller/GroupController.php
Executable file
220
src/Controller/GroupController.php
Executable file
@ -0,0 +1,220 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Form\FormError;
|
||||
|
||||
use App\Entity\Group as Entity;
|
||||
use App\Form\GroupType as Form;
|
||||
|
||||
class GroupController extends AbstractController
|
||||
{
|
||||
private $data = "group";
|
||||
private $route = "app_group";
|
||||
private $render = "Group/";
|
||||
private $entity = "App:Group";
|
||||
|
||||
public function list(Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$datas = $em->getRepository($this->entity)->findAll();
|
||||
|
||||
return $this->render($this->render.'list.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
"useheader" => true,
|
||||
"usesidebar" => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function submit(Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data = new Entity();
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"submit"));
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm(null,$form,$request,$data,"submit");
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'submit',
|
||||
'form' => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
public function update($id,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"update"));
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm($id,$form,$request,$data,"update");
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete($id,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
|
||||
// Controle avant suppression
|
||||
$error=false;
|
||||
if($id<0) $error=true;
|
||||
|
||||
if($error)
|
||||
return $this->redirectToRoute($this->route."_update",["id"=>$id]);
|
||||
else {
|
||||
$em->remove($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
}
|
||||
|
||||
public function select(Request $request)
|
||||
{
|
||||
// S'assurer que c'est un appel ajax
|
||||
if (!$request->isXmlHttpRequest()) {
|
||||
return new JsonResponse(array('message' => 'Interdit'), 400);
|
||||
}
|
||||
|
||||
$output=array();
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$page_limit=$request->query->get('page_limit');
|
||||
$q=$request->query->get('q');
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
if($this->getUser()->Hasrole("ROLE_ADMIN")) {
|
||||
$qb->select('table')->from($this->entity,'table')
|
||||
->where('table.name LIKE :value')
|
||||
->setParameter("value", "%".$q."%")
|
||||
->orderBy('table.name');
|
||||
}
|
||||
else {
|
||||
$qb->select('table')->from($this->entity,'table')
|
||||
->where('table.name LIKE :value')
|
||||
->andwhere(":user MEMBER OF table.users")
|
||||
->setParameter("value", "%".$q."%")
|
||||
->setParameter("user",$this->getUser())
|
||||
->orderBy('table.name');
|
||||
}
|
||||
|
||||
$datas=$qb->setFirstResult(0)->setMaxResults($page_limit)->getQuery()->getResult();
|
||||
foreach($datas as $data) {
|
||||
array_push($output,array("id"=>$data->getId(),"text"=>$data->getName()));
|
||||
}
|
||||
|
||||
$ret_string["results"]=$output;
|
||||
$response = new Response(json_encode($ret_string));
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function info(Request $request)
|
||||
{
|
||||
// S'assurer que c'est un appel ajax
|
||||
if (!$request->isXmlHttpRequest()) {
|
||||
return new JsonResponse(array('message' => 'Interdit'), 400);
|
||||
}
|
||||
|
||||
$output=array();
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$id=$request->get('id');
|
||||
|
||||
$group=$em->getRepository($this->entity)->find($id);
|
||||
$users=$group->getUsers();
|
||||
|
||||
$output=[];
|
||||
$output["id"] = $group->getId();
|
||||
$output["name"] = $group->getName();
|
||||
$output["users"] = [];
|
||||
|
||||
foreach($users as $user) {
|
||||
$tmp=[];
|
||||
$tmp["id"] = $user->getId();
|
||||
$tmp["displayname"] = $user->getId();
|
||||
$tmp["email"] = $user->getEmail();
|
||||
|
||||
array_push($output["users"],$tmp);
|
||||
}
|
||||
|
||||
$response = new Response(json_encode($output));
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
return $response;
|
||||
}
|
||||
|
||||
protected function getErrorForm($id,$form,$request,$data,$mode) {
|
||||
if ($form->get('submit')->isClicked()&&$mode=="delete") {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && $mode=="submit") {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && ($mode=="submit" || $mode=="update")) {
|
||||
// On s'assure que le label ne contient pas des caractères speciaux
|
||||
$string = preg_replace('~[^ éèêôöàïî\'@a-zA-Z0-9._-]~', '', $data->getName());
|
||||
if($string!=$data->getName())
|
||||
{
|
||||
$form->addError(new FormError('Caractères interdit dans ce label'));
|
||||
}
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && !$form->isValid()) {
|
||||
$this->get('session')->getFlashBag()->clear();
|
||||
|
||||
$errors = $form->getErrors();
|
||||
foreach( $errors as $error ) {
|
||||
$request->getSession()->getFlashBag()->add("error", $error->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
119
src/Controller/HomeController.php
Executable file
119
src/Controller/HomeController.php
Executable file
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
class HomeController extends AbstractController
|
||||
{
|
||||
public function home()
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$categorys = $em->getRepository("App:Category")->findAll();
|
||||
$links = $em->getRepository("App:Link")->findAll();
|
||||
$webzines = $em->getRepository("App:Webzine")->findBy([], ['set' => 'ASC', 'order' => 'ASC']);
|
||||
|
||||
return $this->render('Home/home.html.twig',[
|
||||
"useheader" => false,
|
||||
"usesidebar" => false,
|
||||
"usemonocolor" => true,
|
||||
"categorys" => $categorys,
|
||||
"links" => $links,
|
||||
"webzines" => $webzines
|
||||
]);
|
||||
}
|
||||
|
||||
public function feed($nb)
|
||||
{
|
||||
$feeds=[];
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$qb = $em ->createQueryBuilder()
|
||||
->select('e')
|
||||
->from("App:Illustration", 'e');
|
||||
if($nb!=0) $qb->setMaxResults($nb);
|
||||
$illustrations=$qb->getQuery()->getResult();
|
||||
foreach($illustrations as $illustration) {
|
||||
$tmp["path"] = "app_illustration_view";
|
||||
$tmp["type"] = "illustration";
|
||||
$tmp["idcat"] = $illustration->getCategory()->getId();
|
||||
$tmp["cat"] = $illustration->getCategory()->getName();
|
||||
$tmp["id"] = $illustration->getId();
|
||||
$tmp["name"] = $illustration->getName();
|
||||
$tmp["illustration"] = $illustration->getIllustration();
|
||||
$tmp["pubtime"] = $illustration->getSubmittime();
|
||||
$tmp["description"] = $illustration->getDescription();
|
||||
|
||||
array_push($feeds,$tmp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$qb = $em ->createQueryBuilder()
|
||||
->select('e')
|
||||
->from("App:Webzine", 'e');
|
||||
if($nb!=0) $qb->setMaxResults($nb);
|
||||
$webzines=$qb->getQuery()->getResult();
|
||||
foreach($webzines as $webzine) {
|
||||
if($webzine->getWebzinepages()) {
|
||||
$tmp["path"] = "app_webzine_view";
|
||||
$tmp["type"] = "webzine";
|
||||
$tmp["idcat"] = $webzine->getId();
|
||||
$tmp["cat"] = "Webzine".($webzine->getSet()?" - ".$webzine->getSet():"");
|
||||
$tmp["id"] = $webzine->getWebzinepages()[0]->getId();
|
||||
$tmp["name"] = $webzine->getName();
|
||||
$tmp["illustration"] = $webzine->getWebzinepages()[0]->getIllustration();
|
||||
$tmp["pubtime"] = $webzine->getSubmittime();
|
||||
$tmp["description"] = $webzine->getDescription();
|
||||
|
||||
array_push($feeds,$tmp);
|
||||
}
|
||||
}
|
||||
|
||||
$columns = array_column($feeds, 'pubtime');
|
||||
array_multisort($columns, SORT_DESC, $feeds);
|
||||
|
||||
$response = new Response($this->renderView('Home/feed.xml.twig',["feeds" => $feeds]));
|
||||
|
||||
$response->headers->set('Content-Type', 'application/xml; charset=utf-8');
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function admin()
|
||||
{
|
||||
return $this->render('Home/admin.html.twig',[
|
||||
"useheader" => true,
|
||||
"usesidebar" => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function upload(Request $request,$access=null) {
|
||||
// Fichier temporaire uploadé
|
||||
$tmpfile = $request->files->get('upload');
|
||||
$extention = $tmpfile->getClientOriginalExtension();
|
||||
|
||||
// Répertoire de Destination
|
||||
$fs = new Filesystem();
|
||||
$rootdir = $this->getParameter('kernel.project_dir') . '/public';
|
||||
$fs->mkdir($rootdir."/uploads/ckeditor");
|
||||
|
||||
// Fichier cible
|
||||
$targetName = uniqid().".".$extention;
|
||||
$targetFile = $rootdir."/uploads/ckeditor/".$targetName;
|
||||
$targetUrl = "/".$this->getParameter('appAlias')."/uploads/ckeditor/".$targetName;
|
||||
$message = "";
|
||||
|
||||
move_uploaded_file($tmpfile,$targetFile);
|
||||
|
||||
$output["uploaded"]=1;
|
||||
$output["fileName"]=$targetName;
|
||||
$output["url"]=$targetUrl;
|
||||
|
||||
return new Response(json_encode($output));
|
||||
}
|
||||
|
||||
}
|
244
src/Controller/IllustrationController.php
Executable file
244
src/Controller/IllustrationController.php
Executable file
@ -0,0 +1,244 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Form\FormError;
|
||||
|
||||
use App\Entity\Illustration as Entity;
|
||||
use App\Form\IllustrationType as Form;
|
||||
|
||||
class IllustrationController extends AbstractController
|
||||
{
|
||||
private $data = "illustration";
|
||||
private $route = "app_illustration";
|
||||
private $render = "Illustration/";
|
||||
private $entity = "App:Illustration";
|
||||
|
||||
public function list(Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$datas = $em->getRepository($this->entity)->findAll();
|
||||
|
||||
return $this->render($this->render.'list.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
"useheader" => true,
|
||||
"usesidebar" => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function view($idcat,$id,Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
|
||||
$datanext=$this->getDataAllNext($idcat,$id);
|
||||
$dataprev=$this->getDataAllPrev($idcat,$id);
|
||||
|
||||
$pathinfo=pathinfo($data->getIllustration());
|
||||
|
||||
if(!$data) return $this->redirectToRoute('app_home');
|
||||
|
||||
return $this->render($this->render.'view.html.twig', array(
|
||||
$this->data => $data,
|
||||
"prev" => $dataprev,
|
||||
"next" => $datanext,
|
||||
"pathinfo" => $pathinfo,
|
||||
"usemonocolor" => true,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
public function submit($by, Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data = new Entity();
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"submit"));
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm(null,$form,$request,$data,"submit");
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$data->setSubmittime(new \DateTime());
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
if($by=="console")
|
||||
return $this->redirectToRoute($this->route);
|
||||
else
|
||||
return $this->redirectToRoute("app_home");
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => false,
|
||||
$this->data => $data,
|
||||
'mode' => 'submit',
|
||||
'form' => $form->createView(),
|
||||
'by' => $by,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update($id,$by,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"update"));
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm($id,$form,$request,$data,"update");
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à l'illustration
|
||||
if($by=="console")
|
||||
return $this->redirectToRoute($this->route);
|
||||
else
|
||||
return $this->redirectToRoute($this->route.'_view',array("idcat"=>$data->getCategory()->getId(),"id"=> $id));
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => false,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView(),
|
||||
'by' => $by,
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete($id,$by,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
|
||||
// Controle avant suppression
|
||||
$error=false;
|
||||
if($id<0) $error=true;
|
||||
|
||||
if($error)
|
||||
return $this->redirectToRoute($this->route."_update",["id"=>$id]);
|
||||
else {
|
||||
$em->remove($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
if($by=="console")
|
||||
return $this->redirectToRoute($this->route);
|
||||
else
|
||||
return $this->redirectToRoute("app_home");
|
||||
}
|
||||
}
|
||||
|
||||
public function upload()
|
||||
{
|
||||
return $this->render($this->render.'upload.html.twig');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected function getDataAllNext($idcat,$id)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data = $em->createQueryBuilder()
|
||||
->select('e')
|
||||
->from($this->entity, 'e')
|
||||
->where('e.id>:id')
|
||||
->andWhere('e.category=:idcat')
|
||||
->getQuery()
|
||||
->setParameter("id", $id)
|
||||
->setParameter("idcat", $idcat)
|
||||
->setMaxResults(1)
|
||||
->getResult();
|
||||
|
||||
// Si pas de suivant on recherche le premier
|
||||
if(!$data) {
|
||||
$data = $em->createQueryBuilder()
|
||||
->select('e')
|
||||
->from($this->entity, 'e')
|
||||
->Where('e.category=:idcat')
|
||||
->getQuery()
|
||||
->setParameter("idcat", $idcat)
|
||||
->setMaxResults(1)
|
||||
->getResult();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getDataAllPrev($idcat,$id)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data = $em->createQueryBuilder()
|
||||
->select('e')
|
||||
->from($this->entity, 'e')
|
||||
->where('e.id<:id')
|
||||
->andWhere('e.category=:idcat')
|
||||
->orderBy('e.id','DESC')
|
||||
->getQuery()
|
||||
->setParameter("id", $id)
|
||||
->setParameter("idcat", $idcat)
|
||||
->setMaxResults(1)
|
||||
->getResult();
|
||||
|
||||
// Si pas de précedent on recherche le dernier
|
||||
if(!$data) {
|
||||
$data = $em->createQueryBuilder()
|
||||
->select('e')
|
||||
->from($this->entity, 'e')
|
||||
->Where('e.category=:idcat')
|
||||
->orderBy('e.id','DESC')
|
||||
->getQuery()
|
||||
->setParameter("idcat", $idcat)
|
||||
->setMaxResults(1)
|
||||
->getResult();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getErrorForm($id,$form,$request,$data,$mode) {
|
||||
if ($form->get('submit')->isClicked()&&$mode=="delete") {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && $mode=="submit") {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && ($mode=="submit" || $mode=="update")) {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && !$form->isValid()) {
|
||||
$this->get('session')->getFlashBag()->clear();
|
||||
|
||||
$errors = $form->getErrors();
|
||||
foreach( $errors as $error ) {
|
||||
$request->getSession()->getFlashBag()->add("error", $error->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
143
src/Controller/LinkController.php
Executable file
143
src/Controller/LinkController.php
Executable file
@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Form\FormError;
|
||||
|
||||
use App\Entity\Link as Entity;
|
||||
use App\Form\LinkType as Form;
|
||||
|
||||
class LinkController extends AbstractController
|
||||
{
|
||||
private $data = "link";
|
||||
private $route = "app_link";
|
||||
private $render = "Link/";
|
||||
private $entity = "App:Link";
|
||||
|
||||
public function list(Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$datas = $em->getRepository($this->entity)->findAll();
|
||||
|
||||
return $this->render($this->render.'list.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
"useheader" => true,
|
||||
"usesidebar" => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function submit(Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data = new Entity();
|
||||
$data->setOrder(1);
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"submit"));
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm(null,$form,$request,$data,"submit");
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'submit',
|
||||
'form' => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
public function update($id,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"update"));
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm($id,$form,$request,$data,"update");
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete($id,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
|
||||
// Controle avant suppression
|
||||
$error=false;
|
||||
if($id<0) $error=true;
|
||||
|
||||
if($error)
|
||||
return $this->redirectToRoute($this->route."_update",["id"=>$id]);
|
||||
else {
|
||||
$em->remove($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getErrorForm($id,$form,$request,$data,$mode) {
|
||||
if ($form->get('submit')->isClicked()&&$mode=="delete") {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && $mode=="submit") {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && ($mode=="submit" || $mode=="update")) {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && !$form->isValid()) {
|
||||
$this->get('session')->getFlashBag()->clear();
|
||||
|
||||
$errors = $form->getErrors();
|
||||
foreach( $errors as $error ) {
|
||||
$request->getSession()->getFlashBag()->add("error", $error->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
162
src/Controller/SecurityController.php
Executable file
162
src/Controller/SecurityController.php
Executable file
@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\Group;
|
||||
use App\Service\ldapService as ldapService;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
class SecurityController extends AbstractController
|
||||
{
|
||||
public function login(Request $request, AuthenticationUtils $authenticationUtils)
|
||||
{
|
||||
$auth_mode=$this->getParameter("appAuth");
|
||||
switch($auth_mode) {
|
||||
case "MYSQL":
|
||||
return $this->loginMYSQL($request,$authenticationUtils);
|
||||
break;
|
||||
|
||||
case "CAS":
|
||||
return $this->loginCAS($request,$authenticationUtils);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function loginMYSQL(Request $request, AuthenticationUtils $authenticationUtils) {
|
||||
return $this->render('Home/login.html.twig', array(
|
||||
'last_username' => $authenticationUtils->getLastUsername(),
|
||||
'error' => $authenticationUtils->getLastAuthenticationError(),
|
||||
'usemonocolor' => true,
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
public function loginCAS(Request $request, AuthenticationUtils $authenticationUtils)
|
||||
{
|
||||
// Récupération de la cible de navigation
|
||||
$redirect = $this->get('session')->get("_security.main.target_path");
|
||||
|
||||
// Init Client CAS
|
||||
$alias=$this->getParameter('appAlias');
|
||||
\phpCAS::setDebug('/var/www/html/'.$alias.'/var/log/cas.log');
|
||||
\phpCAS::client(CAS_VERSION_2_0, $this->getParameter('casHost'), intval($this->getParameter('casPort')), is_null($this->getParameter('casPath')) ? '' : $this->getParameter('casPath'), false);
|
||||
\phpCAS::setNoCasServerValidation();
|
||||
|
||||
|
||||
// Authentification
|
||||
\phpCAS::forceAuthentication();
|
||||
|
||||
// Récupération UID
|
||||
$username = \phpCAS::getUser();
|
||||
|
||||
// Récupération Attribut
|
||||
$attributes = \phpCAS::getAttributes();
|
||||
|
||||
// Rechercher l'utilisateur
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
if(isset($attributes[$this->getParameter('casUsername')]))
|
||||
$username = $attributes[$this->getParameter('casUsername')];
|
||||
|
||||
if(isset($attributes[$this->getParameter('casEmail')]))
|
||||
$email = $attributes[$this->getParameter('casEmail')];
|
||||
|
||||
if(isset($attributes[$this->getParameter('casLastname')]))
|
||||
$lastname = $attributes[$this->getParameter('casLastname')];
|
||||
|
||||
if(isset($attributes[$this->getParameter('casFirstname')]))
|
||||
$firstname = $attributes[$this->getParameter('casFirstname')];
|
||||
|
||||
$user = $em->getRepository('App:User')->findOneBy(array("username"=>$username));
|
||||
$exists = $user ? true : false;
|
||||
|
||||
if (!$exists) {
|
||||
$user = new User();
|
||||
|
||||
$user->setUsername($username);
|
||||
$user->setLastname($lastname);
|
||||
$user->setFirstname($firstname);
|
||||
$user->setEmail($email);
|
||||
|
||||
$user->setPassword("CASPWD-".$username);
|
||||
$user->setSalt("CASPWD-".$username);
|
||||
|
||||
$em->persist($user);
|
||||
$em->flush();
|
||||
}
|
||||
else {
|
||||
if(isset($lastname)) $user->setLastname($lastname);
|
||||
if(isset($firstname)) $user->setFirstname($firstname);
|
||||
if(isset($email)) $user->setEmail($email);
|
||||
|
||||
$em->persist($user);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
// Sauvegarde des attributes en session
|
||||
$this->get('session')->set('attributes', $attributes);
|
||||
|
||||
// Autoconnexion
|
||||
// Récupérer le token de l'utilisateur
|
||||
$token = new UsernamePasswordToken($user, null, "main", $user->getRoles());
|
||||
$this->get("security.token_storage")->setToken($token);
|
||||
|
||||
// Simuler l'evenement de connexion
|
||||
$event = new InteractiveLoginEvent($request, $token);
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->dispatch($event);
|
||||
|
||||
// Redirection
|
||||
if($redirect)
|
||||
return $this->redirect($redirect);
|
||||
else
|
||||
return $this->redirect($this->generateUrl('app_home'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function logout() {
|
||||
$auth_mode=$this->getParameter("appAuth");
|
||||
switch($auth_mode) {
|
||||
case "MYSQL":
|
||||
return $this->logoutMYSQL();
|
||||
break;
|
||||
|
||||
case "CAS":
|
||||
return $this->logoutCAS();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function logoutMYSQL() {
|
||||
$this->get('security.token_storage')->setToken(null);
|
||||
$this->get('session')->invalidate();
|
||||
|
||||
return $this->redirect($this->generateUrl("app_home"));
|
||||
}
|
||||
|
||||
public function logoutcas() {
|
||||
$this->get('security.token_storage')->setToken(null);
|
||||
$this->get('session')->invalidate();
|
||||
|
||||
// Init Client CAS
|
||||
$alias=$this->getParameter('appAlias');
|
||||
\phpCAS::setDebug('/var/www/html/'.$alias.'/var/log/cas.log');
|
||||
\phpCAS::client(CAS_VERSION_2_0, $this->getParameter('casHost'), intval($this->getParameter('casPort')), is_null($this->getParameter('casPath')) ? '' : $this->getParameter('casPath'), false);
|
||||
\phpCAS::setNoCasServerValidation();
|
||||
|
||||
|
||||
// Logout
|
||||
$url=$this->generateUrl('app_home', array(), UrlGeneratorInterface::ABSOLUTE_URL);
|
||||
\phpCAS::logout(array("service"=>$url));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
245
src/Controller/SlideController.php
Executable file
245
src/Controller/SlideController.php
Executable file
@ -0,0 +1,245 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Form\FormError;
|
||||
|
||||
use App\Entity\Illustration as Entity;
|
||||
use App\Form\IllustrationType as Form;
|
||||
|
||||
class SlideController extends AbstractController
|
||||
{
|
||||
private $data = "illustration";
|
||||
private $route = "app_illustration";
|
||||
private $render = "Illustration/";
|
||||
private $entity = "App:Illustration";
|
||||
|
||||
public function slide(Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$datas = $em->getRepository($this->entity)->findAll();
|
||||
|
||||
return $this->render($this->render.'slide.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
"useheader" => false,
|
||||
"usesidebar" => false,
|
||||
"usemonocolor" => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function view($idcat,$id,Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
|
||||
$datanext=$this->getDataAllNext($idcat,$id);
|
||||
$dataprev=$this->getDataAllPrev($idcat,$id);
|
||||
|
||||
$pathinfo=pathinfo($data->getIllustration());
|
||||
|
||||
if(!$data) return $this->redirectToRoute('app_home');
|
||||
|
||||
return $this->render($this->render.'view.html.twig', array(
|
||||
$this->data => $data,
|
||||
"prev" => $dataprev,
|
||||
"next" => $datanext,
|
||||
"pathinfo" => $pathinfo,
|
||||
"usemonocolor" => true,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
public function submit($by, Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data = new Entity();
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"submit"));
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm(null,$form,$request,$data,"submit");
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$data->setSubmittime(new \DateTime());
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
if($by=="console")
|
||||
return $this->redirectToRoute($this->route);
|
||||
else
|
||||
return $this->redirectToRoute("app_home");
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => false,
|
||||
$this->data => $data,
|
||||
'mode' => 'submit',
|
||||
'form' => $form->createView(),
|
||||
'by' => $by,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update($id,$by,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"update"));
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm($id,$form,$request,$data,"update");
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à l'illustration
|
||||
if($by=="console")
|
||||
return $this->redirectToRoute($this->route);
|
||||
else
|
||||
return $this->redirectToRoute($this->route.'_view',array("idcat"=>$data->getCategory()->getId(),"id"=> $id));
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => false,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView(),
|
||||
'by' => $by,
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete($id,$by,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
|
||||
// Controle avant suppression
|
||||
$error=false;
|
||||
if($id<0) $error=true;
|
||||
|
||||
if($error)
|
||||
return $this->redirectToRoute($this->route."_update",["id"=>$id]);
|
||||
else {
|
||||
$em->remove($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
if($by=="console")
|
||||
return $this->redirectToRoute($this->route);
|
||||
else
|
||||
return $this->redirectToRoute("app_home");
|
||||
}
|
||||
}
|
||||
|
||||
public function upload()
|
||||
{
|
||||
return $this->render($this->render.'upload.html.twig');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected function getDataAllNext($idcat,$id)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data = $em->createQueryBuilder()
|
||||
->select('e')
|
||||
->from($this->entity, 'e')
|
||||
->where('e.id>:id')
|
||||
->andWhere('e.category=:idcat')
|
||||
->getQuery()
|
||||
->setParameter("id", $id)
|
||||
->setParameter("idcat", $idcat)
|
||||
->setMaxResults(1)
|
||||
->getResult();
|
||||
|
||||
// Si pas de suivant on recherche le premier
|
||||
if(!$data) {
|
||||
$data = $em->createQueryBuilder()
|
||||
->select('e')
|
||||
->from($this->entity, 'e')
|
||||
->Where('e.category=:idcat')
|
||||
->getQuery()
|
||||
->setParameter("idcat", $idcat)
|
||||
->setMaxResults(1)
|
||||
->getResult();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getDataAllPrev($idcat,$id)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data = $em->createQueryBuilder()
|
||||
->select('e')
|
||||
->from($this->entity, 'e')
|
||||
->where('e.id<:id')
|
||||
->andWhere('e.category=:idcat')
|
||||
->orderBy('e.id','DESC')
|
||||
->getQuery()
|
||||
->setParameter("id", $id)
|
||||
->setParameter("idcat", $idcat)
|
||||
->setMaxResults(1)
|
||||
->getResult();
|
||||
|
||||
// Si pas de précedent on recherche le dernier
|
||||
if(!$data) {
|
||||
$data = $em->createQueryBuilder()
|
||||
->select('e')
|
||||
->from($this->entity, 'e')
|
||||
->Where('e.category=:idcat')
|
||||
->orderBy('e.id','DESC')
|
||||
->getQuery()
|
||||
->setParameter("idcat", $idcat)
|
||||
->setMaxResults(1)
|
||||
->getResult();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getErrorForm($id,$form,$request,$data,$mode) {
|
||||
if ($form->get('submit')->isClicked()&&$mode=="delete") {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && $mode=="submit") {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && ($mode=="submit" || $mode=="update")) {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && !$form->isValid()) {
|
||||
$this->get('session')->getFlashBag()->clear();
|
||||
|
||||
$errors = $form->getErrors();
|
||||
foreach( $errors as $error ) {
|
||||
$request->getSession()->getFlashBag()->add("error", $error->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
242
src/Controller/UserController.php
Executable file
242
src/Controller/UserController.php
Executable file
@ -0,0 +1,242 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Form\FormError;
|
||||
|
||||
use App\Entity\User as Entity;
|
||||
use App\Form\UserType as Form;
|
||||
|
||||
class UserController extends AbstractController
|
||||
{
|
||||
private $data = "user";
|
||||
private $route = "app_user";
|
||||
private $render = "User/";
|
||||
private $entity = "App:User";
|
||||
|
||||
public function list(Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$datas = $em->getRepository($this->entity)->findAll();
|
||||
|
||||
return $this->render($this->render.'list.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
"useheader" => true,
|
||||
"usesidebar" => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function submit(Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data = new Entity();
|
||||
$data->setAvatar("noavatar.png");
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"submit"));
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm(null,$form,$request,$data,"submit");
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'submit',
|
||||
'form' => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
public function update($id,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
$oldpassword=$data->getPassword();
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"update","appAuth"=>$this->getParameter("appAuth")));
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm(null,$form,$request,$data,"update");
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
|
||||
// Si pas de changement de password on replace l'ancien
|
||||
if(!$data->getPassword()) {
|
||||
$data->setPassword($oldpassword);
|
||||
}
|
||||
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete($id,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
|
||||
// Controle avant suppression
|
||||
$error=false;
|
||||
if($id<0) $error=true;
|
||||
|
||||
if($error)
|
||||
return $this->redirectToRoute($this->route."_update",["id"=>$id]);
|
||||
else {
|
||||
$em->remove($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
}
|
||||
|
||||
public function profil(Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$this->getUser();
|
||||
$oldpassword=$data->getPassword();
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"profil","appAuth"=>$this->getParameter("appAuth")));
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm(null,$form,$request,$data,"update");
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
|
||||
// Si pas de changement de password on replace l'ancien
|
||||
if(!$data->getPassword()) {
|
||||
$data->setPassword($oldpassword);
|
||||
}
|
||||
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute("app_home");
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => false,
|
||||
$this->data => $data,
|
||||
'mode' => 'profil',
|
||||
'form' => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
public function select(Request $request)
|
||||
{
|
||||
// S'assurer que c'est un appel ajax
|
||||
if (!$request->isXmlHttpRequest()) {
|
||||
return new JsonResponse(array('message' => 'Interdit'), 400);
|
||||
}
|
||||
|
||||
$output=array();
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$page_limit=$request->query->get('page_limit');
|
||||
$q=$request->query->get('q');
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('table')->from($this->entity,'table')
|
||||
->where('table.lastname LIKE :value')
|
||||
->where('table.firstname LIKE :value')
|
||||
->setParameter("value", "%".$q."%")
|
||||
->orderBy('table.firstname')
|
||||
->orderBy('table.lastname');
|
||||
|
||||
$datas=$qb->setFirstResult(0)->setMaxResults($page_limit)->getQuery()->getResult();
|
||||
foreach($datas as $data) {
|
||||
array_push($output,array("id"=>$data->getId(),"text"=>$data->getDisplayname()));
|
||||
}
|
||||
|
||||
$ret_string["results"]=$output;
|
||||
$response = new Response(json_encode($ret_string));
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function info(Request $request)
|
||||
{
|
||||
// S'assurer que c'est un appel ajax
|
||||
if (!$request->isXmlHttpRequest()) {
|
||||
return new JsonResponse(array('message' => 'Interdit'), 400);
|
||||
}
|
||||
|
||||
$output=array();
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$id=$request->get('id');
|
||||
|
||||
$user=$em->getRepository($this->entity)->find($id);
|
||||
$output=[];
|
||||
$output["id"] = $user->getId();
|
||||
$output["displayname"] = $user->getDisplayname();
|
||||
$output["email"] = $user->getEmail();
|
||||
|
||||
$response = new Response(json_encode($output));
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
return $response;
|
||||
}
|
||||
|
||||
protected function getErrorForm($id,$form,$request,$data,$mode) {
|
||||
if ($form->get('submit')->isClicked()&&$mode=="delete") {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && $mode=="submit") {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && !$form->isValid()) {
|
||||
$this->get('session')->getFlashBag()->clear();
|
||||
|
||||
$errors = $form->getErrors();
|
||||
foreach( $errors as $error ) {
|
||||
$request->getSession()->getFlashBag()->add("error", $error->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
356
src/Controller/WebzineController.php
Executable file
356
src/Controller/WebzineController.php
Executable file
@ -0,0 +1,356 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Form\FormError;
|
||||
|
||||
use App\Entity\Webzine as Entity;
|
||||
use App\Form\WebzineType as Form;
|
||||
use App\Entity\Webzinepage as Webzinepage;
|
||||
|
||||
class WebzineController extends AbstractController
|
||||
{
|
||||
private $data = "webzine";
|
||||
private $route = "app_webzine";
|
||||
private $render = "Webzine/";
|
||||
private $entity = "App:Webzine";
|
||||
|
||||
public function list(Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$datas = $em->getRepository($this->entity)->findAll();
|
||||
|
||||
return $this->render($this->render.'list.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
"useheader" => true,
|
||||
"usesidebar" => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function view($idcat,$id,Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$webzine=$em->getRepository($this->entity)->find($idcat);
|
||||
$page=$em->getRepository("App:Webzinepage")->find($id);
|
||||
$sets=$em->getRepository($this->entity)->findBy(["set"=>$webzine->getSet()],["order"=>"ASC"]);
|
||||
|
||||
$datanext=$this->getDataAllNext($idcat,$id,$webzine);
|
||||
$dataprev=$this->getDataAllPrev($idcat,$id,$webzine);
|
||||
|
||||
$pathinfo=pathinfo($page->getIllustration());
|
||||
|
||||
if(!$page) return $this->redirectToRoute('app_home');
|
||||
|
||||
return $this->render($this->render.'view.html.twig', array(
|
||||
$this->data => $webzine,
|
||||
"page" => $page,
|
||||
"sets" => $sets,
|
||||
"prev" => $dataprev,
|
||||
"next" => $datanext,
|
||||
"pathinfo" => $pathinfo,
|
||||
"usemonocolor" => true,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
public function submit($by, Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data = new Entity();
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"submit"));
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm(null,$form,$request,$data,"submit");
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$data->setSubmittime(new \DateTime());
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// On récupère les pages et on cacule ceux à ajouter ou à supprimer
|
||||
$lstpages=array_filter(explode(",",$form->get("linkpages")->getData()));
|
||||
|
||||
// Récupération de l'id du webzine
|
||||
$id=$data->getId();
|
||||
$order=0;
|
||||
foreach($lstpages as $pageurl) {
|
||||
$order++;
|
||||
$width=$this->getWidth("uploads/webzine/".$pageurl);
|
||||
$height=$this->getHeight("uploads/webzine/".$pageurl);
|
||||
|
||||
$page= new Webzinepage();
|
||||
$page->setOrder($order);
|
||||
$page->setWidth($width);
|
||||
$page->setHeight($height);
|
||||
$page->setIllustration($pageurl);
|
||||
$page->setWebzine($data);
|
||||
|
||||
$em->persist($page);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
// Retour à la liste
|
||||
if($by=="console")
|
||||
return $this->redirectToRoute($this->route);
|
||||
else
|
||||
return $this->redirectToRoute("app_home");
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => false,
|
||||
$this->data => $data,
|
||||
'mode' => 'submit',
|
||||
'form' => $form->createView(),
|
||||
'by' => $by,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update($id,$by,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
$oldlstpages = array();
|
||||
foreach($data->getWebzinepages() as $page){
|
||||
$oldlstpages[] = $page->getIllustration();
|
||||
}
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"update"));
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm($id,$form,$request,$data,"update");
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
|
||||
// On récupère les pages et on cacule ceux à ajouter ou à supprimer
|
||||
$lstpages=array_filter(explode(",",$form->get("linkpages")->getData()));
|
||||
$removepages=array_diff($oldlstpages,$lstpages);
|
||||
$addpages=array_diff($lstpages,$oldlstpages);
|
||||
|
||||
// Suppression des pages obsolètes
|
||||
$fggotofirst=false;
|
||||
foreach($removepages as $pageurl) {
|
||||
$pagetoremove=$em->getRepository("App:Webzinepage")->findOneBy(["illustration"=>$pageurl]);
|
||||
$data->removeWebzinepage($pagetoremove);
|
||||
}
|
||||
|
||||
// Ajout des nouveaux pages
|
||||
$order=0;
|
||||
foreach($addpages as $pageurl) {
|
||||
$width=$this->getWidth("uploads/webzine/".$pageurl);
|
||||
$height=$this->getHeight("uploads/webzine/".$pageurl);
|
||||
|
||||
$page= new Webzinepage();
|
||||
$page->setWidth($width);
|
||||
$page->setHeight($height);
|
||||
$page->setIllustration($pageurl);
|
||||
$page->setWebzine($data);
|
||||
|
||||
$em->persist($page);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
// Ordonner les pages
|
||||
$order=0;
|
||||
foreach($lstpages as $pageurl) {
|
||||
$order++;
|
||||
$page=$em->getRepository("App:Webzinepage")->findOneBy(["illustration"=>$pageurl]);
|
||||
$page->setOrder($order);
|
||||
$em->persist($page);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
|
||||
// Retour à l'webzine
|
||||
if($by=="console")
|
||||
return $this->redirectToRoute($this->route);
|
||||
else
|
||||
return $this->redirectToRoute($this->route.'_view',array("idcat"=>$data->getId(),"id"=> $data->getWebzinepages()[0]->getId()));
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => false,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView(),
|
||||
'by' => $by,
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete($id,$by,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
|
||||
// Controle avant suppression
|
||||
$error=false;
|
||||
if($id<0) $error=true;
|
||||
|
||||
if($error)
|
||||
return $this->redirectToRoute($this->route."_update",["id"=>$id]);
|
||||
else {
|
||||
$em->remove($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
if($by=="console")
|
||||
return $this->redirectToRoute($this->route);
|
||||
else
|
||||
return $this->redirectToRoute("app_home");
|
||||
}
|
||||
}
|
||||
|
||||
public function upload()
|
||||
{
|
||||
return $this->render($this->render.'upload.html.twig');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected function getDataAllNext($idcat,$id,$webzine)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data = $em->createQueryBuilder()
|
||||
->select('e')
|
||||
->from("App:Webzinepage", 'e')
|
||||
->where('e.id>:id')
|
||||
->andWhere('e.webzine=:idcat')
|
||||
->orderBy("e.order","ASC")
|
||||
->getQuery()
|
||||
->setParameter("id", $id)
|
||||
->setParameter("idcat", $idcat)
|
||||
->setMaxResults(1)
|
||||
->getResult();
|
||||
|
||||
// Si on ne trouve pas de suivant on prend le premier du prochain set
|
||||
if(!$data) {
|
||||
$next = $em->createQueryBuilder()
|
||||
->select('w')
|
||||
->from("App:Webzine", 'w')
|
||||
->where('w.set=:set')
|
||||
->andWhere('w.order>:order')
|
||||
->orderBy("w.order","ASC")
|
||||
->getQuery()
|
||||
->setParameter("set", $webzine->getSet())
|
||||
->setParameter("order", $webzine->getOrder())
|
||||
->setMaxResults(1)
|
||||
->getResult();
|
||||
if($next) {
|
||||
$data = $em->createQueryBuilder()
|
||||
->select('e')
|
||||
->from("App:Webzinepage", 'e')
|
||||
->Where('e.webzine=:idcat')
|
||||
->orderBy("e.order","ASC")
|
||||
->getQuery()
|
||||
->setParameter("idcat", $next[0]->getId())
|
||||
->setMaxResults(1)
|
||||
->getResult();
|
||||
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getDataAllPrev($idcat,$id,$webzine)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data = $em->createQueryBuilder()
|
||||
->select('e')
|
||||
->from("App:Webzinepage", 'e')
|
||||
->where('e.id<:id')
|
||||
->andWhere('e.webzine=:idcat')
|
||||
->orderBy("e.order","DESC")
|
||||
->getQuery()
|
||||
->setParameter("id", $id)
|
||||
->setParameter("idcat", $idcat)
|
||||
->setMaxResults(1)
|
||||
->getResult();
|
||||
// Si on ne trouve pas de précédent on prend le dernier du précédent set
|
||||
if(!$data) {
|
||||
$next = $em->createQueryBuilder()
|
||||
->select('w')
|
||||
->from("App:Webzine", 'w')
|
||||
->where('w.set=:set')
|
||||
->andWhere('w.order<:order')
|
||||
->orderBy("w.order","DESC")
|
||||
->getQuery()
|
||||
->setParameter("set", $webzine->getSet())
|
||||
->setParameter("order", $webzine->getOrder())
|
||||
->setMaxResults(1)
|
||||
->getResult();
|
||||
if($next) {
|
||||
$data = $em->createQueryBuilder()
|
||||
->select('e')
|
||||
->from("App:Webzinepage", 'e')
|
||||
->Where('e.webzine=:idcat')
|
||||
->orderBy("e.order","DESC")
|
||||
->getQuery()
|
||||
->setParameter("idcat", $next[0]->getId())
|
||||
->setMaxResults(1)
|
||||
->getResult();
|
||||
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getHeight($image) {
|
||||
$size = getimagesize($image);
|
||||
$height = $size[1];
|
||||
return $height;
|
||||
}
|
||||
|
||||
// Cacul de la largeur
|
||||
protected function getWidth($image) {
|
||||
$size = getimagesize($image);
|
||||
$width = $size[0];
|
||||
return $width;
|
||||
}
|
||||
|
||||
protected function getErrorForm($id,$form,$request,$data,$mode) {
|
||||
if ($form->get('submit')->isClicked()&&$mode=="delete") {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && $mode=="submit") {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && ($mode=="submit" || $mode=="update")) {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && !$form->isValid()) {
|
||||
$this->get('session')->getFlashBag()->clear();
|
||||
|
||||
$errors = $form->getErrors();
|
||||
foreach( $errors as $error ) {
|
||||
$request->getSession()->getFlashBag()->add("error", $error->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
230
src/Entity/Category.php
Normal file
230
src/Entity/Category.php
Normal file
@ -0,0 +1,230 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Category
|
||||
*
|
||||
* @ORM\Table(name="category")
|
||||
* @ORM\Entity(repositoryClass="App\Repository\CategoryRepository")
|
||||
*/
|
||||
class Category
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=100)
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="roworder", type="integer", nullable=true)
|
||||
*/
|
||||
private $order;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean", nullable=true)
|
||||
*/
|
||||
private $usecategoryconfig;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="integer", nullable=true)
|
||||
*/
|
||||
private $appthumbwidth;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="integer", nullable=true)
|
||||
*/
|
||||
private $appthumbheight;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean", nullable=true)
|
||||
*/
|
||||
private $appthumbfilter;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="integer", nullable=true)
|
||||
*/
|
||||
private $appthumbfiltergrayscale;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="integer", nullable=true)
|
||||
*/
|
||||
private $appthumbfilteropacity;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="integer", nullable=true)
|
||||
*/
|
||||
private $appthumbfiltersepia;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Illustration", mappedBy="category", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
* @ORM\OrderBy({"id" = "DESC"})
|
||||
*/
|
||||
private $illustrations;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->illustrations = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setId(string $id): self
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): self
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOrder(): ?int
|
||||
{
|
||||
return $this->order;
|
||||
}
|
||||
|
||||
public function setOrder(?int $order): self
|
||||
{
|
||||
$this->order = $order;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUsecategoryconfig(): ?bool
|
||||
{
|
||||
return $this->usecategoryconfig;
|
||||
}
|
||||
|
||||
public function setUsecategoryconfig(?bool $usecategoryconfig): self
|
||||
{
|
||||
$this->usecategoryconfig = $usecategoryconfig;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAppthumbwidth(): ?int
|
||||
{
|
||||
return $this->appthumbwidth;
|
||||
}
|
||||
|
||||
public function setAppthumbwidth(?int $appthumbwidth): self
|
||||
{
|
||||
$this->appthumbwidth = $appthumbwidth;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAppthumbheight(): ?int
|
||||
{
|
||||
return $this->appthumbheight;
|
||||
}
|
||||
|
||||
public function setAppthumbheight(?int $appthumbheight): self
|
||||
{
|
||||
$this->appthumbheight = $appthumbheight;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAppthumbfilter(): ?bool
|
||||
{
|
||||
return $this->appthumbfilter;
|
||||
}
|
||||
|
||||
public function setAppthumbfilter(?bool $appthumbfilter): self
|
||||
{
|
||||
$this->appthumbfilter = $appthumbfilter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAppthumbfiltergrayscale(): ?int
|
||||
{
|
||||
return $this->appthumbfiltergrayscale;
|
||||
}
|
||||
|
||||
public function setAppthumbfiltergrayscale(?int $appthumbfiltergrayscale): self
|
||||
{
|
||||
$this->appthumbfiltergrayscale = $appthumbfiltergrayscale;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAppthumbfilteropacity(): ?int
|
||||
{
|
||||
return $this->appthumbfilteropacity;
|
||||
}
|
||||
|
||||
public function setAppthumbfilteropacity(?int $appthumbfilteropacity): self
|
||||
{
|
||||
$this->appthumbfilteropacity = $appthumbfilteropacity;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAppthumbfiltersepia(): ?int
|
||||
{
|
||||
return $this->appthumbfiltersepia;
|
||||
}
|
||||
|
||||
public function setAppthumbfiltersepia(?int $appthumbfiltersepia): self
|
||||
{
|
||||
$this->appthumbfiltersepia = $appthumbfiltersepia;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|Illustration[]
|
||||
*/
|
||||
public function getIllustrations(): Collection
|
||||
{
|
||||
return $this->illustrations;
|
||||
}
|
||||
|
||||
public function addIllustration(Illustration $illustration): self
|
||||
{
|
||||
if (!$this->illustrations->contains($illustration)) {
|
||||
$this->illustrations[] = $illustration;
|
||||
$illustration->setCategory($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeIllustration(Illustration $illustration): self
|
||||
{
|
||||
if ($this->illustrations->removeElement($illustration)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($illustration->getCategory() === $this) {
|
||||
$illustration->setCategory(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
202
src/Entity/Config.php
Normal file
202
src/Entity/Config.php
Normal file
@ -0,0 +1,202 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Cron
|
||||
*
|
||||
* @ORM\Table(name="config")
|
||||
* @ORM\Entity(repositoryClass="App\Repository\ConfigRepository")
|
||||
*/
|
||||
class Config
|
||||
{ /**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=250)
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text")
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="roworder", type="string")
|
||||
*/
|
||||
protected $order;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
protected $visible;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
protected $changeable;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
protected $required;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $grouped;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $category;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text")
|
||||
*/
|
||||
protected $help;
|
||||
|
||||
public function getId(): ?string
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setId(string $id): self
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getValue(): ?string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function setValue(string $value): self
|
||||
{
|
||||
$this->value = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOrder(): ?string
|
||||
{
|
||||
return $this->order;
|
||||
}
|
||||
|
||||
public function setOrder(string $order): self
|
||||
{
|
||||
$this->order = $order;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getVisible(): ?bool
|
||||
{
|
||||
return $this->visible;
|
||||
}
|
||||
|
||||
public function setVisible(bool $visible): self
|
||||
{
|
||||
$this->visible = $visible;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getChangeable(): ?bool
|
||||
{
|
||||
return $this->changeable;
|
||||
}
|
||||
|
||||
public function setChangeable(bool $changeable): self
|
||||
{
|
||||
$this->changeable = $changeable;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRequired(): ?bool
|
||||
{
|
||||
return $this->required;
|
||||
}
|
||||
|
||||
public function setRequired(bool $required): self
|
||||
{
|
||||
$this->required = $required;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getType(): ?string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function setType(string $type): self
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getGrouped(): ?string
|
||||
{
|
||||
return $this->grouped;
|
||||
}
|
||||
|
||||
public function setGrouped(string $grouped): self
|
||||
{
|
||||
$this->grouped = $grouped;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCategory(): ?string
|
||||
{
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
public function setCategory(string $category): self
|
||||
{
|
||||
$this->category = $category;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHelp(): ?string
|
||||
{
|
||||
return $this->help;
|
||||
}
|
||||
|
||||
public function setHelp(string $help): self
|
||||
{
|
||||
$this->help = $help;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTitle(): ?string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function setTitle(string $title): self
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
384
src/Entity/Cron.php
Normal file
384
src/Entity/Cron.php
Normal file
@ -0,0 +1,384 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* Cron
|
||||
*
|
||||
* @ORM\Table(name="cron")
|
||||
* @ORM\Entity(repositoryClass="App\Repository\CronRepository")
|
||||
*/
|
||||
class Cron
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="command", type="string", nullable=false)
|
||||
* @Assert\NotBlank()
|
||||
*
|
||||
*/
|
||||
private $command;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text", nullable=true)
|
||||
*/
|
||||
private $description;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $statut;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime", nullable=false)
|
||||
*/
|
||||
private $submitdate;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime", nullable=true)
|
||||
*/
|
||||
private $startexecdate;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime", nullable=true)
|
||||
*/
|
||||
private $endexecdate;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime", nullable=true)
|
||||
*/
|
||||
private $nextexecdate;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="integer", nullable=true)
|
||||
*/
|
||||
private $repeatcall;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="integer", nullable=true)
|
||||
*/
|
||||
private $repeatexec;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="integer", nullable=true)
|
||||
*/
|
||||
private $repeatinterval;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text", nullable=true)
|
||||
*/
|
||||
private $jsonargument;
|
||||
|
||||
private $statutlabel;
|
||||
|
||||
// A garder pour forcer l'id en init
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
// A garder pour récupérer le label du statut
|
||||
public function getStatutlabel()
|
||||
{
|
||||
switch($this->statut) {
|
||||
case 0: $this->statutlabel="A éxécuter"; break;
|
||||
case 1: $this->statutlabel="Exécution en cours"; break;
|
||||
case 2: $this->statutlabel="OK"; break;
|
||||
case 3: $this->statutlabel="KO"; break;
|
||||
}
|
||||
return $this->statutlabel;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->submitdate = new \DateTime();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set command
|
||||
*
|
||||
* @param string $command
|
||||
*
|
||||
* @return Cron
|
||||
*/
|
||||
public function setCommand($command)
|
||||
{
|
||||
$this->command = $command;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get command
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCommand()
|
||||
{
|
||||
return $this->command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set description
|
||||
*
|
||||
* @param string $description
|
||||
*
|
||||
* @return Cron
|
||||
*/
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set statut
|
||||
*
|
||||
* @param integer $statut
|
||||
*
|
||||
* @return Cron
|
||||
*/
|
||||
public function setStatut($statut)
|
||||
{
|
||||
$this->statut = $statut;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get statut
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getStatut()
|
||||
{
|
||||
return $this->statut;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set submitdate
|
||||
*
|
||||
* @param \DateTime $submitdate
|
||||
*
|
||||
* @return Cron
|
||||
*/
|
||||
public function setSubmitdate($submitdate)
|
||||
{
|
||||
$this->submitdate = $submitdate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get submitdate
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getSubmitdate()
|
||||
{
|
||||
return $this->submitdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set startexecdate
|
||||
*
|
||||
* @param \DateTime $startexecdate
|
||||
*
|
||||
* @return Cron
|
||||
*/
|
||||
public function setStartexecdate($startexecdate)
|
||||
{
|
||||
$this->startexecdate = $startexecdate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get startexecdate
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getStartexecdate()
|
||||
{
|
||||
return $this->startexecdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set endexecdate
|
||||
*
|
||||
* @param \DateTime $endexecdate
|
||||
*
|
||||
* @return Cron
|
||||
*/
|
||||
public function setEndexecdate($endexecdate)
|
||||
{
|
||||
$this->endexecdate = $endexecdate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get endexecdate
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getEndexecdate()
|
||||
{
|
||||
return $this->endexecdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set nextexecdate
|
||||
*
|
||||
* @param \DateTime $nextexecdate
|
||||
*
|
||||
* @return Cron
|
||||
*/
|
||||
public function setNextexecdate($nextexecdate)
|
||||
{
|
||||
$this->nextexecdate = $nextexecdate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get nextexecdate
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getNextexecdate()
|
||||
{
|
||||
return $this->nextexecdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set repeatcall
|
||||
*
|
||||
* @param integer $repeatcall
|
||||
*
|
||||
* @return Cron
|
||||
*/
|
||||
public function setRepeatcall($repeatcall)
|
||||
{
|
||||
$this->repeatcall = $repeatcall;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get repeatcall
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getRepeatcall()
|
||||
{
|
||||
return $this->repeatcall;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set repeatexec
|
||||
*
|
||||
* @param integer $repeatexec
|
||||
*
|
||||
* @return Cron
|
||||
*/
|
||||
public function setRepeatexec($repeatexec)
|
||||
{
|
||||
$this->repeatexec = $repeatexec;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get repeatexec
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getRepeatexec()
|
||||
{
|
||||
return $this->repeatexec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set repeatinterval
|
||||
*
|
||||
* @param integer $repeatinterval
|
||||
*
|
||||
* @return Cron
|
||||
*/
|
||||
public function setRepeatinterval($repeatinterval)
|
||||
{
|
||||
$this->repeatinterval = $repeatinterval;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get repeatinterval
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getRepeatinterval()
|
||||
{
|
||||
return $this->repeatinterval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set jsonargument
|
||||
*
|
||||
* @param string $jsonargument
|
||||
*
|
||||
* @return Cron
|
||||
*/
|
||||
public function setJsonargument($jsonargument)
|
||||
{
|
||||
$this->jsonargument = $jsonargument;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get jsonargument
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getJsonargument()
|
||||
{
|
||||
return $this->jsonargument;
|
||||
}
|
||||
}
|
87
src/Entity/Group.php
Normal file
87
src/Entity/Group.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
|
||||
/**
|
||||
* Group
|
||||
*
|
||||
* @ORM\Entity(repositoryClass="App\Repository\GroupRepository")
|
||||
* @ORM\Table(name="groupe", uniqueConstraints={@ORM\UniqueConstraint(name="name", columns={"name"})})} )
|
||||
* @UniqueEntity("name", message="Ce nom de groupe existe dèja")
|
||||
*/
|
||||
class Group
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="name", type="string")
|
||||
*
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="User", mappedBy="groups")
|
||||
*/
|
||||
protected $users;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->users = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): self
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|User[]
|
||||
*/
|
||||
public function getUsers(): Collection
|
||||
{
|
||||
return $this->users;
|
||||
}
|
||||
|
||||
public function addUser(User $user): self
|
||||
{
|
||||
if (!$this->users->contains($user)) {
|
||||
$this->users[] = $user;
|
||||
$user->addGroup($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeUser(User $user): self
|
||||
{
|
||||
if ($this->users->contains($user)) {
|
||||
$this->users->removeElement($user);
|
||||
$user->removeGroup($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
146
src/Entity/Illustration.php
Normal file
146
src/Entity/Illustration.php
Normal file
@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Illustration
|
||||
*
|
||||
* @ORM\Table(name="illustration")
|
||||
* @ORM\Entity(repositoryClass="App\Repository\IllustrationRepository")
|
||||
*/
|
||||
class Illustration
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=100)
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text", nullable=true)
|
||||
*/
|
||||
private $description;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime")
|
||||
*/
|
||||
private $submittime;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $width;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $height;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=100)
|
||||
*/
|
||||
private $illustration;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Category")
|
||||
*/
|
||||
private $category;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): self
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription(?string $description): self
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSubmittime(): ?\DateTimeInterface
|
||||
{
|
||||
return $this->submittime;
|
||||
}
|
||||
|
||||
public function setSubmittime(\DateTimeInterface $submittime): self
|
||||
{
|
||||
$this->submittime = $submittime;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getWidth(): ?int
|
||||
{
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
public function setWidth(int $width): self
|
||||
{
|
||||
$this->width = $width;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHeight(): ?int
|
||||
{
|
||||
return $this->height;
|
||||
}
|
||||
|
||||
public function setHeight(int $height): self
|
||||
{
|
||||
$this->height = $height;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIllustration(): ?string
|
||||
{
|
||||
return $this->illustration;
|
||||
}
|
||||
|
||||
public function setIllustration(string $illustration): self
|
||||
{
|
||||
$this->illustration = $illustration;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCategory(): ?Category
|
||||
{
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
public function setCategory(?Category $category): self
|
||||
{
|
||||
$this->category = $category;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
80
src/Entity/Link.php
Normal file
80
src/Entity/Link.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Link
|
||||
*
|
||||
* @ORM\Table(name="link")
|
||||
* @ORM\Entity(repositoryClass="App\Repository\LinkRepository")
|
||||
*/
|
||||
class Link
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=100)
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="roworder", type="integer", nullable=true)
|
||||
*/
|
||||
private $order;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text")
|
||||
*/
|
||||
protected $url;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): self
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOrder(): ?int
|
||||
{
|
||||
return $this->order;
|
||||
}
|
||||
|
||||
public function setOrder(?int $order): self
|
||||
{
|
||||
$this->order = $order;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUrl(): ?string
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
public function setUrl(string $url): self
|
||||
{
|
||||
$this->url = $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
50
src/Entity/Script.php
Normal file
50
src/Entity/Script.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* Script
|
||||
*
|
||||
* @ORM\Table(name="script")
|
||||
* @ORM\Entity(repositoryClass="App\Repository\ScriptRepository")
|
||||
*/
|
||||
class Script
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="name", type="string", nullable=false)
|
||||
* @Assert\NotBlank()
|
||||
*
|
||||
*/
|
||||
private $name;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): self
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
270
src/Entity/User.php
Normal file
270
src/Entity/User.php
Normal file
@ -0,0 +1,270 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
|
||||
|
||||
/**
|
||||
* User
|
||||
*
|
||||
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
|
||||
* @ORM\Table(name="user",uniqueConstraints={@ORM\UniqueConstraint(name="username", columns={"username"})})
|
||||
* @UniqueEntity("username", message="Ce nom d'utilisateur existe dèja")
|
||||
*/
|
||||
|
||||
class User implements UserInterface, \Serializable
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="username", type="string", length=255)
|
||||
*/
|
||||
private $username;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="password", type="string", length=255)
|
||||
*/
|
||||
private $password;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*
|
||||
* @ORM\Column(name="roles", type="array", length=255)
|
||||
*/
|
||||
private $roles = array();
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="salt", type="string", length=255)
|
||||
*/
|
||||
private $salt = '';
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=250, nullable=true)
|
||||
*/
|
||||
private $firstname;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=250)
|
||||
*/
|
||||
private $lastname;
|
||||
private $displayname;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=200, nullable=true, options={"default" : 0})
|
||||
*/
|
||||
private $avatar;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=250)
|
||||
*/
|
||||
private $email;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Group", inversedBy="users", cascade={"persist"})
|
||||
* @ORM\JoinTable(name="usergroupe",
|
||||
* joinColumns={@ORM\JoinColumn(name="user", referencedColumnName="id")},
|
||||
* inverseJoinColumns={@ORM\JoinColumn(name="groupe", referencedColumnName="id")}
|
||||
* )
|
||||
*/
|
||||
private $groups;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->groups = new ArrayCollection();
|
||||
$this->surveys = new ArrayCollection();
|
||||
$this->guests = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getUsername(): ?string
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
public function getSalt(): ?string
|
||||
{
|
||||
return $this->salt;
|
||||
}
|
||||
|
||||
public function setPassword($password): self
|
||||
{
|
||||
if($password!=$this->password&&$password!=""&&!is_null($password)){
|
||||
$this->salt = uniqid(mt_rand(), true);
|
||||
$hash = "{SSHA}" . base64_encode(pack("H*", sha1($password . $this->salt)) . $this->salt);
|
||||
|
||||
$this->password = $hash;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPassword(): ?string
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
public function getRoles(): ?array
|
||||
{
|
||||
return $this->roles;
|
||||
}
|
||||
|
||||
public function hasRole(string $role): ?bool
|
||||
{
|
||||
return in_array($role,$this->roles);
|
||||
}
|
||||
|
||||
public function eraseCredentials()
|
||||
{
|
||||
}
|
||||
|
||||
public function serialize()
|
||||
{
|
||||
return serialize(array(
|
||||
$this->id,
|
||||
$this->username,
|
||||
$this->password,
|
||||
$this->salt,
|
||||
));
|
||||
}
|
||||
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
list (
|
||||
$this->id,
|
||||
$this->username,
|
||||
$this->password,
|
||||
$this->salt
|
||||
) = unserialize($serialized, array('allowed_classes' => false));
|
||||
}
|
||||
|
||||
public function getDisplayname()
|
||||
{
|
||||
return $this->firstname." ".$this->lastname;
|
||||
}
|
||||
|
||||
public function setId(int $id): self
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setUsername(string $username): self
|
||||
{
|
||||
$this->username = $username;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function setRoles(array $roles): self
|
||||
{
|
||||
$this->roles = $roles;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setSalt(string $salt): self
|
||||
{
|
||||
$this->salt = $salt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFirstname(): ?string
|
||||
{
|
||||
return $this->firstname;
|
||||
}
|
||||
|
||||
public function setFirstname(?string $firstname): self
|
||||
{
|
||||
$this->firstname = $firstname;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLastname(): ?string
|
||||
{
|
||||
return $this->lastname;
|
||||
}
|
||||
|
||||
public function setLastname(?string $lastname): self
|
||||
{
|
||||
$this->lastname = $lastname;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAvatar(): ?string
|
||||
{
|
||||
if($this->avatar)
|
||||
return $this->avatar;
|
||||
else
|
||||
return "noavatar.png";
|
||||
}
|
||||
|
||||
public function setAvatar(?string $avatar): self
|
||||
{
|
||||
$this->avatar = $avatar;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEmail(): ?string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function setEmail(string $email): self
|
||||
{
|
||||
$this->email = $email;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|Group[]
|
||||
*/
|
||||
public function getGroups(): Collection
|
||||
{
|
||||
return $this->groups;
|
||||
}
|
||||
|
||||
public function addGroup(Group $group): self
|
||||
{
|
||||
if (!$this->groups->contains($group)) {
|
||||
$this->groups[] = $group;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeGroup(Group $group): self
|
||||
{
|
||||
if ($this->groups->contains($group)) {
|
||||
$this->groups->removeElement($group);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
172
src/Entity/Webzine.php
Normal file
172
src/Entity/Webzine.php
Normal file
@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Webzine
|
||||
*
|
||||
* @ORM\Table(name="webzine")
|
||||
* @ORM\Entity(repositoryClass="App\Repository\WebzineRepository")
|
||||
*/
|
||||
class Webzine
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=100)
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text", nullable=true)
|
||||
*/
|
||||
private $description;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime")
|
||||
*/
|
||||
private $submittime;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="setname", type="string", length=100, nullable=true)
|
||||
*/
|
||||
private $set;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="roworder", type="integer", nullable=true)
|
||||
*/
|
||||
private $order;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $mode;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Webzinepage", mappedBy="webzine", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
* @ORM\OrderBy({"order" = "ASC"})
|
||||
*/
|
||||
private $webzinepages;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->webzinepages = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): self
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription(?string $description): self
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSubmittime(): ?\DateTimeInterface
|
||||
{
|
||||
return $this->submittime;
|
||||
}
|
||||
|
||||
public function setSubmittime(\DateTimeInterface $submittime): self
|
||||
{
|
||||
$this->submittime = $submittime;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSet(): ?string
|
||||
{
|
||||
return $this->set;
|
||||
}
|
||||
|
||||
public function setSet(?string $set): self
|
||||
{
|
||||
$this->set = $set;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOrder(): ?int
|
||||
{
|
||||
return $this->order;
|
||||
}
|
||||
|
||||
public function setOrder(?int $order): self
|
||||
{
|
||||
$this->order = $order;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMode(): ?int
|
||||
{
|
||||
return $this->mode;
|
||||
}
|
||||
|
||||
public function setMode(int $mode): self
|
||||
{
|
||||
$this->mode = $mode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|Webzinepage[]
|
||||
*/
|
||||
public function getWebzinepages(): Collection
|
||||
{
|
||||
return $this->webzinepages;
|
||||
}
|
||||
|
||||
public function addWebzinepage(Webzinepage $webzinepage): self
|
||||
{
|
||||
if (!$this->webzinepages->contains($webzinepage)) {
|
||||
$this->webzinepages[] = $webzinepage;
|
||||
$webzinepage->setWebzine($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeWebzinepage(Webzinepage $webzinepage): self
|
||||
{
|
||||
if ($this->webzinepages->removeElement($webzinepage)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($webzinepage->getWebzine() === $this) {
|
||||
$webzinepage->setWebzine(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
111
src/Entity/Webzinepage.php
Normal file
111
src/Entity/Webzinepage.php
Normal file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Illustration
|
||||
*
|
||||
* @ORM\Table(name="webzinepage")
|
||||
* @ORM\Entity(repositoryClass="App\Repository\WebzinepageRepository")
|
||||
*/
|
||||
class Webzinepage
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="roworder", type="integer", nullable=true)
|
||||
*/
|
||||
private $order;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $width;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $height;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=100)
|
||||
*/
|
||||
private $illustration;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Webzine")
|
||||
*/
|
||||
private $webzine;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getOrder(): ?int
|
||||
{
|
||||
return $this->order;
|
||||
}
|
||||
|
||||
public function setOrder(?int $order): self
|
||||
{
|
||||
$this->order = $order;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getWidth(): ?int
|
||||
{
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
public function setWidth(int $width): self
|
||||
{
|
||||
$this->width = $width;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHeight(): ?int
|
||||
{
|
||||
return $this->height;
|
||||
}
|
||||
|
||||
public function setHeight(int $height): self
|
||||
{
|
||||
$this->height = $height;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIllustration(): ?string
|
||||
{
|
||||
return $this->illustration;
|
||||
}
|
||||
|
||||
public function setIllustration(string $illustration): self
|
||||
{
|
||||
$this->illustration = $illustration;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getWebzine(): ?Webzine
|
||||
{
|
||||
return $this->webzine;
|
||||
}
|
||||
|
||||
public function setWebzine(?Webzine $webzine): self
|
||||
{
|
||||
$this->webzine = $webzine;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
96
src/Form/CategoryType.php
Normal file
96
src/Form/CategoryType.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
namespace App\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
|
||||
class CategoryType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$boolean=["non" => "0","oui" => "1"];
|
||||
$thumbwidth=["variable" => 0,"10%" => 1,"20%" => 2];
|
||||
$thumbheight=["carré" => 0,"proportionnelle" => 1,"page"=>2];
|
||||
|
||||
$builder->add('submit',
|
||||
SubmitType::class, [
|
||||
"label" => "Valider",
|
||||
"attr" => ["class" => "btn btn-success no-print"],
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('order',
|
||||
IntegerType::class, [
|
||||
"label" =>"Ordre",
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('name',
|
||||
TextType::class, [
|
||||
"label" =>"Nom",
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('usecategoryconfig',
|
||||
ChoiceType::class, [
|
||||
"label" =>"Utiliser une configuration de style spécifique",
|
||||
"choices" => $boolean,
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('appthumbwidth',
|
||||
ChoiceType::class, [
|
||||
"label" =>"Largeur des miniatures",
|
||||
"choices" => $thumbwidth,
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('appthumbheight',
|
||||
ChoiceType::class, [
|
||||
"label" =>"Hauteur des miniatures",
|
||||
"choices" => $thumbheight,
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('appthumbfilter',
|
||||
ChoiceType::class, [
|
||||
"label" =>"Appliquer un filtre CSS sur les miniatures",
|
||||
"choices" => $boolean,
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('appthumbfiltergrayscale',
|
||||
IntegerType::class, [
|
||||
"label" =>"Filtre grayscale",
|
||||
"attr" => ["min" => "0", "max"=>"100"],
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('appthumbfilteropacity',
|
||||
IntegerType::class, [
|
||||
"label" =>"Filtre opacity",
|
||||
"attr" => ["min" => "0", "max"=>"100"],
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('appthumbfiltersepia',
|
||||
IntegerType::class, [
|
||||
"label" =>"Filtre sepia",
|
||||
"attr" => ["min" => "0", "max"=>"100"],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'App\Entity\Category',
|
||||
'mode' => 'string',
|
||||
));
|
||||
}
|
||||
}
|
191
src/Form/ConfigType.php
Normal file
191
src/Form/ConfigType.php
Normal file
@ -0,0 +1,191 @@
|
||||
<?php
|
||||
namespace App\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use FOS\CKEditorBundle\Form\Type\CKEditorType;
|
||||
|
||||
class ConfigType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('submit',
|
||||
SubmitType::class,
|
||||
array("label" => "Valider",
|
||||
"attr" => array("class" => "btn btn-success")));
|
||||
|
||||
$builder->add('id',
|
||||
TextType::class,
|
||||
array("label" =>"Clé",
|
||||
"label_attr" => array("style" => 'margin-top:15px;'),
|
||||
"attr" => array("class" => "form-control"),
|
||||
'disabled' => true));
|
||||
|
||||
switch($options["type"]) {
|
||||
case "string":
|
||||
$builder->add('value',
|
||||
TextType::class,
|
||||
array("label" => "Valeur",
|
||||
"label_attr" => array("style" => 'margin-top:15px;'),
|
||||
"attr" => array("class" => "form-control"),
|
||||
'required' => ($options["required"]==0?false:true)));
|
||||
break;
|
||||
|
||||
case "boolean":
|
||||
$choices=["oui" => "1","non" => "0"];
|
||||
$builder->add("value", ChoiceType::class,
|
||||
array("label" =>"Valeur",
|
||||
"label_attr" => array("style" => 'margin-top:15px;'),
|
||||
"attr" => array("class" => "form-control"),
|
||||
'required' => ($options["required"]==0?false:true),
|
||||
"choices" => $choices));
|
||||
break;
|
||||
|
||||
case "integer":
|
||||
$builder->add("value",
|
||||
IntegerType::class, [
|
||||
"label" =>"Valeur",
|
||||
"label_attr" => array("style" => 'margin-top:15px;'),
|
||||
"attr" => array("class" => "form-control","min" => "0"),
|
||||
"required" => ($options["required"]==0?false:true),
|
||||
]
|
||||
);
|
||||
break;
|
||||
|
||||
case "pourcentage":
|
||||
$builder->add("value",
|
||||
IntegerType::class, [
|
||||
"label" =>"Valeur",
|
||||
"label_attr" => array("style" => 'margin-top:15px;'),
|
||||
"attr" => array("class" => "form-control","min" => "0", "max"=>"100"),
|
||||
"required" => ($options["required"]==0?false:true),
|
||||
]
|
||||
);
|
||||
break;
|
||||
|
||||
case "thumbwidth":
|
||||
$choices=["variable" => 0,"10%" => 1,"20%" => 2];
|
||||
$builder->add("value",
|
||||
ChoiceType::class, [
|
||||
"label" =>"Valeur",
|
||||
"label_attr" => array("style" => 'margin-top:15px;'),
|
||||
"attr" => array("class" => "form-control"),
|
||||
"required" => ($options["required"]==0?false:true),
|
||||
"choices" => $choices
|
||||
]
|
||||
);
|
||||
break;
|
||||
|
||||
case "thumbheight":
|
||||
$choices=["carré" => 0,"proportionnelle" => 1,"page" => 2];
|
||||
$builder->add("value",
|
||||
ChoiceType::class, [
|
||||
"label" =>"Valeur",
|
||||
"label_attr" => array("style" => 'margin-top:15px;'),
|
||||
"attr" => array("class" => "form-control"),
|
||||
"required" => ($options["required"]==0?false:true),
|
||||
"choices" => $choices
|
||||
]
|
||||
);
|
||||
break;
|
||||
|
||||
case "font":
|
||||
$choices=[
|
||||
"ABeeZee-Regular" => "ABeeZee-Regular",
|
||||
"Acme-Regular" => "Acme-Regular",
|
||||
"AlfaSlabOne-Regular" => "AlfaSlabOne-Regular",
|
||||
"Anton-Regular" => "Anton-Regular",
|
||||
"Baloo-Regular" => "Baloo-Regular",
|
||||
"CarterOne-Regular" => "CarterOne-Regular",
|
||||
"Chewy-Regular" => "Chewy-Regular",
|
||||
"Courgette-Regular" => "Courgette-Regular",
|
||||
"FredokaOne-Regular" => "FredokaOne-Regular",
|
||||
"Grandstander" => "Grandstander",
|
||||
"Helvetica" => "Helvetica",
|
||||
"Justanotherhand-Regular" => "Justanotherhand-Regular",
|
||||
"Lato-Regular" => "Lato-Regular",
|
||||
"LexendDeca-Regular" => "LexendDeca-Regular",
|
||||
"LuckiestGuy-Regular" => "LuckiestGuy-Regular",
|
||||
"Overpass-Black" => "Overpass-Black",
|
||||
"PassionOne" => "PassionOne",
|
||||
"Peacesans" => "Peacesans",
|
||||
"Redressed" => "Redressed",
|
||||
"Righteous-Regular" => "Righteous-Regular",
|
||||
"Roboto-Regular" => "Roboto-Regular",
|
||||
"RubikMonoOne-Regular" => "RubikMonoOne-Regular",
|
||||
"SigmarOne-Regular" => "SigmarOne-Regular",
|
||||
"Signika-Regular" => "Signika-Regular",
|
||||
"Teko-Bold" => "Teko-Bold",
|
||||
"Viga-Regular" => "Viga-Regular",
|
||||
];
|
||||
|
||||
$builder->add("value", ChoiceType::class,
|
||||
array("label" =>"Valeur",
|
||||
"label_attr" => array("style" => 'margin-top:15px;'),
|
||||
"attr" => array("class" => "form-control"),
|
||||
'required' => ($options["required"]==0?false:true),
|
||||
"choices" => $choices));
|
||||
break;
|
||||
|
||||
case "editor":
|
||||
$builder->add('value',
|
||||
CKEditorType::class,[
|
||||
"required" => ($options["required"]==0?false:true),
|
||||
"config" => [
|
||||
'uiColor' => '#ffffff',
|
||||
'height' => 600,
|
||||
'filebrowserUploadRoute' => 'app_ckeditor_upload',
|
||||
'language' => 'fr',
|
||||
]
|
||||
]
|
||||
);
|
||||
break;
|
||||
|
||||
case "logo":
|
||||
$builder->add('value',HiddenType::class);
|
||||
break;
|
||||
|
||||
case "hero":
|
||||
$builder->add('value',HiddenType::class);
|
||||
break;
|
||||
|
||||
case "image":
|
||||
$builder->add('value',HiddenType::class);
|
||||
break;
|
||||
|
||||
case "color":
|
||||
$builder->add('value',
|
||||
TextType::class,
|
||||
array("label" => "Valeur",
|
||||
"label_attr" => array("style" => 'margin-top:15px;'),
|
||||
"attr" => array("class" => "pick-a-color form-control"),
|
||||
'required' => ($options["required"]==0?false:true)));
|
||||
break;
|
||||
}
|
||||
|
||||
$builder->add('help',
|
||||
TextareaType::class,
|
||||
array("label" =>"Aide",
|
||||
"attr" => array("class" => "form-control", "style" => "margin-top:15px; height: 200px;"),
|
||||
'required' => false,
|
||||
'disabled' => true));
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'App\Entity\Config',
|
||||
'mode' => "string",
|
||||
'id' => "string",
|
||||
'type' => "string",
|
||||
'required' => "string",
|
||||
));
|
||||
}
|
||||
}
|
71
src/Form/CronType.php
Normal file
71
src/Form/CronType.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FileType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ColorType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
|
||||
use Trsteel\CkeditorBundle\Form\Type\CkeditorType;
|
||||
|
||||
class CronType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('submit', SubmitType::class, [
|
||||
"label" => "Valider",
|
||||
"attr" => array("class" => "btn btn-success")
|
||||
])
|
||||
|
||||
->add('command', TextType::class, [
|
||||
'label' => 'Commande',
|
||||
"disabled" => true,
|
||||
])
|
||||
|
||||
->add('jsonargument', TextType::class, [
|
||||
'label' => 'Argument Commande au format json',
|
||||
"disabled" => true,
|
||||
])
|
||||
|
||||
->add('statut', ChoiceType::class, [
|
||||
'label' => "Statut",
|
||||
'choices' => array("A éxécuter" => "0","Exécution en cours" => "1","OK" => "2","KO" => "3","Désactivé" => "4")
|
||||
])
|
||||
|
||||
->add('repeatcall', IntegerType::class, [
|
||||
'label' => "Nombre d'éxécution en cas d'echec. Si zéro on le répete à l'infini même si OK"
|
||||
])
|
||||
|
||||
->add('repeatinterval', IntegerType::class, [
|
||||
'label' => "Interval en seconde entre deux éxécution"
|
||||
])
|
||||
|
||||
->add('nextexecdate', DatetimeType::class, [
|
||||
'label' => "Prochaine exécution"
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OptionsResolver $resolver
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => 'App\Entity\Cron',
|
||||
'mode' => 'string'
|
||||
]);
|
||||
}
|
||||
}
|
57
src/Form/GroupType.php
Normal file
57
src/Form/GroupType.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
namespace App\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Tetranz\Select2EntityBundle\Form\Type\Select2EntityType;
|
||||
|
||||
class GroupType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('submit',
|
||||
SubmitType::class, [
|
||||
"label" => "Valider",
|
||||
"attr" => ["class" => "btn btn-success no-print"],
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('name',
|
||||
TextType::class, [
|
||||
"label" =>"Nom",
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('users',
|
||||
Select2EntityType::class, [
|
||||
"label" => "Utilisateurs",
|
||||
"disabled" => false,
|
||||
"required" => false,
|
||||
"multiple" => true,
|
||||
"remote_route" => "app_user_select",
|
||||
"class" => "App:User",
|
||||
"primary_key" => "id",
|
||||
"text_property" => "displayname",
|
||||
"minimum_input_length" => 0,
|
||||
"page_limit" => 100,
|
||||
"allow_clear" => true,
|
||||
"delay" => 250,
|
||||
"cache" => false,
|
||||
"cache_timeout" => 60000,
|
||||
"language" => "fr",
|
||||
"placeholder" => "Selectionner des Utilisateurs",
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'App\Entity\Group',
|
||||
'mode' => 'string',
|
||||
));
|
||||
}
|
||||
}
|
63
src/Form/IllustrationType.php
Normal file
63
src/Form/IllustrationType.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
namespace App\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use FOS\CKEditorBundle\Form\Type\CKEditorType;
|
||||
|
||||
|
||||
class IllustrationType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('submit',
|
||||
SubmitType::class, [
|
||||
"label" => "Valider",
|
||||
"attr" => ["class" => "btn btn-success no-print"],
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('name',
|
||||
TextType::class, [
|
||||
"label" =>"Nom",
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('description',
|
||||
CKEditorType::class, [
|
||||
"required" => false,
|
||||
"config" => [
|
||||
'uiColor' => '#ffffff',
|
||||
'height' => 600,
|
||||
'filebrowserUploadRoute' => 'app_ckeditor_upload',
|
||||
'language' => 'fr',
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('category',
|
||||
EntityType::class, [
|
||||
"class" => "App:Category",
|
||||
"label" => "Categorie",
|
||||
"choice_label"=> "name",
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('illustration',HiddenType::class);
|
||||
$builder->add('width',HiddenType::class);
|
||||
$builder->add('height',HiddenType::class);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'App\Entity\Illustration',
|
||||
'mode' => 'string',
|
||||
));
|
||||
}
|
||||
}
|
48
src/Form/LinkType.php
Normal file
48
src/Form/LinkType.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
namespace App\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
|
||||
class LinkType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('submit',
|
||||
SubmitType::class, [
|
||||
"label" => "Valider",
|
||||
"attr" => ["class" => "btn btn-success no-print"],
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('order',
|
||||
IntegerType::class, [
|
||||
"label" =>"Ordre",
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('name',
|
||||
TextType::class, [
|
||||
"label" =>"Nom",
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('url',
|
||||
TextType::class, [
|
||||
"label" =>"URL",
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'App\Entity\Link',
|
||||
'mode' => 'string',
|
||||
));
|
||||
}
|
||||
}
|
120
src/Form/UserType.php
Normal file
120
src/Form/UserType.php
Normal file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
namespace App\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Tetranz\Select2EntityBundle\Form\Type\Select2EntityType;
|
||||
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
|
||||
class UserType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('avatar',HiddenType::class, array("empty_data" => "noavatar.png"));
|
||||
|
||||
$builder->add('submit',
|
||||
SubmitType::class, [
|
||||
"label" => "Valider",
|
||||
"attr" => ["class" => "btn btn-success no-print"],
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('username',
|
||||
TextType::class, [
|
||||
"label" =>"Login",
|
||||
"disabled" => ($options["mode"]!="submit"),
|
||||
"attr" => ["autocomplete" => "new-password"],
|
||||
]
|
||||
);
|
||||
|
||||
if($options["mode"]!="profil") {
|
||||
$choices=[];
|
||||
$choices['Administrateur']='ROLE_ADMIN';
|
||||
$choices['Modérateur']='ROLE_MODO';
|
||||
$choices['Master']='ROLE_MASTER';
|
||||
$choices['Utilisateur']='ROLE_USER';
|
||||
|
||||
$builder->add('roles',
|
||||
ChoiceType::class, [
|
||||
'choices' => $choices,
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('groups',
|
||||
Select2EntityType::class, [
|
||||
"label" => "Groupes",
|
||||
"disabled" => false,
|
||||
"required" => false,
|
||||
"multiple" => true,
|
||||
"remote_route" => "app_group_select",
|
||||
"class" => "App:Group",
|
||||
"primary_key" => "id",
|
||||
"text_property" => "name",
|
||||
"minimum_input_length" => 0,
|
||||
"page_limit" => 100,
|
||||
"allow_clear" => true,
|
||||
"delay" => 250,
|
||||
"cache" => false,
|
||||
"cache_timeout" => 60000,
|
||||
"language" => "fr",
|
||||
"placeholder" => "Selectionner des Groupes",
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$builder->add('lastname',
|
||||
TextType::class, [
|
||||
"label" =>"Nom",
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('firstname',
|
||||
TextType::class, [
|
||||
"label" =>"Prénom",
|
||||
"required" => false,
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('email',
|
||||
EmailType::class, [
|
||||
"label" =>"Email",
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('password',
|
||||
RepeatedType::class, [
|
||||
"type" => PasswordType::class,
|
||||
"required" => ($options["mode"]=="submit"?true:false),
|
||||
"options" => array("always_empty" => true),
|
||||
"first_options" => array("label" => "Mot de Passe","attr" => array("class" => "form-control", "style" => "margin-bottom:15px", "autocomplete" => "new-password")),
|
||||
"second_options" => array('label' => 'Confirmer Mot de Passe',"attr" => array("class" => "form-control", "style" => "margin-bottom:15px"))
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'App\Entity\User',
|
||||
'mode' => 'string',
|
||||
'appAuth' => 'string',
|
||||
));
|
||||
}
|
||||
}
|
75
src/Form/WebzineType.php
Normal file
75
src/Form/WebzineType.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
namespace App\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use FOS\CKEditorBundle\Form\Type\CKEditorType;
|
||||
|
||||
|
||||
class WebzineType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('submit',
|
||||
SubmitType::class, [
|
||||
"label" => "Valider",
|
||||
"attr" => ["class" => "btn btn-success no-print"],
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('name',
|
||||
TextType::class, [
|
||||
"label" =>"Nom",
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('set',
|
||||
TextType::class, [
|
||||
"label" =>"Série",
|
||||
"required" => false,
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('order',
|
||||
IntegerType::class, [
|
||||
"label" =>"Ordre",
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('mode',
|
||||
ChoiceType::class, [
|
||||
"label" =>"Mode de visualisation des planches",
|
||||
"choices" => ["Planche par Planche"=>0],
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
$builder->add('description',
|
||||
CKEditorType::class, [
|
||||
"required" => false,
|
||||
"config" => [
|
||||
'uiColor' => '#ffffff',
|
||||
'height' => 600,
|
||||
'filebrowserUploadRoute' => 'app_ckeditor_upload',
|
||||
'language' => 'fr',
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('linkpages',HiddenType::class, array("mapped" => false));
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'App\Entity\Webzine',
|
||||
'mode' => 'string',
|
||||
));
|
||||
}
|
||||
}
|
54
src/Kernel.php
Normal file
54
src/Kernel.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
use Symfony\Component\Config\Resource\FileResource;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
|
||||
use Symfony\Component\Routing\RouteCollectionBuilder;
|
||||
|
||||
class Kernel extends BaseKernel
|
||||
{
|
||||
use MicroKernelTrait;
|
||||
|
||||
private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
|
||||
|
||||
public function registerBundles(): iterable
|
||||
{
|
||||
$contents = require $this->getProjectDir().'/config/bundles.php';
|
||||
foreach ($contents as $class => $envs) {
|
||||
if ($envs[$this->environment] ?? $envs['all'] ?? false) {
|
||||
yield new $class();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getProjectDir(): string
|
||||
{
|
||||
return \dirname(__DIR__);
|
||||
}
|
||||
|
||||
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
|
||||
{
|
||||
$container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
|
||||
$container->setParameter('container.dumper.inline_class_loader', \PHP_VERSION_ID < 70400 || $this->debug);
|
||||
$container->setParameter('container.dumper.inline_factories', true);
|
||||
$confDir = $this->getProjectDir().'/config';
|
||||
|
||||
$loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
|
||||
$loader->load($confDir.'/{packages}/'.$this->environment.'/*'.self::CONFIG_EXTS, 'glob');
|
||||
$loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
|
||||
$loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
|
||||
}
|
||||
|
||||
protected function configureRoutes(RouteCollectionBuilder $routes): void
|
||||
{
|
||||
$confDir = $this->getProjectDir().'/config';
|
||||
|
||||
$routes->import($confDir.'/{routes}/'.$this->environment.'/*'.self::CONFIG_EXTS, '/', 'glob');
|
||||
$routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
|
||||
$routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
|
||||
}
|
||||
}
|
15
src/Repository/CategoryRepository.php
Normal file
15
src/Repository/CategoryRepository.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Category;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
|
||||
class CategoryRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Category::class);
|
||||
}
|
||||
}
|
15
src/Repository/ConfigRepository.php
Normal file
15
src/Repository/ConfigRepository.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Config;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
|
||||
class ConfigRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Config::class);
|
||||
}
|
||||
}
|
35
src/Repository/CronRepository.php
Normal file
35
src/Repository/CronRepository.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Cron;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
|
||||
class CronRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Cron::class);
|
||||
}
|
||||
|
||||
public function toExec()
|
||||
{
|
||||
// Les commandes à executer
|
||||
// = statut = 0 (à executer)
|
||||
// = statut = 2 (OK) et derniere execution + interval > now et nombre d'appel = 0
|
||||
// = statut = 3 (KO) et derniere execution + interval > now et nombre d'appel = 0
|
||||
// = statut = 3 (KO) et nombre d'execution < nombre d'appel
|
||||
|
||||
|
||||
$now=new \DateTime();
|
||||
|
||||
$qb = $this->createQueryBuilder('cron')
|
||||
->Where('cron.statut=0')
|
||||
->orWhere('cron.statut=2 AND cron.nextexecdate<:now AND cron.repeatcall=0')
|
||||
->orWhere('cron.statut=3 AND cron.nextexecdate<:now AND cron.repeatcall=0')
|
||||
->orWhere('cron.statut=3 AND cron.nextexecdate<:now AND cron.repeatcall>cron.repeatexec');
|
||||
|
||||
return $qb->getQuery()->setParameter('now',$now->format("Y-m-d H:i:s"))->getResult();
|
||||
}
|
||||
}
|
15
src/Repository/GroupRepository.php
Normal file
15
src/Repository/GroupRepository.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Group;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
|
||||
class GroupRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Group::class);
|
||||
}
|
||||
}
|
15
src/Repository/IllustrationRepository.php
Normal file
15
src/Repository/IllustrationRepository.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Illustration;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
|
||||
class IllustrationRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Illustration::class);
|
||||
}
|
||||
}
|
15
src/Repository/LinkRepository.php
Normal file
15
src/Repository/LinkRepository.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Link;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
|
||||
class LinkRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Link::class);
|
||||
}
|
||||
}
|
15
src/Repository/ScriptRepository.php
Normal file
15
src/Repository/ScriptRepository.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Script;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
|
||||
class ScriptRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Script::class);
|
||||
}
|
||||
}
|
15
src/Repository/UserRepository.php
Normal file
15
src/Repository/UserRepository.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\User;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
|
||||
class UserRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, User::class);
|
||||
}
|
||||
}
|
16
src/Repository/WebzineRepository.php
Normal file
16
src/Repository/WebzineRepository.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Webzine;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
|
||||
class WebzineRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Webzine::class);
|
||||
}
|
||||
|
||||
}
|
15
src/Repository/WebzinepageRepository.php
Normal file
15
src/Repository/WebzinepageRepository.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Webzinepage;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
|
||||
class WebzinepageRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Webzinepage::class);
|
||||
}
|
||||
}
|
51
src/Service/mailService.php
Normal file
51
src/Service/mailService.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
class mailService
|
||||
{
|
||||
protected $mailer;
|
||||
protected $twig;
|
||||
|
||||
public function __construct(\Swift_Mailer $mailer, \Twig\Environment $twig)
|
||||
{
|
||||
$this->mailer = $mailer;
|
||||
$this->twig = $twig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send email
|
||||
*
|
||||
* @param string $template email template
|
||||
* @param mixed $parameters custom params for template
|
||||
* @param string $to to email address or array of email addresses
|
||||
* @param string $from from email address
|
||||
* @param string $fromName from name
|
||||
*
|
||||
* @return boolean send status
|
||||
*/
|
||||
public function sendEmail($subject, $body, $to, $from)
|
||||
{
|
||||
$template = $this->twig->load('Home/mail.html.twig');
|
||||
|
||||
$parameters=["subject"=>$subject,"body"=>$body];
|
||||
$subject = $template->renderBlock('subject', $parameters);
|
||||
$bodyHtml = $template->renderBlock('body', $parameters);
|
||||
|
||||
try {
|
||||
$message = (new \Swift_Message())
|
||||
->setFrom('send@example.com')
|
||||
->setSubject($subject)
|
||||
->setFrom($from)
|
||||
->setTo($to)
|
||||
->setBody($bodyHtml, 'text/html');
|
||||
|
||||
$response = $this->mailer->send($message);
|
||||
|
||||
} catch (\Exception $ex) {
|
||||
return $ex->getMessage();
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
27
src/Service/passwordEncoder.php
Normal file
27
src/Service/passwordEncoder.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace App\Service;
|
||||
|
||||
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
|
||||
|
||||
class passwordEncoder implements PasswordEncoderInterface
|
||||
{
|
||||
|
||||
public function encodePassword($raw, $salt)
|
||||
{
|
||||
$hash = "{SSHA}" . base64_encode(pack("H*", sha1($raw . $salt)) . $salt);
|
||||
return $hash;
|
||||
}
|
||||
|
||||
public function isPasswordValid($encoded, $raw, $salt)
|
||||
{
|
||||
return $encoded === $this->encodePassword($raw, $salt);
|
||||
}
|
||||
|
||||
public function needsRehash(string $encoded): bool
|
||||
{
|
||||
// check whether the current password is hash using an outdated encoder
|
||||
$hashIsOutdated = false;
|
||||
return $hashIsOutdated;
|
||||
}
|
||||
|
||||
}
|
60
src/Service/sessionInit.php
Normal file
60
src/Service/sessionInit.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace App\Service;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
|
||||
class sessionInit {
|
||||
private $container;
|
||||
protected $em;
|
||||
protected $session;
|
||||
|
||||
public function __construct(ContainerInterface $container, EntityManager $em,Session $session)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->session = $session;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function onDomainParse(RequestEvent $event) {
|
||||
$configs = $this->em->getRepository("App:Config")->findAll();
|
||||
$havehero=false;
|
||||
foreach($configs as $config) {
|
||||
if($config->getCategory()=="hero" && $config->getValue()!="") $havehero=true;
|
||||
$this->session->set($config->getId(), strval($config->getValue()));
|
||||
}
|
||||
|
||||
// Valeur par défaut appname
|
||||
if($this->session->get("appname")=="")
|
||||
$this->session->set("appname", $this->container->getParameter('appName'));
|
||||
|
||||
// Valeur par defaut hero
|
||||
if(!$havehero) $this->session->set("hero01", "hero.jpg");
|
||||
|
||||
// Valeur par defaut logo
|
||||
if($this->session->get("logodark")==""&&$this->session->get("logolight")=="") {
|
||||
$this->session->set("logodark", "logo.png");
|
||||
$this->session->set("logolight", "logo.png");
|
||||
}
|
||||
elseif($this->session->get("logodark")=="")
|
||||
$this->session->set("logodark", $this->session->get("logolight"));
|
||||
elseif($this->session->get("logolight")=="")
|
||||
$this->session->set("logolight", $this->session->get("logodark"));
|
||||
|
||||
// Valeur par défaut imgcontact
|
||||
if($this->session->get("imgcontact")=="")
|
||||
$this->session->set("imgcontact", "contact.jpg");
|
||||
|
||||
// Valeur par défaut imglink
|
||||
if($this->session->get("imglink")=="")
|
||||
$this->session->set("imglink", "link.jpg");
|
||||
|
||||
// Calcul des couleurs
|
||||
/*
|
||||
$color = $this->container->get('cadoles.core.service.color');
|
||||
$color->setColor();
|
||||
*/
|
||||
}
|
||||
}
|
194
src/Service/uploadListener.php
Normal file
194
src/Service/uploadListener.php
Normal file
@ -0,0 +1,194 @@
|
||||
<?php
|
||||
namespace App\Service;
|
||||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Oneup\UploaderBundle\Event\PostPersistEvent;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface as Container;
|
||||
|
||||
class uploadListener
|
||||
{
|
||||
private $em;
|
||||
private $session;
|
||||
private $token;
|
||||
private $container;
|
||||
|
||||
public function __construct(EntityManager $em, TokenStorageInterface $token_storage, Session $session, Container $container)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->session = $session;
|
||||
$this->token = $token_storage;
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
protected function getHeight($image) {
|
||||
$size = getimagesize($image);
|
||||
$height = $size[1];
|
||||
return $height;
|
||||
}
|
||||
|
||||
// Cacul de la largeur
|
||||
protected function getWidth($image) {
|
||||
$size = getimagesize($image);
|
||||
$width = $size[0];
|
||||
return $width;
|
||||
}
|
||||
|
||||
protected function resizeImage($image,$width,$height,$scale) {
|
||||
list($imagewidth, $imageheight, $imageType) = getimagesize($image);
|
||||
$imageType = image_type_to_mime_type($imageType);
|
||||
$newImageWidth = ceil($width * $scale);
|
||||
$newImageHeight = ceil($height * $scale);
|
||||
$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
|
||||
switch($imageType) {
|
||||
case "image/gif":
|
||||
$source=imagecreatefromgif($image);
|
||||
break;
|
||||
case "image/pjpeg":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
$source=imagecreatefromjpeg($image);
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/x-png":
|
||||
$source=imagecreatefrompng($image);
|
||||
break;
|
||||
}
|
||||
|
||||
$newImage = imagecreatetruecolor( $newImageWidth, $newImageHeight );
|
||||
imagealphablending( $newImage, false );
|
||||
imagesavealpha( $newImage, true );
|
||||
imagecopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$width,$height);
|
||||
|
||||
switch($imageType) {
|
||||
case "image/gif":
|
||||
imagegif($newImage,$image);
|
||||
break;
|
||||
case "image/pjpeg":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
imagejpeg($newImage,$image,90);
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/x-png":
|
||||
imagepng($newImage,$image);
|
||||
break;
|
||||
}
|
||||
|
||||
chmod($image, 0640);
|
||||
return $image;
|
||||
}
|
||||
|
||||
public function onUpload(PostPersistEvent $event)
|
||||
{
|
||||
$type=$event->getType();
|
||||
|
||||
switch($type) {
|
||||
case "avatar":
|
||||
$file=$event->getFile();
|
||||
$filename=$file->getFilename();
|
||||
$response = $event->getResponse();
|
||||
$response['file'] = $filename;
|
||||
break;
|
||||
|
||||
case "hero":
|
||||
$file=$event->getFile();
|
||||
$filename=$file->getFilename();
|
||||
$response = $event->getResponse();
|
||||
$response['file'] = $filename;
|
||||
break;
|
||||
|
||||
case "image":
|
||||
$file=$event->getFile();
|
||||
$filename=$file->getFilename();
|
||||
$response = $event->getResponse();
|
||||
$response['file'] = $filename;
|
||||
break;
|
||||
|
||||
case "logo":
|
||||
$file=$event->getFile();
|
||||
$filename=$file->getFilename();
|
||||
$response = $event->getResponse();
|
||||
$response['file'] = $filename;
|
||||
break;
|
||||
|
||||
case "illustration":
|
||||
$file=$event->getFile();
|
||||
$request=$event->getRequest();
|
||||
$originalname=$request->files->all()["file"]->getClientOriginalName();
|
||||
$originalname=substr($originalname, 0, stripos($originalname, '.'));
|
||||
|
||||
$filename=$file->getFilename();
|
||||
$width = $this->getWidth('uploads/illustration/'.$filename);
|
||||
$height = $this->getHeight('uploads/illustration/'.$filename);
|
||||
|
||||
$fs = new Filesystem();
|
||||
|
||||
// Création des miniatures proportionnelle
|
||||
$fs->copy('uploads/illustration/'.$filename,'uploads/illustration/thumbori_'.$filename);
|
||||
$max_width=500;
|
||||
$scale = $max_width/$width;
|
||||
$this->resizeImage('uploads/illustration/thumbori_'.$filename,$width,$height,$scale);
|
||||
|
||||
// Création des miniatures redimentionnable en carré
|
||||
$fs->copy('uploads/illustration/'.$filename,'uploads/illustration/thumb_'.$filename);
|
||||
$max_width=500;
|
||||
$scale = $max_width/$width;
|
||||
$this->resizeImage('uploads/illustration/thumb_'.$filename,$width,$height,$scale);
|
||||
|
||||
// Redimentionner si trop gros
|
||||
$max_width=1200;
|
||||
$scale = $max_width/$width;
|
||||
$this->resizeImage('uploads/illustration/'.$filename,$width,$height,$scale);
|
||||
|
||||
// Récupérer la dernière valeur de dimension
|
||||
$width = $this->getWidth('uploads/illustration/'.$filename);
|
||||
$height = $this->getHeight('uploads/illustration/'.$filename);
|
||||
|
||||
$response = $event->getResponse();
|
||||
$response['file'] = $filename;
|
||||
$response['width'] = $width;
|
||||
$response['height'] = $height;
|
||||
$response['originalname'] = $originalname;
|
||||
break;
|
||||
|
||||
case "webzine":
|
||||
$file=$event->getFile();
|
||||
$filename=$file->getFilename();
|
||||
$width = $this->getWidth('uploads/webzine/'.$filename);
|
||||
$height = $this->getHeight('uploads/webzine/'.$filename);
|
||||
|
||||
$fs = new Filesystem();
|
||||
|
||||
// Création des miniatures proportionnelle
|
||||
$fs->copy('uploads/webzine/'.$filename,'uploads/webzine/thumbori_'.$filename);
|
||||
$max_width=350;
|
||||
$scale = $max_width/$width;
|
||||
$this->resizeImage('uploads/webzine/thumbori_'.$filename,$width,$height,$scale);
|
||||
|
||||
// Création des miniatures en carré
|
||||
$fs->copy('uploads/webzine/'.$filename,'uploads/webzine/thumb_'.$filename);
|
||||
$max_width=350;
|
||||
$scale = $max_width/$width;
|
||||
$this->resizeImage('uploads/webzine/thumb_'.$filename,$width,$height,$scale);
|
||||
|
||||
// Redimentionner si trop gros
|
||||
$max_width=1200;
|
||||
$scale = $max_width/$width;
|
||||
$this->resizeImage('uploads/webzine/'.$filename,$width,$height,$scale);
|
||||
|
||||
// Récupérer la dernière valeur de dimension
|
||||
$width = $this->getWidth('uploads/webzine/'.$filename);
|
||||
$height = $this->getHeight('uploads/webzine/'.$filename);
|
||||
|
||||
$response = $event->getResponse();
|
||||
$response['file'] = $filename;
|
||||
$response['width'] = $width;
|
||||
$response['height'] = $height;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
14
src/Service/uploadSamename.php
Normal file
14
src/Service/uploadSamename.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Oneup\UploaderBundle\Uploader\File\FileInterface;
|
||||
use Oneup\UploaderBundle\Uploader\Naming\NamerInterface;
|
||||
|
||||
class uploadSamename implements NamerInterface
|
||||
{
|
||||
public function name(FileInterface $file)
|
||||
{
|
||||
return $file->getClientOriginalName();
|
||||
}
|
||||
}
|
30
src/Twig/AppExtension.php
Normal file
30
src/Twig/AppExtension.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
namespace App\Twig;
|
||||
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
class AppExtension extends AbstractExtension
|
||||
{
|
||||
protected $container;
|
||||
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
new TwigFilter('urlavatar', [$this, 'urlAvatar']),
|
||||
];
|
||||
}
|
||||
|
||||
public function urlAvatar($avatar)
|
||||
{
|
||||
if(stripos($avatar,"http")===0)
|
||||
return $avatar;
|
||||
else
|
||||
return "/".$this->container->getParameter("appAlias")."/uploads/avatar/".$avatar;
|
||||
}
|
||||
|
||||
public function setContainer($container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user