| Current Path : /var/www/iplanru/data/www/i-plan.ru/components/com_pay/models/ |
| Current File : /var/www/iplanru/data/www/i-plan.ru/components/com_pay/models/discount.php |
<?php
// No direct access
defined( '_JEXEC' ) or die;
/**
* Model for edit/create current element
* @author kirdinyuri
*/
class PayModelDiscount extends JModelAdmin
{
/**
* @var JInput|null
*/
private $input;
/**
* classs constructor
* @param array $config
*/
public function __construct( $config = array() )
{
parent::__construct( $config );
$this->input = JFactory::getApplication()->input;
}
/**
* Method of loading the current form
* @param Array $data
* @param Boolean $loadData
* @return Object form data
*/
public function getForm( $data = array(), $loadData = true )
{
$form = $this->loadForm( '', 'discount', array( 'control' => 'jform', 'load_data' => $loadData ) );
if ( empty( $form ) ) {
return false;
}
$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'));
$str=time();
$str1=strtoupper(md5(time().$str));
$str2=strtoupper(md5(time().$str1));
$str3=strtoupper(md5(time().$str2));
$str4=strtoupper(md5(time().$str3));
$itog = substr($str1,0,4).'-'.substr($str2,0,4).'-'.substr($str3,0,4).'-'.substr($str4,0,5);
$form->setValue( 'code', null, $itog );
$user =& JFactory::getUser();
$form->setValue( 'manager', null, $user->id );
$form->setValue( 'date_issue', null, date( 'Y-m-d H:i:s' ) );
$form->setValue( 'date_finish', null, $date_finish );
$form->setValue( 'discount', null, $discount );
return $form;
}
/**
* Method of loading table for current item
* @param Sting $type (name table)
* @param String $prefix (prefix table)
* @param Array $config
* @return Object (The object reference table)
*/
public function getTable( $type = 'pay_discounts', $prefix = 'Table', $config = array() )
{
return JTable::getInstance( $type, $prefix, $config );
}
/**
* Method of loading data to form
* @return Object
*/
protected function loadFormData()
{
$data = JFactory::getApplication()->getUserState( 'com_pay.edit.discount.data', array() );
if ( empty( $data ) ) {
$data = $this->getItem();
}
return $data;
}
/**
* save data
* @param array $data
* @return bool
*/
public function save( $data )
{
return parent::save( $data );
}
}