* @copyright Project-Pro * @license Proprietary - paid license */ if (!defined('_PS_VERSION_')) { exit; } class CustomFeatureTabRule extends ObjectModel { public $id_feature; public $id_feature_value; public $position; public $active; public $title; public $content; public $date_add; public $date_upd; public static $definition = array( 'table' => 'custom_feature_tab', 'primary' => 'id_custom_feature_tab', 'multilang' => true, 'fields' => array( 'id_feature' => array( 'type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true, ), 'id_feature_value' => array( 'type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true, ), 'position' => array( 'type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', ), 'active' => array( 'type' => self::TYPE_BOOL, 'validate' => 'isBool', ), 'date_add' => array( 'type' => self::TYPE_DATE, 'validate' => 'isDate', ), 'date_upd' => array( 'type' => self::TYPE_DATE, 'validate' => 'isDate', ), // Lang fields 'title' => array( 'type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 255, ), 'content' => array( 'type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml', ), ), ); /** * Get active rules matching product features. * * @param array $productFeatures Array from Product::getFeaturesStatic * @param int $idLang Language ID * @return array */ public static function getMatchingRules(array $productFeatures, $idLang) { if (empty($productFeatures)) { return array(); } $conditions = array(); foreach ($productFeatures as $feat) { $conditions[] = '(' . (int) $feat['id_feature'] . ', ' . (int) $feat['id_feature_value'] . ')'; } $sql = 'SELECT cft.*, cftl.`title`, cftl.`content` FROM `' . _DB_PREFIX_ . 'custom_feature_tab` cft LEFT JOIN `' . _DB_PREFIX_ . 'custom_feature_tab_lang` cftl ON cft.`id_custom_feature_tab` = cftl.`id_custom_feature_tab` AND cftl.`id_lang` = ' . (int) $idLang . ' WHERE cft.`active` = 1 AND (cft.`id_feature`, cft.`id_feature_value`) IN (' . implode(',', $conditions) . ') ORDER BY cft.`position` ASC, cft.`id_custom_feature_tab` ASC'; return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); } }