本文整理汇总了PHP中HtmlElementFactory::getMultivalueElements方法的典型用法代码示例。如果您正苦于以下问题:PHP HtmlElementFactory::getMultivalueElements方法的具体用法?PHP HtmlElementFactory::getMultivalueElements怎么用?PHP HtmlElementFactory::getMultivalueElements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlElementFactory
的用法示例。
在下文中一共展示了HtmlElementFactory::getMultivalueElements方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: orderProductForm
//.........这里部分代码省略.........
$preset_value = $option_value['product_option_value_id'];
} elseif (!in_array($option['element_type'], $elements_with_options)) {
$preset_value = $option_value['name'];
}
}
//Apply option price modifier
if ($option_value['prefix'] == '%') {
$price = $tax->calculate($product_info['price'] * $option_value['price'] / 100, $product_info['tax_class_id'], (bool) $this->config->get('config_tax'));
} else {
$price = $tax->calculate($option_value['price'], $product_info['tax_class_id'], (bool) $this->config->get('config_tax'));
}
if ($price != 0) {
$price = $this->currency->format($price);
} else {
$price = '';
}
//Check stock and status
$opt_stock_message = '';
if ($option_value['subtract']) {
if ($option_value['quantity'] <= 0) {
//show out of stock message
$opt_stock_message = ' (' . $this->language->get('text_product_out_of_stock') . ')';
} else {
if ($this->config->get('config_stock_display')) {
$opt_stock_message = ' (' . $option_value['quantity'] . " " . $this->language->get('text_product_in_stock') . ')';
}
}
}
$values[$option_value['product_option_value_id']] = $option_value['name'] . ' ' . $price . ' ' . $opt_stock_message;
}
//if not values are build, nothing to show
if (count($values)) {
//add price to option name if it is not element with options
if (!in_array($option['element_type'], $elements_with_options)) {
$option['name'] .= ' <small>' . $price . '</small>';
if ($opt_stock_message) {
$option['name'] .= '<br />' . $opt_stock_message;
}
}
//set default selection is nothing selected
if (!has_value($preset_value) && $option['element_type'] != 'C') {
if (has_value($default_value)) {
$preset_value = $default_value;
}
}
//show hidden option for admin
if ($option['html_type'] == 'hidden') {
$option['html_type'] = 'input';
}
$value = $preset_value;
//for checkbox with empty value
if ($value == '' && $option['element_type'] == 'C') {
$value = $default_value;
$value = $value == '' ? 1 : $value;
}
$option_data = array('type' => $option['html_type'], 'name' => !in_array($option['element_type'], HtmlElementFactory::getMultivalueElements()) ? 'product[0][option][' . $option['product_option_id'] . ']' : 'product[0][option][' . $option['product_option_id'] . '][]', 'value' => $value, 'options' => $values, 'placeholder' => $option['option_placeholder'], 'regexp_pattern' => $option['regexp_pattern'], 'error_text' => $option['error_text'], 'attr' => ' data-option-id ="' . $option['product_option_id'] . '"');
if ($option['element_type'] == 'C') {
// note: 0 and 1 must be stirng to prevent collision with 'yes'. (in php 'yes'==1) ;-)
$option_data['label_text'] = !in_array($value, array('0', '1')) ? $value : '';
$option_data['checked'] = $preset_value ? true : false;
}
$options[] = array('name' => $option['name'], 'html' => $form->getFieldHtml($option_data));
}
}
$this->data['options'] = $options;
// main product image
$resource = new AResource('image');
$thumbnail = $resource->getMainThumb('products', $product_id, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'), true);
$this->data['image'] = $thumbnail;
$this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $order_product_id ? $this->language->get('button_save') : $this->language->get('button_add')));
$this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'cancel', 'text' => $this->language->get('button_cancel')));
$this->data['form']['fields']['price'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'product[0][price]', 'value' => $preset_values['price'], 'attr' => ' readonly'));
if (!$options && $product_info['subtract']) {
if ($product_info['quantity']) {
$this->data['column_quantity'] = $this->language->get('column_quantity') . ' (' . $this->language->get('text_product_in_stock') . ': ' . $product_info['quantity'] . ')';
} else {
$this->data['column_quantity'] = $this->language->get('column_quantity') . ' (' . $this->language->get('text_product_out_of_stock') . ')';
}
}
$this->data['form']['fields']['quantity'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'product[0][quantity]', 'value' => $preset_values['quantity'], 'attr' => ' size="4"'));
$this->data['form']['fields']['total'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'product[0][total]', 'value' => $preset_values['total'], 'attr' => 'readonly'));
$this->data['form']['fields']['product_id'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'product_id', 'value' => $product_id));
$this->data['form']['fields']['order_product_id'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'order_product_id', 'value' => (int) $order_product_id));
//url to storefront response controller. Note: if admin under ssl - use https for url and otherwise
$order_store_id = $order_info['store_id'];
$this->loadModel('setting/store');
$store_info = $this->model_setting_store->getStore($order_store_id);
if (HTTPS === true && $store_info['config_ssl_url']) {
$total_calc_url = $store_info['config_ssl_url'] . 'index.php?rt=r/product/product/calculateTotal';
} elseif (HTTPS === true && !$store_info['config_ssl_url']) {
$total_calc_url = str_replace('http://', 'https://', $store_info['config_url']) . 'index.php?rt=r/product/product/calculateTotal';
} else {
$total_calc_url = $store_info['config_url'] . 'index.php?rt=r/product/product/calculateTotal';
}
$this->data['total_calc_url'] = $total_calc_url;
//update controller data
$this->extensions->hk_UpdateData($this, __FUNCTION__);
$this->view->batchAssign($this->data);
$this->processTemplate('responses/product/product_form.tpl');
}
示例2: validateAttributeData
/**
* method for validation of data based on global attributes requirements
* @param array $data - usually it's a $_POST
* @return array - array with error text for each of invalid field data
*/
public function validateAttributeData($data = array())
{
$errors = array();
$this->load->language('catalog/attribute');
// load language for file upload text errors
foreach ($this->attributes as $attribute_info) {
// for multivalue required fields
if (in_array($attribute_info['element_type'], HtmlElementFactory::getMultivalueElements()) && !sizeof($data[$attribute_info['attribute_id']]) && $attribute_info['required'] == '1') {
$errors[$attribute_info['attribute_id']] = $this->language->get('entry_required') . ' ' . $attribute_info['name'];
}
// for required string values
if ($attribute_info['required'] == '1' && !in_array($attribute_info['element_type'], array('K', 'U'))) {
if (!is_array($data[$attribute_info['attribute_id']])) {
$data[$attribute_info['attribute_id']] = trim($data[$attribute_info['attribute_id']]);
if ($data[$attribute_info['attribute_id']] == '') {
//if empty string!
$errors[$attribute_info['attribute_id']] = $this->language->get('entry_required') . ' ' . $attribute_info['name'];
}
} else {
if (!$data[$attribute_info['attribute_id']]) {
// if empty array
$errors[$attribute_info['attribute_id']] = $this->language->get('entry_required') . ' ' . $attribute_info['name'];
}
}
}
// check by regexp
if (has_value($attribute_info['regexp_pattern'])) {
if (!is_array($data[$attribute_info['attribute_id']])) {
//for string value
if (!preg_match($attribute_info['regexp_pattern'], $data[$attribute_info['attribute_id']])) {
$errors[$attribute_info['attribute_id']] .= ' ' . $attribute_info['error_text'];
}
} else {
// for array's values
foreach ($data[$attribute_info['attribute_id']] as $dd) {
if (!preg_match($attribute_info['regexp_pattern'], $dd)) {
$errors[$attribute_info['attribute_id']] .= ' ' . $attribute_info['error_text'];
break;
}
}
}
}
//for captcha
if ($attribute_info['element_type'] == 'K' && (!isset($this->session->data['captcha']) || $this->session->data['captcha'] != $data[$attribute_info['attribute_id']])) {
$errors[$attribute_info['attribute_id']] = $this->language->get('error_captcha');
}
// for file
if ($attribute_info['element_type'] == 'U' && ($this->request->files[$attribute_info['attribute_id']]['tmp_name'] || $attribute_info['required'] == '1')) {
$fm = new AFile();
$file_path_info = $fm->getUploadFilePath($data['settings']['directory'], $this->request->files[$attribute_info['attribute_id']]['name']);
$file_data = array('name' => $file_path_info['name'], 'path' => $file_path_info['path'], 'type' => $this->request->files[$attribute_info['attribute_id']]['type'], 'tmp_name' => $this->request->files[$attribute_info['attribute_id']]['tmp_name'], 'error' => $this->request->files[$attribute_info['attribute_id']]['error'], 'size' => $this->request->files[$attribute_info['attribute_id']]['size']);
$file_errors = $fm->validateFileOption($attribute_info['settings'], $file_data);
if ($file_errors) {
$errors[$attribute_info['attribute_id']] .= implode(' ', $file_errors);
}
}
}
return $errors;
}
示例3: main
//.........这里部分代码省略.........
$opt_stock_message = $option_value['quantity'] . " " . $this->language->get('text_instock');
}
}
}
$values[$option_value['product_option_value_id']] = $option_value['name'] . ' ' . $price . ' ' . $opt_stock_message;
}
//if not values are build, nothing to show
if (count($values)) {
$value = '';
//add price to option name if it is not element with options
if (!in_array($option['element_type'], $elements_with_options)) {
$option['name'] .= ' <small>' . $price . '</small>';
if ($opt_stock_message) {
$option['name'] .= '<br />' . $opt_stock_message;
}
$value = $default_value ? $default_value : $name;
}
//set default selection is nothing selected
if (!has_value($value)) {
if (has_value($default_value)) {
$value = $default_value;
} else {
if (in_array($option['element_type'], $elements_with_options) && $option['element_type'] != 'S') {
//set first from the list to default
reset($values);
$value = key($values);
}
}
}
//for checkbox with empty value
if ($value == '' && $option['element_type'] == 'C') {
$value = 1;
}
$option_data = array('type' => $option['html_type'], 'name' => !in_array($option['element_type'], HtmlElementFactory::getMultivalueElements()) ? 'option[' . $option['product_option_id'] . ']' : 'option[' . $option['product_option_id'] . '][]', 'value' => $value, 'options' => $values, 'required' => $option['required'], 'placeholder' => $option['option_placeholder'], 'regexp_pattern' => $option['regexp_pattern'], 'error_text' => $option['error_text']);
if ($option['element_type'] == 'C') {
if (!in_array($value, array('0', '1'))) {
$option_data['label_text'] = $value;
}
$option_data['checked'] = $preset_value ? true : false;
}
$options[] = array('name' => $option['name'], 'html' => $this->html->buildElement($option_data));
}
}
$this->data['options'] = $options;
//handle stock messages
// if track stock is off. no messages needed.
if ($this->model_catalog_product->isStockTrackable($product_id)) {
$total_quantity = $this->model_catalog_product->hasAnyStock($product_id);
$this->data['track_stock'] = true;
//out of stock if no quantity and no stick checkout is disabled
if ($total_quantity <= 0 && !$this->config->get('config_stock_checkout')) {
$this->data['in_stock'] = false;
//show out of stock message
$this->data['stock'] = $product_info['stock_status'];
} else {
$this->data['in_stock'] = true;
if ($this->config->get('config_stock_display')) {
$this->data['stock'] = $product_info['quantity'];
} else {
$this->data['stock'] = $this->language->get('text_instock');
}
}
//check if we need to disable product for no stock
if ($this->config->get('config_nostock_autodisable') && $total_quantity <= 0) {
//set available data
$pd_identifiers = "ID: " . $product_id;
示例4: validateFormData
/**
* method for validation of data based on form fields requirements
* @param array $data - usually it's a $_POST
* @return array - array with error text for each of invalid field data
*/
public function validateFormData($data = array())
{
$errors = array();
$this->_loadFields();
$this->load->language('checkout/cart');
// load language for file upload text errors
foreach ($this->fields as $field) {
// for multivalue required fields
if (in_array($field['element_type'], HtmlElementFactory::getMultivalueElements()) && !sizeof($data[$field['field_name']]) && $field['required'] == 'Y') {
$errors[$field['field_name']] = $field['name'] . ' ' . $this->language->get('text_field_required');
}
// for required string values
if ($field['required'] == 'Y' && !in_array($field['element_type'], array('K', 'J', 'U'))) {
if (!is_array($data[$field['field_name']])) {
$data[$field['field_name']] = trim($data[$field['field_name']]);
//if empty string!
if ($data[$field['field_name']] == '') {
$errors[$field['field_name']] = $field['name'] . ' ' . $this->language->get('text_field_required');
}
} else {
// if empty array
if (!$data[$field['field_name']]) {
$errors[$field['field_name']] = $field['name'] . ' ' . $this->language->get('text_field_required');
}
}
}
// check by regexp
if (has_value($field['regexp_pattern'])) {
if (!is_array($data[$field['field_name']])) {
//for string value
if (!preg_match($field['regexp_pattern'], $data[$field['field_name']])) {
// show error only for field with value or required
if ($data[$field['field_name']] && $field['required'] != 'Y' || $field['required'] == 'Y') {
$errors[$field['field_name']] .= ' ' . $field['error_text'];
}
}
} else {
// for array's values
foreach ($data[$field['field_name']] as $dd) {
if (!preg_match($field['regexp_pattern'], $dd)) {
if ($dd && $field['required'] != 'Y' || $field['required'] == 'Y') {
$errors[$field['field_name']] .= ' ' . $field['error_text'];
}
break;
}
}
}
}
//for captcha or recaptcha
if ($field['element_type'] == 'K' || $field['element_type'] == 'J') {
if ($this->config->get('config_recaptcha_secret_key')) {
require_once DIR_VENDORS . '/google_recaptcha/autoload.php';
$recaptcha = new \ReCaptcha\ReCaptcha($this->config->get('config_recaptcha_secret_key'));
$resp = $recaptcha->verify($data['g-recaptcha-response'], $this->request->server['REMOTE_ADDR']);
if (!$resp->isSuccess() && $resp->getErrorCodes()) {
$errors[$field['field_name']] = $this->language->get('error_captcha');
}
} else {
if (!isset($this->session->data['captcha']) || $this->session->data['captcha'] != $data[$field['field_name']]) {
$errors[$field['field_name']] = $this->language->get('error_captcha');
}
}
}
// for file
if ($field['element_type'] == 'U' && ($this->request->files[$field['field_name']]['tmp_name'] || $field['required'] == 'Y')) {
$fm = new AFile();
$file_path_info = $fm->getUploadFilePath($data['settings']['directory'], $this->request->files[$field['field_name']]['name']);
$file_data = array('name' => $file_path_info['name'], 'path' => $file_path_info['path'], 'type' => $this->request->files[$field['field_name']]['type'], 'tmp_name' => $this->request->files[$field['field_name']]['tmp_name'], 'error' => $this->request->files[$field['field_name']]['error'], 'size' => $this->request->files[$field['field_name']]['size']);
$file_errors = $fm->validateFileOption($field['settings'], $file_data);
if ($file_errors) {
$errors[$field['field_name']] .= implode(' ', $file_errors);
}
}
}
return $errors;
}
示例5: buildDownloadForm
/**
* @param array $file_data
* @param string $tpl
*/
public function buildDownloadForm($file_data, $tpl)
{
$this->data = array();
//init controller data
$this->extensions->hk_InitData($this, __FUNCTION__);
$this->loadLanguage('catalog/files');
$this->loadModel('localisation/order_status');
$this->loadModel('catalog/download');
$product_id = $file_data['product_id'];
$order_statuses = $this->model_localisation_order_status->getOrderStatuses();
$this->data['date_added'] = dateISO2Display($file_data['date_added'], $this->language->get('date_format_short') . ' ' . $this->language->get('time_format'));
$this->data['date_modified'] = dateISO2Display($file_data['date_modified'], $this->language->get('date_format_short') . ' ' . $this->language->get('time_format'));
$this->data['action'] = $this->html->getSecureURL('r/product/product/processDownloadForm', '&product_id=' . $product_id);
$this->data['form_title'] = $this->language->get('text_edit') . ' ' . $this->language->get('text_product');
$this->data['download_id'] = (int) $file_data['download_id'];
if ($this->data['download_id']) {
$form = new AForm('HS');
$this->data['update'] = $this->html->getSecureURL('listing_grid/download/update_field', '&id=' . $this->data['download_id']);
} else {
$form = new AForm('HT');
}
$form->setForm(array('form_name' => 'downloadFrm' . $file_data['download_id'], 'update' => $this->data['update']));
$this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'downloadFrm' . $file_data['download_id'], 'attr' => 'confirm-exit="true"', 'action' => $this->data['action']));
$this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => (int) $this->data['download_id'] ? $this->language->get('button_save') : $this->language->get('text_add'), 'style' => 'button1'));
$this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'cancel', 'href' => $this->html->getSecureURL('catalog/product_files', '&product_id=' . $product_id), 'text' => $this->language->get('button_cancel'), 'style' => 'button2'));
$rl = new AResource('download');
$rl_dir = $rl->getTypeDir();
$resource_id = $rl->getIdFromHexPath(str_replace($rl_dir, '', $file_data['filename']));
$resource_info = $rl->getResource($resource_id);
$thumbnail = $rl->getResourceThumb($resource_id, 30, 30);
if ($resource_info['resource_path']) {
$this->data['icon'] = $this->html->buildResourceImage(array('url' => $thumbnail, 'width' => 30, 'height' => 30, 'attr' => 'alt="' . $resource_info['title'] . '"'));
} else {
$this->data['icon'] = $resource_info['resource_code'];
}
if ($resource_id) {
$this->data['preview']['href'] = $this->html->getSecureURL('common/resource_library/get_resource_preview', '&resource_id=' . $resource_id, true);
$this->data['preview']['path'] = 'resources/' . $file_data['filename'];
}
$r = $this->dispatch('responses/common/resource_library/get_resource_html_single', array('type' => 'download', 'wrapper_id' => 'download_' . (int) $this->data['download_id'], 'resource_id' => $resource_id, 'field' => 'download_rl_path_' . $this->data['download_id']));
$this->data['resource'] = $r->dispatchGetOutput();
$resources_scripts = $this->dispatch('responses/common/resource_library/get_resources_scripts', array('object_name' => 'downloads', 'object_id' => (int) $this->data['download_id'], 'types' => 'download', 'mode' => 'url'));
$this->data['resources_scripts'] = $resources_scripts->dispatchGetOutput();
$this->data['form']['fields']['download_rl_path'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'download_rl_path_' . $this->data['download_id'], 'value' => htmlspecialchars($file_data['filename'], ENT_COMPAT, 'UTF-8')));
$this->data['form']['fields']['status'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'status', 'value' => 1, 'checked' => $file_data['status'] ? true : false, 'style' => 'btn_switch'));
$orders_count = $this->model_catalog_download->getTotalOrdersWithProduct($product_id);
if ($orders_count) {
$this->data['push_to_customers'] = $this->html->buildElement(array('type' => 'button', 'name' => 'push_to_customers', 'title' => sprintf($this->language->get('text_push_to_orders'), $orders_count), 'text' => $this->language->get('text_push'), 'href' => $this->html->getSecureURL('r/product/product/pushToCustomers', '&product_id=' . $product_id . '&download_id=' . $this->data['download_id']), 'style' => 'button2', 'attr' => 'data-orders-count="' . $orders_count . '"'));
}
$this->data['maplist'] = array();
$file_data['map_list'] = (array) $file_data['map_list'];
foreach ($file_data['map_list'] as $map_id => $map_name) {
if ($map_id == $product_id) {
continue;
}
$this->data['maplist'][] = array('href' => $this->html->getSecureURL('catalog/product_files', '&product_id=' . $map_id . '&download_id=' . $this->data['download_id'], true), 'text' => $map_name);
}
if (!sizeof($this->data['maplist'])) {
$this->data['already_shared'] = false;
} else {
$this->data['already_shared'] = true;
}
$this->data['delete_unmap_href'] = $this->html->getSecureURL('catalog/product_files', '&act=' . ($file_data['shared'] ? 'unmap' : 'delete') . '&product_id=' . $product_id . '&download_id=' . $this->data['download_id'], true);
$this->data['form']['fields']['shared'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'shared', 'value' => $file_data['shared'], 'attr' => $this->data['already_shared'] ? ' disabled=disabled' : ''));
if ($file_data['shared']) {
$this->data['text_attention_shared'] = $this->language->get('attention_shared');
}
$this->data['form']['fields']['download_id'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'download_id', 'value' => $this->data['download_id']));
$this->data['form']['fields']['name'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'name', 'value' => $file_data['name'], 'attr' => ' maxlength="64" '));
$this->data['form']['fields']['mask'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'mask', 'value' => $file_data['mask']));
$this->data['form']['fields']['max_downloads'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'max_downloads', 'value' => $file_data['max_downloads'], 'style' => 'small-field'));
$this->data['form']['fields']['activate'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'activate', 'value' => $file_data['activate'], 'options' => array('' => $this->language->get('text_select'), 'before_order' => $this->language->get('text_before_order'), 'immediately' => $this->language->get('text_immediately'), 'order_status' => $this->language->get('text_on_order_status'), 'manually' => $this->language->get('text_manually')), 'required' => true, 'style' => 'download_activate no-save'));
$options = array('' => $this->language->get('text_select'));
foreach ($order_statuses as $order_status) {
$options[$order_status['order_status_id']] = $order_status['name'];
}
$this->data['form']['fields']['order_statuses'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'activate_order_status_id', 'value' => $file_data['activate_order_status_id'], 'options' => $options, 'required' => true, 'style' => 'no-save'));
$this->data['form']['fields']['sort_order'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'sort_order', 'style' => 'small-field', 'value' => $file_data['sort_order']));
$this->data['form']['fields']['expire_days'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'expire_days', 'style' => 'small-field', 'value' => $file_data['expire_days']));
/*
* DOWNLOAD ATTRIBUTES PIECE OF FORM
* */
$attributes = $this->model_catalog_download->getDownloadAttributes($this->data['download_id']);
$elements = HtmlElementFactory::getAvailableElements();
$html_multivalue_elements = HtmlElementFactory::getMultivalueElements();
$html_elements_with_options = HtmlElementFactory::getElementsWithOptions();
if (!$attributes) {
$attr_mng = new AAttribute_Manager('download_attribute');
$attr_type_id = $attr_mng->getAttributeTypeID('download_attribute');
$this->data['text_no_download_attributes_yet'] = sprintf($this->language->get('text_no_download_attributes_yet'), $this->html->getSecureURL('catalog/attribute/insert', '&attribute_type_id=' . $attr_type_id));
} else {
foreach ($attributes as $attribute) {
$html_type = $elements[$attribute['element_type']]['type'];
if (!$html_type || !$attribute['status']) {
continue;
}
//.........这里部分代码省略.........