Browse Source

[Administration] Utilisateurs > liste : configuration du nombre d'utilisateurs affichés par page

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
10383c4b6a
5 changed files with 19 additions and 7 deletions
  1. +2
    -3
      backend/controllers/ProducerController.php
  2. +2
    -1
      backend/views/user/index.php
  3. +5
    -0
      common/components/PageSizer.php
  4. +5
    -3
      common/logic/Producer/Producer/Service/ProducerPageSizer.php
  5. +5
    -0
      common/logic/Producer/Producer/Wrapper/ProducerContainer.php

+ 2
- 3
backend/controllers/ProducerController.php View File



public function actionPagesize() public function actionPagesize()
{ {
$producerManager = $this->getProducerManager();
$producerCurrent = $this->getProducerCurrent(); $producerCurrent = $this->getProducerCurrent();
$request = Yii::$app->request; $request = Yii::$app->request;

$entity = $request->post('entity'); $entity = $request->post('entity');
$pageSize = $request->post('pagesize'); $pageSize = $request->post('pagesize');


$producerManager->updatePagesize($producerCurrent, $entity, $pageSize);
$this->getProducerContainer()->getProducerPageSizer()
->updatePagesize($producerCurrent, $entity, $pageSize);


$referer = strtok(Yii::$app->request->referrer, "?"); $referer = strtok(Yii::$app->request->referrer, "?");
return $this->redirect($referer); return $this->redirect($referer);

+ 2
- 1
backend/views/user/index.php View File

<?= GridView::widget([ <?= GridView::widget([
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'filterModel' => $searchModel, 'filterModel' => $searchModel,
'summary' => $producerManager->getPageSizeSummary($producer, 'user', 'Utilisateurs'),
'summary' => $this->getProducerContainer()->getProducerPageSizer()
->getPageSizeSummary($producer, 'user', 'Utilisateurs'),
'columns' => [ 'columns' => [
[ [
'attribute' => 'username', 'attribute' => 'username',

+ 5
- 0
common/components/PageSizer.php View File

return $pageSizeOptionsArray; return $pageSizeOptionsArray;
} }


public function isPageSizeExist(int $pageSize): bool
{
return in_array($pageSize, self::$pageSizeOptions);
}

} }

+ 5
- 3
common/logic/Producer/Producer/Service/ProducerPageSizer.php View File

{ {
protected ProducerSolver $producerSolver; protected ProducerSolver $producerSolver;
protected ProducerBuilder $producerBuilder; protected ProducerBuilder $producerBuilder;
protected PageSizer $pageSizer;


public function loadDependencies(): void public function loadDependencies(): void
{ {
$this->pageSizer = \Yii::$app->pageSizer;
$this->producerSolver = $this->loadService(ProducerSolver::class); $this->producerSolver = $this->loadService(ProducerSolver::class);
$this->producerBuilder = $this->loadService(ProducerBuilder::class); $this->producerBuilder = $this->loadService(ProducerBuilder::class);
} }
return $this->producerSolver->getConfig($pageSizeConfig, $producer) ?: PageSizer::DEFAULT_PAGE_SIZE ; return $this->producerSolver->getConfig($pageSizeConfig, $producer) ?: PageSizer::DEFAULT_PAGE_SIZE ;
} }


public function getPageSizeSummary(Producer $producer, string $entity, string $labelEntity)
public function getPageSizeSummary(Producer $producer, string $entity, string $labelEntity): string
{ {
return \Yii::$app->pageSizer->getForm($entity, $labelEntity, $this->getPageSize($producer, $entity));
return $this->pageSizer->getForm($entity, $labelEntity, $this->getPageSize($producer, $entity));
} }


public function updatePagesize(Producer $producer, string $entity, int $pageSize) public function updatePagesize(Producer $producer, string $entity, int $pageSize)
{ {
$field = $this->getPageSizeConfigName($entity); $field = $this->getPageSizeConfigName($entity);


if(isset($producer->$field)) {
if(isset($producer->$field) && $this->pageSizer->isPageSizeExist($pageSize)) {
$producer->$field = $pageSize; $producer->$field = $pageSize;
$this->producerBuilder->update($producer); $this->producerBuilder->update($producer);
} }

+ 5
- 0
common/logic/Producer/Producer/Wrapper/ProducerContainer.php View File

{ {
return ProducerUtils::getInstance(); return ProducerUtils::getInstance();
} }

public function getProducerPageSizer(): ProducerPageSizer
{
return ProducerPageSizer::getInstance();
}
} }

Loading…
Cancel
Save