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


PHP ObjectModel::formatValue方法代码示例

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


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

示例1: renderForm

 /**
  * renderForm contains all necessary initialization needed for all tabs
  *
  * @return void
  */
 public function renderForm()
 {
     // This nice code (irony) is here to store the product name, because the row after will erase product name in multishop context
     $this->product_name = $this->object->name[$this->context->language->id];
     if (!method_exists($this, 'initForm' . $this->tab_display)) {
         return;
     }
     $product = $this->object;
     // Product for multishop
     $this->context->smarty->assign('bullet_common_field', '');
     if (Shop::isFeatureActive() && $this->display == 'edit') {
         if (Shop::getContext() != Shop::CONTEXT_SHOP) {
             $this->context->smarty->assign(array('display_multishop_checkboxes' => true, 'multishop_check' => Tools::getValue('multishop_check')));
         }
         if (Shop::getContext() != Shop::CONTEXT_ALL) {
             $this->context->smarty->assign('bullet_common_field', '<img src="themes/' . $this->context->employee->bo_theme . '/img/bullet_orange.png" style="vertical-align: bottom" />');
             $this->context->smarty->assign('display_common_field', true);
         }
     }
     $this->tpl_form_vars['tabs_preloaded'] = $this->available_tabs;
     $this->tpl_form_vars['product_type'] = (int) Tools::getValue('type_product', $product->getType());
     $this->getLanguages();
     $this->tpl_form_vars['id_lang_default'] = Configuration::get('PS_LANG_DEFAULT');
     $this->tpl_form_vars['currentIndex'] = self::$currentIndex;
     $this->tpl_form_vars['display_multishop_checkboxes'] = Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP && $this->display == 'edit';
     $this->fields_form = array('');
     $this->tpl_form_vars['token'] = $this->token;
     $this->tpl_form_vars['combinationImagesJs'] = $this->getCombinationImagesJs();
     $this->tpl_form_vars['PS_ALLOW_ACCENTED_CHARS_URL'] = (int) Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL');
     $this->tpl_form_vars['post_data'] = Tools::jsonEncode($_POST);
     $this->tpl_form_vars['save_error'] = !empty($this->errors);
     // autoload rich text editor (tiny mce)
     $this->tpl_form_vars['tinymce'] = true;
     $iso = $this->context->language->iso_code;
     $this->tpl_form_vars['iso'] = file_exists(_PS_ROOT_DIR_ . '/js/tiny_mce/langs/' . $iso . '.js') ? $iso : 'en';
     $this->tpl_form_vars['ad'] = dirname($_SERVER['PHP_SELF']);
     if (Validate::isLoadedObject($this->object)) {
         $id_product = (int) $this->object->id;
     } else {
         $id_product = (int) Tools::getvalue('id_product');
     }
     $this->tpl_form_vars['form_action'] = $this->context->link->getAdminLink('AdminProducts') . '&amp;' . ($id_product ? 'id_product=' . (int) $id_product : 'addproduct');
     $this->tpl_form_vars['id_product'] = $id_product;
     // Transform configuration option 'upload_max_filesize' in octets
     $upload_max_filesize = Tools::getOctets(ini_get('upload_max_filesize'));
     // Transform configuration option 'upload_max_filesize' in MegaOctets
     $upload_max_filesize = $upload_max_filesize / 1024 / 1024;
     $this->tpl_form_vars['upload_max_filesize'] = $upload_max_filesize;
     $this->tpl_form_vars['country_display_tax_label'] = $this->context->country->display_tax_label;
     $this->tpl_form_vars['has_combinations'] = $this->object->hasAttributes();
     $this->product_exists_in_shop = true;
     if ($this->display == 'edit' && Validate::isLoadedObject($product) && Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP && !$product->isAssociatedToShop($this->context->shop->id)) {
         $this->product_exists_in_shop = false;
         if ($this->tab_display == 'Informations') {
             $this->displayWarning($this->l('Warning: The product does not exist in this shop.'));
         }
         $default_product = new Product();
         $definition = ObjectModel::getDefinition($product);
         foreach ($definition['fields'] as $field_name => $field) {
             if (isset($field['shop']) && $field['shop']) {
                 $product->{$field_name} = ObjectModel::formatValue($default_product->{$field_name}, $field['type']);
             }
         }
     }
     // let's calculate this once for all
     if (!Validate::isLoadedObject($this->object) && Tools::getValue('id_product')) {
         $this->errors[] = 'Unable to load object';
     } else {
         $this->_displayDraftWarning($this->object->active);
         // if there was an error while saving, we don't want to lose posted data
         if (!empty($this->errors)) {
             $this->copyFromPost($this->object, $this->table);
         }
         $this->initPack($this->object);
         $this->{'initForm' . $this->tab_display}($this->object);
         $this->tpl_form_vars['product'] = $this->object;
         if ($this->ajax) {
             if (!isset($this->tpl_form_vars['custom_form'])) {
                 throw new PrestaShopException('custom_form empty for action ' . $this->tab_display);
             } else {
                 return $this->tpl_form_vars['custom_form'];
             }
         }
     }
     $parent = parent::renderForm();
     $this->addJqueryPlugin(array('autocomplete', 'fancybox', 'typewatch'));
     return $parent;
 }
开发者ID:rongandat,项目名称:vatfairfoot,代码行数:93,代码来源:AdminProductsController.php

示例2: renderForm

 public function renderForm()
 {
     $this->product_name = $this->object->name[$this->context->language->id];
     if (!method_exists($this, 'initForm' . $this->tab_display)) {
         return;
     }
     $product = $this->object;
     $this->context->smarty->assign('bullet_common_field', '');
     if (Shop::isFeatureActive() && $this->display == 'edit') {
         if (Shop::getContext() != Shop::CONTEXT_SHOP) {
             $this->context->smarty->assign(array('display_multishop_checkboxes' => true, 'multishop_check' => Tools::getValue('multishop_check')));
         }
         if (Shop::getContext() != Shop::CONTEXT_ALL) {
             $this->context->smarty->assign('bullet_common_field', '<i class="icon-circle text-orange"></i>');
             $this->context->smarty->assign('display_common_field', true);
         }
     }
     $this->tpl_form_vars['tabs_preloaded'] = $this->available_tabs;
     $this->tpl_form_vars['product_type'] = (int) Tools::getValue('type_product', $product->getType());
     $this->getLanguages();
     $this->tpl_form_vars['id_lang_default'] = Configuration::get('PS_LANG_DEFAULT');
     $this->tpl_form_vars['currentIndex'] = self::$currentIndex;
     $this->tpl_form_vars['display_multishop_checkboxes'] = Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP && $this->display == 'edit';
     $this->fields_form = array('');
     $this->tpl_form_vars['token'] = $this->token;
     $this->tpl_form_vars['combinationImagesJs'] = $this->getCombinationImagesJs();
     $this->tpl_form_vars['PS_ALLOW_ACCENTED_CHARS_URL'] = (int) Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL');
     $this->tpl_form_vars['post_data'] = json_encode($_POST);
     $this->tpl_form_vars['save_error'] = !empty($this->errors);
     $this->tpl_form_vars['mod_evasive'] = Tools::apacheModExists('evasive');
     $this->tpl_form_vars['mod_security'] = Tools::apacheModExists('security');
     $this->tpl_form_vars['ps_force_friendly_product'] = Configuration::get('PS_FORCE_FRIENDLY_PRODUCT');
     $this->tpl_form_vars['tinymce'] = true;
     $iso = $this->context->language->iso_code;
     $this->tpl_form_vars['iso'] = file_exists(_PS_CORE_DIR_ . '/js/tiny_mce/langs/' . $iso . '.js') ? $iso : 'en';
     $this->tpl_form_vars['path_css'] = _THEME_CSS_DIR_;
     $this->tpl_form_vars['ad'] = __PS_BASE_URI__ . basename(_PS_ADMIN_DIR_);
     if (Validate::isLoadedObject($this->object)) {
         $id_product = (int) $this->object->id;
     } else {
         $id_product = (int) Tools::getvalue('id_product');
     }
     $this->tpl_form_vars['form_action'] = $this->context->link->getAdminLink('AdminProducts') . '&' . ($id_product ? 'id_product=' . (int) $id_product : 'addproduct');
     $this->tpl_form_vars['id_product'] = $id_product;
     $upload_max_filesize = Tools::getOctets(ini_get('upload_max_filesize'));
     $upload_max_filesize = $upload_max_filesize / 1024 / 1024;
     $this->tpl_form_vars['upload_max_filesize'] = $upload_max_filesize;
     $this->tpl_form_vars['country_display_tax_label'] = $this->context->country->display_tax_label;
     $this->tpl_form_vars['has_combinations'] = $this->object->hasAttributes();
     $this->product_exists_in_shop = true;
     if ($this->display == 'edit' && Validate::isLoadedObject($product) && Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP && !$product->isAssociatedToShop($this->context->shop->id)) {
         $this->product_exists_in_shop = false;
         if ($this->tab_display == 'Informations') {
             $this->displayWarning($this->l('Warning: The product does not exist in this shop'));
         }
         $default_product = new Product();
         $definition = ObjectModel::getDefinition($product);
         foreach ($definition['fields'] as $field_name => $field) {
             if (isset($field['shop']) && $field['shop']) {
                 $product->{$field_name} = ObjectModel::formatValue($default_product->{$field_name}, $field['type']);
             }
         }
     }
     if (!Validate::isLoadedObject($this->object) && Tools::getValue('id_product')) {
         $this->errors[] = 'Unable to load object';
     } else {
         $this->_displayDraftWarning($this->object->active);
         if (!empty($this->errors)) {
             $this->copyFromPost($this->object, $this->table);
         }
         $this->initPack($this->object);
         $this->{'initForm' . $this->tab_display}($this->object);
         $this->tpl_form_vars['product'] = $this->object;
         if ($this->ajax) {
             if (!isset($this->tpl_form_vars['custom_form'])) {
                 throw new PrestaShopException('custom_form empty for action ' . $this->tab_display);
             } else {
                 return $this->tpl_form_vars['custom_form'];
             }
         }
     }
     $parent = parent::renderForm();
     $this->addJqueryPlugin(array('autocomplete', 'fancybox', 'typewatch'));
     return $parent;
 }
开发者ID:jordangidoin,项目名称:prestatest,代码行数:85,代码来源:AdminProductsController.php

示例3: duplicateObject

    /**
     * Takes current object ID, gets its values from database,
     * saves them in a new row and loads newly saved values as a new object.
     *
     * @return ObjectModel|false
     * @throws PrestaShopDatabaseException
     */
    public function duplicateObject()
    {
        $definition = ObjectModel::getDefinition($this);
        $res = Db::getInstance()->getRow('
					SELECT *
					FROM `' . _DB_PREFIX_ . bqSQL($definition['table']) . '`
					WHERE `' . bqSQL($definition['primary']) . '` = ' . (int) $this->id);
        if (!$res) {
            return false;
        }
        unset($res[$definition['primary']]);
        foreach ($res as $field => &$value) {
            if (isset($definition['fields'][$field])) {
                $value = ObjectModel::formatValue($value, $definition['fields'][$field]['type'], false, true, !empty($definition['fields'][$field]['allow_null']));
            }
        }
        if (!Db::getInstance()->insert($definition['table'], $res)) {
            return false;
        }
        $object_id = Db::getInstance()->Insert_ID();
        if (isset($definition['multilang']) && $definition['multilang']) {
            $result = Db::getInstance()->executeS('
			SELECT *
			FROM `' . _DB_PREFIX_ . bqSQL($definition['table']) . '_lang`
			WHERE `' . bqSQL($definition['primary']) . '` = ' . (int) $this->id);
            if (!$result) {
                return false;
            }
            foreach ($result as &$row) {
                foreach ($row as $field => &$value) {
                    if (isset($definition['fields'][$field])) {
                        $value = ObjectModel::formatValue($value, $definition['fields'][$field]['type'], false, true, !empty($definition['fields'][$field]['allow_null']));
                    }
                }
            }
            // Keep $row2, you cannot use $row because there is an unexplicated conflict with the previous usage of this variable
            foreach ($result as $row2) {
                $row2[$definition['primary']] = (int) $object_id;
                if (!Db::getInstance()->insert($definition['table'] . '_lang', $row2)) {
                    return false;
                }
            }
        }
        /** @var ObjectModel $object_duplicated */
        $object_duplicated = new $definition['classname']((int) $object_id);
        $object_duplicated->duplicateShops((int) $this->id);
        return $object_duplicated;
    }
开发者ID:jpodracky,项目名称:dogs,代码行数:55,代码来源:ObjectModel.php

示例4: formatFields

 /**
  * @since 1.5.0
  * @param int $type FORMAT_COMMON or FORMAT_LANG or FORMAT_SHOP
  * @param int $id_lang If this parameter is given, only take lang fields
  * @return array
  */
 protected function formatFields($type, $id_lang = null)
 {
     $fields = array();
     // Set primary key in fields
     if (isset($this->id)) {
         $fields[$this->def['primary']] = $this->id;
     }
     foreach ($this->def['fields'] as $field => $data) {
         $value = $this->{$field};
         $fields[$field] = ObjectModel::formatValue($value, $data['type']);
     }
     return $fields;
 }
开发者ID:jessylenne,项目名称:sf2-technical-test,代码行数:19,代码来源:ObjectModel.php

示例5: formatValue

 /**
  * Format a value with the type of the given field
  *
  * @param mixed $value
  * @param string $field Field name
  * @return mixed
  */
 protected function formatValue($value, $field)
 {
     $info = $this->getFieldInfo($field);
     if (is_array($value)) {
         $results = array();
         foreach ($value as $item) {
             $results[] = ObjectModel::formatValue($item, $info['type'], true);
         }
         return $results;
     }
     return ObjectModel::formatValue($value, $info['type'], true);
 }
开发者ID:jicheng17,项目名称:pengwine,代码行数:19,代码来源:Collection.php

示例6: formatFields

 /**
  * @since 1.5.0
  * @param int $type FORMAT_COMMON or FORMAT_LANG or FORMAT_SHOP
  * @param int $id_lang If this parameter is given, only take lang fields
  * @return array
  */
 protected function formatFields($type, $id_lang = null)
 {
     $fields = array();
     // Set primary key in fields
     if (isset($this->id)) {
         $fields[$this->def['primary']] = $this->id;
     }
     foreach ($this->def['fields'] as $field => $data) {
         // Only get fields we need for the type
         // E.g. if only lang fields are filtered, ignore fields without lang => true
         if ($type == self::FORMAT_LANG && empty($data['lang']) || $type == self::FORMAT_SHOP && empty($data['shop']) || $type == self::FORMAT_COMMON && (!empty($data['shop']) || !empty($data['lang']))) {
             continue;
         }
         if (is_array($this->update_fields)) {
             if ((!empty($data['lang']) || !empty($data['shop'])) && (empty($this->update_fields[$field]) || $type == self::FORMAT_LANG && empty($this->update_fields[$field][$id_lang]))) {
                 continue;
             }
         }
         // Get field value, if value is multilang and field is empty, use value from default lang
         $value = $this->{$field};
         if ($type == self::FORMAT_LANG && $id_lang && is_array($value)) {
             if (!empty($value[$id_lang])) {
                 $value = $value[$id_lang];
             } else {
                 if (!empty($data['required'])) {
                     $value = $value[Configuration::get('PS_LANG_DEFAULT')];
                 } else {
                     $value = '';
                 }
             }
         }
         // Format field value
         $fields[$field] = ObjectModel::formatValue($value, $data['type']);
     }
     return $fields;
 }
开发者ID:rrameshsat,项目名称:Prestashop,代码行数:42,代码来源:ObjectModel.php


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