Added admin tool for ivt product import

This commit is contained in:
Frank Schubert
2023-05-05 13:53:30 +02:00
parent 8214acd3e9
commit 93727c3bf9
4 changed files with 104 additions and 20 deletions

View File

@@ -1,3 +1,8 @@
<?php
$pagination_baseurl = $this->getUrl($Mod,"ivtImportMatchProducts");
$pagination_baseurl_params = ["filter" => $filter];
$pagination_entity_name = "IVT Products";
?>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/header.php"); ?>
<!-- start page title -->
@@ -19,33 +24,50 @@
<div class="row">
<div class="col-12">
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination.php"); ?>
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination-summary.php"); ?>
<table class="table table-sm table-striped table-hover">
<tr>
<th class="text-right">IVT Produkt</th>
<th>Preis</th>
<th>Interval</th>
<th>Typ</th>
<th></th>
<th style="border-left: 1px solid #000">thetool Produkt</th>
<th>ivt_id hinterlegt</th>
</tr>
<?php foreach($ivtproducts as $ip): ?>
<tr>
<td class="text-right"><?=$ip->name?></td>
<td><?=$ip->price?></td>
<td><?=$ip->interval?></td>
<td><?=$ip->typ?></td>
<td style="border-left: 1px solid #000">
<select class="form-control" name="product[<?=$ip->id?>]" id="product_<?=$ip->id?>">
<option></option>
</select>
</td>
</tr>
<?php $match = false; ?>
<tr>
<td class="text-right"><?=$ip->name?></td>
<td><?=$ip->price?></td>
<td><?=$ip->interval?></td>
<td><?=$ip->typ?></td>
<td><?=$ip->id?></td>
<td style="border-left: 1px solid #000">
<select class="form-control" name="product[<?=$ip->id?>]" id="product_<?=$ip->id?>">
<option></option>
<?php foreach($products as $p): ?>
<?php if($p->ivt_id == $ip->id) $match = "prod"; ?>
<option value="<?=$p->id?>" <?=($p->ivt_id == $ip->id) ? "selected='selected'" : ""?>><?=$p->name?></option>
<?php endforeach; ?>
</select>
</td>
<td><?=($match == "prod") ? "<i class='fas fa-check text-success'></i>" : ""?></td>
</tr>
<?php endforeach; ?>
</table>
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination-summary.php"); ?>
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination.php"); ?>
</div>
</div>
<script type="text/javascript">
<?php
/*
var products = [
<?php foreach(ProductModel::getActive() as $product): ?>
{id: <?=$product->id?>, name: '<?=$product->name?>'},
@@ -58,6 +80,9 @@
});
$("select[name^=product").append(new_options);
*/
?>
$("select[name^=product").select2({placeholder: ""});
</script>

View File

@@ -66,15 +66,24 @@ if($mfPagination_pagecount < 12) {
}
if(count($pagination_baseurl_params)) {
$baseurl_with_params = $pagination_baseurl."?".http_build_query($pagination_baseurl_params);
if(substr($baseurl_with_params, -1, 1) != "&" && substr($baseurl_with_params, -1, 1) != "?") {
$baseurl_with_params .= "&";
}
} else {
$baseurl_with_params = $pagination_baseurl."?";
}
?>
<nav>
<ul class="pagination justify-content-center mb-1">
<li class="page-item <?=($pagination['start'] - $pagination['count'] < 0) ? "disabled" : ""?>">
<a class="page-link" href="<?=$this->getUrl($Mod, "Index", ["filter" => $filter])?>" tabindex="-1">Erste</a>
<a class="page-link" href="<?=$baseurl_with_params?>" tabindex="-1">Erste</a>
</li>
<li class="page-item <?=($pagination['start'] - $pagination['count'] < 0) ? "disabled" : ""?>">
<a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => $pagination['start'] - $pagination['count'], "filter" => $filter])?>" tabindex="-1">Zurück</a>
<a class="page-link" href="<?=$baseurl_with_params?>s=<?=($pagination['start'] - $pagination['count'])?>" tabindex="-1">Zurück</a>
</li>
<?php foreach($mfPagination_pages as $mfPageIndex => $mfPage):?>
<?php if($mfPage == "separator_before" || $mfPage == "separator_after"): ?>
@@ -82,11 +91,15 @@ if($mfPagination_pagecount < 12) {
<?php continue; endif; ?>
<li class="page-item <?=($mfPage['current']) ? "disabled font-weight-bold text-secondary" : ""?>"><a class="page-link" href="<?=$mfPage['url']?>"><?=$mfPageIndex+1?></a></li>
<?php endforeach; ?>
<li class="page-item <?=($pagination['maxItems'] / ($pagination['start'] + $pagination['count']) < 1) ? "disabled" : ""?>">
<a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => $pagination['start'] + $pagination['count'], "filter" => $filter])?>">Weiter</a>
<li class="page-item <?=($pagination['maxItems'] / ($pagination['start'] + $pagination['count']) <= 1) ? "disabled" : ""?>">
<a class="page-link" href="<?=$baseurl_with_params?>s=<?=($pagination['start'] + $pagination['count'])?>">Weiter</a>
</li>
<li class="page-item <?=($pagination['maxItems'] / ($pagination['start'] + $pagination['count']) < 1) ? "disabled" : ""?>">
<a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => ($pagination['maxItems'] - $pagination['maxItems'] % $pagination['count']), "filter" => $filter])?>">Letzte</a>
<li class="page-item <?=($pagination['maxItems'] / ($pagination['start'] + $pagination['count']) <= 1) ? "disabled" : ""?>">
<?php if($pagination['maxItems'] % $pagination['count'] == 0): ?>
<a class="page-link" href="<?=$baseurl_with_params?>s=<?=($pagination['maxItems'] - $pagination['count'])?>">Letzte</a>
<?php else: ?>
<a class="page-link" href="<?=$baseurl_with_params?>s=<?=($pagination['maxItems'] - $pagination['maxItems'] % $pagination['count'])?>">Letzte</a>
<?php endif; ?>
</li>
</ul>
</nav>

View File

@@ -41,8 +41,40 @@ class AdminController extends mfBaseController {
protected function ivtImportMatchProductsAction() {
$this->layout()->setTemplate("Admin/ivtimport_product_match");
$ivtproducts = IvtProductModel::getAll();
$filter_name = MFAPPNAME.'-Admin-ivtimport_product-filter';
if($this->request->resetFilter) {
unset($_SESSION[$filter_name]);
}
$filter = [];
if(is_array($this->request->filter)) {
$filter = $this->request->filter;
$_SESSION[$filter_name] = $filter;
} else {
if(array_key_exists($filter_name, $_SESSION) && count($_SESSION[$filter_name])) {
$filter = $_SESSION[$filter_name];
}
}
$this->layout->set("filter", $filter);
//$filter = $this->getPreparedFilter($filter);
// pagination defaults
$pagination = [];
$pagination['start'] = 0;
$pagination['count'] = 20;
$pagination['maxItems'] = 0;
if(is_numeric($this->request->s)) {
$pagination['start'] = intval($this->request->s);
}
//var_dump($filter);exit;
$pagination['maxItems'] = IvtProductModel::count($filter);
$ivtproducts = IvtProductModel::search($filter, $pagination);
$this->layout()->set("pagination", $pagination);
$this->layout()->set("ivtproducts", $ivtproducts);
$this->layout()->set("products", ProductModel::getActive());
}
}

View File

@@ -37,12 +37,26 @@ class IvtProductModel {
return null;
}
public static function count($filter) {
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
$where = self::getSqlFilter($filter);
$sql = "SELECT COUNT(*) cnt FROM products WHERE $where ORDER by id";
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
return $data->cnt;
}
return 0;
}
public static function search($filter, $limit = false) {
$items = [];
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM products $where ORDER by id";
$sql = "SELECT * FROM products WHERE $where ORDER by id";
mfLoghandler::singleton()->debug($sql);
if(is_array($limit) && count($limit)) {