Просмотр исходного кода

[Administration] Gestion de l'affichage des messages d'alerte

feature/rotating_product
Guillaume Bourgeois 5 месяцев назад
Родитель
Сommit
0d1c4d9591
16 измененных файлов: 166 добавлений и 5 удалений
  1. +8
    -0
      backend/controllers/DevelopmentController.php
  2. +6
    -1
      backend/controllers/ProducerController.php
  3. +1
    -1
      backend/forms/AdminSettingsForm.php
  4. +18
    -0
      backend/views/development/index.php
  5. +3
    -1
      backend/views/layouts/content.php
  6. +1
    -0
      backend/views/producer-admin/_form.php
  7. +3
    -0
      common/views/alert_message.php
  8. +26
    -0
      console/migrations/m240617_090650_alter_column_producer_option_display_message_new_opendistrib_version.php
  9. +26
    -0
      console/migrations/m240617_092952_add_colmun_producer_alert_message_read_at.php
  10. +17
    -1
      domain/Producer/Producer/Producer.php
  11. +6
    -0
      domain/Producer/Producer/ProducerManager.php
  12. +6
    -0
      domain/Producer/Producer/ProducerModule.php
  13. +25
    -0
      domain/Producer/Producer/ProducerResolver.php
  14. +1
    -1
      domain/Setting/Setting.php
  15. +2
    -0
      domain/Setting/SettingDetails/Admin/AdminSettingDefinition.php
  16. +17
    -0
      domain/Setting/SettingDetails/Admin/AlertMessage/AdminAlertMessageUpdatedAtSetting.php

+ 8
- 0
backend/controllers/DevelopmentController.php Просмотреть файл

@@ -92,4 +92,12 @@ class DevelopmentController extends BackendController
'versionsArray' => $versionsRenderArray
]);
}

public function actionUpdateDisplayMessageNewSoukeVersion(int $displayMessage)
{
$producer = $this->getProducerCurrent();
$producer->option_display_message_new_opendistrib_version = (bool) $displayMessage;
$producer->save();
return $this->redirect('index');
}
}

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

@@ -177,6 +177,12 @@ class ProducerController extends BackendController
return $this->redirect(\Yii::$app->request->referrer);
}

public function actionUpdateAlertMessageReadAt()
{
$this->getProducerModule()->getManager()->readAlertMessage($this->getProducerCurrent());
return $this->redirect(\Yii::$app->request->referrer);
}

public function actionPagesize()
{
$producerCurrent = $this->getProducerCurrent();
@@ -193,5 +199,4 @@ class ProducerController extends BackendController
$referer = strtok(Yii::$app->request->referrer, "?");
return $this->redirect($referer);
}

}

+ 1
- 1
backend/forms/AdminSettingsForm.php Просмотреть файл

@@ -22,7 +22,7 @@ class AdminSettingsForm extends Model
$rulesArray = [];
$typesArray = [
'string' => ['string', 'text'],
'date' => ['date'],
'date' => ['safe'],
'boolean' => ['boolean'],
'integer' => ['integer'],
'double' => ['double', 'float'],

+ 18
- 0
backend/views/development/index.php Просмотреть файл

@@ -47,6 +47,8 @@ use common\helpers\GlobalParam;
$this->setTitle('Développement');
$this->addBreadcrumb($this->getTitle());

$producer = GlobalParam::getCurrentProducer();

?>

<div class="development-index">
@@ -69,6 +71,22 @@ $this->addBreadcrumb($this->getTitle());
</div>
</div>
<div class="col-md-4">

<div id="panel-participate" class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Être prévenu des mises à jour</h3>
</div>
<div class="panel-body">
<p>
Afficher un message d'alerte quand une nouvelle version de <em>Souke</em> est mise en ligne.
</p>
<div class="btn-group" role="group">
<a href="<?= Yii::$app->urlManager->createUrl(['development/update-display-message-new-souke-version', 'displayMessage' => 1]) ?>" class="btn <?= $producer->option_display_message_new_opendistrib_version ? 'btn-success' : 'btn-default' ?>">Oui</a>
<a href="<?= Yii::$app->urlManager->createUrl(['development/update-display-message-new-souke-version', 'displayMessage' => 0]) ?>" class="btn <?= $producer->option_display_message_new_opendistrib_version ? 'btn-default' : 'btn-danger' ?>">Non</a>
</div>
</div>
</div>

<div id="panel-participate" class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Participer</h3>

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

@@ -44,6 +44,7 @@ use common\helpers\GlobalParam;
$producerModule = $this->getProducerModule();
$adminSettingBag = $this->getSettingModule()->getAdminSettingBag();
$sharedPointSaleModule = $this->getSharedPointSaleModule();
$producer = GlobalParam::getCurrentProducer();

?>
<div class="content-wrapper">
@@ -83,11 +84,12 @@ $sharedPointSaleModule = $this->getSharedPointSaleModule();
<section class="content">

<?php echo $this->renderFile('@common/views/alert_message.php', [
'display' => $adminSettingBag->get('adminAlertMessageDisplay'),
'display' => $adminSettingBag->get('adminAlertMessageDisplay') && $producerModule->getResolver()->isAlertMessageDisplayed($producer),
'type' => $adminSettingBag->get('adminAlertMessageType'),
'title' => $adminSettingBag->get('adminAlertMessageTitle'),
'icon' => $adminSettingBag->get('adminAlertMessageIcon'),
'message' => $adminSettingBag->get('adminAlertMessage'),
'buttonClose' => true
]) ?>

<?php $producer = GlobalParam::getCurrentProducer(); ?>

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

@@ -65,6 +65,7 @@ use yii\widgets\ActiveForm;
<?= $form->field($model, 'code')->label('Code d\'accès') ?>
<?= $form->field($model, 'admin_comment')->textarea(['rows' => 7]) ?>
<?= $form->field($model, 'is_new')->checkbox() ?>
<?= $form->field($model, 'latest_version_opendistrib') ?>
</div>
</div>
</div>

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

@@ -27,5 +27,8 @@ use yii\helpers\Html;
<?= nl2br($message); ?>
<?php endif; ?>
</p>
<?php if(isset($buttonClose) && $buttonClose): ?>
<a href="<?= Yii::$app->urlManager->createUrl(['producer/update-alert-message-read-at']) ?>" class="close"><span aria-hidden="true">×</span></a>
<?php endif; ?>
</div>
<?php endif; ?>

+ 26
- 0
console/migrations/m240617_090650_alter_column_producer_option_display_message_new_opendistrib_version.php Просмотреть файл

@@ -0,0 +1,26 @@
<?php

use yii\db\Migration;
use yii\db\Schema;

/**
* Class m240617_090650_alter_column_producer_option_display_message_new_opendistrib_version
*/
class m240617_090650_alter_column_producer_option_display_message_new_opendistrib_version extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->alterColumn('producer', 'option_display_message_new_opendistrib_version', Schema::TYPE_BOOLEAN.' DEFAULT 1');
}

/**
* {@inheritdoc}
*/
public function safeDown()
{

}
}

+ 26
- 0
console/migrations/m240617_092952_add_colmun_producer_alert_message_read_at.php Просмотреть файл

@@ -0,0 +1,26 @@
<?php

use yii\db\Migration;
use yii\db\Schema;

/**
* Class m240617_092952_add_colmun_producer_alert_message_read_at
*/
class m240617_092952_add_colmun_producer_alert_message_read_at extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('producer', 'alert_message_read_at', Schema::TYPE_DATETIME);
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('producer', 'alert_message_read_at');
}
}

+ 17
- 1
domain/Producer/Producer/Producer.php Просмотреть файл

@@ -359,7 +359,8 @@ class Producer extends ActiveRecordCommon
'option_dashboard_date_start',
'option_dashboard_date_end',
'option_leave_period_start',
'option_leave_period_end'
'option_leave_period_end',
'alert_message_read_at'
], 'safe'],
[
['option_leave_period_start', 'option_leave_period_end'],
@@ -599,6 +600,21 @@ class Producer extends ActiveRecordCommon
return $this;
}

public function getAlertMessageReadAt(): ?\DateTime
{
if($this->alert_message_read_at) {
return new \DateTime($this->alert_message_read_at);
}

return null;
}

public function setAlertMessageReadAt(\DateTime $alertMessageReadAt): self
{
$this->alert_message_read_at = $alertMessageReadAt->format('Y-m-d H:i:s');
return $this;
}

/*
* Relations
*/

+ 6
- 0
domain/Producer/Producer/ProducerManager.php Просмотреть файл

@@ -17,6 +17,12 @@ class ProducerManager extends AbstractService implements ManagerInterface
$this->producerRepository = $this->loadService(ProducerRepository::class);
}

public function readAlertMessage(Producer $producer)
{
$producer->setAlertMessageReadAt(new \DateTime());
return $producer->save();
}

public function sendEmailNewProducer(Producer $producer): void
{
\Yii::$app->mailerService->sendAdmin(

+ 6
- 0
domain/Producer/Producer/ProducerModule.php Просмотреть файл

@@ -14,6 +14,7 @@ class ProducerModule extends AbstractModule
ProducerRepository::class,
ProducerBuilder::class,
ProducerNotifier::class,
ProducerResolver::class,
ProducerManager::class,
ProducerPageSizer::class,
DolibarrProducerUtils::class,
@@ -46,6 +47,11 @@ class ProducerModule extends AbstractModule
return ProducerNotifier::getInstance();
}

public function getResolver(): ProducerResolver
{
return ProducerResolver::getInstance();
}

public function getUtils(): ProducerManager
{
return ProducerManager::getInstance();

+ 25
- 0
domain/Producer/Producer/ProducerResolver.php Просмотреть файл

@@ -0,0 +1,25 @@
<?php

namespace domain\Producer\Producer;

use domain\_\AbstractResolver;
use domain\Setting\AdminSettingBag;

class ProducerResolver extends AbstractResolver
{
public function isAlertMessageDisplayed(Producer $producer): bool
{
// @TODO : modifier le chargement de cette classe quand la hiérarchie des services sera revue
$alertMessageUpdatedAt = AdminSettingBag::getInstance()->get('adminAlertMessageUpdatedAt');
$alertMessageReadAt = $producer->getAlertMessageReadAt();

if($alertMessageUpdatedAt) {
$alertMessageUpdatedAt = new \DateTime($alertMessageUpdatedAt);
if($alertMessageReadAt && $alertMessageReadAt >= $alertMessageUpdatedAt) {
return false;
}
}

return true;
}
}

+ 1
- 1
domain/Setting/Setting.php Просмотреть файл

@@ -62,7 +62,7 @@ class Setting extends ActiveRecordCommon
[['id_producer'], 'exist', 'skipOnError' => true, 'targetClass' => Producer::class, 'targetAttribute' => ['id_producer' => 'id']],
[['name', 'string', 'text'], 'string'],
[['name','string'], 'string', 'max' => 255],
[['date'], 'date', 'format' => 'php:Y-m-d'],
[['date'], 'safe'],
[['integer'], 'integer'],
[['float', 'double'], 'number'],
[['boolean'], 'boolean'],

+ 2
- 0
domain/Setting/SettingDetails/Admin/AdminSettingDefinition.php Просмотреть файл

@@ -7,6 +7,7 @@ use domain\Setting\SettingDetails\Admin\AlertMessage\AdminAlertMessageIconSettin
use domain\Setting\SettingDetails\Admin\AlertMessage\AdminAlertMessageSetting;
use domain\Setting\SettingDetails\Admin\AlertMessage\AdminAlertMessageTitleSetting;
use domain\Setting\SettingDetails\Admin\AlertMessage\AdminAlertMessageTypeSetting;
use domain\Setting\SettingDetails\Admin\AlertMessage\AdminAlertMessageUpdatedAtSetting;
use domain\Setting\SettingDetails\Admin\AlertMessage\AdminSupportAlertMessageDisplaySetting;
use domain\Setting\SettingDetails\Admin\AlertMessage\AdminSupportAlertMessageIconSetting;
use domain\Setting\SettingDetails\Admin\AlertMessage\AdminSupportAlertMessageSetting;
@@ -51,6 +52,7 @@ class AdminSettingDefinition extends SettingDefinition
new AdminAlertMessageIconSetting(),
new AdminAlertMessageTitleSetting(),
new AdminAlertMessageSetting(),
new AdminAlertMessageUpdatedAtSetting(),
],
self::SUBSECTION_ALERT_MESSAGE_SUPPORT => [
new AdminSupportAlertMessageDisplaySetting(),

+ 17
- 0
domain/Setting/SettingDetails/Admin/AlertMessage/AdminAlertMessageUpdatedAtSetting.php Просмотреть файл

@@ -0,0 +1,17 @@
<?php

namespace domain\Setting\SettingDetails\Admin\AlertMessage;

use domain\Setting\SettingDetails\AbstractSettingDetail;

class AdminAlertMessageUpdatedAtSetting extends AbstractSettingDetail
{
public function __construct()
{
$this
->setName('adminAlertMessageUpdatedAt')
->setLabel("Date de mise à jour")
->setTypeString()
->setFormTypeInput();
}
}

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