Alan Lam 3 лет назад
Родитель
Сommit
4b464a53f1
2 измененных файлов с 92 добавлено и 1 удалено
  1. 30 1
      controllers/products.php
  2. 62 0
      views/products.php

+ 30 - 1
controllers/products.php

@@ -2,11 +2,40 @@
 
 namespace App;
 
+use App\Constraint\HasTextConstraint;
+
 $core = Core::getInstance();
 $core->addBreadcrumb("/products", __("Products"));
 
 $nvp = [];
 
+$request = Request::fromRequest();
+
+$product_id = $request->int("product_id");
+if($product_id) {
+	$nvp["id"] = $product_id;
+}
+
+$supplier_id = $request->int("supplier_id");
+if($supplier_id) {
+	$nvp["supplier_id"] = $supplier_id;
+}
+
+$name = $request->string("name");
+if($name) {
+	$nvp["name"] = new HasTextConstraint($name);
+}
+
+$sku = $request->string("sku");
+if($sku) {
+	$nvp["sku"] = new HasTextConstraint($sku);
+}
+
+$type = $request->int("type");
+if($type) {
+	$nvp["type"] = $type;
+}
+
 $count = Product::count($nvp);
 
 $pagination = new Pagination($count);
@@ -19,5 +48,5 @@ $products = Product::query($nvp, [
 ]);
 
 View::include("header");
-View::include("products", compact("products", "pagination"));
+View::include("products", compact("products", "pagination", "product_id", "supplier_id", "name", "sku", "type"));
 View::include("footer");

+ 62 - 0
views/products.php

@@ -2,9 +2,16 @@
 
 namespace App;
 
+use App\Helpers\HtmlHelper;
+
 /**
  * @var Product[] $products
  * @var Pagination $pagination
+ * @var int $product_id
+ * @var int $supplier_id
+ * @var string $name
+ * @var string $sku
+ * @var int $type
  */
 
 ?>
@@ -20,6 +27,61 @@ namespace App;
 	</div>
 </div>
 
+<div class="card mb-3">
+	<div class="card-header">
+		<?=htmlspecialchars(__("Filters"))?>
+	</div>
+	<div class="card-body">
+		<form action="/products" method="get">
+			<div class="row">
+				<div class="col-sm-4">
+					<div class="mb-3">
+						<label class="form-label" for="product-id"><?=htmlspecialchars(__("ID"))?></label>
+						<input class="form-control" type="number" name="product_id" id="product-id" placeholder="<?=htmlspecialchars(__("Type ID"))?>" value="<?=htmlspecialchars($product_id)?>" />
+					</div>
+				</div>
+				<div class="col-sm-4">
+					<div class="mb-3">
+						<label class="form-label" for="supplier-id"><?= htmlspecialchars(__("Supplier")) ?></label>
+						<select class="form-control" name="supplier_id" id="supplier-id">
+							<option value=""><?= htmlspecialchars(__("Any Supplier")) ?></option>
+							<?php
+							HtmlHelper::renderOptions(Supplier::getOptions(), $supplier_id);
+							?>
+						</select>
+					</div>
+				</div>
+				<div class="col-sm-4">
+					<div class="mb-3">
+						<label class="form-label" for="name"><?= htmlspecialchars(__("Name")) ?></label>
+						<input class="form-control" type="text" name="name" id="name" placeholder="<?= htmlspecialchars(__("Type name")) ?>" value="<?=htmlspecialchars($name)?>" />
+					</div>
+				</div>
+				<div class="col-sm-4">
+					<div class="mb-3">
+						<label class="form-label" for="sku"><?= htmlspecialchars(__("SKU")) ?></label>
+						<input class="form-control" type="text" name="sku" id="sku" placeholder="<?= htmlspecialchars(__("Type SKU")) ?>" value="<?=htmlspecialchars($sku)?>" />
+					</div>
+				</div>
+				<div class="col-sm-4">
+					<div class="mb-3">
+						<label class="form-label" for="type"><?=htmlspecialchars(__("Type"))?></label>
+						<select class="form-control" name="type" id="type">
+							<option value=""><?=htmlspecialchars(__("Any Type"))?></option>
+							<?php
+							HtmlHelper::renderOptions(Product::getTypeOptions(), $type);
+							?>
+						</select>
+					</div>
+				</div>
+			</div>
+			<button class="btn btn-primary" type="submit">
+				<?=htmlspecialchars(__("Submit"))?>
+			</button>
+		</form>
+	</div>
+</div>
+
 <?php
 if(empty($products)) {
 	?>