Merge branch 'add_manufacturer'

This commit is contained in:
Erik Thuning 2019-07-16 15:00:53 +02:00
commit a412256598
6 changed files with 48 additions and 10 deletions

@ -1,6 +1,7 @@
create table `product` (
`id` bigint(20) not null auto_increment,
primary key(`id`),
`brand` varchar(64) not null,
`name` varchar(64) not null,
`invoice` varchar(64) not null,
`serial` varchar(64) not null,

@ -180,6 +180,16 @@
value="¤name¤" />
</td>
</tr>
<tr>
<td>
Tillverkare:
</td>
<td>
<input type="text"
name="brand"
value="¤brand¤" />
</td>
</tr>
<tr>
<td>
Fakturanummer:

@ -1,6 +1,7 @@
<?php
class Product {
private $id = 0;
private $brand = '';
private $name = '';
private $invoice = '';
private $serial = '';
@ -9,19 +10,22 @@ class Product {
private $info = array();
private $tags = array();
public static function create_product($name = '',
$invoice = '',
$serial = '',
$info = array(),
$tags = array()) {
public static function create_product(
$brand,
$name,
$invoice,
$serial,
$info = array(),
$tags = array()
) {
$now = time();
begin_trans();
try {
$stmt = 'insert into
`product`(`name`, `invoice`, `serial`, `createtime`)
values (?, ?, ?, ?)';
`product`(`brand`, `name`, `invoice`, `serial`, `createtime`)
values (?, ?, ?, ?, ?)';
$ins_prod = prepare($stmt);
bind($ins_prod, 'sssi', $name, $invoice, $serial, $now);
bind($ins_prod, 'ssssi', $brand, $name, $invoice, $serial, $now);
execute($ins_prod);
$product = new Product($serial, 'serial');
foreach($info as $field => $value) {
@ -70,6 +74,7 @@ class Product {
bind($get, 'i', $this->id);
execute($get);
$product = result_single($get);
$this->brand = $product['brand'];
$this->name = $product['name'];
$this->invoice = $product['invoice'];
$this->serial = $product['serial'];
@ -118,6 +123,7 @@ class Product {
case 'status':
$matchvalues[] = $this->get_status();
case 'fritext':
$matchvalues[] = $this->brand;
$matchvalues[] = $this->name;
$matchvalues[] = $this->serial;
$matchvalues[] = $this->invoice;
@ -188,6 +194,18 @@ class Product {
return new Service($result['id']);
}
public function get_brand() {
return $this->brand;
}
public function set_brand($newbrand) {
$update = prepare('update `product` set `brand`=? where `id`=?');
bind($update, 'si', $newbrand, $this->id);
execute($update);
$this->brand = $newbrand;
return true;
}
public function get_name() {
return $this->name;
}

@ -74,6 +74,7 @@ class ProductPage extends Page {
$this->fragments['tag']);
}
$fields = array('id' => $this->product->get_id(),
'brand' => $this->product->get_brand(),
'name' => $this->product->get_name(),
'serial' => $this->product->get_serial(),
'invoice' => $this->product->get_invoice(),

@ -8,7 +8,7 @@ class SearchPage extends Page {
if(isset($_GET['q']) && !$_GET['q']) {
unset($_GET['q']);
}
$this->terms = $this->translate_keys($_GET);
$this->terms = $_GET;
}
private function do_search() {
@ -17,7 +17,7 @@ class SearchPage extends Page {
return $out;
}
foreach(array('user', 'product') as $type) {
$result = $this->search($type, $this->terms);
$result = $this->search($type, $this->translate_keys($this->terms));
if($result) {
$out[$type] = $result;
}
@ -33,6 +33,10 @@ class SearchPage extends Page {
case 'q':
$newkey = 'fritext';
break;
case 'tillverkare':
case 'märke':
$newkey = 'brand';
break;
case 'namn':
$newkey = 'name';
break;

@ -219,6 +219,10 @@ function suggest($type) {
}
function match($testvalues, $matchvalues) {
# match only presence of field (if no value given)
if(!$testvalues && $matchvalues) {
return true;
}
if(!is_array($testvalues)) {
$testvalues = array($testvalues);
}