Guillaume Bourgeois 5 лет назад
Родитель
Сommit
37317fbe97
16 измененных файлов: 116 добавлений и 172 удалений
  1. +21
    -111
      backend/controllers/CronController.php
  2. +1
    -9
      backend/controllers/DistributionController.php
  3. +2
    -2
      backend/controllers/ProductController.php
  4. +2
    -17
      backend/views/layouts/main.php
  5. +1
    -1
      backend/views/site/login.php
  6. +24
    -3
      common/models/Distribution.php
  7. +27
    -2
      common/models/Producer.php
  8. +10
    -0
      common/views/_analytics.php
  9. +3
    -1
      frontend/controllers/SiteController.php
  10. +2
    -10
      frontend/views/layouts/main.php
  11. +1
    -0
      frontend/views/site/index.php
  12. +0
    -7
      frontend/views/site/login.php
  13. +8
    -0
      frontend/views/site/producer.php
  14. +12
    -8
      producer/controllers/ProducerBaseController.php
  15. +1
    -0
      producer/views/layouts/main.php
  16. +1
    -1
      producer/views/site/contact.php

+ 21
- 111
backend/controllers/CronController.php Просмотреть файл

@@ -79,125 +79,35 @@ class CronController extends BackendController
}

/**
* Initialise la base de données de démo avec les données de l'environnement
* de production (en modifiant les données privées).
* Initialise le compte de démonstration.
*
* @param string $key
*/
public function actionInitDatabaseDemo($key = '')
public function actionInitDemo($key = '')
{
if ($key == '45432df6e842ac71aa0b5bb6b9f25d44' && YII_ENV == 'demo') {

$arrayLastnames = [
'Martin', 'Bernard', 'Thomas', 'Petit', 'Robert', 'Richard', 'Durand', 'Dubois',
'Moreau', 'Laurent', 'Simon', 'Michel', 'Lefebvre', 'Leroy', 'Roux', 'David',
'Bertrand', 'Morel', 'Fournier', 'Girard', 'Bonnet', 'Dupont', 'Lambert', 'Fontaine',
'Rousseau', 'Vincent', 'Muller', 'Lefevre', 'Faure', 'Andre', 'Mercier', 'Blanc', 'Guerin',
'Boyer', 'Garnier', 'Chevalier', 'François', 'Legrand', 'Gauthier', 'Garcia', 'Perrin',
'Robin', 'Clement', 'Morin', 'Nicolas', 'Henry', 'Roussel', 'Mathieu', 'Gautier', 'Masson',
'Marchand', 'Duval', 'Denis', 'Dumont', 'Marie', 'Lemaire', 'Noël', 'Meyer', 'Dufour',
'Meunier', 'Brun', 'Blanchard', 'Giraud', 'Joly', 'Rivière', 'Lucas', 'Brunet', 'Gaillard', 'Barbier',
'Arnaud', 'Martinez', 'Gerard', 'Roche', 'Renard', 'Schmitt', 'Roy', 'Leroux', 'Colin', 'Vidal',
'Caron', 'Picard', 'Roger', 'Fabre', 'Aubert', 'Lemoine', 'Renaud', 'Dumas', 'Lacroix', 'Olivier',
'Philippe', 'Bourgeois', 'Pierre', 'Benoit', 'Rey', 'Leclerc', 'Payet', 'Rolland', 'Lecomte', 'Lopez',
'Jean', 'Dupuis', 'Guillot', 'Hubert', 'Berger', 'Carpentier', 'Sanchez', 'Dupuis', 'Moulin',
'Louis', 'Deschamps', 'Huet', 'Vasseur', 'Perez', 'Trouillot', 'Fusillier', 'Massenot', 'Boucher', 'Fleury',
'Royer', 'Klein', 'Jacquet', 'Jaquin', 'Adam', 'Paris', 'Poirier', 'Aubry', 'Guyot', 'Carré', 'Charles',
'Charpentier', 'Menard', 'Bailly', 'Bertin', 'Le Gall', 'Collet', 'Leger', 'Bouvier', 'Millet', 'Daniel',
'Langlois', 'Pelletier', 'Perrier', 'Leblanc', 'Lebrun', 'Monnier', 'Michaud', 'Laporte', 'Carlier',
'Pasquier', 'Delaunay', 'Lamy', 'Gilbert', 'Lejeune', 'Pichon', 'Cordier', 'Barthelemy', 'Perret', 'Reynaud',
'Humbert', 'Marechal', 'Bernard', 'Lemaitre', 'Gay', 'Bouchet', 'Da Silva', 'Chauvin', 'Chevalier', 'Tessier',
'Poulain', 'Girondin', 'Gillet', 'Guichard'
];

$arrayNames = [
'Adel', 'Antonin', 'Armand', 'Arnaud', 'Aymeric', 'Baptiste', 'Barnabé', 'Bernard', 'Brice', 'Baudouin',
'Camille', 'Cassandre', 'Célestin', 'Christian', 'Clément', 'Cyril', 'Claude', 'Damien', 'Daniel', 'David',
'Delphin', 'Denis', 'Didier', 'Dimitri', 'Dorothée', 'Désiré', 'Edgard', 'Etienne', 'Eugène', 'Eudes', 'Eric',
'Fabien', 'Fabrice', 'Flavien', 'Florent', 'Francois', 'Frédéric', 'Gabin', 'Gabriel', 'Gautier', 'Gilles', 'Guy',
'Hervé', 'Huvert', 'Hugues', 'Hector', 'Jacques', 'Jason', 'Jean', 'Jeannot', 'Johan', 'Julien', 'Léon', 'Lionel', 'Loïc',
'Lucas', 'Luc', 'Lucien', 'Maurice', 'Maxence', 'Maxime', 'Michel', 'Morgan', 'Nicolas', 'Normand', 'Norbert', 'Olivier,',
'Pascal', 'Patrice', 'Pierrick', 'Raphael', 'Roland', 'Stéphane', 'Sylvain', 'Sylvestre', 'Timothée', 'Thomas', 'Tristan',
'Ulysse', 'Vincent', 'Victor', 'Vivien',
'Adeline', 'Albane', 'Alix', 'Amélie', 'Arielle', 'Aurelle', 'Blandine', 'Blanche', 'Brigitte', 'Berthe', 'Camille', 'Capucine',
'Catherine', 'Cécile', 'Charlotte', 'Chloé', 'Claudine', 'Clémenence', 'Constance', 'Cyrielle', 'Corinne', 'Danielle',
'Delphine', 'Denise', 'Dominique', 'Diane', 'Édith', 'Éliane', 'Éléonore', 'Émilie', 'Emmanuelle', 'Ève', 'Évelyne',
'Fanny', 'Flavie', 'Flore', 'Françoise', 'Gabrielle', 'Gaëlle', 'Geneviève', 'Georgette', 'Germaine', 'Gertrude', 'Gisèle',
'Gwenaëlle', 'Hélène', 'Héloïse', 'Henriette', 'Huguette', 'Inès', 'Isabelle', 'Jacqueline', 'Jeanne', 'Joëlle', 'Joséphine',
'Juliette', 'Justine', 'Julie', 'Laura', 'Laure', 'Léa', 'Léonie', 'Lucie', 'Lucienne', 'Lorraine', 'Lucille', 'Ludivine', 'Lydie',
'Margot', 'Marion', 'Marlène', 'Marthe', 'Mélodie', 'Monique', 'Noémie', 'Nadine', 'Nadège', 'Océane', 'Odette', 'Odile', 'Paulette',
'Rose', 'Roseline', 'Renée', 'Sabine', 'Sophie', 'Suzanne', 'Sylvie', 'Thérèse',
];

$arrayNamesChecked = [];
$arrayLastnameschecked = [];

$users = User::searchAll([
'user_producer.id_producer' => 1
]) ;

foreach ($users as $u) {
if ($u->email != 'producer@opendistrib.net') {
do {
$indexLastname = rand(0, count($arrayLastnames) - 1);
$indexName = rand(0, count($arrayNames) - 1);
} while (isset($arrayLastnameschecked[$i_nom]) || isset($arrayNamesChecked[$i_prenom]));

$arrayLastnameschecked[$i_nom] = true;
$arrayNamesChecked[$i_prenom] = true;

$lastname = $arrayLastnameschecked[$indexLastname];
$name = $arrayNamesChecked[$indexName];

$u->name = $name;
$u->lastname = $lastname;

$email = strtolower($name) . '.' . strtolower($lastname) . '@yopmail.com';
$email = htmlentities($email, ENT_NOQUOTES, 'utf-8');
$email = preg_replace('#&([A-za-z])(?:acute|cedil|caron|circ|grave|orn|ring|slash|th|tilde|uml);#', '\1', $email);
$email = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $email); // pour les ligatures e.g. 'œ'
$email = preg_replace('#&[^;]+;#', '', $email); // supprime les autres caractères
$email = str_replace(' ', '', $email);
$u->email = $email;

$u->telephone = '0600000000';
} else {
/*
* Le hash du mot de passe en production est volontairement corrompu
* pour empêcher la connexion des utilisateurs via ce compte en prod.
* Lors de l'initialisation des utilisateurs sur l'espace de démo,
* on remet le bon hash pour que ce compte soit disponible.
*/
$u->password_hash = '$2y$13$2D5T3Eo0pySmtlAuEGcfmOdTR5mleog8Y6YPGhop/ych6pbj6aN2y';
if($key == '45432df6e842ac71aa0b5bb6b9f25d44') {
$producer = Producer::getDemoAccount() ;
if($producer) {
// initialisation de la distribution à J+7
$dateTime = strtotime("+7 day") ;
$dayStr = strtolower(date('l', $dateTime)) ;
$fieldDeliveryDay = 'delivery_'.$dayStr ;
$pointsSaleArray = PointSale::searchAll(['point_sale.id_producer' => $producer->id]) ;
$activeDistribution = false ;
foreach($pointsSaleArray as $pointSale) {
if($pointSale->$fieldDeliveryDay) {
$activeDistribution = true ;
}
}

$u->save();
}

$arrayOrders = Order::find()
->where('username IS NOT NULL')
->all();

foreach ($arrayOrders as $order) {
$lastname = $arrayLastnames[rand(0, count($arrayLastnames) - 1)];
$name = $arrayNames[rand(0, count($arrayNames) - 1)];

$c->username = $name . ' ' . $lastname;

$c->save();
}

$arraySubscription = Subscription::find()
->where('username IS NOT NULL')
->all();

foreach ($arraySubscription as $subscription) {
$lastname = $arrayLastnames[rand(0, count($arrayLastnames) - 1)];
$name = $arrayNames[rand(0, count($arrayNames) - 1)];
$c->username = $name . ' ' . $lastname;
$c->save();
if($activeDistribution) {
$distribution = Distribution::initDistribution(date('Y-m-d',$dateTime), $producer->id) ;
$distribution->active(true) ;
}
}
}
}

/**

+ 1
- 9
backend/controllers/DistributionController.php Просмотреть файл

@@ -604,15 +604,7 @@ class DistributionController extends BackendController
}
if($distribution) {
PointSaleDistribution::setAll($distribution->id, true);
$distribution->active = (int) $active ;
$distribution->save() ;

if ($active) {
// ajout des abonnements
Subscription::addAll($distribution->date);
}
$distribution->active($active) ;
return ['success'] ;
}

+ 2
- 2
backend/controllers/ProductController.php Просмотреть файл

@@ -112,9 +112,9 @@ class ProductController extends BackendController

if ($model->load(Yii::$app->request->post()) && $model->save()) {
$lastProductOrder = Product::find()->orderBy('order DESC')->one() ;
$lastProductOrder = Product::find()->where('id_producer = :id_producer')->params([':id_producer' => Producer::getId()])->orderBy('order DESC')->one() ;
if($lastProductOrder) {
$model->order = $lastProductOrder->order ++ ;
$model->order = ++ $lastProductOrder->order ;
}
Upload::uploadFile($model, 'photo');

+ 2
- 17
backend/views/layouts/main.php Просмотреть файл

@@ -95,23 +95,8 @@ if (Yii::$app->controller->action->id === 'login') {
</div>

<?php $this->endBody() ?>
<!-- analytics -->
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');

ga('create', 'UA-86917043-1', 'auto');
ga('send', 'pageview');
</script>
<?= $this->render('@common/views/_analytics.php'); ?>
</body>
</html>
<?php $this->endPage() ?>

+ 1
- 1
backend/views/site/login.php Просмотреть файл

@@ -63,7 +63,7 @@ $fieldOptions2 = [
</div>
<!-- /.login-logo -->
<div class="login-box-body">
<?php $form = ActiveForm::begin(['id' => 'login-form', 'enableClientValidation' => false]); ?>

<?= $form

+ 24
- 3
common/models/Distribution.php Просмотреть файл

@@ -148,13 +148,19 @@ class Distribution extends ActiveRecordCommon
* @param string $date
* @return Production
*/
public static function initDistribution($date)
public static function initDistribution($date, $idProducer = 0)
{
$distribution = null ;
if ($date != '') {
$distribution = Distribution::searchOne([
$paramsDistribution = [
'date' => $date
]) ;
] ;
if($idProducer) {
$paramsDistribution['distribution.id_producer'] = (int) $idProducer ;
}
$distribution = Distribution::searchOne($paramsDistribution) ;
if (!$distribution) {
$distribution = new Distribution;
@@ -342,4 +348,19 @@ class Distribution extends ActiveRecordCommon
$pointSaleDistribution->save() ;
}

/**
* Active ou désactive la distribution.
*/
public function active($active = true)
{
PointSaleDistribution::setAll($this->id, true);
$this->active = (int) $active ;
$this->save() ;

if ($active) {
// ajout des abonnements
Subscription::addAll($this->date);
}
}
}

+ 27
- 2
common/models/Producer.php Просмотреть файл

@@ -366,7 +366,7 @@ class Producer extends ActiveRecordCommon
* @param integer $id_producer
* @return UserProducer
*/
public static function addUser($idUser, $idProducer)
public static function addUser($idUser, $idProducer, $bookmark = 1)
{
$userProducer = UserProducer::searchOne([
'user_producer.id_user' => $idUser,
@@ -379,7 +379,7 @@ class Producer extends ActiveRecordCommon
$newUserProducer->id_user = $idUser;
$newUserProducer->credit = 0;
$newUserProducer->active = 1;
$newUserProducer->bookmark = 1;
$newUserProducer->bookmark = (int) $bookmark ;
$newUserProducer->save();
} else {
if (!$userProducer->active) {
@@ -489,5 +489,30 @@ class Producer extends ActiveRecordCommon
return '' ;
}
/**
* Retourne le compte producteur de démonstration.
*
* @return Producer
*/
public static function getDemoAccount()
{
$producer = Producer::find()->where('name LIKE \'Démo\'')->one() ;
return $producer ;
}
/**
* Retourne true si le compte est un compte de démo.
*
* @return boolean
*/
public function isDemo()
{
if(strpos($this->name, 'Démo') !== false) {
return true ;
}
return false ;
}
}

+ 10
- 0
common/views/_analytics.php Просмотреть файл

@@ -0,0 +1,10 @@
<!-- analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-86917043-1', 'auto');
ga('send', 'pageview');
</script>

+ 3
- 1
frontend/controllers/SiteController.php Просмотреть файл

@@ -135,7 +135,9 @@ class SiteController extends FrontendController
*/
public function actionIndex()
{
return $this->render('index');
return $this->render('index', [
'producerDemoAccount' => Producer::getDemoAccount()
]);
}
/**

+ 2
- 10
frontend/views/layouts/main.php Просмотреть файл

@@ -232,16 +232,8 @@ if(!Yii::$app->user->isGuest && Yii::$app->user->identity->id_producer > 0) {
<?php $this->endBody() ?>
<!-- analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-86917043-1', 'auto');
ga('send', 'pageview');
</script>
<?= $this->render('@common/views/_analytics.php'); ?>
</body>
</html>
<?php $this->endPage() ?>

+ 1
- 0
frontend/views/site/index.php Просмотреть файл

@@ -71,6 +71,7 @@ $this->setTitle('Logiciel libre de distribution alimentaire') ;
<div class="panel-body">
<p class="presentation">Simplifiez la distribution de vos produits<br /> avec des outils adaptés.</p>
<a class="btn btn-primary" href="<?= Yii::$app->urlManagerFrontend->createUrl(['site/signup']) ; ?>"><span class="glyphicon glyphicon-user"></span> Je crée mon espace</a>
<?php if($producerDemoAccount) : ?><a class="btn btn-default" href="<?= Yii::$app->urlManagerFrontend->createUrl(['site/producer', 'id' => $producerDemoAccount->id]) ; ?>"><span class="glyphicon glyphicon-blackboard"></span> Démonstration</a><?php endif; ?>
<a class="btn btn-default" href="<?= Yii::$app->urlManagerFrontend->createUrl(['site/contact']) ; ?>"><span class="glyphicon glyphicon-info-sign"></span> Demande d'informations</a>
</div>
</div>

+ 0
- 7
frontend/views/site/login.php Просмотреть файл

@@ -54,13 +54,6 @@ $this->params['breadcrumbs'][] = $this->title;
<div class="col-lg-5">
<p>Pas encore de compte ? <a class="" href="<?php echo Yii::$app->urlManager->createUrl('site/signup') ; ?>">Je m'inscris</a></p>
<?php if(YII_ENV == 'demo') : ?>
<div class="alert alert-warning">
Identifiant : <strong>producer@laboiteapain.net</strong><br />
Mot de passe : <strong>laboiteapain</strong>
</div>
<?php endif; ?>
<?php $form = ActiveForm::begin(['id' => 'login-form']); ?>
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'password')->passwordInput() ?>

+ 8
- 0
frontend/views/site/producer.php Просмотреть файл

@@ -53,6 +53,14 @@ $this->title = 'Producteur '.Html::encode($producer->name) ;
<div class="col-md-6">
<h2>Connexion</h2>
<?php if(isset($producer) && $producer->isDemo()) : ?>
<div class="alert alert-warning">
<p>Merci d'utiliser les identifiants suivants pour vous connecter à l'espace de démonstration :</p>
Identifiant : <strong>demo@opendistrib.net</strong><br />
Mot de passe : <strong>opendistrib</strong>
</div>
<?php endif; ?>
<?php $form = ActiveForm::begin(['id' => 'login-form','enableClientValidation'=> false]); ?>
<?= $form->field($loginForm, 'email') ?>
<?= $form->field($loginForm, 'password')->passwordInput() ?>

+ 12
- 8
producer/controllers/ProducerBaseController.php Просмотреть файл

@@ -58,9 +58,15 @@ class ProducerBaseController extends CommonController
public function beforeAction($event)
{
$producer = $this->getProducer() ;
$userProducer = UserProducer::find()
->where([
'id_user' => User::getCurrentId(),
'id_producer' => $producer->id
])
->one() ;
/*
* Producteur protègé par un code
*/
@@ -73,18 +79,12 @@ class ProducerBaseController extends CommonController
}
// si l'utilisateur est connecté et qu'il n'a pas encore saisi de code
else {
$userProducer = UserProducer::find()
->where([
'id_user' => User::getCurrentId(),
'id_producer' => $producer->id
])
->one() ;
if(!$userProducer || ($userProducer && !$userProducer->active)) {
$this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-code','id' => $producer->id])) ;
}
}
}
/*
* Producteur hors ligne
*/
@@ -92,6 +92,10 @@ class ProducerBaseController extends CommonController
$this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-offline','id' => $producer->id])) ;
}
if(!$userProducer) {
Producer::addUser(User::getCurrentId(), $producer->id, 0) ;
}
return parent::beforeAction($event);
}

+ 1
- 0
producer/views/layouts/main.php Просмотреть файл

@@ -303,6 +303,7 @@ if(!Yii::$app->user->isGuest) {
</footer>

<?php $this->endBody() ?>
<?= $this->render('@common/views/_analytics.php'); ?>
</body>
</html>
<?php $this->endPage() ?>

+ 1
- 1
producer/views/site/contact.php Просмотреть файл

@@ -53,7 +53,7 @@ $this->setTitle('Contact');
<?= $form->field($model, 'body')->textArea(['rows' => 6]) ?>
<?php echo $form->field($model, 'verifyCode')->widget(yii\captcha\Captcha::className(), [
'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
'template' => '<div class="row"><div class="col-md-12">{image}</div><div class="col-md-12">{input}</div></div>',
]); ?>
<div class="form-group">

Загрузка…
Отмена
Сохранить