Your IP : 216.73.216.170


Current Path : /var/www/iplanru/data/www/i-plan.ru/administrator/components/com_pay/tables/
Upload File :
Current File : /var/www/iplanru/data/www/i-plan.ru/administrator/components/com_pay/tables/pay_discounts.php

<?php

// No direct access
defined( '_JEXEC' ) or die;

/**
 * Object Class Table
 * @author Aleks.Denezh
 */
class TablePay_Discounts extends JTable
{

	/**
	 * Class constructor
	 * @param Object $db (database link object)
	 */
	function __construct( &$db )
	{
		parent::__construct( '#__pay_discounts', 'id', $db );
	}

	/**
	 * Method for loading data into the object field
	 * @param Array $array (Featured in the field of data)
	 * @param String $ignore
	 * @return Boolean result
	 */
	public function bind( $array, $ignore = '' )
	{
		//$app = JFactory::getApplication();
		//$componentParams = $app->getParams('com_pay');
		$componentParams = JComponentHelper::getParams('com_pay');
		$discount = $componentParams->get('discount', '1');
		$duration = $componentParams->get('duration', '0');
		
		$date_finish = date('Y-m-d H:i:s', strtotime ('+'.$duration.' day'));
		
		if ( isset( $array['rules'] ) && is_array( $array['rules'] ) ) {
			$rules = new JAccessRules( $array['rules'] );
			$this->setRules( $rules );
		}

		if ( isset( $array['params'] ) && is_array( $array['params'] ) )
		{
			$registry = new JRegistry;
			$registry->loadArray( $array['params'] );
			$array['params'] = (string) $registry;
		}
		
		if ( $array['code']=='' ) {
            $array['code'] = $this->getcode(date( 'Y-m-d H:i:s' ));
        }
        
        if ( $array['date_issue']=='' or $array['date_issue']=='0000-00-00 00:00:00' ) {
            $array['date_issue'] = date( 'Y-m-d H:i:s' );
        }
        
        if ( $array['date_finish']=='' or $array['date_finish']=='0000-00-00 00:00:00' ) {
            $array['date_finish'] = $date_finish;
        }
        
        if ( $array['discount']=='' or $array['discount']=='1' or $array['discount']=='0' ) {
            $array['discount'] = $discount;
        }
        
		return parent::bind( $array, $ignore );
	}
	
	

	
	protected function getcode($str){
		$str1=strtoupper(md5(time().$str));
		$str2=strtoupper(md5(time().$str1));
		$str3=strtoupper(md5(time().$str2));
		$str4=strtoupper(md5(time().$str3));
		return substr($str1,0,4).'-'.substr($str2,0,4).'-'.substr($str3,0,4).'-'.substr($str4,0,5);
	}
	
	
	protected function _getAssetName()
    {
        $k = $this->_tbl_key;
        return 'com_pay.discount.' . ( int )$this->$k;
    }
	
	protected function _getAssetParentId( $table = null, $id = null )
    {
        $asset = JTable::getInstance( 'Asset' );
        $asset->loadByName( 'com_pay' );
        return $asset->id;
    }
    
    
}