@@ -174,14 +174,13 @@ class ProducerController extends BackendController | |||
public function actionPagesize() | |||
{ | |||
$producerManager = $this->getProducerManager(); | |||
$producerCurrent = $this->getProducerCurrent(); | |||
$request = Yii::$app->request; | |||
$entity = $request->post('entity'); | |||
$pageSize = $request->post('pagesize'); | |||
$producerManager->updatePagesize($producerCurrent, $entity, $pageSize); | |||
$this->getProducerContainer()->getProducerPageSizer() | |||
->updatePagesize($producerCurrent, $entity, $pageSize); | |||
$referer = strtok(Yii::$app->request->referrer, "?"); | |||
return $this->redirect($referer); |
@@ -68,7 +68,8 @@ $this->render('_menu', [ | |||
<?= GridView::widget([ | |||
'dataProvider' => $dataProvider, | |||
'filterModel' => $searchModel, | |||
'summary' => $producerManager->getPageSizeSummary($producer, 'user', 'Utilisateurs'), | |||
'summary' => $this->getProducerContainer()->getProducerPageSizer() | |||
->getPageSizeSummary($producer, 'user', 'Utilisateurs'), | |||
'columns' => [ | |||
[ | |||
'attribute' => 'username', |
@@ -31,4 +31,9 @@ class PageSizer | |||
return $pageSizeOptionsArray; | |||
} | |||
public function isPageSizeExist(int $pageSize): bool | |||
{ | |||
return in_array($pageSize, self::$pageSizeOptions); | |||
} | |||
} |
@@ -10,9 +10,11 @@ class ProducerPageSizer extends AbstractUtils | |||
{ | |||
protected ProducerSolver $producerSolver; | |||
protected ProducerBuilder $producerBuilder; | |||
protected PageSizer $pageSizer; | |||
public function loadDependencies(): void | |||
{ | |||
$this->pageSizer = \Yii::$app->pageSizer; | |||
$this->producerSolver = $this->loadService(ProducerSolver::class); | |||
$this->producerBuilder = $this->loadService(ProducerBuilder::class); | |||
} | |||
@@ -28,16 +30,16 @@ class ProducerPageSizer extends AbstractUtils | |||
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) | |||
{ | |||
$field = $this->getPageSizeConfigName($entity); | |||
if(isset($producer->$field)) { | |||
if(isset($producer->$field) && $this->pageSizer->isPageSizeExist($pageSize)) { | |||
$producer->$field = $pageSize; | |||
$this->producerBuilder->update($producer); | |||
} |
@@ -50,4 +50,9 @@ class ProducerContainer extends AbstractContainer | |||
{ | |||
return ProducerUtils::getInstance(); | |||
} | |||
public function getProducerPageSizer(): ProducerPageSizer | |||
{ | |||
return ProducerPageSizer::getInstance(); | |||
} | |||
} |