} | } | ||||
/** | /** | ||||
* 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 | * @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) ; | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | /** |
} | } | ||||
if($distribution) { | 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'] ; | return ['success'] ; | ||||
} | } | ||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | 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) { | if($lastProductOrder) { | ||||
$model->order = $lastProductOrder->order ++ ; | |||||
$model->order = ++ $lastProductOrder->order ; | |||||
} | } | ||||
Upload::uploadFile($model, 'photo'); | Upload::uploadFile($model, 'photo'); |
</div> | </div> | ||||
<!-- /.login-logo --> | <!-- /.login-logo --> | ||||
<div class="login-box-body"> | <div class="login-box-body"> | ||||
<?php $form = ActiveForm::begin(['id' => 'login-form', 'enableClientValidation' => false]); ?> | <?php $form = ActiveForm::begin(['id' => 'login-form', 'enableClientValidation' => false]); ?> | ||||
<?= $form | <?= $form |
* @param string $date | * @param string $date | ||||
* @return Production | * @return Production | ||||
*/ | */ | ||||
public static function initDistribution($date) | |||||
public static function initDistribution($date, $idProducer = 0) | |||||
{ | { | ||||
$distribution = null ; | $distribution = null ; | ||||
if ($date != '') { | if ($date != '') { | ||||
$distribution = Distribution::searchOne([ | |||||
$paramsDistribution = [ | |||||
'date' => $date | 'date' => $date | ||||
]) ; | |||||
] ; | |||||
if($idProducer) { | |||||
$paramsDistribution['distribution.id_producer'] = (int) $idProducer ; | |||||
} | |||||
$distribution = Distribution::searchOne($paramsDistribution) ; | |||||
if (!$distribution) { | if (!$distribution) { | ||||
$distribution = new Distribution; | $distribution = new Distribution; | ||||
$pointSaleDistribution->save() ; | $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); | |||||
} | |||||
} | |||||
} | } |
* @param integer $id_producer | * @param integer $id_producer | ||||
* @return UserProducer | * @return UserProducer | ||||
*/ | */ | ||||
public static function addUser($idUser, $idProducer) | |||||
public static function addUser($idUser, $idProducer, $bookmark = 1) | |||||
{ | { | ||||
$userProducer = UserProducer::searchOne([ | $userProducer = UserProducer::searchOne([ | ||||
'user_producer.id_user' => $idUser, | 'user_producer.id_user' => $idUser, | ||||
$newUserProducer->id_user = $idUser; | $newUserProducer->id_user = $idUser; | ||||
$newUserProducer->credit = 0; | $newUserProducer->credit = 0; | ||||
$newUserProducer->active = 1; | $newUserProducer->active = 1; | ||||
$newUserProducer->bookmark = 1; | |||||
$newUserProducer->bookmark = (int) $bookmark ; | |||||
$newUserProducer->save(); | $newUserProducer->save(); | ||||
} else { | } else { | ||||
if (!$userProducer->active) { | if (!$userProducer->active) { | ||||
return '' ; | 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 ; | |||||
} | |||||
} | } | ||||
*/ | */ | ||||
public function actionIndex() | public function actionIndex() | ||||
{ | { | ||||
return $this->render('index'); | |||||
return $this->render('index', [ | |||||
'producerDemoAccount' => Producer::getDemoAccount() | |||||
]); | |||||
} | } | ||||
/** | /** |
<div class="panel-body"> | <div class="panel-body"> | ||||
<p class="presentation">Simplifiez la distribution de vos produits<br /> avec des outils adaptés.</p> | <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> | <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> | <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> | ||||
</div> | </div> |
<div class="col-lg-5"> | <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> | <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']); ?> | <?php $form = ActiveForm::begin(['id' => 'login-form']); ?> | ||||
<?= $form->field($model, 'email') ?> | <?= $form->field($model, 'email') ?> | ||||
<?= $form->field($model, 'password')->passwordInput() ?> | <?= $form->field($model, 'password')->passwordInput() ?> |
<div class="col-md-6"> | <div class="col-md-6"> | ||||
<h2>Connexion</h2> | <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]); ?> | <?php $form = ActiveForm::begin(['id' => 'login-form','enableClientValidation'=> false]); ?> | ||||
<?= $form->field($loginForm, 'email') ?> | <?= $form->field($loginForm, 'email') ?> | ||||
<?= $form->field($loginForm, 'password')->passwordInput() ?> | <?= $form->field($loginForm, 'password')->passwordInput() ?> |
public function beforeAction($event) | public function beforeAction($event) | ||||
{ | { | ||||
$producer = $this->getProducer() ; | $producer = $this->getProducer() ; | ||||
$userProducer = UserProducer::find() | |||||
->where([ | |||||
'id_user' => User::getCurrentId(), | |||||
'id_producer' => $producer->id | |||||
]) | |||||
->one() ; | |||||
/* | /* | ||||
* Producteur protègé par un code | * Producteur protègé par un code | ||||
*/ | */ | ||||
} | } | ||||
// si l'utilisateur est connecté et qu'il n'a pas encore saisi de code | // si l'utilisateur est connecté et qu'il n'a pas encore saisi de code | ||||
else { | else { | ||||
$userProducer = UserProducer::find() | |||||
->where([ | |||||
'id_user' => User::getCurrentId(), | |||||
'id_producer' => $producer->id | |||||
]) | |||||
->one() ; | |||||
if(!$userProducer || ($userProducer && !$userProducer->active)) { | if(!$userProducer || ($userProducer && !$userProducer->active)) { | ||||
$this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-code','id' => $producer->id])) ; | $this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-code','id' => $producer->id])) ; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* Producteur hors ligne | * Producteur hors ligne | ||||
*/ | */ | ||||
$this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-offline','id' => $producer->id])) ; | $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); | return parent::beforeAction($event); | ||||
} | } | ||||