Browse Source

[Technique] ParameterBag : service dédié à la récupération des paramètres système #1192

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
8bfc7ca741
17 changed files with 71 additions and 32 deletions
  1. +1
    -1
      backend/controllers/CronController.php
  2. +1
    -1
      backend/views/development/index.php
  3. +1
    -1
      backend/views/stats-admin/matomo.php
  4. +2
    -2
      backend/views/support/index.php
  5. +3
    -3
      common/components/MailerService.php
  6. +35
    -0
      common/components/ParameterBag.php
  7. +3
    -0
      common/config/main.php
  8. +7
    -7
      common/helpers/Alwaysdata.php
  9. +5
    -4
      common/helpers/GlobalParam.php
  10. +2
    -2
      common/logic/Producer/Producer/Service/ProducerUtils.php
  11. +1
    -1
      common/logic/User/User/Service/UserSolver.php
  12. +2
    -2
      common/mail/signup-html.php
  13. +2
    -2
      common/mail/signup-text.php
  14. +2
    -2
      common/views/matomo.php
  15. +2
    -2
      frontend/controllers/SiteController.php
  16. +1
    -1
      frontend/views/site/index.php
  17. +1
    -1
      frontend/views/site/service.php

+ 1
- 1
backend/controllers/CronController.php View File

'orders' => $arrayOrders 'orders' => $arrayOrders
] ]
) )
->setFrom([Yii::$app->params['adminEmail'] => 'distrib']);
->setFrom([Yii::$app->parameterBag->get('adminEmail') => 'distrib']);


if (is_array($arrayOrders) && count($arrayOrders)) { if (is_array($arrayOrders) && count($arrayOrders)) {
$subject = '[Opendistrib] Commandes du ' . date('d/m', strtotime($date)); $subject = '[Opendistrib] Commandes du ' . date('d/m', strtotime($date));

+ 1
- 1
backend/views/development/index.php View File

<ul class="contacts"> <ul class="contacts">
<li> <li>
<span class="glyphicon glyphicon-earphone"></span> <span class="glyphicon glyphicon-earphone"></span>
<p><?= Html::a('Prendre rendez-vous', Yii::$app->params['appointmentUrl'], ['class' => '', 'target' => '_blank']); ?></p>
<p><?= Html::a('Prendre rendez-vous', Yii::$app->parameterBag->get('appointmentUrl'), ['class' => '', 'target' => '_blank']); ?></p>
</li> </li>
<li> <li>
<span class="glyphicon glyphicon-envelope"></span> <span class="glyphicon glyphicon-envelope"></span>

+ 1
- 1
backend/views/stats-admin/matomo.php View File



?> ?>


<iframe id="matomoframe" src="<?= Yii::$app->params['matomoWidgetDashbordUrl']; ?>" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="800px"></iframe>
<iframe id="matomoframe" src="<?= Yii::$app->parameterBag->get('matomoWidgetDashbordUrl'); ?>" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="800px"></iframe>

+ 2
- 2
backend/views/support/index.php View File

<span class="info-box-text">Me contacter directement</span> <span class="info-box-text">Me contacter directement</span>
<span class="info-box-text"> <span class="info-box-text">
<br/> <br/>
<strong><?= Yii::$app->params['adminPhoneNumber'] ?></strong>
<strong><?= Yii::$app->parameterBag->get('adminPhoneNumber'); ?></strong>
</span> </span>
</div> </div>
</div> </div>
<span class="info-box-icon bg-yellow"><i class="fa fa-calendar"></i></span> <span class="info-box-icon bg-yellow"><i class="fa fa-calendar"></i></span>
<div class="info-box-content"> <div class="info-box-content">
<span class="info-box-text"><br/> <span class="info-box-text"><br/>
<?= Html::a('Prendre rendez-vous', Yii::$app->params['appointmentUrl'], ['class' => 'btn btn-sm btn-default', 'target' => '_blank']); ?>
<?= Html::a('Prendre rendez-vous', Yii::$app->parameterBag->get('appointmentUrl'), ['class' => 'btn btn-sm btn-default', 'target' => '_blank']); ?>
</span> </span>
</div> </div>
</div> </div>

+ 3
- 3
common/components/MailerService.php View File



public function sendAdmin(string $subject, string $view, array $params = []) public function sendAdmin(string $subject, string $view, array $params = [])
{ {
$message = $this->composeBase(\Yii::$app->params['adminEmail'], $view, $params);
$message = $this->composeBase(\Yii::$app->parameterBag->get('adminEmail'), $view, $params);
$this->initMessageFromSite($message, $subject); $this->initMessageFromSite($message, $subject);
$message->send(); $message->send();
} }


private function initMessageFromSite(MessageInterface $message, string $subject) private function initMessageFromSite(MessageInterface $message, string $subject)
{ {
$message->setFrom([\Yii::$app->params['adminEmail'] => \Yii::$app->params['siteName']]);
$message->setSubject($this->buildSubject(\Yii::$app->params['siteName'], $subject));
$message->setFrom([\Yii::$app->parameterBag->get('adminEmail') => \Yii::$app->parameterBag->get('siteName')]);
$message->setSubject($this->buildSubject(\Yii::$app->parameterBag->get('siteName'), $subject));
return $message; return $message;
} }



+ 35
- 0
common/components/ParameterBag.php View File

<?php

namespace common\components;

use yii\base\ErrorException;

class ParameterBag
{
protected array $parameters = [];

public function __construct()
{
$this->parameters = \Yii::$app->params;
}

public function get(string $name)
{
if(isset($this->parameters[$name])) {
return $this->parameters[$name];
}
else {
throw new ErrorException('Paramètre '.$name.' non défini.');
}
}

public function has(string $name)
{
return \array_key_exists($name, $this->parameters);
}

public function set(string $name, $value)
{
$this->parameters[$name] = $value;
}
}

+ 3
- 0
common/config/main.php View File

} }
}, },
'components' => [ 'components' => [
'parameterBag' => [
'class' => 'common\components\ParameterBag'
],
'assetManager' => [ 'assetManager' => [
'linkAssets' => YII_ENV == "dev" ? 'true' : false, 'linkAssets' => YII_ENV == "dev" ? 'true' : false,
], ],

+ 7
- 7
common/helpers/Alwaysdata.php View File

public static function createProducerEmailRedirection(Producer $producer) public static function createProducerEmailRedirection(Producer $producer)
{ {
return self::post('mailbox',[ return self::post('mailbox',[
'domain' => \Yii::$app->params['alwaysdataDomainOpendistribId'],
'domain' => \Yii::$app->parameterBag->get('alwaysdataDomainOpendistribId'),
'name' => $producer->slug, 'name' => $producer->slug,
'password' => Password::generate(13), 'password' => Password::generate(13),
'redirect_enabled' => true, 'redirect_enabled' => true,
self::checkConfiguration(); self::checkConfiguration();


return new Client([ return new Client([
'base_uri' => \Yii::$app->params['alwaysdataApiUrl'].$resource.'/',
'auth' => [\Yii::$app->params['alwaysdataApiKey'].' account='.\Yii::$app->params['alwaysdataAccount'], ''],
'base_uri' => \Yii::$app->parameterBag->get('alwaysdataApiUrl').$resource.'/',
'auth' => [\Yii::$app->parameterBag->get('alwaysdataApiKey').' account='.\Yii::$app->parameterBag->get('alwaysdataAccount'), ''],
]); ]);
} }


private static function checkConfiguration() private static function checkConfiguration()
{ {
if(!isset(\Yii::$app->params['alwaysdataApiUrl'])
|| !isset(\Yii::$app->params['alwaysdataAccount'])
|| !isset(\Yii::$app->params['alwaysdataApiKey'])
|| !isset(\Yii::$app->params['alwaysdataDomainOpendistribId'])) {
if(!\Yii::$app->parameterBag->has('alwaysdataApiUrl')
|| !\Yii::$app->parameterBag->has('alwaysdataAccount')
|| !\Yii::$app->parameterBag->has('alwaysdataApiKey')
|| !\Yii::$app->parameterBag->has('alwaysdataDomainOpendistribId')) {


throw new ErrorException('Configuration API Alwaysdata absente ou incomplète dans params-local.php'); throw new ErrorException('Configuration API Alwaysdata absente ou incomplète dans params-local.php');
} }

+ 5
- 4
common/helpers/GlobalParam.php View File

return self::getCurrentProducer(); return self::getCurrentProducer();
} else { } else {


return \Yii::$app->params[$key];
return \Yii::$app->parameterBag->get($key);
} }
} }




public static function getCurrentProducer() public static function getCurrentProducer()
{ {
if (\Yii::$app->params['producer'] == false) {
\Yii::$app->params['producer'] = Producer::searchOne();
if(!\Yii::$app->parameterBag->has('producer') || !\Yii::$app->parameterBag->get('producer')) {
\Yii::$app->parameterBag->set('producer', Producer::searchOne());
} }
return \Yii::$app->params['producer'];

return \Yii::$app->parameterBag->get('producer');
} }


/** /**

+ 2
- 2
common/logic/Producer/Producer/Service/ProducerUtils.php View File

], [ ], [
'producer' => $producer 'producer' => $producer
]) ])
->setTo(\Yii::$app->params['adminEmail'])
->setFrom([\Yii::$app->params['adminEmail'] => 'distrib'])
->setTo(\Yii::$app->parameterBag->get('adminEmail'))
->setFrom([\Yii::$app->parameterBag->get('adminEmail') => 'Opendistrib'])
->setSubject('[Opendistrib] Nouveau producteur') ->setSubject('[Opendistrib] Nouveau producteur')
->send(); ->send();
} }

+ 1
- 1
common/logic/User/User/Service/UserSolver.php View File

if (empty($token)) { if (empty($token)) {
return false; return false;
} }
$expire = \Yii::$app->params['user.passwordResetTokenExpire'];
$expire = \Yii::$app->parameterBag->get('user.passwordResetTokenExpire');
$parts = explode('_', $token); $parts = explode('_', $token);
$timestamp = (int)end($parts); $timestamp = (int)end($parts);
return $timestamp + $expire >= time(); return $timestamp + $expire >= time();

+ 2
- 2
common/mail/signup-html.php View File



<?php if($user->status == User::STATUS_PRODUCER): ?> <?php if($user->status == User::STATUS_PRODUCER): ?>
<p>Vous pouvez dès maintenant vous connecter à l'<a href="<?= Yii::$app->urlManagerBackend->createAbsoluteUrl(['site/index']); ?>">administration</a> pour configurer votre compte producteur.</p> <p>Vous pouvez dès maintenant vous connecter à l'<a href="<?= Yii::$app->urlManagerBackend->createAbsoluteUrl(['site/index']); ?>">administration</a> pour configurer votre compte producteur.</p>
<p>Si vous avez des questions ou si vous avez besoin d'être accompagné lors de cette étape, n'hésitez pas à me contacter en réponse à ce mail ou directement au <strong><?= Yii::$app->params['adminPhoneNumber'] ?></strong>.</p>
<p>Si vous avez des questions ou si vous avez besoin d'être accompagné lors de cette étape, n'hésitez pas à me contacter en réponse à ce mail ou directement au <strong><?= Yii::$app->parameterBag->get('adminPhoneNumber') ?></strong>.</p>
<?php else: ?> <?php else: ?>
<?php if(!is_null($producer)): ?> <?php if(!is_null($producer)): ?>
<p>Vous pouvez maintenant <a href="<?= Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => $producer->slug]); ?>">passer commande</a> chez votre producteur <strong><?= Html::encode($producer->name); ?></strong>.</p> <p>Vous pouvez maintenant <a href="<?= Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => $producer->slug]); ?>">passer commande</a> chez votre producteur <strong><?= Html::encode($producer->name); ?></strong>.</p>
<?php endif; ?> <?php endif; ?>


<p>À bientôt,<br /> <p>À bientôt,<br />
<?= Yii::$app->params['adminFirstname'] ?></p>
<?= Yii::$app->parameterBag->get('adminFirstname') ?></p>

+ 2
- 2
common/mail/signup-text.php View File

Vous pouvez dès maintenant vous connecter à l'administration pour configurer votre compte : Vous pouvez dès maintenant vous connecter à l'administration pour configurer votre compte :
<?= Yii::$app->urlManagerBackend->createAbsoluteUrl(['site/index']); ?> <?= Yii::$app->urlManagerBackend->createAbsoluteUrl(['site/index']); ?>


Si vous avez des questions ou si vous avez besoin d'être accompagné lors de cette étape, n'hésitez pas à me contacter en réponse à ce mail ou directement au <?= Yii::$app->params['adminPhoneNumber'] ?>.
Si vous avez des questions ou si vous avez besoin d'être accompagné lors de cette étape, n'hésitez pas à me contacter en réponse à ce mail ou directement au <?= Yii::$app->parameterBag->get('adminPhoneNumber'); ?>.
<?= Yii::$app->urlManagerBackend->createAbsoluteUrl(['site/index']); ?> <?= Yii::$app->urlManagerBackend->createAbsoluteUrl(['site/index']); ?>
<?php else: ?> <?php else: ?>
<?php if(!is_null($producer)): ?> <?php if(!is_null($producer)): ?>
<?php endif; ?> <?php endif; ?>


À bientôt, À bientôt,
<?= Yii::$app->params['adminFirstname'] ?>
<?= Yii::$app->parameterBag->get('adminFirstname') ?>

+ 2
- 2
common/views/matomo.php View File

_paq.push(['trackPageView']); _paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']); _paq.push(['enableLinkTracking']);
(function() { (function() {
var u="//<?= Yii::$app->params['matomoUrl']; ?>/";
var u="//<?= Yii::$app->parameterBag->get('matomoUrl'); ?>/";
_paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '<?= Yii::$app->params['matomoIdSite']; ?>']);
_paq.push(['setSiteId', '<?= Yii::$app->parameterBag->get('matomoIdSite'); ?>']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})(); })();

+ 2
- 2
frontend/controllers/SiteController.php View File

$countUsersActive = $userManager->countUsersActiveLastThreeMonths(); $countUsersActive = $userManager->countUsersActiveLastThreeMonths();
$averageOrdersPerDay = $orderManager->countGlobalUserOrdersAverageLastSevenDays(); $averageOrdersPerDay = $orderManager->countGlobalUserOrdersAverageLastSevenDays();
$averageTurnover = $orderManager->getAverageTurnoverLastThreeMonths(); $averageTurnover = $orderManager->getAverageTurnoverLastThreeMonths();
$resultMatomoApiVisitSummary = json_decode(file_get_contents(Yii::$app->params['matomoApiVisitSummaryUrl']));
$resultMatomoApiVisitSummary = json_decode(file_get_contents(Yii::$app->parameterBag->get('matomoApiVisitSummaryUrl')));
$numberVisitsMonth = $resultMatomoApiVisitSummary->nb_uniq_visitors; $numberVisitsMonth = $resultMatomoApiVisitSummary->nb_uniq_visitors;


return $this->renderPartial('_about_few_numbers', [ return $this->renderPartial('_about_few_numbers', [
$model = new ContactForm(); $model = new ContactForm();


if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if ($model->sendEmail(Yii::$app->params['adminEmail'])) {
if ($model->sendEmail(Yii::$app->parameterBag->get('adminEmail'))) {
$this->setFlash('success', 'Votre message a bien été envoyé. Nous vous répondrons dès que possible.'); $this->setFlash('success', 'Votre message a bien été envoyé. Nous vous répondrons dès que possible.');
} }
else { else {

+ 1
- 1
frontend/views/site/index.php View File

<span class="glyphicon glyphicon-plus-sign"></span> En savoir plus <span class="glyphicon glyphicon-plus-sign"></span> En savoir plus
</a> </a>
<?php if (Yii::$app->user->isGuest): ?><br /><?php endif; ?> <?php if (Yii::$app->user->isGuest): ?><br /><?php endif; ?>
<a class="btn btn-default" href="<?= \Yii::$app->params['appointmentUrl']; ?>" target="_blank">
<a class="btn btn-default" href="<?= \Yii::$app->parameterBag->get('appointmentUrl'); ?>" target="_blank">
<span class="glyphicon glyphicon-education"></span> Je demande une démo <span class="glyphicon glyphicon-education"></span> Je demande une démo
</a> </a>
<?php if (Yii::$app->user->isGuest): ?> <?php if (Yii::$app->user->isGuest): ?>

+ 1
- 1
frontend/views/site/service.php View File

href="<?= $this->getUrlManagerFrontend()->createUrl(['site/producer', 'id' => 32]); ?>"> href="<?= $this->getUrlManagerFrontend()->createUrl(['site/producer', 'id' => 32]); ?>">
<span class="glyphicon glyphicon-check"></span> Je teste le logiciel <span class="glyphicon glyphicon-check"></span> Je teste le logiciel
</a> </a>
<a class="btn btn-default" href="<?= \Yii::$app->params['appointmentUrl']; ?>"
<a class="btn btn-default" href="<?= \Yii::$app->parameterBag->get('appointmentUrl'); ?>"
target="_blank"> target="_blank">
<span class="glyphicon glyphicon-education"></span> Je demande une démo <span class="glyphicon glyphicon-education"></span> Je demande une démo
</a> </a>

Loading…
Cancel
Save