<?
namespace front\controls;
class ShopProducer
{
  static public function products()
  {
    global $page, $lang_id;

    $producer = new \shop\Producer( \S::get( 'producer_id' ) );

    $page['show_title'] = true;
    $page['language']['title'] = $producer['name'];

    $results = \shop\Producer::producer_products( $producer['id'], $lang_id, (int) \S::get( 'bs' ) );

    if ( $results['ls'] > 1 )
    {
      $pager = \Tpl::view( 'site/pager', [
        'ls' => $results['ls'],
        'bs' => (int) \S::get( 'bs' ) ? (int) \S::get( 'bs' ) : 1,
        'page' => $page,
        'link' => 'producent/' . \S::seo( $producer['name'] )
      ] );
    }

    return \Tpl::view( 'shop-producer/products', [
      'producer' => $producer,
      'products' => $results['products'],
      'pager' => $pager
    ] );
  }

  static public function list()
  {
    global $mdb, $page;

    $page['show_title'] = true;
    $page['language']['title'] = 'Producenci';

    $rows = $mdb -> select( 'pp_shop_producer', 'id', [ 'status' => 1, 'ORDER' => [ 'name' => 'ASC' ] ] );
    if ( \S::is_array_fix( $rows ) ) foreach ( $rows as $row )
      $producers[] = new \shop\Producer( $row );

    return \Tpl::view( 'shop-producer/list', [
      'producers' => $producers
    ] );
  }
}