mirror of
https://forge.chapril.org/tykayn/caisse-bliss
synced 2025-06-20 01:44:42 +02:00
up to sf 7
This commit is contained in:
parent
a39b6239b0
commit
501795a8fa
16586 changed files with 19384005 additions and 0 deletions
648
v1/old/Controller/DefaultController.php
Executable file
648
v1/old/Controller/DefaultController.php
Executable file
|
@ -0,0 +1,648 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Controller;
|
||||
|
||||
use AppBundle\Entity\ExpenseKind;
|
||||
use AppBundle\Entity\Product;
|
||||
use AppBundle\Entity\ProductCategory;
|
||||
use AppBundle\Entity\ProductSold;
|
||||
use AppBundle\Entity\SellRecord;
|
||||
use AppBundle\Service\OwnerService;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
|
||||
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
||||
use Symfony\Component\Serializer\Encoder\XmlEncoder;
|
||||
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
||||
use Symfony\Component\Serializer\Serializer;
|
||||
|
||||
class DefaultController extends Controller {
|
||||
|
||||
private $ownerService;
|
||||
private $tokenManager;
|
||||
|
||||
public function __construct( CsrfTokenManagerInterface $tokenManager = null, OwnerService $ownerService ) {
|
||||
$this->tokenManager = $tokenManager;
|
||||
$this->ownerService = $ownerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/", name="homepage")
|
||||
*/
|
||||
public function indexAction( Request $request ) {
|
||||
$m = $this->getDoctrine()->getManager();
|
||||
$userRepo = $m->getRepository( 'AppBundle:User' );
|
||||
$allUsers = $userRepo->findAll();
|
||||
|
||||
// replace this example code with whatever you need
|
||||
return $this->render( 'default/index.html.twig',
|
||||
[
|
||||
'usersCount' => count( $allUsers ),
|
||||
'base_dir' => realpath( $this->getParameter( 'kernel.project_dir' ) ) . DIRECTORY_SEPARATOR,
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/dashboard", name="dashboard")
|
||||
*/
|
||||
public function dashboardAction( Request $request ) {
|
||||
$m = $this->getDoctrine()->getManager();
|
||||
$currentUser = $this->getUser();
|
||||
|
||||
// TODO on first login set default values
|
||||
$lastFestival = $currentUser->getActiveFestival();
|
||||
if ( ! $lastFestival ) {
|
||||
$lastFestival = $m->getRepository( 'AppBundle:Festival' )
|
||||
->findOneBy( [ 'user' => $this->getUser()->getId() ],
|
||||
[ 'id' => 'desc' ],
|
||||
0,
|
||||
1 );
|
||||
}
|
||||
if ( $lastFestival ) {
|
||||
$lastFestival->recalculateChiffreAffaire();
|
||||
}
|
||||
$categRepo = $m->getRepository( 'AppBundle:ProductCategory' );
|
||||
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
|
||||
$categories = $categRepo->findAll();
|
||||
$recentSells = $sellingRepo->findBy( [ 'user' => $currentUser->getId() ], [ 'id' => 'desc' ], 0, 5 );
|
||||
|
||||
return $this->render( 'logged/dashboard.html.twig',
|
||||
[
|
||||
'lastFestival' => $lastFestival,
|
||||
'categories' => $categories,
|
||||
'currentUser' => $currentUser,
|
||||
'recentSells' => $recentSells,
|
||||
'base_dir' => realpath( $this->getParameter( 'kernel.project_dir' ) ) . DIRECTORY_SEPARATOR,
|
||||
] );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* envoyer un email
|
||||
*/
|
||||
public function emailAction() {
|
||||
$name = "noble barbare";
|
||||
$message = \Swift_Message::newInstance()
|
||||
->setSubject( 'Hello Email' )
|
||||
->setFrom( 'test-symfony-tykayn@caisse.ciperbliss.com' )
|
||||
->setTo( 'tykayn@gmail.com' )
|
||||
->setBody( $this->renderView( 'default/test-email.html.twig' ),
|
||||
'text/html' );
|
||||
$this->get( 'mailer' )->send( $message );
|
||||
|
||||
//return 'yay test de mail';
|
||||
return $this->render(
|
||||
'default/test-email.html.twig',
|
||||
[
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* get user products
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function getMyProductsAction() {
|
||||
$m = $this->getDoctrine()->getManager();
|
||||
|
||||
|
||||
$currentUser = $this->getUser();
|
||||
if ( ! $currentUser ) {
|
||||
return new JsonResponse( [
|
||||
'categories' => [ [] ],
|
||||
'recentSells' => [ [ '' ] ],
|
||||
] );
|
||||
}
|
||||
|
||||
$ownerService = $this->ownerService;
|
||||
$ownerService->setupNewFestival( $currentUser );
|
||||
$activeFestival = $currentUser->getActiveFestival();
|
||||
|
||||
$categRepo = $m->getRepository( 'AppBundle:ProductCategory' );
|
||||
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
|
||||
|
||||
|
||||
$categories = $ownerService->serializeCategoriesOfUser( $currentUser );
|
||||
|
||||
|
||||
$recentSells = $sellingRepo->findBy( [ 'user' => $currentUser->getId() ], [ 'id' => 'desc' ], 0, 5 );
|
||||
|
||||
return new JsonResponse( [
|
||||
'categories' => $categories,
|
||||
'recentSells' => count( $recentSells ),
|
||||
'lastFestival' => $activeFestival->makeArray(),
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* get user expenses
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function getMyExpensesAction() {
|
||||
$m = $this->getDoctrine()->getManager();
|
||||
|
||||
|
||||
$currentUser = $this->getUser();
|
||||
if ( ! $currentUser ) {
|
||||
return new JsonResponse( [
|
||||
'expenses' => [ [] ],
|
||||
] );
|
||||
}
|
||||
|
||||
$ownerService = $this->ownerService;
|
||||
$ownerService->setupNewFestival( $currentUser );
|
||||
$expensesOfUser = $ownerService->serializeExpensesOfUser( $currentUser );
|
||||
|
||||
return new JsonResponse( [
|
||||
'expenses' => $expensesOfUser,
|
||||
'disponibility' => $currentUser->getDisponibility(),
|
||||
'averageMonthlyEarnings' => $currentUser->getAverageMonthlyEarnings(),
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* recieve the json containing the expanse config of a user
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse the list of expanses
|
||||
*/
|
||||
public function saveMyExpensesAction( Request $request ) {
|
||||
|
||||
$json = json_decode( $request->getContent(), true );
|
||||
$currentUser = $this->getUser();
|
||||
$m = $this->getDoctrine()->getManager();
|
||||
$myExpenses = $currentUser->getExpenses();
|
||||
$categoriesByID = [];
|
||||
|
||||
foreach ( $myExpenses as $expense ) {
|
||||
$categoriesByID[ $expense->getId() ] = $expense;
|
||||
}
|
||||
// loop on the json config for expanse
|
||||
// save the user configuration
|
||||
foreach ( $json[ 'expenses' ] as $expens ) {
|
||||
|
||||
if ( isset( $expens[ 'id' ] ) ) {
|
||||
$foundExpense = $categoriesByID[ $expens[ 'id' ] ];
|
||||
if ( $foundExpense ) {
|
||||
// update existing expenses of logged in user
|
||||
$foundExpense->setName( $expens[ 'name' ] );
|
||||
$foundExpense->setAmount( $expens[ 'amount' ] );
|
||||
$foundExpense->setDelay( $expens[ 'delay' ] );
|
||||
$foundExpense->setRepeatitions( $expens[ 'repeat' ] );
|
||||
$foundExpense->setEnabled( $expens[ 'enabled' ] );
|
||||
$m->persist( $foundExpense );
|
||||
}
|
||||
} else {
|
||||
// create new expense for user
|
||||
$newExpense = new ExpenseKind();
|
||||
$newExpense->setUser( $currentUser );
|
||||
$newExpense->setName( $expens[ 'name' ] );
|
||||
$newExpense->setDelay( $expens[ 'delay' ] );
|
||||
$newExpense->setAmount( $expens[ 'amount' ] );
|
||||
$newExpense->setRepeatitions( $expens[ 'repeat' ] );
|
||||
$newExpense->setEnabled( $expens[ 'enabled' ] );
|
||||
$m->persist( $newExpense );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$currentUser->setDisponibility( $json[ 'config' ][ 'disponibility' ] );
|
||||
$currentUser->setAverageMonthlyEarnings( $json[ 'config' ][ 'averageMonthlyEarnings' ] );
|
||||
|
||||
|
||||
$m->persist( $currentUser );
|
||||
$m->flush();
|
||||
|
||||
$ownerService = $this->ownerService;
|
||||
$expensesOfUser = $ownerService->serializeExpensesOfUser( $currentUser );
|
||||
|
||||
return new JsonResponse( [
|
||||
'expenses' => $expensesOfUser,
|
||||
'disponibility' => $currentUser->getDisponibility(),
|
||||
'averageMonthlyEarnings' => $currentUser->getAverageMonthlyEarnings(),
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* add a selling record corresponding to one client
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function addSellingAction( Request $request ) {
|
||||
|
||||
$json = json_decode( $request->getContent(), true );
|
||||
$currentUser = $this->getUser();
|
||||
$m = $this->getDoctrine()->getManager();
|
||||
$newSellRecord = new SellRecord();
|
||||
// sort user categories
|
||||
$myCategories = $currentUser->getCategories();
|
||||
$categoriesByID = [];
|
||||
foreach ( $myCategories as $my_category ) {
|
||||
$categoriesByID[ $my_category->getId() ] = $my_category;
|
||||
}
|
||||
|
||||
$productsModels = $m->getRepository( 'AppBundle:Product' )->findAll();
|
||||
$productsModelsByID = [];
|
||||
foreach ( $productsModels as $product ) {
|
||||
$productsModelsByID[ $product->getId() ] = $product;
|
||||
}
|
||||
|
||||
$sumAmount = 0;
|
||||
foreach ( $json[ 'activeSelling' ] as $record ) {
|
||||
$productModel = $productsModelsByID[ $record[ 'id' ] ];
|
||||
$newProductSold = new ProductSold();
|
||||
$newProductSold->setName( $record[ 'name' ] );
|
||||
$newProductSold->setImage( "image mock" );
|
||||
$newProductSold->setUser( $currentUser );
|
||||
$newProductSold->setPrice( $record[ 'price' ] );
|
||||
$newProductSold->setComment( $json[ 'sellingComment' ] );
|
||||
$newProductSold->setProduct( $productModel );
|
||||
$newProductSold->setSellRecords( $newSellRecord );
|
||||
// link selling record with user, festival
|
||||
$currentUser->addProductsSold( $newProductSold );
|
||||
// persist all
|
||||
$productModel->setStockCount( $productModel->getStockCount() - 1 );
|
||||
$m->persist( $productModel );
|
||||
$m->persist( $newProductSold );
|
||||
$m->persist( $newProductSold );
|
||||
$sumAmount += $record[ 'price' ];
|
||||
}
|
||||
|
||||
$festivalFound = $m->getRepository( 'AppBundle:Festival' )->find( $json[ 'activeFestival' ][ 'id' ] );
|
||||
$newSellRecord->setFestival( $festivalFound );
|
||||
$newSellRecord->setAmount( $sumAmount );
|
||||
$newSellRecord->setDate( new \DateTime() );
|
||||
$newSellRecord->setUser( $currentUser );
|
||||
$newSellRecord->setPaidByClient( $json[ 'paidByClient' ] );
|
||||
$newSellRecord->setComment( $json[ 'sellingComment' ] );
|
||||
|
||||
|
||||
$festivalFound->addSellRecord( $newSellRecord );
|
||||
$currentUser->addSellRecords( $newSellRecord );
|
||||
|
||||
$m->persist( $newSellRecord );
|
||||
$m->persist( $currentUser );
|
||||
$m->persist( $festivalFound );
|
||||
$m->flush();
|
||||
|
||||
$festivalFound->recalculateChiffreAffaire();
|
||||
$m->persist( $festivalFound );
|
||||
$m->flush();
|
||||
|
||||
// setup dates
|
||||
|
||||
// fetch back history of selling
|
||||
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
|
||||
$lastSellings = $sellingRepo->findBy( [ 'user' => $currentUser->getId() ], [ 'id' => 'desc' ], 0, 3 );
|
||||
|
||||
return new JsonResponse( [
|
||||
"message" => "ok",
|
||||
"activeFestival" => $festivalFound->makeArray(),
|
||||
"newChiffreAffaire" => $festivalFound->getChiffreAffaire(),
|
||||
"clientsCount" => count( $festivalFound->getSellRecords() ),
|
||||
"recent_sellings" => json_encode( $lastSellings ),
|
||||
"dump" => $json,
|
||||
], 200 );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get the history of user's sellings
|
||||
* @Route("/history", name="history")
|
||||
*/
|
||||
public function historyAction() {
|
||||
$currentUser = $this->getUser();
|
||||
$m = $this->getDoctrine()->getManager();
|
||||
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
|
||||
$allSellingList = $sellingRepo->findBy( [ 'user' => $currentUser->getId() ], [ 'id' => 'desc' ] );
|
||||
$mySellings = array_splice( $allSellingList, 0, 15 );
|
||||
$chiffreAffaires = 0;
|
||||
|
||||
$myFestivals = $currentUser->getFestivals();
|
||||
|
||||
$statisticsFestivals = [
|
||||
];
|
||||
|
||||
foreach ( $myFestivals as $festival ) {
|
||||
$statisticsFestivals[] = [
|
||||
'date' => $festival->getDateCreation(),
|
||||
'name' => $festival->getName(),
|
||||
'clients_count' => count( $festival->getSellRecords() ),
|
||||
'chiffreAffaire' => $festival->getChiffreAffaire(),
|
||||
];
|
||||
}
|
||||
$statisticsSoldProducts = [
|
||||
// ['name' => 'bidule', 'count' => 0, 'value' => 0],
|
||||
];
|
||||
|
||||
$statsForFestivalMock = [
|
||||
[ 'name' => 'festoche bidule', 'clients_count' => 125, 'chiffreAffaire' => 236, 'date' => new \DateTime() ],
|
||||
];
|
||||
foreach ( $allSellingList as $client ) {
|
||||
foreach ( $client->getProductsSold() as $product ) {
|
||||
$chiffreAffaires += $product->getPrice();
|
||||
}
|
||||
}
|
||||
foreach ( $mySellings as $client ) {
|
||||
foreach ( $client->getProductsSold() as $product ) {
|
||||
$chiffreAffaires += $product->getPrice();
|
||||
|
||||
if ( ! isset( $statisticsSoldProducts[ $product->getName() ] ) ) {
|
||||
$statisticsSoldProducts[ $product->getName() ] =
|
||||
[
|
||||
'name' => $product->getName(),
|
||||
'count' => 0,
|
||||
'value' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
$statisticsSoldProducts[ $product->getName() ][ 'count' ] ++;
|
||||
$statisticsSoldProducts[ $product->getName() ][ 'value' ] = $statisticsSoldProducts[ $product->getName() ][ 'value' ] + intval( $product->getPrice() );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render( 'logged/history.html.twig',
|
||||
[
|
||||
// 'statisticsFestivals' => $statsForFestivalMock, // mock of festival stats
|
||||
'statisticsFestivals' => $statisticsFestivals,
|
||||
'statisticsSoldProducts' => $statisticsSoldProducts,
|
||||
'chiffreAffaires' => $chiffreAffaires,
|
||||
'recentSells' => $mySellings,
|
||||
'allSellings' => count( $mySellings ),
|
||||
'base_dir' => realpath( $this->getParameter( 'kernel.project_dir' ) ) . DIRECTORY_SEPARATOR,
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* export user data in JSON
|
||||
* @return JsonResponse
|
||||
* @Route("/logged/export-all-json", name="export_all_json")
|
||||
*/
|
||||
public function exportJsonAction() {
|
||||
$currentUser = $this->getUser();
|
||||
$m = $this->getDoctrine()->getManager();
|
||||
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
|
||||
$encoders = [ new XmlEncoder(), new JsonEncoder() ];
|
||||
$normalizers = [ new ObjectNormalizer() ];
|
||||
|
||||
$serializer = new Serializer( $normalizers, $encoders );
|
||||
|
||||
$mySellings = $sellingRepo->findByUser( $currentUser->getId() );
|
||||
$export = [
|
||||
'export_version' => '1.0',
|
||||
'user' => $serializer->normalize( $currentUser,
|
||||
null,
|
||||
[ 'attributes' => [ 'id', 'username', 'email', 'salt', 'password' ] ] ),
|
||||
'products' => $serializer->normalize( $currentUser->getProducts(),
|
||||
null,
|
||||
[ 'attributes' => [ 'id', 'name', 'price' ] ] ),
|
||||
'categories' => $serializer->normalize( $currentUser->getCategories(),
|
||||
null,
|
||||
[ 'attributes' => [ 'id', 'name' ] ] ),
|
||||
'series_festivals' => $serializer->normalize( $currentUser->getSeriesFestivals(),
|
||||
null, ['attributes'=> [
|
||||
'id', 'name',
|
||||
]]),
|
||||
'festivals' => $serializer->normalize( $currentUser->getFestivals(),
|
||||
null,
|
||||
[ 'attributes' => [ 'id', 'name', 'chiffreAffaire','fraisInscription','fraisHebergement','fraisTransport','fraisRepas' ] ] ),
|
||||
'sellings' => $serializer->normalize( $mySellings,
|
||||
null,
|
||||
[ 'attributes' => [ 'id', 'amount', 'paidByClient', 'comment', 'gender' ] ] ),
|
||||
];
|
||||
|
||||
return new JsonResponse( $export );
|
||||
}
|
||||
|
||||
/**
|
||||
* export all clients
|
||||
* @Route("/export-all", name="export_all")
|
||||
*/
|
||||
public function exportAllAction() {
|
||||
// TODO
|
||||
$currentUser = $this->getUser();
|
||||
$m = $this->getDoctrine()->getManager();
|
||||
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
|
||||
$mySellings = $sellingRepo->findByUser( $currentUser->getId() );
|
||||
|
||||
$fileName = "export_caisse-cipherbliss_" . $currentUser->getUsername() . '_' . date( 'Y-m-d_H-i-s' );
|
||||
|
||||
$handle = fopen( 'php://memory', 'r+' );
|
||||
$firstLine = [
|
||||
'product sold id',
|
||||
'date',
|
||||
'hour',
|
||||
'min',
|
||||
'sec',
|
||||
'client comment',
|
||||
'client paid',
|
||||
'product name',
|
||||
'product image',
|
||||
'product category id',
|
||||
'product category name',
|
||||
'product price',
|
||||
'festival id',
|
||||
'festival name',
|
||||
'festival creation date',
|
||||
'caisse before',
|
||||
'caisse after',
|
||||
'festival ca',
|
||||
'festival comment',
|
||||
];
|
||||
// save the column headers
|
||||
fputcsv( $handle,
|
||||
$firstLine );
|
||||
|
||||
$chiffreAffaires = 0;
|
||||
foreach ( $mySellings as $sellRecord ) {
|
||||
foreach ( $sellRecord->getProductsSold() as $productSold ) {
|
||||
$chiffreAffaires += $productSold->getPrice();
|
||||
// add a line to the csv file
|
||||
fputcsv( $handle,
|
||||
[
|
||||
$productSold->getId(),
|
||||
$sellRecord->getDate()->format( 'c' ),
|
||||
$sellRecord->getDate()->format( 'H' ),
|
||||
$sellRecord->getDate()->format( 'i' ),
|
||||
$sellRecord->getDate()->format( 's' ),
|
||||
$sellRecord->getComment(),
|
||||
$sellRecord->getPaidByClient(),
|
||||
$productSold->getName(),
|
||||
$productSold->getImage(),
|
||||
$productSold->getProduct()->getCategory()->getId(),
|
||||
$productSold->getProduct()->getCategory()->getName(),
|
||||
$productSold->getPrice(),
|
||||
] );
|
||||
if ( $sellRecord->getFestival() ) {
|
||||
fputcsv( $handle,
|
||||
[
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
$sellRecord->getFestival()->getId(),
|
||||
$sellRecord->getFestival()->getName(),
|
||||
$sellRecord->getFestival()->getDateCreation()->format( 'c' ),
|
||||
$sellRecord->getFestival()->getFondDeCaisseAvant(),
|
||||
$sellRecord->getFestival()->getFondDeCaisseApres(),
|
||||
$sellRecord->getFestival()->getChiffreAffaire(),
|
||||
$sellRecord->getFestival()->getComment(),
|
||||
] );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
rewind( $handle );
|
||||
$content = stream_get_contents( $handle );
|
||||
fclose( $handle );
|
||||
|
||||
return new Response(
|
||||
$content, 200, [
|
||||
'Content-Type' => 'application/force-download',
|
||||
'Content-Disposition' => 'attachment; filename="' . $fileName . '.csv"',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Route("/set-active-festival/{id}", name="set_active_festival")
|
||||
*/
|
||||
public function setActiveFestivalAction( $id ) {
|
||||
$currentUser = $this->getUser();
|
||||
$m = $this->getDoctrine()->getManager();
|
||||
$repo = $m->getRepository( 'AppBundle:Festival' );
|
||||
|
||||
$currentUser->setActiveFestival( $repo->find( $id ) );
|
||||
$m->persist( $currentUser );
|
||||
$m->flush();
|
||||
|
||||
// replace this example code with whatever you need
|
||||
return $this->redirectToRoute( 'festival_index' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/import", name="import")
|
||||
*/
|
||||
public function importAction() {
|
||||
$currentUser = $this->getUser();
|
||||
$m = $this->getDoctrine()->getManager();
|
||||
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
|
||||
|
||||
return $this->render( 'logged/import.html.twig',
|
||||
[
|
||||
'base_dir' => '',
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/previsionnel", name="previsionnel")
|
||||
*/
|
||||
public function previsionnelAction() {
|
||||
// $currentUser = $this->getUser();
|
||||
// $m = $this->getDoctrine()->getManager();
|
||||
// $sellingRepo = $m->getRepository('AppBundle:SellRecord');
|
||||
|
||||
return $this->render( 'logged/previsionnel.html.twig',
|
||||
[
|
||||
'base_dir' => '',
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* import lots of products at once
|
||||
* @Route("/mass-create", name="mass_create")
|
||||
*/
|
||||
public function massCreateAction( Request $request ) {
|
||||
$currentUser = $this->getUser();
|
||||
$m = $this->getDoctrine()->getManager();
|
||||
|
||||
$myCategories = $currentUser->getCategories();
|
||||
$myCategoriesByName = [];
|
||||
$myProductsByName = [];
|
||||
$currentCategory = new ProductCategory();
|
||||
$currentCategory
|
||||
->addUser( $currentUser )
|
||||
->setName( 'default category' );
|
||||
|
||||
foreach ( $myCategories as $my_category ) {
|
||||
$myCategoriesByName [ $my_category->getName() ] = $my_category;
|
||||
foreach ( $my_category->getProducts() as $product ) {
|
||||
$myProductsByName[ $product->getName() ] = $product;
|
||||
}
|
||||
$currentCategory = $my_category;
|
||||
}
|
||||
$massLines = $request->request->get( 'produits' );
|
||||
if ( $request->getMethod() == 'POST' ) {
|
||||
$lines = preg_split( '/$\R?^/m', trim( $massLines ) );
|
||||
foreach ( $lines as $line ) {
|
||||
|
||||
if ( strpos( $line, ':' ) ) {
|
||||
// manage catgegories
|
||||
$boom = explode( ':', trim( $line ) );
|
||||
$firstPart = $boom[ 0 ];
|
||||
$value = $boom[ 1 ];
|
||||
if ( $firstPart === 'catégorie' && $value ) {
|
||||
// look for category by name
|
||||
if ( ! isset( $myCategoriesByName[ $value ] ) ) {
|
||||
$newCateg = new ProductCategory();
|
||||
$newCateg
|
||||
->addUser( $currentUser )
|
||||
->setName( $value );
|
||||
$currentUser->addCategory( $newCateg );
|
||||
$m->persist( $newCateg );
|
||||
$currentCategory = $newCateg; // associate further categories with the newly created one
|
||||
} else {
|
||||
// echo " la catégorie existe déjà";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// manage product
|
||||
$boom = explode( ';', $line );
|
||||
$productName = $boom[ 0 ];
|
||||
$price = 0;
|
||||
if ( $boom[ 1 ] ) {
|
||||
$price = intval( str_replace( '€', '', $boom[ 1 ] ) );// removing euro symbol
|
||||
}
|
||||
// or create new product
|
||||
if ( $productName && ! isset( $myProductsByName[ $productName ] ) ) {
|
||||
$newProduct = new Product();
|
||||
$newProduct->setCategory( $currentCategory )
|
||||
->setName( $productName )
|
||||
->setStockCount( 500 )
|
||||
->setUser( $currentUser )
|
||||
->setPrice( $price );
|
||||
$currentUser->addProduct( $newProduct );
|
||||
$m->persist( $newProduct );
|
||||
}// look for existing products
|
||||
else {
|
||||
$myProductsByName[ $productName ]->setPrice( $price );
|
||||
}
|
||||
}
|
||||
|
||||
$m->persist( $currentUser );
|
||||
}
|
||||
// check with existing categories and products, sort them by name.
|
||||
// save all
|
||||
$m->flush();
|
||||
}
|
||||
|
||||
return $this->render( 'logged/import.html.twig',
|
||||
[] );
|
||||
}
|
||||
|
||||
}
|
141
v1/old/Controller/FestivalController.php
Executable file
141
v1/old/Controller/FestivalController.php
Executable file
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Controller;
|
||||
|
||||
use AppBundle\Entity\Festival;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Festival controller.
|
||||
*
|
||||
* @Route("festival")
|
||||
*/
|
||||
class FestivalController extends Controller {
|
||||
/**
|
||||
* Lists all festival entities.
|
||||
*
|
||||
* @Route("/", name="festival_index")
|
||||
* @Method("GET")
|
||||
*/
|
||||
public function indexAction() {
|
||||
|
||||
$festivals = $this->getUser()->getFestivals();
|
||||
|
||||
return $this->render( 'festival/index.html.twig',
|
||||
[
|
||||
'festivals' => $festivals,
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new festival entity.
|
||||
*
|
||||
* @Route("/new", name="festival_new")
|
||||
* @Method({"GET", "POST"})
|
||||
*/
|
||||
public function newAction( Request $request ) {
|
||||
$festival = new Festival();
|
||||
$festival->setUser( $this->getUser() );
|
||||
$festival->setDateCreation( new \DateTime() );
|
||||
$form = $this->createForm( 'AppBundle\Form\FestivalType', $festival );
|
||||
$form->handleRequest( $request );
|
||||
|
||||
if ( $form->isSubmitted() && $form->isValid() ) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist( $festival );
|
||||
$em->persist( $this->getUser() );
|
||||
$em->flush();
|
||||
|
||||
return $this->redirectToRoute( 'festival_show', [ 'id' => $festival->getId() ] );
|
||||
}
|
||||
|
||||
return $this->render( 'festival/new.html.twig',
|
||||
[
|
||||
'festival' => $festival,
|
||||
'form' => $form->createView(),
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and displays a festival entity.
|
||||
*
|
||||
* @Route("/{id}", name="festival_show")
|
||||
* @Method("GET")
|
||||
*/
|
||||
public function showAction( Festival $festival ) {
|
||||
$deleteForm = $this->createDeleteForm( $festival );
|
||||
if ( $festival->getUser()->getId() !== $this->getUser()->getId() ) {
|
||||
$this->denyAccessUnlessGranted( 'ROLE_ADMIN' );
|
||||
}
|
||||
|
||||
return $this->render( 'festival/show.html.twig',
|
||||
[
|
||||
'festival' => $festival,
|
||||
'delete_form' => $deleteForm->createView(),
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a form to edit an existing festival entity.
|
||||
*
|
||||
* @Route("/{id}/edit", name="festival_edit")
|
||||
* @Method({"GET", "POST"})
|
||||
*/
|
||||
public function editAction( Request $request, Festival $festival ) {
|
||||
$deleteForm = $this->createDeleteForm( $festival );
|
||||
$editForm = $this->createForm( 'AppBundle\Form\FestivalType', $festival );
|
||||
$editForm->handleRequest( $request );
|
||||
|
||||
if ( $editForm->isSubmitted() && $editForm->isValid() ) {
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
|
||||
return $this->redirectToRoute( 'festival_edit', [ 'id' => $festival->getId() ] );
|
||||
}
|
||||
|
||||
return $this->render( 'festival/edit.html.twig',
|
||||
[
|
||||
'festival' => $festival,
|
||||
'edit_form' => $editForm->createView(),
|
||||
'delete_form' => $deleteForm->createView(),
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a festival entity.
|
||||
*
|
||||
* @Route("/{id}", name="festival_delete")
|
||||
* @Method("DELETE")
|
||||
*/
|
||||
public function deleteAction( Request $request, Festival $festival ) {
|
||||
if ( $festival->getUser()->getId() !== $this->getUser()->getId() ) {
|
||||
$this->denyAccessUnlessGranted( 'ROLE_ADMIN' );
|
||||
}
|
||||
$form = $this->createDeleteForm( $festival );
|
||||
$form->handleRequest( $request );
|
||||
|
||||
if ( $form->isSubmitted() && $form->isValid() ) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->remove( $festival );
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
return $this->redirectToRoute( 'festival_index' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a form to delete a festival entity.
|
||||
*
|
||||
* @param Festival $festival The festival entity
|
||||
*
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
private function createDeleteForm( Festival $festival ) {
|
||||
return $this->createFormBuilder()
|
||||
->setAction( $this->generateUrl( 'festival_delete', [ 'id' => $festival->getId() ] ) )
|
||||
->setMethod( 'DELETE' )
|
||||
->getForm();
|
||||
}
|
||||
}
|
38
v1/old/Controller/LegalController.php
Executable file
38
v1/old/Controller/LegalController.php
Executable file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Controller;
|
||||
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
|
||||
|
||||
class LegalController extends Controller {
|
||||
|
||||
private $tokenManager;
|
||||
|
||||
public function __construct( CsrfTokenManagerInterface $tokenManager = null ) {
|
||||
$this->tokenManager = $tokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/tos", name="tos")
|
||||
*/
|
||||
public function tosAction( Request $request ) {
|
||||
|
||||
return $this->render( 'legal/tos.html.twig',
|
||||
[] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/privacy", name="privacy")
|
||||
*/
|
||||
public function privacyAction( Request $request ) {
|
||||
|
||||
// replace this example code with whatever you need
|
||||
return $this->render( 'legal/privacy.html.twig',
|
||||
[] );
|
||||
}
|
||||
|
||||
|
||||
}
|
152
v1/old/Controller/ProductCategoryController.php
Executable file
152
v1/old/Controller/ProductCategoryController.php
Executable file
|
@ -0,0 +1,152 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Controller;
|
||||
|
||||
use AppBundle\Entity\ProductCategory;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Productcategory controller.
|
||||
*
|
||||
* @Route("productcategory")
|
||||
*/
|
||||
class ProductCategoryController extends Controller {
|
||||
/**
|
||||
* Lists all productCategory entities.
|
||||
*
|
||||
* @Route("/", name="productcategory_index")
|
||||
* @Method("GET")
|
||||
*/
|
||||
public function indexAction() {
|
||||
|
||||
$currentUser = $this->getUser();
|
||||
$productCategories = $currentUser->getCategories();
|
||||
|
||||
return $this->render( 'productcategory/index.html.twig',
|
||||
[
|
||||
'productCategories' => $productCategories,
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new productCategory entity.
|
||||
*
|
||||
* @Route("/new", name="productcategory_new")
|
||||
* @Method({"GET", "POST"})
|
||||
*/
|
||||
public function newAction( Request $request ) {
|
||||
$productCategory = new Productcategory();
|
||||
$currentUser = $this->getUser();
|
||||
$currentUser->addCategory( $productCategory );
|
||||
$productCategory->setUsers( [ $currentUser ] );
|
||||
$form = $this->createForm( 'AppBundle\Form\ProductCategoryType', $productCategory );
|
||||
$form->handleRequest( $request );
|
||||
|
||||
if ( $form->isSubmitted() && $form->isValid() ) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist( $productCategory );
|
||||
$em->persist( $currentUser );
|
||||
$em->flush();
|
||||
|
||||
return $this->redirectToRoute( 'productcategory_index' );
|
||||
}
|
||||
|
||||
return $this->render( 'productcategory/new.html.twig',
|
||||
[
|
||||
'productCategory' => $productCategory,
|
||||
'form' => $form->createView(),
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and displays a productCategory entity.
|
||||
*
|
||||
* @Route("/{id}", name="productcategory_show")
|
||||
* @Method("GET")
|
||||
*/
|
||||
public function showAction( ProductCategory $productCategory ) {
|
||||
if ( $productCategory->getUser()->getId() !== $this->getUser()->getId() ) {
|
||||
$this->denyAccessUnlessGranted( 'ROLE_ADMIN' );
|
||||
}
|
||||
$deleteForm = $this->createDeleteForm( $productCategory );
|
||||
|
||||
return $this->render( 'productcategory/show.html.twig',
|
||||
[
|
||||
'productCategory' => $productCategory,
|
||||
'delete_form' => $deleteForm->createView(),
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a form to edit an existing productCategory entity.
|
||||
*
|
||||
* @Route("/{id}/edit", name="productcategory_edit")
|
||||
* @Method({"GET", "POST"})
|
||||
*/
|
||||
public function editAction( Request $request, ProductCategory $productCategory ) {
|
||||
if ( ! $productCategory->hasUser( $this->getUser()->getId() ) ) {
|
||||
$this->denyAccessUnlessGranted( 'ROLE_ADMIN' );
|
||||
}
|
||||
|
||||
$deleteForm = $this->createDeleteForm( $productCategory );
|
||||
$currentUser = $this->getUser();
|
||||
$productCategory->setUsers( [ $currentUser ] );
|
||||
$editForm = $this->createForm( 'AppBundle\Form\ProductCategoryType', $productCategory );
|
||||
$editForm->handleRequest( $request );
|
||||
|
||||
if ( $editForm->isSubmitted() && $editForm->isValid() ) {
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
|
||||
return $this->redirectToRoute( 'productcategory_edit', [ 'id' => $productCategory->getId() ] );
|
||||
}
|
||||
|
||||
return $this->render( 'productcategory/edit.html.twig',
|
||||
[
|
||||
'productCategory' => $productCategory,
|
||||
'edit_form' => $editForm->createView(),
|
||||
'delete_form' => $deleteForm->createView(),
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a productCategory entity.
|
||||
*
|
||||
* @Route("/{id}", name="productcategory_delete")
|
||||
* @Method("DELETE")
|
||||
*/
|
||||
public function deleteAction( Request $request, ProductCategory $productCategory ) {
|
||||
if ( $productCategory->hasUser( $this->getUser()->getId() ) ) {
|
||||
$this->denyAccessUnlessGranted( 'ROLE_ADMIN' );
|
||||
}
|
||||
$form = $this->createDeleteForm( $productCategory );
|
||||
$form->handleRequest( $request );
|
||||
|
||||
if ( $form->isSubmitted() && $form->isValid() ) {
|
||||
if ( ! $productCategory->hasUser( $this->getUser()->getId() ) ) {
|
||||
$this->denyAccessUnlessGranted( 'ROLE_ADMIN' );
|
||||
}
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->remove( $productCategory );
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
return $this->redirectToRoute( 'productcategory_index' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a form to delete a productCategory entity.
|
||||
*
|
||||
* @param ProductCategory $productCategory The productCategory entity
|
||||
*
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
private function createDeleteForm( ProductCategory $productCategory ) {
|
||||
return $this->createFormBuilder()
|
||||
->setAction( $this->generateUrl( 'productcategory_delete', [ 'id' => $productCategory->getId() ] ) )
|
||||
->setMethod( 'DELETE' )
|
||||
->getForm();
|
||||
}
|
||||
}
|
159
v1/old/Controller/ProductController.php
Executable file
159
v1/old/Controller/ProductController.php
Executable file
|
@ -0,0 +1,159 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Controller;
|
||||
|
||||
use AppBundle\Entity\Product;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Product controller.
|
||||
*
|
||||
* @Route("product")
|
||||
*/
|
||||
class ProductController extends Controller {
|
||||
/**
|
||||
* Lists all product entities.
|
||||
*
|
||||
* @Route("/", name="product_index")
|
||||
* @Method("GET")
|
||||
*/
|
||||
public function indexAction() {
|
||||
|
||||
$products = $this->getUser()->getProducts();
|
||||
|
||||
return $this->render( 'product/index.html.twig',
|
||||
[
|
||||
'products' => $products,
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new product entity.
|
||||
*
|
||||
* @Route("/new", name="product_new")
|
||||
* @Method({"GET", "POST"})
|
||||
*/
|
||||
public function newAction( Request $request ) {
|
||||
$user = $this->getUser();
|
||||
$product = new Product();
|
||||
$product->setUser( $user );
|
||||
$product->setPrice( 1 );
|
||||
$product->setStockCount( 500 );
|
||||
$form = $this->createForm( 'AppBundle\Form\ProductType', $product );
|
||||
$form->handleRequest( $request );
|
||||
$user = $this->getUser();
|
||||
if ( $user && $user->getCategories() ) {
|
||||
$product->setCategory( $user->getCategories()[ 0 ] );
|
||||
}
|
||||
if ( $form->isSubmitted() && $form->isValid() ) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist( $product );
|
||||
$em->flush();
|
||||
|
||||
return $this->redirectToRoute( 'product_show', [ 'id' => $product->getId() ] );
|
||||
}
|
||||
|
||||
return $this->render( 'product/new.html.twig',
|
||||
[
|
||||
'product' => $product,
|
||||
'form' => $form->createView(),
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and displays a product entity.
|
||||
*
|
||||
* @Route("/{id}", name="product_show")
|
||||
* @Method("GET")
|
||||
*/
|
||||
public function showAction( Product $product ) {
|
||||
if ( $product->getUser()->getId() !== $this->getUser()->getId() ) {
|
||||
$this->denyAccessUnlessGranted( 'ROLE_ADMIN' );
|
||||
}
|
||||
$deleteForm = $this->createDeleteForm( $product );
|
||||
if ( $product->getUser()->getId() !== $this->getUser()->getId() ) {
|
||||
|
||||
$this->denyAccessUnlessGranted( 'ROLE_ADMIN' );
|
||||
}
|
||||
|
||||
return $this->render( 'product/show.html.twig',
|
||||
[
|
||||
'product' => $product,
|
||||
'delete_form' => $deleteForm->createView(),
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a form to edit an existing product entity.
|
||||
*
|
||||
* @Route("/{id}/edit", name="product_edit")
|
||||
* @Method({"GET", "POST"})
|
||||
*/
|
||||
public function editAction( Request $request, Product $product ) {
|
||||
|
||||
if ( $product->getUser()->getId() !== $this->getUser()->getId() ) {
|
||||
|
||||
$this->denyAccessUnlessGranted( 'ROLE_ADMIN' );
|
||||
}
|
||||
|
||||
$deleteForm = $this->createDeleteForm( $product );
|
||||
$editForm = $this->createForm( 'AppBundle\Form\ProductType', $product );
|
||||
$editForm->handleRequest( $request );
|
||||
|
||||
if ( $editForm->isSubmitted() && $editForm->isValid() ) {
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
|
||||
return $this->redirectToRoute( 'product_edit', [ 'id' => $product->getId() ] );
|
||||
}
|
||||
|
||||
return $this->render( 'product/edit.html.twig',
|
||||
[
|
||||
'product' => $product,
|
||||
'edit_form' => $editForm->createView(),
|
||||
'delete_form' => $deleteForm->createView(),
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a product entity.
|
||||
*
|
||||
* @Route("/{id}", name="product_delete")
|
||||
* @Method("DELETE")
|
||||
*/
|
||||
public function deleteAction( Request $request, Product $product ) {
|
||||
if ( $product->getUser()->getId() !== $this->getUser()->getId() ) {
|
||||
$this->denyAccessUnlessGranted( 'ROLE_ADMIN' );
|
||||
}
|
||||
$form = $this->createDeleteForm( $product );
|
||||
$form->handleRequest( $request );
|
||||
|
||||
if ( $form->isSubmitted() && $form->isValid() ) {
|
||||
if ( $product->getUser()->getId() !== $this->getUser()->getId() ) {
|
||||
|
||||
$this->denyAccessUnlessGranted( 'ROLE_ADMIN' );
|
||||
}
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->remove( $product );
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
return $this->redirectToRoute( 'product_index' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a form to delete a product entity.
|
||||
*
|
||||
* @param Product $product The product entity
|
||||
*
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
private function createDeleteForm( Product $product ) {
|
||||
return $this->createFormBuilder()
|
||||
->setAction( $this->generateUrl( 'product_delete', [ 'id' => $product->getId() ] ) )
|
||||
->setMethod( 'DELETE' )
|
||||
->getForm();
|
||||
}
|
||||
}
|
141
v1/old/Controller/SellRecordController.php
Executable file
141
v1/old/Controller/SellRecordController.php
Executable file
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Controller;
|
||||
|
||||
use AppBundle\Entity\SellRecord;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
|
||||
/**
|
||||
* Sellrecord controller.
|
||||
*
|
||||
* @Route("sellrecord")
|
||||
*/
|
||||
class SellRecordController extends Controller {
|
||||
/**
|
||||
* Lists all sellRecord entities.
|
||||
*
|
||||
* @Route("/", name="sellrecord_index")
|
||||
* @Method("GET")
|
||||
*/
|
||||
public function indexAction() {
|
||||
|
||||
$sellRecords = $this->getUser()->getProductsSold();
|
||||
|
||||
return $this->render( 'sellrecord/index.html.twig',
|
||||
[
|
||||
'sellRecords' => $sellRecords,
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new sellRecord entity.
|
||||
*
|
||||
* @Route("/new", name="sellrecord_new")
|
||||
* @Method({"GET", "POST"})
|
||||
*/
|
||||
public function newAction( Request $request ) {
|
||||
$sellRecord = new Sellrecord();
|
||||
$sellRecord->setUser( $this->getUser() );
|
||||
$form = $this->createForm( 'AppBundle\Form\SellRecordType', $sellRecord );
|
||||
$form->handleRequest( $request );
|
||||
|
||||
if ( $form->isSubmitted() && $form->isValid() ) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist( $sellRecord );
|
||||
$em->flush();
|
||||
|
||||
return $this->redirectToRoute( 'sellrecord_show', [ 'date' => $sellRecord->getDate() ] );
|
||||
}
|
||||
|
||||
return $this->render( 'sellrecord/new.html.twig',
|
||||
[
|
||||
'sellRecord' => $sellRecord,
|
||||
'form' => $form->createView(),
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and displays a sellRecord entity.
|
||||
*
|
||||
* @Route("/{date}", name="sellrecord_show")
|
||||
* @Method("GET")
|
||||
*/
|
||||
public function showAction( SellRecord $sellRecord ) {
|
||||
if ( $sellRecord->getUser()->getId() !== $this->getUser()->getId() ) {
|
||||
$this->denyAccessUnlessGranted( 'ROLE_ADMIN' );
|
||||
}
|
||||
$deleteForm = $this->createDeleteForm( $sellRecord );
|
||||
if ( ! $sellRecord->getUser() == $this->getUser()->getId() ) {
|
||||
$this->denyAccessUnlessGranted( 'ROLE_ADMIN' );
|
||||
}
|
||||
|
||||
return $this->render( 'sellrecord/show.html.twig',
|
||||
[
|
||||
'sellRecord' => $sellRecord,
|
||||
'delete_form' => $deleteForm->createView(),
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a form to edit an existing sellRecord entity.
|
||||
*
|
||||
* @Route("/{date}/edit", name="sellrecord_edit")
|
||||
* @Method({"GET", "POST"})
|
||||
*/
|
||||
public function editAction( Request $request, SellRecord $sellRecord ) {
|
||||
if ( ! $sellRecord->getUser() == $this->getUser()->getId() ) {
|
||||
$this->denyAccessUnlessGranted( 'ROLE_ADMIN' );
|
||||
}
|
||||
$deleteForm = $this->createDeleteForm( $sellRecord );
|
||||
$editForm = $this->createForm( 'AppBundle\Form\SellRecordType', $sellRecord );
|
||||
$editForm->handleRequest( $request );
|
||||
|
||||
if ( $editForm->isSubmitted() && $editForm->isValid() ) {
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
|
||||
return $this->redirectToRoute( 'sellrecord_edit', [ 'date' => $sellRecord->getDate() ] );
|
||||
}
|
||||
|
||||
return $this->render( 'sellrecord/edit.html.twig',
|
||||
[
|
||||
'sellRecord' => $sellRecord,
|
||||
'edit_form' => $editForm->createView(),
|
||||
'delete_form' => $deleteForm->createView(),
|
||||
] );
|
||||
}
|
||||
/**
|
||||
* Deletes a sellRecord entity.
|
||||
*
|
||||
* @Route("/delete/{id}", name="sellrecord_delete")
|
||||
*/
|
||||
public function deleteAction( Request $request, SellRecord $id) {
|
||||
$sellRecord = $id;
|
||||
if ( $sellRecord->getUser()->getId() !== $this->getUser()->getId() ) {
|
||||
$this->denyAccessUnlessGranted( 'ROLE_ADMIN' );
|
||||
}
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->remove( $sellRecord );
|
||||
$em->flush();
|
||||
|
||||
return $this->redirectToRoute( 'history' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a form to delete a sellRecord entity.
|
||||
*
|
||||
* @param SellRecord $sellRecord The sellRecord entity
|
||||
*
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
private function createDeleteForm( SellRecord $sellRecord ) {
|
||||
return $this->createFormBuilder()
|
||||
->setAction( $this->generateUrl( 'sellrecord_delete', [ 'date' => $sellRecord->getDate() ] ) )
|
||||
->setMethod( 'DELETE' )
|
||||
->getForm();
|
||||
}
|
||||
}
|
140
v1/old/Controller/SerieFestivalController.php
Executable file
140
v1/old/Controller/SerieFestivalController.php
Executable file
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Controller;
|
||||
|
||||
use AppBundle\Entity\SerieFestival;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Seriefestival controller.
|
||||
*
|
||||
* @Route("seriefestival")
|
||||
*/
|
||||
class SerieFestivalController extends Controller
|
||||
{
|
||||
/**
|
||||
* Lists all serieFestival entities.
|
||||
*
|
||||
* @Route("/", name="seriefestival_index")
|
||||
* @Method("GET")
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$serieFestivals = $em->getRepository('AppBundle:SerieFestival')->findAll();
|
||||
|
||||
return $this->render('seriefestival/index.html.twig', array(
|
||||
'serieFestivals' => $serieFestivals,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new serieFestival entity.
|
||||
*
|
||||
* @Route("/new", name="seriefestival_new")
|
||||
* @Method({"GET", "POST"})
|
||||
*/
|
||||
public function newAction(Request $request)
|
||||
{
|
||||
$usr= $this->getUser();
|
||||
|
||||
$serieFestival = new Seriefestival();
|
||||
$serieFestival->setUser($usr);
|
||||
|
||||
$form = $this->createForm('AppBundle\Form\SerieFestivalType', $serieFestival);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($serieFestival);
|
||||
$em->flush();
|
||||
|
||||
return $this->redirectToRoute('seriefestival_show', array('id' => $serieFestival->getId()));
|
||||
}
|
||||
|
||||
return $this->render('seriefestival/new.html.twig', array(
|
||||
'serieFestival' => $serieFestival,
|
||||
'form' => $form->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and displays a serieFestival entity.
|
||||
*
|
||||
* @Route("/{id}", name="seriefestival_show")
|
||||
* @Method("GET")
|
||||
*/
|
||||
public function showAction(SerieFestival $serieFestival)
|
||||
{
|
||||
$deleteForm = $this->createDeleteForm($serieFestival);
|
||||
|
||||
return $this->render('seriefestival/show.html.twig', array(
|
||||
'serieFestival' => $serieFestival,
|
||||
'delete_form' => $deleteForm->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a form to edit an existing serieFestival entity.
|
||||
*
|
||||
* @Route("/{id}/edit", name="seriefestival_edit")
|
||||
* @Method({"GET", "POST"})
|
||||
*/
|
||||
public function editAction(Request $request, SerieFestival $serieFestival)
|
||||
{
|
||||
$deleteForm = $this->createDeleteForm($serieFestival);
|
||||
$editForm = $this->createForm('AppBundle\Form\SerieFestivalType', $serieFestival);
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
|
||||
return $this->redirectToRoute('seriefestival_edit', array('id' => $serieFestival->getId()));
|
||||
}
|
||||
|
||||
return $this->render('seriefestival/edit.html.twig', array(
|
||||
'serieFestival' => $serieFestival,
|
||||
'edit_form' => $editForm->createView(),
|
||||
'delete_form' => $deleteForm->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a serieFestival entity.
|
||||
*
|
||||
* @Route("/{id}", name="seriefestival_delete")
|
||||
* @Method("DELETE")
|
||||
*/
|
||||
public function deleteAction(Request $request, SerieFestival $serieFestival)
|
||||
{
|
||||
$form = $this->createDeleteForm($serieFestival);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->remove($serieFestival);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('seriefestival_index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a form to delete a serieFestival entity.
|
||||
*
|
||||
* @param SerieFestival $serieFestival The serieFestival entity
|
||||
*
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
private function createDeleteForm(SerieFestival $serieFestival)
|
||||
{
|
||||
return $this->createFormBuilder()
|
||||
->setAction($this->generateUrl('seriefestival_delete', array('id' => $serieFestival->getId())))
|
||||
->setMethod('DELETE')
|
||||
->getForm()
|
||||
;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue