Compare commits
5 commits
master
...
AnsPractic
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d24bdfa22d | ||
|
|
94a27e13c4 | ||
|
|
9ea0224880 | ||
|
|
2db8d5cd06 | ||
|
|
42a3e34a98 |
31 changed files with 1215 additions and 142 deletions
|
|
@ -90,3 +90,7 @@ HUB_JO_KEY=hub_jo_count
|
||||||
# hub geofence
|
# hub geofence
|
||||||
HUB_GEOFENCE_ENABLE=set_to_true_or_false
|
HUB_GEOFENCE_ENABLE=set_to_true_or_false
|
||||||
HUB_FILTER_ENABLE=set_to_true_or_false
|
HUB_FILTER_ENABLE=set_to_true_or_false
|
||||||
|
|
||||||
|
###> symfony/mailer ###
|
||||||
|
# MAILER_DSN=null://null
|
||||||
|
###< symfony/mailer ###
|
||||||
|
|
|
||||||
12
compose.override.yaml
Normal file
12
compose.override.yaml
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
services:
|
||||||
|
###> symfony/mailer ###
|
||||||
|
mailer:
|
||||||
|
image: axllent/mailpit
|
||||||
|
ports:
|
||||||
|
- "1025"
|
||||||
|
- "8025"
|
||||||
|
environment:
|
||||||
|
MP_SMTP_AUTH_ACCEPT_ANY: 1
|
||||||
|
MP_SMTP_AUTH_ALLOW_INSECURE: 1
|
||||||
|
###< symfony/mailer ###
|
||||||
|
|
@ -28,6 +28,7 @@
|
||||||
"ext-iconv": "*",
|
"ext-iconv": "*",
|
||||||
"composer/package-versions-deprecated": "1.11.99.4",
|
"composer/package-versions-deprecated": "1.11.99.4",
|
||||||
"data-dog/audit-bundle": "^0.1.10",
|
"data-dog/audit-bundle": "^0.1.10",
|
||||||
|
"doctrine/annotations": "^1.13",
|
||||||
"doctrine/common": "^2",
|
"doctrine/common": "^2",
|
||||||
"doctrine/doctrine-bundle": "^2",
|
"doctrine/doctrine-bundle": "^2",
|
||||||
"doctrine/doctrine-migrations-bundle": "^2",
|
"doctrine/doctrine-migrations-bundle": "^2",
|
||||||
|
|
|
||||||
19
composer.lock
generated
19
composer.lock
generated
|
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "653f8558c75614dd65421cb3eb48c29b",
|
"content-hash": "da765755121aaeb5c5a43aa74d7eeb76",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "composer/package-versions-deprecated",
|
"name": "composer/package-versions-deprecated",
|
||||||
|
|
@ -4400,22 +4400,25 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/flex",
|
"name": "symfony/flex",
|
||||||
"version": "v1.17.3",
|
"version": "v1.21.8",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/symfony/flex.git",
|
"url": "https://github.com/symfony/flex.git",
|
||||||
"reference": "acd0b5018fe9c2f5be6c67367987b5c723c0e096"
|
"reference": "bda5f869ac51c8e985a6fe9f964c4cb78228a369"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/symfony/flex/zipball/acd0b5018fe9c2f5be6c67367987b5c723c0e096",
|
"url": "https://api.github.com/repos/symfony/flex/zipball/bda5f869ac51c8e985a6fe9f964c4cb78228a369",
|
||||||
"reference": "acd0b5018fe9c2f5be6c67367987b5c723c0e096",
|
"reference": "bda5f869ac51c8e985a6fe9f964c4cb78228a369",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"composer-plugin-api": "^1.0|^2.0",
|
"composer-plugin-api": "^1.0|^2.0",
|
||||||
"php": ">=7.1"
|
"php": ">=7.1"
|
||||||
},
|
},
|
||||||
|
"conflict": {
|
||||||
|
"composer/semver": "<1.7.2"
|
||||||
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"composer/composer": "^1.0.2|^2.0",
|
"composer/composer": "^1.0.2|^2.0",
|
||||||
"symfony/dotenv": "^4.4|^5.0|^6.0",
|
"symfony/dotenv": "^4.4|^5.0|^6.0",
|
||||||
|
|
@ -4445,7 +4448,7 @@
|
||||||
"description": "Composer plugin for Symfony",
|
"description": "Composer plugin for Symfony",
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/symfony/flex/issues",
|
"issues": "https://github.com/symfony/flex/issues",
|
||||||
"source": "https://github.com/symfony/flex/tree/v1.17.3"
|
"source": "https://github.com/symfony/flex/tree/v1.21.8"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
|
@ -4461,7 +4464,7 @@
|
||||||
"type": "tidelift"
|
"type": "tidelift"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2021-11-22T18:48:50+00:00"
|
"time": "2024-10-07T08:51:39+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/framework-bundle",
|
"name": "symfony/framework-bundle",
|
||||||
|
|
@ -7969,5 +7972,5 @@
|
||||||
"ext-iconv": "*"
|
"ext-iconv": "*"
|
||||||
},
|
},
|
||||||
"platform-dev": [],
|
"platform-dev": [],
|
||||||
"plugin-api-version": "2.3.0"
|
"plugin-api-version": "2.6.0"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -672,6 +672,30 @@ catalyst_auth:
|
||||||
acls:
|
acls:
|
||||||
- id: item_pricing.update
|
- id: item_pricing.update
|
||||||
label: Update
|
label: Update
|
||||||
|
|
||||||
|
- id: entity_list
|
||||||
|
label: EntityTypes
|
||||||
|
acls:
|
||||||
|
- id: entity.menu
|
||||||
|
label: Menu
|
||||||
|
- id: entity.add
|
||||||
|
label: Add
|
||||||
|
- id: entity.update
|
||||||
|
label: Update
|
||||||
|
- id: entity.delete
|
||||||
|
label: Delete
|
||||||
|
- id: entity.list
|
||||||
|
label: List
|
||||||
|
|
||||||
|
- id: leaflet
|
||||||
|
label: Leaflet
|
||||||
|
acls:
|
||||||
|
- id: leaflet.menu
|
||||||
|
label: Menu
|
||||||
|
- id: leaflet.update
|
||||||
|
label: Update
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
api:
|
api:
|
||||||
user_entity: "App\\Entity\\ApiUser"
|
user_entity: "App\\Entity\\ApiUser"
|
||||||
|
|
|
||||||
|
|
@ -306,3 +306,12 @@ catalyst_menu:
|
||||||
acl: item_pricing.update
|
acl: item_pricing.update
|
||||||
label: Item Pricing
|
label: Item Pricing
|
||||||
parent: item
|
parent: item
|
||||||
|
|
||||||
|
- id: entity_list
|
||||||
|
acl: entity.menu
|
||||||
|
label: EntityTypes
|
||||||
|
|
||||||
|
- id: leaflet
|
||||||
|
acl: leaflet.menu
|
||||||
|
label: Leaflet
|
||||||
|
|
||||||
|
|
|
||||||
3
config/packages/mailer.yaml
Normal file
3
config/packages/mailer.yaml
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
framework:
|
||||||
|
mailer:
|
||||||
|
dsn: '%env(MAILER_DSN)%'
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
#index:
|
|
||||||
# path: /
|
|
||||||
# controller: App\Controller\DefaultController::index
|
|
||||||
#
|
|
||||||
#
|
|
||||||
4
config/routes/leaflet.yaml
Normal file
4
config/routes/leaflet.yaml
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
leaflet:
|
||||||
|
path: /leaflet
|
||||||
|
controller: App\Controller\LeafletController::index
|
||||||
|
methods: [GET]
|
||||||
34
config/routes/test.yaml
Normal file
34
config/routes/test.yaml
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
entity_list:
|
||||||
|
path: /test
|
||||||
|
controller: App\Controller\EntityController::index
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
entity_rows:
|
||||||
|
path: /test/rowdata
|
||||||
|
controller: App\Controller\EntityController::datatableRows
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
entity_add_form:
|
||||||
|
path: /test/newform
|
||||||
|
controller: App\Controller\EntityController::addForm
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
entity_add_submit:
|
||||||
|
path: /test
|
||||||
|
controller: App\Controller\EntityController::addSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
entity_update_form:
|
||||||
|
path: /test/{id}
|
||||||
|
controller: App\Controller\EntityController::updateForm
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
entity_update_submit:
|
||||||
|
path: /test/{id}
|
||||||
|
controller: App\Controller\EntityController::updateSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
entity_delete:
|
||||||
|
path: /test/{id}
|
||||||
|
controller: App\Controller\EntityController::deleteSubmit
|
||||||
|
methods: [DELETE]
|
||||||
|
|
@ -33,6 +33,8 @@ services:
|
||||||
resource: '../src/*'
|
resource: '../src/*'
|
||||||
exclude: '../src/{Entity,Migrations,Tests,Menu,Access}'
|
exclude: '../src/{Entity,Migrations,Tests,Menu,Access}'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# controllers are imported separately to make sure services can be injected
|
# controllers are imported separately to make sure services can be injected
|
||||||
# as action arguments even if you don't extend any base controller class
|
# as action arguments even if you don't extend any base controller class
|
||||||
App\Controller\:
|
App\Controller\:
|
||||||
|
|
@ -169,6 +171,13 @@ services:
|
||||||
#App\Service\GISManagerInterface: "@App\\Service\\GISManager\\Bing"
|
#App\Service\GISManagerInterface: "@App\\Service\\GISManager\\Bing"
|
||||||
App\Service\GISManagerInterface: "@App\\Service\\GISManager\\OpenStreet"
|
App\Service\GISManagerInterface: "@App\\Service\\GISManager\\OpenStreet"
|
||||||
#App\Service\GISManagerInterface: "@App\\Service\\GISManager\\Google"
|
#App\Service\GISManagerInterface: "@App\\Service\\GISManager\\Google"
|
||||||
|
|
||||||
|
App\EventListener\ProductAddedListener:
|
||||||
|
arguments:
|
||||||
|
$mailer: '@mailer' # Autowire the mailer service
|
||||||
|
$entityManager: '@doctrine.orm.entity_manager' # Autowire the EntityManager
|
||||||
|
tags:
|
||||||
|
- { name: 'kernel.event_listener', event: 'App\Event\ProductAdded', method: 'onProductAdded' }
|
||||||
|
|
||||||
App\EventListener\JobOrderActiveCacheListener:
|
App\EventListener\JobOrderActiveCacheListener:
|
||||||
arguments:
|
arguments:
|
||||||
|
|
|
||||||
0
description
Normal file
0
description
Normal file
0
id
Normal file
0
id
Normal file
0
item
Normal file
0
item
Normal file
0
price
Normal file
0
price
Normal file
272
src/Controller/EntityController.php
Normal file
272
src/Controller/EntityController.php
Normal file
|
|
@ -0,0 +1,272 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Entity;
|
||||||
|
use App\Event\ProductAdded;
|
||||||
|
use Doctrine\ORM\Query;
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
|
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
||||||
|
|
||||||
|
|
||||||
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||||
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
|
||||||
|
|
||||||
|
use Catalyst\MenuBundle\Annotation\Menu;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class EntityController extends Controller{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Menu(selected="entity_list")
|
||||||
|
* @IsGranted("entity.list")
|
||||||
|
*/
|
||||||
|
public function index ()
|
||||||
|
{
|
||||||
|
return $this->render('entity/list.html.twig');
|
||||||
|
}
|
||||||
|
|
||||||
|
private $eventDispatcher;
|
||||||
|
|
||||||
|
public function __construct(EventDispatcherInterface $eventDispatcher)
|
||||||
|
{
|
||||||
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Menu(selected="entity_list")
|
||||||
|
* @IsGranted("entity.add")
|
||||||
|
*/
|
||||||
|
public function addForm()
|
||||||
|
{
|
||||||
|
$entity = new Entity();
|
||||||
|
$params = [
|
||||||
|
'obj' => $entity,
|
||||||
|
'mode' => 'create',
|
||||||
|
];
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('entity/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @IsGranted("entity.add")
|
||||||
|
*/
|
||||||
|
public function addSubmit(Request $req, EntityManagerInterface $em, ValidatorInterface $validator)
|
||||||
|
{
|
||||||
|
$test = new Entity();
|
||||||
|
|
||||||
|
$this->setObject($test, $req);
|
||||||
|
|
||||||
|
// validate
|
||||||
|
$errors = $validator->validate($test);
|
||||||
|
|
||||||
|
// initialize error list
|
||||||
|
$error_array = [];
|
||||||
|
|
||||||
|
// add errors to list
|
||||||
|
foreach ($errors as $error) {
|
||||||
|
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if any errors were found
|
||||||
|
if (!empty($error_array)) {
|
||||||
|
// return validation failure response
|
||||||
|
return $this->json([
|
||||||
|
'success' => false,
|
||||||
|
'errors' => $error_array
|
||||||
|
], 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
// validated! save the entity
|
||||||
|
$em->persist($test);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
$this->eventDispatcher->dispatch(new ProductAdded($test));
|
||||||
|
|
||||||
|
// return successful response
|
||||||
|
return $this->json([
|
||||||
|
'success' => 'Changes have been saved!'
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Menu(selected="entity_list")
|
||||||
|
* @IsGranted("entity.update")
|
||||||
|
*/
|
||||||
|
public function updateForm($id, EntityManagerInterface $em, Entity $e)
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$params['obj'] = $e;
|
||||||
|
$params['mode'] = 'update';
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('entity/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @IsGranted("entity.update")
|
||||||
|
*/
|
||||||
|
public function updateSubmit(Request $req, EntityManagerInterface $em, ValidatorInterface $validator, Entity $e)
|
||||||
|
{
|
||||||
|
$this->setObject($e, $req);
|
||||||
|
|
||||||
|
// validate
|
||||||
|
$errors = $validator->validate($e);
|
||||||
|
|
||||||
|
// initialize error list
|
||||||
|
$error_array = [];
|
||||||
|
|
||||||
|
// add errors to list
|
||||||
|
foreach ($errors as $error) {
|
||||||
|
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if any errors were found
|
||||||
|
if (!empty($error_array)) {
|
||||||
|
// return validation failure response
|
||||||
|
return $this->json([
|
||||||
|
'success' => false,
|
||||||
|
'errors' => $error_array
|
||||||
|
], 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
// validated! save the entity
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
$this->eventDispatcher->dispatch(new ProductAdded($e));
|
||||||
|
|
||||||
|
// return successful response
|
||||||
|
return $this->json([
|
||||||
|
'success' => 'Changes have been saved!'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @IsGranted("entity.delete")
|
||||||
|
*/
|
||||||
|
public function deleteSubmit(EntityManagerInterface $em, Entity $entity)
|
||||||
|
{
|
||||||
|
// delete this object
|
||||||
|
$em->remove($entity);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
// response
|
||||||
|
$response = new Response();
|
||||||
|
$response->setStatusCode(Response::HTTP_OK);
|
||||||
|
$response->send();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setObject(Entity $obj, Request $req)
|
||||||
|
{
|
||||||
|
// set and save values
|
||||||
|
$obj->setItem($req->request->get('item'))
|
||||||
|
->setPrice($req->request->get('price'))
|
||||||
|
->setDescription($req->request->get('description'));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setQueryFilters($datatable, QueryBuilder $query)
|
||||||
|
{
|
||||||
|
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
|
||||||
|
$query->where('q.item LIKE :filter')
|
||||||
|
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @IsGranted("entity.list")
|
||||||
|
*/
|
||||||
|
public function datatableRows(Request $req)
|
||||||
|
{
|
||||||
|
// get query builder
|
||||||
|
$qb = $this->getDoctrine()
|
||||||
|
->getRepository(Entity::class)
|
||||||
|
->createQueryBuilder('q');
|
||||||
|
|
||||||
|
// get datatable params
|
||||||
|
$datatable = $req->request->get('datatable');
|
||||||
|
|
||||||
|
// count total records
|
||||||
|
$tquery = $qb->select('COUNT(q)');
|
||||||
|
$this->setQueryFilters($datatable, $tquery);
|
||||||
|
$total = $tquery->getQuery()
|
||||||
|
->getSingleScalarResult();
|
||||||
|
|
||||||
|
// get current page number
|
||||||
|
$page = $datatable['pagination']['page'] ?? 1;
|
||||||
|
|
||||||
|
$perpage = $datatable['pagination']['perpage'];
|
||||||
|
$offset = ($page - 1) * $perpage;
|
||||||
|
|
||||||
|
// add metadata
|
||||||
|
$meta = [
|
||||||
|
'page' => $page,
|
||||||
|
'perpage' => $perpage,
|
||||||
|
'pages' => ceil($total / $perpage),
|
||||||
|
'total' => $total,
|
||||||
|
'sort' => 'asc',
|
||||||
|
'field' => 'id'
|
||||||
|
];
|
||||||
|
|
||||||
|
// build query
|
||||||
|
$query = $qb->select('q');
|
||||||
|
$this->setQueryFilters($datatable, $query);
|
||||||
|
|
||||||
|
// check if sorting is present, otherwise use default
|
||||||
|
if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) {
|
||||||
|
$order = $datatable['sort']['sort'] ?? 'asc';
|
||||||
|
$query->orderBy('q.' . $datatable['sort']['field'], $order);
|
||||||
|
} else {
|
||||||
|
$query->orderBy('q.id', 'asc');
|
||||||
|
}
|
||||||
|
|
||||||
|
// get rows for this page
|
||||||
|
$obj_rows = $query->setFirstResult($offset)
|
||||||
|
->setMaxResults($perpage)
|
||||||
|
->getQuery()
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
// process rows
|
||||||
|
$rows = [];
|
||||||
|
foreach ($obj_rows as $orow) {
|
||||||
|
// add row data
|
||||||
|
$row['id'] = $orow->getID();
|
||||||
|
$row['item'] = $orow->getItem();
|
||||||
|
$row['price'] = $orow->getPrice();
|
||||||
|
$row['description'] = $orow->getDescription();
|
||||||
|
|
||||||
|
|
||||||
|
// add row metadata
|
||||||
|
$row['meta'] = [
|
||||||
|
'update_url' => '',
|
||||||
|
'delete_url' => ''
|
||||||
|
];
|
||||||
|
|
||||||
|
// add crud urls
|
||||||
|
if ($this->isGranted('entity.update'))
|
||||||
|
$row['meta']['update_url'] = $this->generateUrl('entity_update_form', ['id' => $row['id']]);
|
||||||
|
if ($this->isGranted('entity.delete'))
|
||||||
|
$row['meta']['delete_url'] = $this->generateUrl('entity_delete', ['id' => $row['id']]);
|
||||||
|
|
||||||
|
$rows[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->json([
|
||||||
|
'meta' => $meta,
|
||||||
|
'data' => $rows
|
||||||
|
]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
27
src/Controller/LeafletController.php
Normal file
27
src/Controller/LeafletController.php
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// src/Controller/LeafletController.php
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
|
||||||
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||||
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
|
||||||
|
|
||||||
|
use Catalyst\MenuBundle\Annotation\Menu;
|
||||||
|
|
||||||
|
class LeafletController extends AbstractController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Menu(selected="leaflet")
|
||||||
|
* @IsGranted("leaflet.menu")
|
||||||
|
*/
|
||||||
|
public function index(): Response
|
||||||
|
{
|
||||||
|
return $this->render('leaflet/index.html.twig', [
|
||||||
|
'message' => 'Hello from LeafletController!',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
75
src/Entity/Entity.php
Normal file
75
src/Entity/Entity.php
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Repository\TestRepository;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Entity(repositoryClass=TestRepository::class)
|
||||||
|
*/
|
||||||
|
class Entity
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @ORM\Id
|
||||||
|
* @ORM\GeneratedValue
|
||||||
|
* @ORM\Column(type="integer")
|
||||||
|
*/
|
||||||
|
private $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=255)
|
||||||
|
*/
|
||||||
|
private $item;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="decimal", precision=8, scale=2)
|
||||||
|
*/
|
||||||
|
private $price;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="text")
|
||||||
|
*/
|
||||||
|
private $description;
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getItem(): ?string
|
||||||
|
{
|
||||||
|
return $this->item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setItem(string $item): self
|
||||||
|
{
|
||||||
|
$this->item = $item;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPrice(): ?string
|
||||||
|
{
|
||||||
|
return $this->price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPrice(string $price): self
|
||||||
|
{
|
||||||
|
$this->price = $price;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescription(): ?string
|
||||||
|
{
|
||||||
|
return $this->description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDescription(string $description): self
|
||||||
|
{
|
||||||
|
$this->description = $description;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
21
src/Event/ProductAdded.php
Normal file
21
src/Event/ProductAdded.php
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
// src/Event/ProductAdded.php
|
||||||
|
namespace App\Event;
|
||||||
|
use Symfony\Contracts\EventDispatcher\Event;
|
||||||
|
|
||||||
|
use App\Entity\Entity;
|
||||||
|
|
||||||
|
class ProductAdded
|
||||||
|
{
|
||||||
|
private $product;
|
||||||
|
|
||||||
|
public function __construct(Entity $product)
|
||||||
|
{
|
||||||
|
$this->product = $product;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getProduct(): Entity
|
||||||
|
{
|
||||||
|
return $this->product;
|
||||||
|
}
|
||||||
|
}
|
||||||
48
src/EventListener/ProductAddedListener.php
Normal file
48
src/EventListener/ProductAddedListener.php
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\EventListener;
|
||||||
|
|
||||||
|
use App\Event\ProductAdded;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Component\Mailer\MailerInterface;
|
||||||
|
use Symfony\Component\Mime\Email;
|
||||||
|
|
||||||
|
class ProductAddedListener
|
||||||
|
{
|
||||||
|
private $mailer;
|
||||||
|
private $entityManager;
|
||||||
|
|
||||||
|
public function __construct(MailerInterface $mailer, EntityManagerInterface $entityManager)
|
||||||
|
{
|
||||||
|
$this->mailer = $mailer;
|
||||||
|
$this->entityManager = $entityManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onProductAdded(ProductAdded $event)
|
||||||
|
{
|
||||||
|
// Get all products in the database
|
||||||
|
$items = $this->entityManager->getRepository('App:Entity')->findAll();
|
||||||
|
|
||||||
|
// Convert to JSON format
|
||||||
|
$itemData = [];
|
||||||
|
foreach ($items as $item) {
|
||||||
|
$itemData[] = [
|
||||||
|
'id' => $item->getId(),
|
||||||
|
'item' => $item->getItem(),
|
||||||
|
'price' => $item->getPrice(),
|
||||||
|
'description' => $item->getDescription(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$jsonItems = json_encode($itemData, JSON_PRETTY_PRINT);
|
||||||
|
|
||||||
|
// Send an email with the JSON data
|
||||||
|
$email = (new Email())
|
||||||
|
->from('ansleytheking@gmail.coml')
|
||||||
|
->to('ansley.sze@foodgroup.ph')
|
||||||
|
->subject('New Product Added - Item List in JSON')
|
||||||
|
->text('A new product has been added. Here is the complete list of items in JSON format.')
|
||||||
|
->attach($jsonItems, 'items.json', 'application/json');
|
||||||
|
|
||||||
|
$this->mailer->send($email);
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/Migrations/Version20241017062927.php
Normal file
39
src/Migrations/Version20241017062927.php
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20241017062927 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription() : string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema) : void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||||
|
|
||||||
|
$this->addSql('CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, placeholder VARCHAR(120) NOT NULL, password LONGTEXT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
|
||||||
|
$this->addSql('ALTER TABLE battery CHANGE date_update date_update timestamp default current_timestamp on update current_timestamp');
|
||||||
|
$this->addSql('ALTER TABLE sap_battery CHANGE date_update date_update timestamp default current_timestamp on update current_timestamp');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema) : void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||||
|
|
||||||
|
$this->addSql('DROP TABLE test');
|
||||||
|
$this->addSql('ALTER TABLE battery CHANGE date_update date_update DATETIME DEFAULT CURRENT_TIMESTAMP');
|
||||||
|
$this->addSql('ALTER TABLE sap_battery CHANGE date_update date_update DATETIME DEFAULT CURRENT_TIMESTAMP');
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/Migrations/Version20241018002028.php
Normal file
39
src/Migrations/Version20241018002028.php
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20241018002028 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription() : string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema) : void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||||
|
|
||||||
|
$this->addSql('ALTER TABLE battery CHANGE date_update date_update timestamp default current_timestamp on update current_timestamp');
|
||||||
|
$this->addSql('ALTER TABLE sap_battery CHANGE date_update date_update timestamp default current_timestamp on update current_timestamp');
|
||||||
|
$this->addSql('ALTER TABLE test ADD item VARCHAR(255) NOT NULL, ADD price NUMERIC(10, 2) NOT NULL, DROP placeholder, CHANGE password description LONGTEXT NOT NULL');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema) : void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||||
|
|
||||||
|
$this->addSql('ALTER TABLE battery CHANGE date_update date_update DATETIME DEFAULT CURRENT_TIMESTAMP');
|
||||||
|
$this->addSql('ALTER TABLE sap_battery CHANGE date_update date_update DATETIME DEFAULT CURRENT_TIMESTAMP');
|
||||||
|
$this->addSql('ALTER TABLE test ADD placeholder VARCHAR(120) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, DROP item, DROP price, CHANGE description password LONGTEXT CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`');
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/Migrations/Version20241018012501.php
Normal file
39
src/Migrations/Version20241018012501.php
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20241018012501 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription() : string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema) : void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||||
|
|
||||||
|
$this->addSql('CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, item VARCHAR(255) NOT NULL, price NUMERIC(8, 2) NOT NULL, description LONGTEXT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
|
||||||
|
$this->addSql('ALTER TABLE battery CHANGE date_update date_update timestamp default current_timestamp on update current_timestamp');
|
||||||
|
$this->addSql('ALTER TABLE sap_battery CHANGE date_update date_update timestamp default current_timestamp on update current_timestamp');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema) : void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||||
|
|
||||||
|
$this->addSql('DROP TABLE test');
|
||||||
|
$this->addSql('ALTER TABLE battery CHANGE date_update date_update DATETIME DEFAULT CURRENT_TIMESTAMP');
|
||||||
|
$this->addSql('ALTER TABLE sap_battery CHANGE date_update date_update DATETIME DEFAULT CURRENT_TIMESTAMP');
|
||||||
|
}
|
||||||
|
}
|
||||||
37
src/Migrations/Version20241023070137.php
Normal file
37
src/Migrations/Version20241023070137.php
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20241023070137 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription() : string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema) : void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||||
|
|
||||||
|
$this->addSql('ALTER TABLE battery CHANGE date_update date_update timestamp default current_timestamp on update current_timestamp');
|
||||||
|
$this->addSql('ALTER TABLE sap_battery CHANGE date_update date_update timestamp default current_timestamp on update current_timestamp');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema) : void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||||
|
|
||||||
|
$this->addSql('ALTER TABLE battery CHANGE date_update date_update DATETIME DEFAULT CURRENT_TIMESTAMP');
|
||||||
|
$this->addSql('ALTER TABLE sap_battery CHANGE date_update date_update DATETIME DEFAULT CURRENT_TIMESTAMP');
|
||||||
|
}
|
||||||
|
}
|
||||||
50
src/Repository/NotifsRepository.php
Normal file
50
src/Repository/NotifsRepository.php
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\Notifs;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method Notifs|null find($id, $lockMode = null, $lockVersion = null)
|
||||||
|
* @method Notifs|null findOneBy(array $criteria, array $orderBy = null)
|
||||||
|
* @method Notifs[] findAll()
|
||||||
|
* @method Notifs[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||||
|
*/
|
||||||
|
class NotifsRepository extends ServiceEntityRepository
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, Notifs::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * @return Notifs[] Returns an array of Notifs objects
|
||||||
|
// */
|
||||||
|
/*
|
||||||
|
public function findByExampleField($value)
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('n')
|
||||||
|
->andWhere('n.exampleField = :val')
|
||||||
|
->setParameter('val', $value)
|
||||||
|
->orderBy('n.id', 'ASC')
|
||||||
|
->setMaxResults(10)
|
||||||
|
->getQuery()
|
||||||
|
->getResult()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
public function findOneBySomeField($value): ?Notifs
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('n')
|
||||||
|
->andWhere('n.exampleField = :val')
|
||||||
|
->setParameter('val', $value)
|
||||||
|
->getQuery()
|
||||||
|
->getOneOrNullResult()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
50
src/Repository/TestRepository.php
Normal file
50
src/Repository/TestRepository.php
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\Entity;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method Test|null find($id, $lockMode = null, $lockVersion = null)
|
||||||
|
* @method Test|null findOneBy(array $criteria, array $orderBy = null)
|
||||||
|
* @method Test[] findAll()
|
||||||
|
* @method Test[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||||
|
*/
|
||||||
|
class TestRepository extends ServiceEntityRepository
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, Entity::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * @return Test[] Returns an array of Test objects
|
||||||
|
// */
|
||||||
|
/*
|
||||||
|
public function findByExampleField($value)
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('t')
|
||||||
|
->andWhere('t.exampleField = :val')
|
||||||
|
->setParameter('val', $value)
|
||||||
|
->orderBy('t.id', 'ASC')
|
||||||
|
->setMaxResults(10)
|
||||||
|
->getQuery()
|
||||||
|
->getResult()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
public function findOneBySomeField($value): ?Test
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('t')
|
||||||
|
->andWhere('t.exampleField = :val')
|
||||||
|
->setParameter('val', $value)
|
||||||
|
->getQuery()
|
||||||
|
->getOneOrNullResult()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
12
symfony.lock
12
symfony.lock
|
|
@ -242,6 +242,18 @@
|
||||||
"symfony/inflector": {
|
"symfony/inflector": {
|
||||||
"version": "v4.0.2"
|
"version": "v4.0.2"
|
||||||
},
|
},
|
||||||
|
"symfony/mailer": {
|
||||||
|
"version": "4.4",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "4.3",
|
||||||
|
"ref": "df66ee1f226c46f01e85c29c2f7acce0596ba35a"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"config/packages/mailer.yaml"
|
||||||
|
]
|
||||||
|
},
|
||||||
"symfony/maker-bundle": {
|
"symfony/maker-bundle": {
|
||||||
"version": "1.0",
|
"version": "1.0",
|
||||||
"recipe": {
|
"recipe": {
|
||||||
|
|
|
||||||
151
templates/entity/form.html.twig
Normal file
151
templates/entity/form.html.twig
Normal file
|
|
@ -0,0 +1,151 @@
|
||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<!-- BEGIN: Subheader -->
|
||||||
|
<div class="m-subheader">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<div class="mr-auto">
|
||||||
|
<h3 class="m-subheader__title">Product list</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- END: Subheader -->
|
||||||
|
<div class="m-content">
|
||||||
|
<!--Begin::Section-->
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xl-6">
|
||||||
|
<div class="m-portlet m-portlet--mobile">
|
||||||
|
<div class="m-portlet__head">
|
||||||
|
<div class="m-portlet__head-caption">
|
||||||
|
<div class="m-portlet__head-title">
|
||||||
|
<span class="m-portlet__head-icon">
|
||||||
|
<i class="la la-industry"></i>
|
||||||
|
</span>
|
||||||
|
<h3 class="m-portlet__head-text">
|
||||||
|
{% if mode == 'update' %}
|
||||||
|
Edit Product Type
|
||||||
|
<small>{{ obj.getItem() }}</small>
|
||||||
|
{% else %}
|
||||||
|
New Product Type
|
||||||
|
{% endif %}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<form id="row-form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ mode == 'update' ? url('entity_update_submit', {'id': obj.getId()}) : url('entity_add_submit') }}">
|
||||||
|
<div class="m-portlet__body">
|
||||||
|
<div class="form-group m-form__group row no-border">
|
||||||
|
<label class="col-lg-3 col-form-label" data-field="item">
|
||||||
|
Item:
|
||||||
|
</label>
|
||||||
|
<div class="col-lg-9">
|
||||||
|
<input type="text" name="item" class="form-control m-input" value="{{ obj.getItem() }}">
|
||||||
|
<div class="form-control-feedback hide" data-field="item"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group m-form__group row no-border">
|
||||||
|
<label class="col-lg-3 col-form-label" data-field="price">
|
||||||
|
Price:
|
||||||
|
</label>
|
||||||
|
<div class="col-lg-9">
|
||||||
|
<input type="number" step="0.01" name="price" class="form-control m-input" value="{{ obj.getPrice() }}">
|
||||||
|
<div class="form-control-feedback hide" data-field="price"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group m-form__group row no-border">
|
||||||
|
<label class="col-lg-3 col-form-label" data-field="description">
|
||||||
|
Description:
|
||||||
|
</label>
|
||||||
|
<div class="col-lg-9">
|
||||||
|
<textarea name="description" class="form-control m-input">{{ obj.getDescription() }}</textarea>
|
||||||
|
<div class="form-control-feedback hide" data-field="description"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="m-portlet__foot m-portlet__foot--fit">
|
||||||
|
<div class="m-form__actions m-form__actions--solid m-form__actions--right">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12">
|
||||||
|
<button type="submit" class="btn btn-success">Submit</button>
|
||||||
|
<a href="{{ url('entity_list') }}" class="btn btn-secondary">Back</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
$("#row-form").submit(function(e) {
|
||||||
|
var form = $(this);
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: "POST",
|
||||||
|
url: form.prop('action'),
|
||||||
|
data: form.serialize()
|
||||||
|
}).done(function(response) {
|
||||||
|
// remove all error classes
|
||||||
|
removeErrors();
|
||||||
|
swal({
|
||||||
|
title: 'Done!',
|
||||||
|
text: 'Your changes have been saved!',
|
||||||
|
type: 'success',
|
||||||
|
onClose: function() {
|
||||||
|
window.location.href = "{{ url('entity_list') }}";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).fail(function(response) {
|
||||||
|
if (response.status == 422) {
|
||||||
|
var errors = response.responseJSON.errors;
|
||||||
|
var firstfield = false;
|
||||||
|
|
||||||
|
// remove all error classes first
|
||||||
|
removeErrors();
|
||||||
|
|
||||||
|
// display errors contextually
|
||||||
|
$.each(errors, function(field, msg) {
|
||||||
|
var formfield = $("[name='" + field + "']");
|
||||||
|
var label = $("label[data-field='" + field + "']");
|
||||||
|
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||||
|
|
||||||
|
// add error classes to bad fields
|
||||||
|
formfield.addClass('form-control-danger');
|
||||||
|
label.addClass('has-danger');
|
||||||
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
|
|
||||||
|
// check if this field comes first in DOM
|
||||||
|
var domfield = formfield.get(0);
|
||||||
|
|
||||||
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
|
firstfield = domfield;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// focus on first bad field
|
||||||
|
firstfield.focus();
|
||||||
|
|
||||||
|
// scroll to above that field to make it visible
|
||||||
|
$('html, body').animate({
|
||||||
|
scrollTop: $(firstfield).offset().top - 200
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// remove all error classes
|
||||||
|
function removeErrors() {
|
||||||
|
$(".form-control-danger").removeClass('form-control-danger');
|
||||||
|
$("[data-field]").removeClass('has-danger');
|
||||||
|
$(".form-control-feedback[data-field]").addClass('hide');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
154
templates/entity/list.html.twig
Normal file
154
templates/entity/list.html.twig
Normal file
|
|
@ -0,0 +1,154 @@
|
||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<!-- BEGIN: Subheader -->
|
||||||
|
<div class="m-subheader">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<div class="mr-auto">
|
||||||
|
<h3 class="m-subheader__title">
|
||||||
|
Items
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- END: Subheader -->
|
||||||
|
<div class="m-content">
|
||||||
|
<!--Begin::Section-->
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xl-12">
|
||||||
|
<div class="m-portlet m-portlet--mobile">
|
||||||
|
<div class="m-portlet__body">
|
||||||
|
<div class="m-form m-form--label-align-right m--margin-top-20 m--margin-bottom-30">
|
||||||
|
<div class="row align-items-center">
|
||||||
|
<div class="col-xl-8 order-2 order-xl-1">
|
||||||
|
<div class="form-group m-form__group row align-items-center">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="m-input-icon m-input-icon--left">
|
||||||
|
<input type="text" class="form-control m-input m-input--solid" placeholder="Search..." id="data-rows-search">
|
||||||
|
<span class="m-input-icon__icon m-input-icon__icon--left">
|
||||||
|
<span><i class="la la-search"></i></span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-xl-4 order-1 order-xl-2 m--align-right">
|
||||||
|
<a href="{{ url('entity_add_form') }}" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
|
||||||
|
<span>
|
||||||
|
<i class="la la-industry"></i>
|
||||||
|
<span>New Item</span>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
<div class="m-separator m-separator--dashed d-xl-none"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!--begin: Datatable -->
|
||||||
|
<div id="data-rows"></div>
|
||||||
|
<!--end: Datatable -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
var options = {
|
||||||
|
data: {
|
||||||
|
type: 'remote',
|
||||||
|
source: {
|
||||||
|
read: {
|
||||||
|
url: '{{ url("entity_rows") }}',
|
||||||
|
method: 'POST'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
saveState: {
|
||||||
|
cookie: false,
|
||||||
|
webstorage: false
|
||||||
|
},
|
||||||
|
pageSize: 10,
|
||||||
|
serverPaging: true,
|
||||||
|
serverFiltering: true,
|
||||||
|
serverSorting: true
|
||||||
|
},
|
||||||
|
layout: {
|
||||||
|
scroll: true
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
field: 'id',
|
||||||
|
title: 'ID',
|
||||||
|
width: 30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'item',
|
||||||
|
title: 'Name'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'price',
|
||||||
|
title: 'Price'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'description',
|
||||||
|
title: 'Description'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'Actions',
|
||||||
|
width: 110,
|
||||||
|
title: 'Actions',
|
||||||
|
sortable: false,
|
||||||
|
overflow: 'visible',
|
||||||
|
template: function (row, index, datatable) {
|
||||||
|
var actions = '';
|
||||||
|
|
||||||
|
if (row.meta.update_url != '') {
|
||||||
|
actions += '<a href="' + row.meta.update_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" data-id="' + row.name + '" title="Edit"><i class="la la-edit"></i></a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (row.meta.delete_url != '') {
|
||||||
|
actions += '<a href="' + row.meta.delete_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill btn-delete" data-id="' + row.name + '" title="Delete"><i class="la la-trash"></i></a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return actions;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
search: {
|
||||||
|
onEnter: false,
|
||||||
|
input: $('#data-rows-search'),
|
||||||
|
delay: 400
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var table = $("#data-rows").mDatatable(options);
|
||||||
|
|
||||||
|
$(document).on('click', '.btn-delete', function(e) {
|
||||||
|
var url = $(this).prop('href');
|
||||||
|
var id = $(this).data('id');
|
||||||
|
var btn = $(this);
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
swal({
|
||||||
|
title: 'Confirmation',
|
||||||
|
html: 'Are you sure you want to delete <strong>' + id + '</strong>?',
|
||||||
|
type: 'warning',
|
||||||
|
showCancelButton: true
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.value) {
|
||||||
|
$.ajax({
|
||||||
|
method: "DELETE",
|
||||||
|
url: url
|
||||||
|
}).done(function(response) {
|
||||||
|
table.row(btn.parents('tr')).remove();
|
||||||
|
table.reload();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|
@ -10,133 +10,5 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- END: Subheader -->
|
<!-- END: Subheader -->
|
||||||
<div class="m-content">
|
|
||||||
<!--Begin::Section-->
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-xl-6">
|
|
||||||
<div class="m-portlet m-portlet--mobile">
|
|
||||||
<div class="m-portlet__head">
|
|
||||||
<div class="m-portlet__head-caption">
|
|
||||||
<div class="m-portlet__head-title">
|
|
||||||
<span class="m-portlet__head-icon">
|
|
||||||
<i class="la la-industry"></i>
|
|
||||||
</span>
|
|
||||||
<h3 class="m-portlet__head-text">
|
|
||||||
{% if mode == 'update' %}
|
|
||||||
Edit Item Type
|
|
||||||
<small>{{ obj.getName() }}</small>
|
|
||||||
{% else %}
|
|
||||||
New Item Type
|
|
||||||
{% endif %}
|
|
||||||
</h3>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<form id="row-form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ mode == 'update' ? url('item_type_update_submit', {'id': obj.getId()}) : url('item_type_add_submit') }}">
|
|
||||||
<div class="m-portlet__body">
|
|
||||||
<div class="form-group m-form__group row no-border">
|
|
||||||
<label class="col-lg-3 col-form-label" data-field="name">
|
|
||||||
Name:
|
|
||||||
</label>
|
|
||||||
<div class="col-lg-9">
|
|
||||||
<input type="text" name="name" class="form-control m-input" value="{{ obj.getName() }}">
|
|
||||||
<div class="form-control-feedback hide" data-field="name"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group m-form__group row no-border">
|
|
||||||
<label class="col-lg-3 col-form-label" data-field="code">
|
|
||||||
Code:
|
|
||||||
</label>
|
|
||||||
<div class="col-lg-9">
|
|
||||||
<input type="text" name="code" class="form-control m-input" value="{{ obj.getCode() }}">
|
|
||||||
<div class="form-control-feedback hide" data-field="code"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="m-portlet__foot m-portlet__foot--fit">
|
|
||||||
<div class="m-form__actions m-form__actions--solid m-form__actions--right">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-12">
|
|
||||||
<button type="submit" class="btn btn-success">Submit</button>
|
|
||||||
<a href="{{ url('item_type_list') }}" class="btn btn-secondary">Back</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block scripts %}
|
|
||||||
<script>
|
|
||||||
$(function() {
|
|
||||||
$("#row-form").submit(function(e) {
|
|
||||||
var form = $(this);
|
|
||||||
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
method: "POST",
|
|
||||||
url: form.prop('action'),
|
|
||||||
data: form.serialize()
|
|
||||||
}).done(function(response) {
|
|
||||||
// remove all error classes
|
|
||||||
removeErrors();
|
|
||||||
swal({
|
|
||||||
title: 'Done!',
|
|
||||||
text: 'Your changes have been saved!',
|
|
||||||
type: 'success',
|
|
||||||
onClose: function() {
|
|
||||||
window.location.href = "{{ url('item_type_list') }}";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}).fail(function(response) {
|
|
||||||
if (response.status == 422) {
|
|
||||||
var errors = response.responseJSON.errors;
|
|
||||||
var firstfield = false;
|
|
||||||
|
|
||||||
// remove all error classes first
|
|
||||||
removeErrors();
|
|
||||||
|
|
||||||
// display errors contextually
|
|
||||||
$.each(errors, function(field, msg) {
|
|
||||||
var formfield = $("[name='" + field + "']");
|
|
||||||
var label = $("label[data-field='" + field + "']");
|
|
||||||
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
|
||||||
|
|
||||||
// add error classes to bad fields
|
|
||||||
formfield.addClass('form-control-danger');
|
|
||||||
label.addClass('has-danger');
|
|
||||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
|
||||||
|
|
||||||
// check if this field comes first in DOM
|
|
||||||
var domfield = formfield.get(0);
|
|
||||||
|
|
||||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
|
||||||
firstfield = domfield;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// focus on first bad field
|
|
||||||
firstfield.focus();
|
|
||||||
|
|
||||||
// scroll to above that field to make it visible
|
|
||||||
$('html, body').animate({
|
|
||||||
scrollTop: $(firstfield).offset().top - 200
|
|
||||||
}, 100);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// remove all error classes
|
|
||||||
function removeErrors() {
|
|
||||||
$(".form-control-danger").removeClass('form-control-danger');
|
|
||||||
$("[data-field]").removeClass('has-danger');
|
|
||||||
$(".form-control-feedback[data-field]").addClass('hide');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
89
templates/leaflet/index.html.twig
Normal file
89
templates/leaflet/index.html.twig
Normal file
|
|
@ -0,0 +1,89 @@
|
||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Leaflet Map with Layers{% endblock %}
|
||||||
|
|
||||||
|
{% block stylesheets %}
|
||||||
|
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.3/dist/leaflet.css" />
|
||||||
|
<style>
|
||||||
|
#map {
|
||||||
|
height: 500px; /* You can adjust the height here */
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<h2>Leaflet Map</h2>
|
||||||
|
|
||||||
|
<div id="map" class="w-full h-96 mb-4"></div>
|
||||||
|
<div id="coordinates" class="text-gray-600 text-sm mt-4"></div>
|
||||||
|
|
||||||
|
<script src="https://unpkg.com/leaflet@1.9.3/dist/leaflet.js"></script>
|
||||||
|
<script>
|
||||||
|
// Base layers: Streets and Satellite
|
||||||
|
var streets = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||||
|
maxZoom: 19,
|
||||||
|
});
|
||||||
|
|
||||||
|
var satellite = L.tileLayer('https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', {
|
||||||
|
maxZoom: 17,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Initialize the map
|
||||||
|
var map = L.map('map', {
|
||||||
|
center: [14.5995, 120.9842], // Latitude, Longitude of Manila
|
||||||
|
zoom: 13,
|
||||||
|
layers: [streets] // Set default layer
|
||||||
|
});
|
||||||
|
|
||||||
|
// Base layers for diff map sets
|
||||||
|
var baseMaps = {
|
||||||
|
"Streets": streets,
|
||||||
|
"Satellite": satellite
|
||||||
|
};
|
||||||
|
|
||||||
|
// Switch between base layers
|
||||||
|
L.control.layers(baseMaps).addTo(map);
|
||||||
|
|
||||||
|
// Add markers for cities
|
||||||
|
var manilaMarker = L.marker([14.5995, 120.9842]).addTo(map)
|
||||||
|
.bindPopup("<b>Manila</b><br>Capital of the Philippines").openPopup();
|
||||||
|
|
||||||
|
var sanJuanMarker = L.marker([14.6042, 121.0293]).addTo(map)
|
||||||
|
.bindPopup("<b>San Juan City</b><br>Known for historical sites.");
|
||||||
|
|
||||||
|
var quezonMarker = L.marker([14.6760, 121.0437]).addTo(map)
|
||||||
|
.bindPopup("<b>Quezon City</b><br>Largest city in Metro Manila.");
|
||||||
|
|
||||||
|
// Add click event listener for adding new markers
|
||||||
|
map.on('click', function(e) {
|
||||||
|
var lat = e.latlng.lat; // Get latitude
|
||||||
|
var lng = e.latlng.lng; // Get longitude
|
||||||
|
|
||||||
|
// Create a new marker
|
||||||
|
var newMarker = L.marker([lat, lng]).addTo(map);
|
||||||
|
|
||||||
|
// Create a delete button inside the popup
|
||||||
|
var deleteButton = `<button onclick="deleteMarker(${lat}, ${lng})"
|
||||||
|
style='background-color: red; color: white; padding: 5px;'>Delete Marker</button>`;
|
||||||
|
|
||||||
|
// Add a popup to the marker with the "Save Marker" and "Delete" button
|
||||||
|
newMarker.bindPopup("<b>Save Marker</b><br>" + deleteButton).openPopup();
|
||||||
|
|
||||||
|
// Update the coordinates in the div
|
||||||
|
document.getElementById('coordinates').innerHTML =
|
||||||
|
'Coordinates: Latitude ' + lat + ', Longitude ' + lng;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Function to delete marker based on lat/lng
|
||||||
|
function deleteMarker(lat, lng) {
|
||||||
|
map.eachLayer(function (layer) {
|
||||||
|
if (layer instanceof L.Marker) {
|
||||||
|
if (layer.getLatLng().lat === lat && layer.getLatLng().lng === lng) {
|
||||||
|
map.removeLayer(layer); // Remove the marker
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
Loading…
Reference in a new issue