<?php

/**
 * SEO Mega Pack
 * 
 * @author marsilea15 <marsilea15@gmail.com>
 */

require_once VQMod::modCheck( DIR_SYSTEM . 'library/smk/extensions/abstract_generator.php' );

class SeoMegaPack_SeoImagesGenerator extends SeoMegaPack_AbstractGenerator {
	
	/**
	 * @var array 
	 */
	protected $_tags			= array(
		'{product_name}'	=> 'product_name',
		'{category}'		=> 'category_name',
		'{model}'			=> 'model',
		'{brand}'			=> 'brand_name',
		'{sku}'				=> 'sku',
		'{upc}'				=> 'upc'
	);
	
	/**
	 * @var string
	 */
	protected $_name		= 'seo_images_generator';
	protected $_shortName	= 'si';
	
	/**
	 * @var string
	 */
	protected $_title		= 'SEO Images';
	
	/**
	 * @var int
	 */
	protected $_sort		= 0.7;
	
	/**
	 * @var bool
	 */
	protected $_previewUrl		= false;
	
	/**
	 * @var bool
	 */
	protected $_generateUrl		= false;	
	
	/**
	 * @var string 
	 */
	protected $_group		= 'products';
	
	/**
	 * @var string 
	 */
	protected $_icon		= 'picture';
	
	/**
	 * @var string 
	 */
	protected $_version		= '2';
	
	/**
	 * @return void
	 */
	public function clear( $mode = NULL, $onlyAutoGenerated = false ) {
		$this->db->query("
			DELETE FROM
				" . DB_PREFIX . "smp_image
		");
		
		$this->cache->delete('smp_seo_image');
		$this->cache->delete('smp_seo_image_id');
	}
	
	/**
	 * @return string
	 */
	public function description() {
		$desc = '';
		
		if( parent::description() ) {
			$desc .= parent::description();
			$desc .= '<br /><br />';
		}
		$desc .= 'Remember! When you make changes in the parameter list, click "Clear"';
		
		return $desc;
	}
	
	/**
	 * @return int
	 */
	public function getParams() {
		$params = parent::getParams();
		
		return $params;
	}
	
	/**
	 * @return void
	 */
	public function install() {
		parent::install();
		
		$this->db->query('
			CREATE TABLE IF NOT EXISTS `' . DB_PREFIX . 'smp_image` (
				`smp_image_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
				`file` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
				`ext` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
				`slug` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
				`language_id` int(11) NOT NULL,
				`gn` char(5) NOT NULL,
				`gi` char(5) NOT NULL,
				PRIMARY KEY (`smp_image_id`)
			) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1');
	}
	
	public function update() {
		if( version_compare( $this->config->get( 'smp_' . $this->shortName() . '_is_install' ), '1.0.3', '<' ) ) {
			$this->addColumn('gn', 'char(5) COLLATE utf8_unicode_ci NOT NULL', 'smp_image');
			$this->addColumn('gi', 'char(5) COLLATE utf8_unicode_ci NOT NULL', 'smp_image');
		}
		
		$this->install();
	}
	
	/**
	 * @return void
	 */
	public function uninstall() {
		parent::uninstall();
		
		$this->cache->delete('smp_seo_image');
		$this->cache->delete('smp_seo_image_id');
		
		$this->db->query('DROP TABLE IF EXISTS `' . DB_PREFIX . 'smp_image`');
	}
}