48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
namespace admin\Controllers;
|
|
|
|
use Domain\Product\ProductRepository;
|
|
|
|
class ProductArchiveController
|
|
{
|
|
private ProductRepository $productRepository;
|
|
|
|
public function __construct(ProductRepository $productRepository)
|
|
{
|
|
$this->productRepository = $productRepository;
|
|
}
|
|
|
|
public function list(): string
|
|
{
|
|
$current_page = \S::get_session( 'archive_products_list_current_page' );
|
|
|
|
if ( !$current_page ) {
|
|
$current_page = 1;
|
|
\S::set_session( 'archive_products_list_current_page', $current_page );
|
|
}
|
|
|
|
$query = \S::get_session( 'archive_products_list_query' );
|
|
$query_array = [];
|
|
if ( $query ) {
|
|
parse_str( $query, $query_array );
|
|
}
|
|
|
|
return \Tpl::view( 'product_archive/products-list', [
|
|
'current_page' => $current_page,
|
|
'query_array' => $query_array,
|
|
'pagination_max' => ceil( \admin\factory\ShopProduct::count_product( [ 'archive' => 1 ] ) / 10 )
|
|
] );
|
|
}
|
|
|
|
public function unarchive(): void
|
|
{
|
|
if ( $this->productRepository->unarchive( (int) \S::get( 'product_id' ) ) )
|
|
\S::alert( 'Produkt został przywrócony z archiwum.' );
|
|
else
|
|
\S::alert( 'Podczas przywracania produktu z archiwum wystąpił błąd. Proszę spróbować ponownie' );
|
|
|
|
header( 'Location: /admin/product_archive/products_list/' );
|
|
exit;
|
|
}
|
|
}
|