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` ( create table `product` (
`id` bigint(20) not null auto_increment, `id` bigint(20) not null auto_increment,
primary key(`id`), primary key(`id`),
`brand` varchar(64) not null,
`name` varchar(64) not null, `name` varchar(64) not null,
`invoice` varchar(64) not null, `invoice` varchar(64) not null,
`serial` varchar(64) not null, `serial` varchar(64) not null,

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

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

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

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

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