<?php
namespace factory;
class Campaigns
{
  static public function get_clients()
  {
    global $mdb;
    return $mdb -> select( 'clients', '*', [ 'ORDER' => [ 'name' => 'ASC' ] ] );
  }

  static public function get_campaigns_list( $client_id )
  {
    global $mdb;
    return $mdb -> select( 'campaigns', '*', [ 'client_id' => $client_id, 'ORDER' => [ 'campaign_name' => 'ASC' ] ] );
  }

  static public function get_campaign_history_data( $campaign_id, $start, $length, $revert = false )
  {
    global $mdb;
    if ( $revert )
      return $mdb -> select( 'campaigns_history', '*', [ 'campaign_id' => $campaign_id, 'LIMIT' => [ $start, $length ], 'ORDER' => [ 'date_add' => 'ASC' ] ] );
    else
      return $mdb -> select( 'campaigns_history', '*', [ 'campaign_id' => $campaign_id, 'LIMIT' => [ $start, $length ], 'ORDER' => [ 'date_add' => 'DESC' ] ] );
  }

  static public function get_records_total_campaign_history_data( $campaign_id )
  {
    global $mdb;
    return $mdb -> count( 'campaigns_history', [ 'campaign_id' => $campaign_id ] );
  }
}