<?php

/**
 * @package		SP Transfer
 * @subpackage	Components
 * @copyright	SP CYEND - All rights reserved.
 * @author		SP CYEND
 * @link		http://www.cyend.com
 * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

include_once JPATH_COMPONENT . '/models/com.php';

class SPTransferModelCom_Banners extends SPTransferModelCom
{

    public function categories($ids = null)    {
        $this->destination_table = $this->factory->getTable('Category', 'JTable');        
        $this->task->state = 2; //state for success
        
        parent::categories($ids);
    }
    public function banner_clients($ids = null)    {
        JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_banners'.DS.'tables');
        $this->destination_table = $this->factory->getTable('Client', 'BannersTable');
        $this->task->query = 'SELECT * 
            FROM #__' . $this->task->name . '
            WHERE ' . $this->id . ' > 0';
        $this->task->state = 4; //state for success
        $this->items($ids);   
    }
    public function banners($ids = null)    {
        JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_banners'.DS.'tables');
        $this->destination_table = $this->factory->getTable('Banner', 'BannersTable');
        $this->task->query = 'SELECT * 
            FROM #__' . $this->task->name . '
            WHERE ' . $this->id . ' > 0';
        
        $this->items($ids);   
    }
    public function categories_fix($ids = null)    {               
        $this->destination_table = $this->factory->getTable('Category', 'JTable');        
        $this->task->state = 4; //state for success
        
        parent::categories_fix($ids);
    }
    public function banner_clients_fix($ids = null)    {
        $task = $this->task;
        $this->factory->writeLog('<h2>' . JText::_($task->extension_name) . ' - ' . JText::_($task->extension_name . '_' . $task->name) . ' - ' . JText::_('COM_SPTRANSFER_FIX') . '</h2>');
        $this->factory->writeLog('<p>' . JText::_(COM_SPTRANSFER_NOTHING_TO_TRANSFER) . '</p>');
        return;
    }
    public function banners_fix($ids = null)    {
        JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_banners'.DS.'tables');
        $this->destination_table = $this->factory->getTable('Banner', 'BannersTable');
        $this->task->query = 'SELECT * 
            FROM #__' . $this->task->name . '
            WHERE catid > 0';
        
        $this->items_fix($ids);
    }
}
