public function getSubForm() { $this->loadLanguage('design/blocks'); $listing_datasource = $this->request->post_or_get('listing_datasource'); //need to reset get variable for switch case $this->request->get['listing_datasource'] = $listing_datasource; $listing_manager = new AListingManager((int) $this->request->get['custom_block_id']); $this->data['data_sources'] = $listing_manager->getListingDataSources(); // if request for non-existant datasource if (!in_array($listing_datasource, array_keys($this->data['data_sources']))) { return null; } if (strpos($listing_datasource, 'custom_') !== FALSE) { $this->getCustomListingSubForm(); } elseif ($listing_datasource == 'media') { $this->getMediaListingSubForm(); } elseif ($listing_datasource == '') { return null; } else { $this->getAutoListingSubForm(); } }
public function getCustomListListingGridData() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); // json-response for jqgrid $this->load->library('json'); // if datasource was switched $layout_manager = new ALayoutManager(); $custom_block_id = (int) $this->request->get['custom_block_id']; $listing_datasource = $this->request->post_or_get('listing_datasource'); $info = $layout_manager->getBlockDescriptions($custom_block_id); $info = is_array($info) ? current($info) : ''; $info = unserialize($info['content']); $custom_list = array(); $lm = new AListingManager($custom_block_id); $this->data['data_sources'] = $lm->getListingDataSources(); if ($info['listing_datasource'] == $listing_datasource) { $list = $lm->getCustomList(); if ($list) { foreach ($list as $row) { $custom_list[$row['id']] = $row['sort_order']; } } } //load data source language and model $this->loadLanguage($this->data['data_sources'][$listing_datasource]['language']); $this->loadModel($this->data['data_sources'][$listing_datasource]['model']); $this->loadModel('tool/image'); //Prepare filter config $grid_filter_params = array('name', 'sort_order', 'model'); $filter = new AFilter(array('method' => 'post', 'grid_filter_params' => $grid_filter_params)); $filter_data = $filter->getFilterData(); //call data source model total method to get total based on set filter $model = $this->{'model_' . str_replace('/', '_', $this->data['data_sources'][$listing_datasource]['model'])}; $total = call_user_func_array(array($model, $this->data['data_sources'][$listing_datasource]['total_method']), array($filter_data)); $response = new stdClass(); $response->page = $filter->getParam('page'); $response->total = $filter->calcTotalPages($total); $response->records = $total; $response->userdata = (object) array(''); //call data source model method to get all records based on set filter $model = $this->{'model_' . str_replace('/', '_', $this->data['data_sources'][$listing_datasource]['model'])}; $results = call_user_func_array(array($model, $this->data['data_sources'][$listing_datasource]['method']), array($filter_data)); $i = 0; $resource = new AResource('image'); $response->userdata = (object) array('page' => '', 'selId' => array()); $data_type = $this->data['data_sources'][$listing_datasource]['data_type']; //product_id, category_id etc $id_list = $custom_list ? array_keys($custom_list) : array(); if ($results) { foreach ($results as $result) { $list_item_id = $result[$data_type]; //for pre-select if (in_array($list_item_id, $id_list) || in_array($list_item_id, array_keys($this->session->data['listing_selected']))) { $response->userdata->selId[] = $list_item_id; } $thumbnail = $resource->getMainThumb($this->data['data_sources'][$listing_datasource]['rl_object_name'], $list_item_id, 36, 36, true); $response->rows[$i]['id'] = $list_item_id; $response->rows[$i]['cell'] = array($thumbnail['thumb_html'], $result['name']); if (strpos($listing_datasource, 'product') !== FALSE) { $response->rows[$i]['cell'][] = $result['model']; } if ($custom_list[$list_item_id]) { $value = $custom_list[$list_item_id]; } else { $value = $this->session->data['listing_selected'][$list_item_id]['sort_order']; } //TODO: need find solution to replace html hardcode in all response controllers $response->rows[$i]['cell'][] = '<a class="btn_action" href="JavaScript:void(0);" onclick="showPopup(\'' . $this->html->getSecureURL($this->data['data_sources'][$listing_datasource]['view_path'], '&' . $data_type . '=' . $list_item_id) . '\')" title="' . $this->language->get('text_view') . '">' . '<img src="' . RDIR_TEMPLATE . 'image/icons/icon_grid_view.png" alt="' . $this->language->get('text_edit') . '" /></a>'; $i++; } } //update controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); $this->response->addJSONHeader(); $this->response->setOutput(AJson::encode($response)); }
private function _getListingForm() { if (isset($this->session->data['warning'])) { $this->data['error_warning'] = $this->session->data['warning']; $this->session->data['warning'] = ''; } else { $this->data['error_warning'] = ''; } $this->view->assign('success', $this->session->data['success']); if (isset($this->session->data['success'])) { unset($this->session->data['success']); } $this->document->initBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE)); $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('design/blocks'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: ')); $this->data['cancel'] = $this->html->getSecureURL('design/blocks'); if (!isset($this->request->get['custom_block_id'])) { $this->data['action'] = $this->html->getSecureURL('design/blocks/insert'); $this->data['heading_title'] = $this->language->get('text_create'); $this->data['update'] = ''; $form = new AForm('ST'); } else { $this->data['action'] = $this->html->getSecureURL('design/blocks/edit', '&custom_block_id=' . $this->request->get['custom_block_id']); $this->data['heading_title'] = $this->language->get('text_edit') . ' ' . $this->data['name']; $this->data['update'] = $this->html->getSecureURL('listing_grid/blocks_grid/update_field', '&custom_block_id=' . $this->request->get['custom_block_id']); $form = new AForm('HS'); } $this->document->addBreadcrumb(array('href' => $this->data['action'], 'text' => $this->data['heading_title'], 'separator' => ' :: ', 'current' => true)); $form->setForm(array('form_name' => 'BlockFrm', 'update' => $this->data['update'])); $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'BlockFrm', 'attr' => 'data-confirm-exit="true"', 'action' => $this->data['action'])); $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('button_save'), 'style' => 'button1')); $this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'cancel', 'text' => $this->language->get('button_cancel'), 'style' => 'button2')); if (isset($this->request->get['custom_block_id'])) { $this->data['form']['fields']['block_status'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'block_status', 'value' => $this->data['status'], 'style' => 'btn_switch status_switch')); $this->data['form']['text']['block_status'] = $this->html->convertLinks($this->language->get('entry_block_status')); $this->data['form']['fields']['block_status_note'] = ''; $this->data['form']['text']['block_status_note'] = $this->html->convertLinks($this->language->get('entry_block_status_note')); } $lm = new ALayoutManager(); foreach ($this->data['custom_block_types'] as $txt_id) { $block = $lm->getBlockByTxtId($txt_id); if ($block['block_id']) { $blocks[$block['block_id']] = $this->language->get('text_' . $txt_id); if ($txt_id == 'listing_block') { $default_block_type = $block['block_id']; } } } if (isset($this->request->get['custom_block_id'])) { // need to khow what type of listing is that $this->data['content'] = unserialize($this->data['content']); $this->data['autoload'] = 'load_subform({\'listing_datasource\': \'' . $this->data['content']['listing_datasource'] . '\'});'; } $this->data['form']['fields']['block_name'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'block_id', 'value' => $default_block_type)); $this->data['form']['fields']['block_name'] .= $form->getFieldHtml(array('type' => 'input', 'name' => 'block_name', 'value' => $this->data['name'], 'multilingual' => true, 'required' => true)); $this->data['form']['text']['block_name'] = $this->language->get('entry_block_name'); $this->data['form']['fields']['block_title'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'block_title', 'required' => true, 'multilingual' => true, 'value' => $this->data['title'])); $this->data['form']['text']['block_title'] = $this->language->get('entry_block_title'); // list of templates for block $tmpl_ids = $this->extensions->getInstalled('template'); $tmpl_ids[] = 'default'; $this->data['block_wrappers'] = array(); foreach ($tmpl_ids as $tmpl_id) { // for tpls of block that stores in db $layout_manager = new ALayoutManager($tmpl_id); $block = $layout_manager->getBlockByTxtId('listing_block'); $block_templates = (array) $layout_manager->getBlockTemplates($block['block_id']); foreach ($block_templates as $item) { if ($item['template']) { $this->data['block_wrappers'][$item['template']] = $item['template']; } } } //Automatic block template selection mode based on parent is limited to 1 template per location //To extend, allow custom block's template to be selected to suppress automatic selection //for tpls that stores in main.php (other extensions templates) $ext_tpls = $this->extensions->getExtensionTemplates(); foreach ($ext_tpls as $section) { foreach ($section as $s => $tpls) { if ($s != 'storefront') { continue; } foreach ($tpls as $tpl) { if (isset($this->data['block_wrappers'][$tpl]) || strpos($tpl, 'blocks/listing_block/') === false) { continue; } $this->data['block_wrappers'][$tpl] = $tpl; } } } $tpls = glob(DIR_STOREFRONT . 'view/*/template/blocks/listing_block/*.tpl'); foreach ($tpls as $tpl) { $pos = strpos($tpl, 'blocks/listing_block/'); $tpl = substr($tpl, $pos); if (!isset($this->data['block_wrappers'][$tpl])) { $this->data['block_wrappers'][$tpl] = $tpl; } } ksort($this->data['block_wrappers']); array_unshift($this->data['block_wrappers'], $this->language->get('text_automatic')); $this->data['form']['fields']['block_wrapper'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'block_wrapper', 'options' => $this->data['block_wrappers'], 'value' => $this->data['block_wrapper'])); $this->data['form']['text']['block_wrapper'] = $this->language->get('entry_block_wrapper'); $this->data['form']['fields']['block_framed'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'block_framed', 'value' => $this->data['block_framed'], 'style' => 'btn_switch')); $this->data['form']['text']['block_framed'] = $this->language->get('entry_block_framed'); $this->data['form']['fields']['block_description'] = $form->getFieldHtml(array('type' => 'textarea', 'name' => 'block_description', 'value' => $this->data['description'], 'attr' => ' style="height: 50px;"', 'multilingual' => true)); $this->data['form']['text']['block_description'] = $this->language->get('entry_block_description'); $listing_manager = new AListingManager((int) $this->request->get['custom_block_id']); $listing_datasources = array('' => array('text' => 'text_select_listing')); $listing_datasources = array_merge($listing_datasources, $listing_manager->getListingDataSources()); foreach ($listing_datasources as $k => $v) { $listing_datasources[$k] = $this->language->get($v['text']); } $default_listing_datasource = $this->data['content']['listing_datasource']; $this->data['form']['fields']['listing_datasource'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'listing_datasource', 'options' => $listing_datasources, 'value' => $default_listing_datasource, 'style' => 'no-save')); $this->data['form']['text']['listing_datasource'] = $this->language->get('entry_listing_datasource'); if (!isset($this->data['subform_url'])) { $this->data['subform_url'] = $this->html->getSecureURL('listing_grid/blocks_grid/getsubform', $this->request->get['custom_block_id'] ? '&custom_block_id=' . $this->request->get['custom_block_id'] : ''); } $this->view->batchAssign($this->language->getASet()); $this->view->batchAssign($this->data); $this->view->assign('form_language_switch', $this->html->getContentLanguageSwitcher()); $this->view->assign('language_code', $this->session->data['language']); $this->view->assign('help_url', $this->gen_help_url('block_edit')); $this->view->assign('rl', $this->html->getSecureURL('common/resource_library', '&object_name=custom_block&type=image&mode=url')); $this->processTemplate('pages/design/blocks_form_listing.tpl'); }