Продолжения статьи Создание истории поиска. часть 1 (сайт)
Первым делом сделаем сразу ссылку для захода на страницу нашей истории поиска в админке. Для этого нужно в файле admin/controller/common/menu создать ссылку на контроллер. Находим строчку «$data['home'] = $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL');» и после нее добавляем «$data['search_history'] = $this->url->link('extension/search_history', 'token=' . $this->session->data['token'], 'SSL');». В данном случае мы объявляем переменную для тпловського файла для ссылки. Еще в этом файле нам нужно объявить языковую переменную, например, возьмем код «$data['text_search_history'] = $this->language->get('text_search_history');» и вставим после кода «$this->load->language('common/menu');». З данным файлом мы закончили.
Теперь второй этап. Сначала пишем контроллер.
Зайдем в папку admin/controller/extension и создадим файл например search_history.php. В самом файле Пишем код:
public function delete() {
<?php class
ControllerExtensionSearchHistory extends Controller {
public function index() {
$this->load->model('extension/search_history');
$this->load->language('extension/search_history');
$this->document->setTitle($this->language->get('heading_title'));
$data['heading_title'] = $this->language->get('heading_title');
$data['column_name'] = $this->language->get('column_name');
$data['column_count'] = $this->language->get('column_count');
$data['column_date_added'] = $this->language->get('column_date_added');
$data['text_no_results'] = $this->language->get('text_no_results');
$data['text_confirm'] = $this->language->get('text_confirm');
$data['heading_title'] = $this->language->get('heading_title');
$data['column_name'] = $this->language->get('column_name');
$data['column_count'] = $this->language->get('column_count');
$data['column_date_added'] = $this->language->get('column_date_added');
$data['text_no_results'] = $this->language->get('text_no_results');
$data['text_confirm'] = $this->language->get('text_confirm');
$data['button_delete'] =
$this->language->get('button_delete');
$url = '';
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' =>
$this->language->get('text_home'),
'href' =>
$this->url->link('common/home', 'token=' .
$this->session->data['token'], 'SSL')
);
$data['breadcrumbs'][] = array(
'text' =>
$this->language->get('heading_title'),
'href' =>
$this->url->link('extension/news', 'token=' .
$this->session->data['token'] . $url, 'SSL')
);
);
/*Вывод списка запросов*/
$history_search = $this->model_extension_search_history->getSelectHistorySearch();
$history_search = $this->model_extension_search_history->getSelectHistorySearch();
foreach ($history_search as
$history) {
$data['histories'][] = array(
'id' => $history['id'],
'name' => $history['name'],
'count' => $history['count'],
'date_added' =>
$history['date_added']
);
}
if
(isset($this->request->post['selected'])) {
$data['selected'] = (array)$this->request->post['selected'];
} else {
$data['selected'] = array();
}
$data['delete'] =
$this->url->link('extension/search_history/delete', 'token=' .
$this->session->data['token'] . $url, 'SSL');
/*pagination*/
$history_total =
$this->model_extension_search_history->getTotalSearchHistory();
if (isset($this->request->get['page'])) {
if (isset($this->request->get['page'])) {
$page = $this->request->get['page'];
} else {
$page = 1;
}
$url = '';
$pagination = new Pagination();
$pagination->total =
$history_total;
$pagination->page = $page;
$pagination->limit = 15;
$pagination->url =
$this->url->link('extension/search_history', 'token=' .
$this->session->data['token'] . $url . '&page={page}', 'SSL');
$data['pagination'] = $pagination->render();
$data['results'] =
sprintf($this->language->get('text_pagination'), ($history_total) ?
(($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0,
((($page - 1) * $this->config->get('config_limit_admin')) >
($history_total - $this->config->get('config_limit_admin'))) ?
$history_total : ((($page - 1) * $this->config->get('config_limit_admin'))
+ $this->config->get('config_limit_admin')), $history_total,
ceil($history_total / $this->config->get('config_limit_admin')));
$data['header'] =
$this->load->controller('common/header');
$data['column_left'] =
$this->load->controller('common/column_left');
$data['footer'] =
$this->load->controller('common/footer');
$this->response->setOutput($this->load->view('extension/search_history.tpl',
$data));
}
public function delete() {
$this->load->model('extension/search_history');
if
(isset($this->request->post['selected'])) {
foreach ($this->request->post['selected'] as $id) {
$this->model_extension_search_history->deleteHistory($id);
}
$this->session->data['success'] =
$this->language->get('text_success');
$url
= '';
$this->response->redirect($this->url->link('extension/search_history',
'token=' . $this->session->data['token']
. $url, 'SSL'));
}
}}
Теперь создаем tpl’ овский файл для отображения информации. Для этого зайдем в папку «admin/view/template/extension» и создадим файл «search_history.tpl». В данном файле пишем следующий код:
<?php echo $header; ?>
<?php echo $column_left; ?>
<div id="content">
<div
class="page-header">
<div
class="container-fluid">
<div class="pull-right">
<button type="button"
data-toggle="tooltip" title="<?php echo $button_delete;
?>" class="btn btn-danger" onclick="confirm('<?php
echo $text_confirm; ?>') ? $('#form-history').submit() :
false;">
<i class="fa fa-trash-o"></i>
</button>
</div>
<i class="fa fa-trash-o"></i>
</button>
</div>
<h1><?php echo $heading_title; ?></h1>
</div>
</div>
<div
class="container-fluid">
<div
class="panel panel-default">
<div class="panel-body">
<div class="tab-content">
<div class="tab-pane active"
id="tab-general">
<form action="<?php
echo $delete; ?>" method="post"
enctype="multipart/form-data" id="form-history">
<div
class="table-responsive">
<table class="table table-bordered table-hover">
<thead>
<tr>
<td style="width: 1px;"
class="text-center">
<input type="checkbox"
onclick="$('input[name*=\'selected\']').prop('checked',
this.checked);" />
</td>
<td class="text-left">
<?php echo $column_name; ?>
</td>
<td class="text-left">
<?php echo $column_count; ?>
</td>
<td class="text-left">
<?php echo $column_date_added;
?>
</td>
</tr>
</thead>
<tbody>
<?php if (isset($histories)) { ?>
<?php foreach ($histories as $history) {
?>
<tr>
<td
class="text-center">
<?php if (in_array($history['id'],
$selected)) { ?>
<input type="checkbox"
name="selected[]" value="<?php echo $history['id'];
?>" checked="checked" />
<?php } else { ?>
<input type="checkbox"
name="selected[]" value="<?php echo $history['id'];
?>" />
<?php } ?>
</td>
<td class="text-left"><?php echo
$history['name']; ?>
</td>
<td class="text-left"><?php echo
$history['count']; ?>
</td>
<td class="text-left"><?php echo
$history['date_added']; ?></td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td class="text-center"
colspan="7">
<?php echo $text_no_results; ?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</form>
<div
class="row">
<div
class="col-sm-6 text-left"><?php echo $pagination; ?>
</div>
<div
class="col-sm-6 text-right"><?php echo $results; ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php echo $footer; ?>
Теперь нам нужен файл, который обращается к базе и считывает информацию. Для этого зайдем в папку «/admin/model/extension/» и создадим файл «search_history.php». В данном файле нужно написать следующий код:
return $query->row['total'];
<?php
class ModelExtensionSearchHistory
extends Model {
public
function getTotalSearchHistory() {
$query = $this->db->query("SELECT COUNT(*) AS total FROM "
. DB_PREFIX . "history_search");
}
public function
getSelectHistorySearch() {
$query
= $this->db->query("SELECT * FROM " . DB_PREFIX .
"history_search WHERE 1");
return $query->rows;
}
public
function deleteHistory($id) {
$this->db->query("DELETE FROM " . DB_PREFIX .
"history_search WHERE id = '" . (int)$id . "'");
}
}
Все, теперь админка готова. Создания файлов для записи данных в следующей статье.
Создания таблицы для записи данных по истории поиска на Опенкарт рассмотрим в следующей статье.
Создания таблицы для записи данных по истории поиска на Опенкарт рассмотрим в следующей статье.
Комментарии
Отправить комментарий