File: /home4/cca63905/www/nueva/modules/roja45quotationsprofree/classes/QuotationStatus.php
<?php
/**
* QuotationStatus.
*
* @author Roja45 <support@roja45.com>
* @copyright 2016 Roja45
* @license license.txt
* @category QuotationStatus
*
* 2016 ROJA45 - All rights reserved.
*
* DISCLAIMER
* Changing this file will render any support provided by us null and void.
*/
/**
* QuotationStatus.
*
* @author Roja45
* @copyright 2016 Roja45
* @license license.txt
* @category Class
*
* 2016 ROJA45 - All rights reserved.
*
* DISCLAIMER
* Changing this file will render any support provided by us null and void.
*/
class QuotationStatus extends ObjectModel
{
public static $RCVD = 'RCVD';
public static $SENT = 'SENT';
public static $ACPT = 'ACPT';
public static $CART = 'CART';
public static $ORDR = 'ORDR';
public static $CLSD = 'CLSD';
public static $INCP = 'INCP';
public static $DLTD = 'DLTD';
public static $CUSR = 'CUSR';
public static $MESG = 'MESG';
public static $CCLD = 'CCLD';
public static $CORD = 'CORD';
public static $NWQT = 'NWQT';
/** @var string Name */
public $status;
/** @var string Template name if there is any e-mail to send */
public $answer_template;
/** @var bool Send an e-mail to customer ? */
public $send_email;
/** @var bool Send an e-mail to customer ? */
public $notify_admin;
public $code;
/** @var string Display state in the specified color */
public $color;
public $unremovable;
/**
* @see ObjectModel::$definition
*/
public static $definition = array(
'table' => 'roja45_quotationspro_status',
'primary' => 'id_roja45_quotation_status',
'multilang' => true,
'fields' => array(
'send_email' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'notify_admin' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'code' => array('type' => self::TYPE_STRING, 'validate' => 'isModuleName'),
'color' => array('type' => self::TYPE_STRING, 'validate' => 'isColor'),
'unremovable' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'answer_template' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 64),
/* Lang fields */
'status' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 64),
),
);
public function add($auto_date = true, $null_values = false)
{
$status = QuotationStatus::getQuotationStatusByType($this->code);
if (count($status)) {
throw new PrestaShopException('Quotation status code is not unique.');
}
return parent::add($auto_date, $null_values);
}
/**
* Get all available order statuses.
*
* @param int $id_lang Language id for status name
*
* @return array Order statuses
*/
public static function getQuotationStates($id_lang)
{
$cache_id = 'QuotationStatus::getQuotationStates'.(int) $id_lang;
if (!Cache::isStored($cache_id)) {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT *
FROM `'._DB_PREFIX_.'roja45_quotationspro_status` qs
LEFT JOIN `'._DB_PREFIX_.'roja45_quotationspro_status_lang` qsl ON (qs.`id_roja45_quotation_status` = qsl.`id_roja45_quotation_status` AND qsl.`id_lang` = '.(int) $id_lang.')
ORDER BY qs.`id_roja45_quotation_status` ASC');
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
}
public static function getQuotationStatusByType($status_code)
{
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT qs.id_roja45_quotation_status
FROM `'._DB_PREFIX_.'roja45_quotationspro_status` qs
WHERE qs.code = "'.pSQL($status_code).'"');
return $result;
}
public static function isStatus($id_roja45_quotation_status, $status)
{
$quotation_status = new QuotationStatus($id_roja45_quotation_status);
return ($quotation_status->code = $status) ? true : false;
}
public function isRemovable()
{
return !($this->unremovable);
}
}