On avance sur LivraisonParSecteurs

This commit is contained in:
2021-02-04 08:39:38 +01:00
parent 2165100ac7
commit aa5a914df3
14 changed files with 485 additions and 45 deletions

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="livraisonparsecteurs.back.config" path="/admin/module/LivraisonParSecteurs">
<default key="_controller">LivraisonParSecteurs\Controller\BackOfficeController::viewAction</default>
</route>
<route id="livraisonparsecteurs.back.price" path="/admin/module/LivraisonParSecteurs/config">
<default key="_controller">LivraisonParSecteurs\Controller\BackOfficeController::updatePrice</default>
</route>
<route id="livraisonparsecteurs.toggle.visible" path="/admin/module/LivraisonParSecteurs/toggle-online/{id}" methods="post">
<default key="_controller">LivraisonParSecteurs\Controller\BackOfficeController::toggleActive</default>
<requirement key="id">\d+</requirement>
</route>
</routes>

View File

@@ -0,0 +1,2 @@
# Sqlfile -> Database map
thelia.sql=thelia

View File

@@ -1,70 +1,48 @@
# This is a fix for InnoDB in MySQL >= 4.1.x # This is a fix for InnoDB in MySQL >= 4.1.x
# It "suspends judgement" for fkey relationships until are tables are set. # It "suspends judgement" for fkey relationships until are tables are set.
SET FOREIGN_KEY_CHECKS = 0; SET FOREIGN_KEY_CHECKS = 0;
-- --------------------------------------------------------------------- -- ---------------------------------------------------------------------
-- secteur -- lps_secteur
-- --------------------------------------------------------------------- -- ---------------------------------------------------------------------
DROP TABLE IF EXISTS `lps_secteur`; DROP TABLE IF EXISTS `lps_secteur`;
CREATE TABLE `lps_secteur` CREATE TABLE `lps_secteur`
( (
`id` INTEGER NOT NULL AUTO_INCREMENT, `id` INTEGER NOT NULL,
`nom` VARCHAR(50) NOT NULL `nom` VARCHAR(50) NOT NULL,
`active` TINYINT DEFAULT 1 NOT NULL,
`created_at` DATETIME,
`updated_at` DATETIME,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB; ) ENGINE=InnoDB;
INSERT INTO `lps_secteur`(`id`,`nom`) VALUES (1, 'Capso'), (2, 'Pays de Lumbres'), (3, 'Haut des Flanders'), (4, 'Flandres intérieur');
-- --------------------------------------------------------------------- -- ---------------------------------------------------------------------
-- secteur_commune -- lps_secteur_commune
-- --------------------------------------------------------------------- -- ---------------------------------------------------------------------
DROP TABLE IF EXISTS `lps_secteur_commune`; DROP TABLE IF EXISTS `lps_secteur_commune`;
CREATE TABLE `lps_secteur_commune` CREATE TABLE `lps_secteur_commune`
( (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`id_secteur` INTEGER NOT NULL, `id_secteur` INTEGER NOT NULL,
`zipcode` VARCHAR(10) NOT NULL `zipcode` VARCHAR(10) NOT NULL,
PRIMARY KEY (`id_secteur`,`zipcode`) `created_at` DATETIME,
CONSTRAINT `fk_id_secteur` `updated_at` DATETIME,
PRIMARY KEY (`id`),
INDEX `fi_secteur_commune_secteur` (`id_secteur`),
CONSTRAINT `fk_secteur_commune_secteur`
FOREIGN KEY (`id_secteur`) FOREIGN KEY (`id_secteur`)
REFERENCES `lps_secteur` (`id`) REFERENCES `lps_secteur` (`id`)
ON UPDATE RESTRICT
ON DELETE CASCADE,
CONSTRAINT `fk_zipcode`
FOREIGN KEY (`zipcode`)
REFERENCES `address` (`zipcode`)
ON UPDATE RESTRICT
ON DELETE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB; ) ENGINE=InnoDB;
-- --------------------------------------------------------------------- INSERT INTO `lps_secteur_commune`(`id_secteur`,`zipcode`) VALUES
-- secteur_horaires
-- ---------------------------------------------------------------------
DROP TABLE IF EXISTS `lps_secteur_horaires`;
CREATE TABLE `lps_secteur_horaires`
(
`id_secteur` INTEGER NOT NULL,
`jour` TINYINT NOT NULL,
`heure_debut` TIME NOT NULL,
`heure_fin` TIME NOT NULL
PRIMARY KEY (`id_secteur`,`jour`)
) ENGINE=InnoDB;
-- ---------------------------------------------------------------------
-- Insertion des données
-- ---------------------------------------------------------------------
INSERT INTO `secteur`(`id`,`nom`) VALUES
(1, 'Capso'),
(2, 'Pays de Lumbres'),
(3, 'Haut des Flanders'),
(4, 'Flandres intérieur')
);
INSERT INTO `secteur_commune`(`id_secteur`,`zipcode`) VALUES
(1,'62120'), (1,'62120'),
(1,'62129'), (1,'62129'),
(1,'62219'), (1,'62219'),
@@ -72,7 +50,9 @@ INSERT INTO `secteur_commune`(`id_secteur`,`zipcode`) VALUES
(1,'62510'), (1,'62510'),
(1,'62570'), (1,'62570'),
(1,'62575'), (1,'62575'),
(1,'62910'), (1,'62910');
INSERT INTO `lps_secteur_commune`(`id_secteur`,`zipcode`) VALUES
(2,'62010'), (2,'62010'),
(2,'62024'), (2,'62024'),
(2,'62088'), (2,'62088'),
@@ -91,9 +71,30 @@ INSERT INTO `secteur_commune`(`id_secteur`,`zipcode`) VALUES
(2,'62882'), (2,'62882'),
(2,'62897'), (2,'62897'),
(2,'62898'), (2,'62898'),
(2,'62905') (2,'62905');
);
-- ---------------------------------------------------------------------
-- lps_secteur_horaires
-- ---------------------------------------------------------------------
DROP TABLE IF EXISTS `lps_secteur_horaires`;
CREATE TABLE `lps_secteur_horaires`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`id_secteur` INTEGER NOT NULL,
`jour` INTEGER NOT NULL,
`heure_debut` TIME NOT NULL,
`heure_fin` TIME NOT NULL,
`created_at` DATETIME,
`updated_at` DATETIME,
PRIMARY KEY (`id`),
INDEX `fi_secteur_horaires_secteur` (`id_secteur`),
CONSTRAINT `fk_secteur_horaires_secteur`
FOREIGN KEY (`id_secteur`)
REFERENCES `lps_secteur` (`id`)
ON DELETE CASCADE
) ENGINE=InnoDB;
# This restores the fkey checks, after having unset them earlier # This restores the fkey checks, after having unset them earlier
SET FOREIGN_KEY_CHECKS = 1; SET FOREIGN_KEY_CHECKS = 1;

View File

@@ -0,0 +1,28 @@
<?php
namespace LivraisonParSecteurs\Controller;
use Thelia\Controller\Admin\BaseAdminController;
/**
* Class BackOfficeController
* @package LivraisonParSecteurs\Controller
*/
class BackOfficeController extends BaseAdminController
{
public function viewAction($params = [])
{
return $this->render("secteurs");
}
public function toggleActive($params = [])
{
return $this->render("secteurs");
}
public function updatePrice($params = [])
{
return $this->render("secteurs");
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace LivraisonParSecteurs\Form;
use LivraisonParSecteurs\LivraisonParSecteurs;
use Thelia\Form\BaseForm;
use Symfony\Component\Validator\Constraints;
/**
* Class ConfigForm
* @package LivraisonParSecteurs\Form
*/
class ConfigForm extends BaseForm
{
protected function buildForm()
{
$this->formBuilder
->add(
'price',
'number',
[
'constraints' => [new Constraints\NotBlank()],
'required' => true,
'label' => $this->translator->trans('Price', [], LivraisonParSecteurs::DOMAIN_NAME),
'label_attr' => ['for' => 'price'],
'data' => LivraisonParSecteurs::getConfigValue('price', 0)
]
);
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace LivraisonParSecteurs\Hook;
use LivraisonParSecteurs\LivraisonParSecteurs;
use Thelia\Core\Event\Hook\HookRenderEvent;
use Thelia\Core\Hook\BaseHook;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\SecurityContext;
/**
* Class AdminHook
*/
class AdminHook extends BaseHook
{
protected $securityContext;
public function __construct(SecurityContext $securityContext)
{
$this->securityContext = $securityContext;
}
public function onModuleConfig(HookRenderEvent $event)
{
$isGranted = $this->securityContext->isGranted(
["ADMIN"],
[],
[LivraisonParSecteurs::getModuleCode()],
[AccessManager::VIEW]
);
if ($isGranted) {
$event->add($this->render("secteurs.html", $event->getArguments()));
}
}
public function onModuleConfigJs(HookRenderEvent $event)
{
$event->add($this->render('script/livraisonparsecteurs-js.html'));
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace LivraisonParSecteurs\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use LivraisonParSecteurs\Model\LpsSecteurQuery;
/**
* Class AreaLoop
* @package LivraisonParSecteurs\Loop
*/
class AreaLoop extends BaseLoop implements PropelSearchLoopInterface
{
public $countable = false;
public $timestampable = false;
public $versionable = false;
/**
* @param LoopResult $loopResult
*
* @return LoopResult
*/
public function parseResults(LoopResult $loopResult)
{
foreach ($loopResult->getResultDataCollection() as $lps_area) {
$loopResultRow = new LoopResultRow($lps_area);
$loopResultRow
->set("ID", $lps_area->getId())
->set("NAME", $lps_area->getNom())
->set("ACTIVE", $lps_area->getActive())
->set("DELIVERY_DAYS", "Lundi....")
;
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
/**
* @inheritdoc
*/
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntListTypeArgument('id'),
Argument::createIntListTypeArgument('active')
);
}
/**
* @inheritdoc
*/
public function buildModelCriteria()
{
$query = LpsSecteurQuery::create();
return $query->orderByNom();
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace LivraisonParSecteurs\Model;
use LivraisonParSecteurs\Model\Base\LpsSecteur as BaseLpsSecteur;
/**
* Skeleton subclass for representing a row from the 'lps_secteur' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class LpsSecteur extends BaseLpsSecteur
{
}

View File

@@ -0,0 +1,20 @@
<?php
namespace LivraisonParSecteurs\Model;
use LivraisonParSecteurs\Model\Base\LpsSecteurCommune as BaseLpsSecteurCommune;
/**
* Skeleton subclass for representing a row from the 'lps_secteur_commune' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class LpsSecteurCommune extends BaseLpsSecteurCommune
{
}

View File

@@ -0,0 +1,20 @@
<?php
namespace LivraisonParSecteurs\Model;
use LivraisonParSecteurs\Model\Base\LpsSecteurCommuneQuery as BaseLpsSecteurCommuneQuery;
/**
* Skeleton subclass for performing query and update operations on the 'lps_secteur_commune' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class LpsSecteurCommuneQuery extends BaseLpsSecteurCommuneQuery
{
}

View File

@@ -0,0 +1,20 @@
<?php
namespace LivraisonParSecteurs\Model;
use LivraisonParSecteurs\Model\Base\LpsSecteurHoraires as BaseLpsSecteurHoraires;
/**
* Skeleton subclass for representing a row from the 'lps_secteur_horaires' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class LpsSecteurHoraires extends BaseLpsSecteurHoraires
{
}

View File

@@ -0,0 +1,20 @@
<?php
namespace LivraisonParSecteurs\Model;
use LivraisonParSecteurs\Model\Base\LpsSecteurHorairesQuery as BaseLpsSecteurHorairesQuery;
/**
* Skeleton subclass for performing query and update operations on the 'lps_secteur_horaires' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class LpsSecteurHorairesQuery extends BaseLpsSecteurHorairesQuery
{
}

View File

@@ -0,0 +1,20 @@
<?php
namespace LivraisonParSecteurs\Model;
use LivraisonParSecteurs\Model\Base\LpsSecteurQuery as BaseLpsSecteurQuery;
/**
* Skeleton subclass for performing query and update operations on the 'lps_secteur' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class LpsSecteurQuery extends BaseLpsSecteurQuery
{
}

View File

@@ -0,0 +1,133 @@
{extends file="admin-layout.tpl"}
{block name="no-return-functions"}
{$admin_current_location = 'module'}
{/block}
{block name="page-title"}{intl l='Configuration'}{/block}
{block name="check-resource"}admin.module{/block}
{block name="check-access"}view{/block}
{block name="check-module"}LivraisonParSecteurs{/block}
{block name="main-content"}
<div id="wrapper" class="container">
{if $general_error}
<div class="alert alert-danger">
{$general_error}
</div>
{/if}
<div class="general-block-decorator">
<div class="title title-without-tabs">
{intl l="Home delivery cost" d='livraisonparsecteurs'}
</div>
{form name='livraisonparsecteurs.config_form'}
<form action="{url path='/admin/module/LivraisonParSecteurs/config'}" method="post" class="form-inline">
{form_hidden_fields form=$form}
{if $form_error}
<div class="alert alert-danger">{$form_error_message}</div>
{/if}
{form_field form=$form field="price"}
<div class="form-group">
<label class="control-label" for="{$label_attr.for}">
{$label}
</label>
<input type="text" id="{$label_attr.for}" class="form-control" name="{$name}" value="{$value}"
{if $required}required{/if} />
</div>
{/form_field}
<div class="form-group">
<button class="btn btn-info" type="submit">{intl l='Save' d='livraisonparsecteurs'}</button>
</div>
</form>
{/form}
</div>
<div class="general-block-decorator">
<div class="table-responsive">
<table class="table table-striped table-condensed" id="areas-table">
<caption class="clearfix">
{intl l='My areas' d='livraisonparsecteurs'}
</caption>
<thead>
<tr>
{$order}
<th>
{intl l="Area name" d='livraisonparsecteurs'}
</th>
<th>
{intl l="Active" d='livraisonparsecteurs'}
</th>
<th>
{intl l="Delivery days" d='livraisonparsecteurs'}
</th>
<th>
{intl l="Actions" d='livraisonparsecteurs'}
</th>
</tr>
</thead>
<tbody>
{loop name="areas" type="lps_area" backend_context="yes" order=$order force_return=true}
<tr>
<td>
<a href="{url path='/admin/module/LivraisonParSecteurs/secteurs/edit' area_id=$ID}">{$NAME}</a>
</td>
<td>
<div class="make-switch switch-small toggle-visible" data-id="{$ID}" data-on="success"
data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>"
data-off-label="<i class='glyphicon glyphicon-remove'></i>">
<input type="checkbox" class="link" {if $ACTIVE == 1}checked="checked"{/if}>
</div>
</td>
<td>
{$DELIVERY_DAYS}
</td>
<td>
<div class="btn-group">
<a class="btn btn-default btn-xs" title="{intl l='Edit this area'}" href="{url path='/admin/module/LivraisonParSecteurs/secteurs/edit' area_id=$ID}">
<i class="glyphicon glyphicon-edit"></i>
</a>
<a class="btn btn-default btn-xs area-delete" title="{intl l='Delete this area'}" data-target="#area-delete" data-toggle="modal" data-id="{$ID}">
<i class="glyphicon glyphicon-trash"></i>
</a>
</div>
</td>
</tr>
{/loop}
</tbody>
</table>
</div>
</div>
</div>
{/block}
{block name="javascript-initialization"}
{javascripts file='assets/js/bootstrap-switch/bootstrap-switch.js'}
<script src="{$asset_url}"></script>
<script>
$(function() {
$('a.area-delete').click(function(ev) {
$('#area_delete_id').val($(this).data('id'));
});
$(".toggle-visible").on('switch-change', function (event, data) {
$.ajax({
method: "POST",
url: "{url path='admin/module/LivraisonParSecteurs/secteurs/toggle-online/'}" + $(this).data('id')
});
});
});
</script>
{/javascripts}
{/block}