当前位置: 首页>>代码示例>>PHP>>正文


PHP Configuration::sqlRestriction方法代码示例

本文整理汇总了PHP中Configuration::sqlRestriction方法的典型用法代码示例。如果您正苦于以下问题:PHP Configuration::sqlRestriction方法的具体用法?PHP Configuration::sqlRestriction怎么用?PHP Configuration::sqlRestriction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Configuration的用法示例。


在下文中一共展示了Configuration::sqlRestriction方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sqlRestriction

 protected static function sqlRestriction($id_shop_group, $id_shop)
 {
     ConfigurationKPI::setKpiDefinition();
     $r = parent::sqlRestriction($id_shop_group, $id_shop);
     ConfigurationKPI::unsetKpiDefinition();
     return $r;
 }
开发者ID:prestanesia,项目名称:PrestaShop,代码行数:7,代码来源:ConfigurationKPI.php

示例2: updateValue

    /**
     * Update configuration key and value into database (automatically insert if key does not exist)
     *
     * @param string $key Key
     * @param mixed $values $values is an array if the configuration is multilingual, a single string else.
     * @param boolean $html Specify if html is authorized in value
     * @param int $id_shop_group
     * @param int $id_shop
     * @return boolean Update result
     */
    public static function updateValue($key, $values, $html = false, $id_shop_group = null, $id_shop = null)
    {
        if (!Validate::isConfigName($key)) {
            die(Tools::displayError());
        }
        if ($id_shop === null) {
            $id_shop = Shop::getContextShopID(true);
        }
        if ($id_shop_group === null) {
            $id_shop_group = Shop::getContextShopGroupID(true);
        }
        if (!is_array($values)) {
            $is_i18n = false;
            $values = array($values);
        } else {
            $is_i18n = true;
        }
        $result = true;
        foreach ($values as $lang => $value) {
            $stored_value = Configuration::get($key, $lang, $id_shop_group, $id_shop);
            // if there isn't a $stored_value, we must insert $value
            if (!is_numeric($value) && $value === $stored_value || is_numeric($value) && $value == $stored_value && Configuration::hasKey($key, $lang)) {
                continue;
            }
            // If key already exists, update value
            if (Configuration::hasKey($key, $lang, $id_shop_group, $id_shop)) {
                if (!$lang) {
                    // Update config not linked to lang
                    $result &= Db::getInstance()->update(self::$definition['table'], array('value' => pSQL($value, $html), 'date_upd' => date('Y-m-d H:i:s')), '`name` = \'' . pSQL($key) . '\'' . Configuration::sqlRestriction($id_shop_group, $id_shop), 1, true);
                } else {
                    // Update multi lang
                    $sql = 'UPDATE `' . _DB_PREFIX_ . bqSQL(self::$definition['table']) . '_lang` cl
							SET cl.value = \'' . pSQL($value, $html) . '\',
								cl.date_upd = NOW()
							WHERE cl.id_lang = ' . (int) $lang . '
								AND cl.`' . bqSQL(self::$definition['primary']) . '` = (
									SELECT c.`' . bqSQL(self::$definition['primary']) . '`
									FROM `' . _DB_PREFIX_ . bqSQL(self::$definition['table']) . '` c
									WHERE c.name = \'' . pSQL($key) . '\'' . Configuration::sqlRestriction($id_shop_group, $id_shop) . ')';
                    $result &= Db::getInstance()->execute($sql);
                }
            } else {
                if (!($configID = Configuration::getIdByName($key, $id_shop_group, $id_shop))) {
                    $newConfig = new Configuration();
                    $newConfig->name = $key;
                    if ($id_shop) {
                        $newConfig->id_shop = (int) $id_shop;
                    }
                    if ($id_shop_group) {
                        $newConfig->id_shop_group = (int) $id_shop_group;
                    }
                    if (!$lang) {
                        $newConfig->value = $value;
                    }
                    $result &= $newConfig->add(true, true);
                    $configID = $newConfig->id;
                }
                if ($lang) {
                    $result &= Db::getInstance()->insert(self::$definition['table'] . '_lang', array(self::$definition['primary'] => $configID, 'id_lang' => $lang, 'value' => pSQL($value, $html), 'date_upd' => date('Y-m-d H:i:s')));
                }
            }
        }
        Configuration::set($key, $values, $id_shop_group, $id_shop);
        return $result;
    }
开发者ID:dev-lav,项目名称:htdocs,代码行数:75,代码来源:Configuration.php

示例3: updateValue

    /**
     * Update configuration key and value into database (automatically insert if key does not exist)
     *
     * @param string $key Key
     * @param mixed $values $values is an array if the configuration is multilingual, a single string else.
     * @param boolean $html Specify if html is authorized in value
     * @param int $id_shop_group
     * @param int $id_shop
     * @return boolean Update result
     */
    public static function updateValue($key, $values, $html = false, $id_shop_group = null, $id_shop = null)
    {
        if (!Validate::isConfigName($key)) {
            die(Tools::displayError());
        }
        if ($id_shop === null) {
            $id_shop = Shop::getContextShopID(true);
        }
        if ($id_shop_group === null) {
            $id_shop_group = Shop::getContextShopGroupID(true);
        }
        if (!is_array($values)) {
            $is_i18n = false;
            $values = array($values);
        } else {
            $is_i18n = true;
        }
        $result = true;
        foreach ($values as $lang => $value) {
            if ($value === Configuration::get($key, $lang, $id_shop_group, $id_shop)) {
                continue;
            }
            // If key already exists, update value
            if (Configuration::hasKey($key, $lang, $id_shop_group, $id_shop)) {
                if (!$lang) {
                    // Update config not linked to lang
                    $result &= Db::getInstance()->update('configuration', array('value' => pSQL($value, $html), 'date_upd' => date('Y-m-d H:i:s')), '`name` = \'' . pSQL($key) . '\'' . Configuration::sqlRestriction($id_shop_group, $id_shop), true, true);
                } else {
                    // Update multi lang
                    $sql = 'UPDATE ' . _DB_PREFIX_ . 'configuration_lang cl
							SET cl.value = \'' . pSQL($value, $html) . '\',
								cl.date_upd = NOW()
							WHERE cl.id_lang = ' . (int) $lang . '
								AND cl.id_configuration = (
									SELECT c.id_configuration
									FROM ' . _DB_PREFIX_ . 'configuration c
									WHERE c.name = \'' . pSQL($key) . '\'' . Configuration::sqlRestriction($id_shop_group, $id_shop) . ')';
                    $result &= Db::getInstance()->execute($sql);
                }
            } else {
                if (!($configID = Configuration::getIdByName($key, $id_shop_group, $id_shop))) {
                    $newConfig = new Configuration();
                    $newConfig->name = $key;
                    if ($id_shop) {
                        $newConfig->id_shop = (int) $id_shop;
                    }
                    if ($id_shop_group) {
                        $newConfig->id_shop_group = (int) $id_shop_group;
                    }
                    if (!$lang) {
                        $newConfig->value = $value;
                    }
                    $result &= $newConfig->add(true, true);
                    $configID = $newConfig->id;
                }
                if ($lang) {
                    $result &= Db::getInstance()->insert('configuration_lang', array('id_configuration' => $configID, 'id_lang' => $lang, 'value' => pSQL($value, $html), 'date_upd' => date('Y-m-d H:i:s')));
                }
            }
            if (!$is_i18n) {
                Configuration::set($key, $value, $id_shop_group, $id_shop);
            }
        }
        if ($is_i18n) {
            Configuration::set($key, $values, $id_shop_group, $id_shop);
        }
        return $result;
    }
开发者ID:rrameshsat,项目名称:Prestashop,代码行数:78,代码来源:Configuration.php

示例4: updateValue

 /**
  * Update configuration key and value into database (automatically insert if key does not exist)
  *
  * Values are inserted/updated directly using SQL, because using (Configuration) ObjectModel
  * may not insert values correctly (for example, HTML is escaped, when it should not be).
  * @TODO Fix saving HTML values in Configuration model
  *
  * @param string $key Key
  * @param mixed $values $values is an array if the configuration is multilingual, a single string else.
  * @param bool $html Specify if html is authorized in value
  * @param int $id_shop_group
  * @param int $id_shop
  * @return bool Update result
  */
 public static function updateValue($key, $values, $html = false, $id_shop_group = null, $id_shop = null)
 {
     if (!Validate::isConfigName($key)) {
         die(sprintf(Tools::displayError('[%s] is not a valid configuration key'), Tools::htmlentitiesUTF8($key)));
     }
     if ($id_shop === null || !Shop::isFeatureActive()) {
         $id_shop = Shop::getContextShopID(true);
     }
     if ($id_shop_group === null || !Shop::isFeatureActive()) {
         $id_shop_group = Shop::getContextShopGroupID(true);
     }
     if (!is_array($values)) {
         $values = array($values);
     }
     if ($html) {
         foreach ($values as &$value) {
             $value = Tools::purifyHTML($value);
         }
         unset($value);
     }
     $result = true;
     foreach ($values as $lang => $value) {
         $stored_value = Configuration::get($key, $lang, $id_shop_group, $id_shop);
         // if there isn't a $stored_value, we must insert $value
         if (!is_numeric($value) && $value === $stored_value || is_numeric($value) && $value == $stored_value && Configuration::hasKey($key, $lang)) {
             continue;
         }
         // If key already exists, update value
         if (Configuration::hasKey($key, $lang, $id_shop_group, $id_shop)) {
             if (!$lang) {
                 // Update config not linked to lang
                 $result &= Db::getInstance()->update(self::$definition['table'], array('value' => pSQL($value, $html), 'date_upd' => date('Y-m-d H:i:s')), '`name` = \'' . pSQL($key) . '\'' . Configuration::sqlRestriction($id_shop_group, $id_shop), 1, true);
             } else {
                 // Update multi lang
                 $sql = 'UPDATE `' . _DB_PREFIX_ . bqSQL(self::$definition['table']) . '_lang` cl
                         SET cl.value = \'' . pSQL($value, $html) . '\',
                             cl.date_upd = NOW()
                         WHERE cl.id_lang = ' . (int) $lang . '
                             AND cl.`' . bqSQL(self::$definition['primary']) . '` = (
                                 SELECT c.`' . bqSQL(self::$definition['primary']) . '`
                                 FROM `' . _DB_PREFIX_ . bqSQL(self::$definition['table']) . '` c
                                 WHERE c.name = \'' . pSQL($key) . '\'' . Configuration::sqlRestriction($id_shop_group, $id_shop) . ')';
                 $result &= Db::getInstance()->execute($sql);
             }
         } else {
             if (!($configID = Configuration::getIdByName($key, $id_shop_group, $id_shop))) {
                 $now = date('Y-m-d H:i:s');
                 $data = array('id_shop_group' => $id_shop_group ? (int) $id_shop_group : null, 'id_shop' => $id_shop ? (int) $id_shop : null, 'name' => pSQL($key), 'value' => $lang ? null : pSQL($value, $html), 'date_add' => $now, 'date_upd' => $now);
                 $result &= Db::getInstance()->insert(self::$definition['table'], $data, true);
                 $configID = Db::getInstance()->Insert_ID();
             }
             if ($lang) {
                 $result &= Db::getInstance()->insert(self::$definition['table'] . '_lang', array(self::$definition['primary'] => $configID, 'id_lang' => (int) $lang, 'value' => pSQL($value, $html), 'date_upd' => date('Y-m-d H:i:s')));
             }
         }
     }
     Configuration::set($key, $values, $id_shop_group, $id_shop);
     return $result;
 }
开发者ID:stratsimir,项目名称:PrestaShop,代码行数:73,代码来源:Configuration.php


注:本文中的Configuration::sqlRestriction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。