<?php
namespace admin\controls;
class GlobelusAdverts
{  
  public static function disabled_by_admin() {
    \admin\factory\GlobelusAdverts::disabled_by_admin( \S::get( 'advert_id' ), \S::get( 'disabled_by_admin' ) );
    exit;
  }
  
  public static function answers()
  {
    return \Tpl::view( 'globelus-adverts/anwers' );
  }
  
  public static function answers_list()
  {
    return \admin\view\GlobelusAdverts::answers_list(
              \admin\factory\GlobelusAdverts::advert_details( \S::get( 'id' ) ),
              \admin\factory\GlobelusAdverts::answers_list( \S::get( 'id' ) )
            );
  }
  
  public static function advert_preview()
  {
    return \Tpl::view( 'globelus-adverts/advert-preview', [
      'advert' => \admin\factory\GlobelusAdverts::advert_details( \S::get( 'id' ) ),
      'countries' => \front\factory\Globelus::countries(),
      'categories' => \front\factory\GlobelusAdverts::categories(),
      'voivodeships' => \front\factory\Globelus::get_voivodeships_list()
    ] );
  }
  
  public static function advert_delete()
  {
    if ( \admin\factory\GlobelusAdverts::advert_delete( \S::get( 'id' ) ) )
      \S::alert( 'Ogłoszenie zostało usunięte.' );

    header( 'Location: /admin/globelus_adverts/main_view/' );
    exit;
  }
  
  public static function main_view()
  {
    \admin\factory\GlobelusAdverts::update_active_to();
    
    return \admin\view\GlobelusAdverts::main_view(
              \admin\factory\GlobelusAdverts::firms_list()
            );
  }
}
