Attributes can be set in products now
This commit is contained in:
@@ -75,7 +75,7 @@
|
||||
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
|
||||
<a href="<?=self::getUrl("User", "Index", ["filter" => ["address_id" => $address->id]])?>" title="Benutzer anzeigen"><i class="fas fa-users"></i></a>
|
||||
<a href="<?=self::getUrl("Address", "edit", ["id" => $address->id])?>"><i class="far fa-edit" title="Bearbeiten"></i></a>
|
||||
<a href="<?=self::getUrl("Address", "delete", ["id" => $address->id])?>" class="text-danger" title="Löschen"><i class="fas fa-trash"></i></a>
|
||||
<a href="<?=self::getUrl("Address", "delete", ["id" => $address->id])?>" onclick="if(!confirm('Person/Firma wirklich löschen?')) return false;" class="text-danger" title="Löschen"><i class="fas fa-trash"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
|
||||
@@ -178,16 +178,18 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if(is_array($attributes) && count($attributes)): ?>
|
||||
<h4 class="header-title mb-2">Zusatzdaten</h4>
|
||||
<?php if(is_array($product->attributes) && count($product->attributes)): ?>
|
||||
<h4 class="header-title mb-2">Produktattribute</h4>
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="rtrcode">RTR Betreiber ID</label>
|
||||
<div class="col-lg-10">
|
||||
<input class="form-control" name="attributes[rtrcode]" id="rtrcode" value="<?=$address->attributes['rtrcode']->value?>">
|
||||
<?php foreach($product->attributes as $attrib): ?>
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="attributes_<?=$attrib->producttechattribute_id?>"><?=$attrib->displayname?></label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control" name="attributes[<?=$attrib->producttechattribute_id?>]" id="attributes_<?=$attrib->producttechattribute_id?>" value="<?=$attrib->value?>" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
235
Layout/default/Producttech/Form.php
Normal file
235
Layout/default/Producttech/Form.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/header.php"); ?>
|
||||
|
||||
<div class="wrapper">
|
||||
<div class="container-fluid">
|
||||
|
||||
<!-- start page title -->
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="page-title-box">
|
||||
<div class="page-title-right">
|
||||
<ol class="breadcrumb m-0">
|
||||
<li class="breadcrumb-item"><a href="<?=self::getUrl("Dashboard")?>">the-tool</a></li>
|
||||
<li class="breadcrumb-item"><a href="<?=self::getUrl("Product")?>">Produkte</a></li>
|
||||
<li class="breadcrumb-item"><a href="<?=self::getUrl("Producttech")?>">Technologien</a></li>
|
||||
<li class="breadcrumb-item active"><?=($producttech->id) ? "bearbeiten" : "Neu" ?></li>
|
||||
</ol>
|
||||
</div>
|
||||
<h4 class="page-title">Produkte</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end page title -->
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4 class="header-title mb-2"><?=($producttech->id) ? "Technologie bearbeiten" : "Neue Technologie"?></h4>
|
||||
|
||||
<form class="form-horizontal" method="post" action="<?=self::getUrl("Producttech", "save")?>">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
|
||||
<input type="hidden" name="id" value="<?=$producttech->id?>" />
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="name">Name</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control" name="name" id="name" value="<?=$producttech->name?>" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="customer_type">Kundentyp</label>
|
||||
<div class="col-lg-10">
|
||||
<select class="select2 form-control " name="customer_type" id="customer_type">
|
||||
<option value="residential" <?=($producttech->customer_type != "business") ? "selected='selected'" : ""?>>Residential</option>
|
||||
<option value="business" <?=($producttech->customer_type == "business") ? "selected='selected'" : ""?>>Business</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="description">Beschreibung</label>
|
||||
<div class="col-lg-10">
|
||||
<textarea name="description" id="description" class="form-control" rows="2"><?=$producttech->description?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h4 class="header-title mb-2">Produktattribute</h4>
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
|
||||
<?php if(is_array($producttech->attributes) && count($producttech->attributes)): ?>
|
||||
<?php $i=0; foreach($producttech->attributes as $attribute): ?>
|
||||
<div class="p-2 <?=($i % 2 == 0) ? "bg-light" : ""?>">
|
||||
<div class="row">
|
||||
<div class="col-md-11 float-left">
|
||||
<h4 class="header-title">Attribut <span class="text-monospace text-pink"><?=$attribute->name?></span></h4>
|
||||
</div>
|
||||
<div class="col-md-1 float-right">
|
||||
<small><a class="text-danger" href="<?=self::getUrl("ProducttechAttribute", "delete", ['id' => $attribute->id])?>" onclick="if(!confirm('Attribut wirklich löschen?')) return false;"><i class="fas fa-trash-alt"></i> löschen</a></small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label for="attributes_<?=$attribute->id?>_name">Name <small class="text-monospace">[a-z0-9._-]</small></label>
|
||||
<input type="text" class="form-control" id="attributes_<?=$attribute->id?>_name" name="attributes[<?=$attribute->id?>][name]" value="<?=$attribute->name?>" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label for="attributes_<?=$attribute->id?>_displayname">Anzeigename</label>
|
||||
<input type="text" class="form-control" id="attributes_<?=$attribute->id?>_displayname" name="attributes[<?=$attribute->id?>][displayname]" value="<?=$attribute->displayname?>" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label for="attributes_<?=$attribute->id?>_value">Standardwert</label>
|
||||
<input type="text" class="form-control" id="attributes_<?=$attribute->id?>_value" name="attributes[<?=$attribute->id?>][value]" value="<?=$attribute->value?>">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="attributes_<?=$attribute->id?>_description">Beschreibung</label>
|
||||
<input type="text" class="form-control" id="attributes_<?=$attribute->id?>_description" name="attributes[<?=$attribute->id?>][description]" value="<?=$attribute->description?>" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="attributes_<?=$attribute->id?>_note">Interne Notiz</label>
|
||||
<input type="text" class="form-control" id="attributes_<?=$attribute->id?>_note" name="attributes[<?=$attribute->id?>][note]" value="<?=$attribute->note?>" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php $i++; endforeach; ?>
|
||||
|
||||
<?php endif; ?>
|
||||
<hr />
|
||||
<h4 class="header-title">Neues Attribut:</h4>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label for="attributes_new_name">Name <small class="text-monospace">[a-z0-9._-]</small></label>
|
||||
<input type="text" class="form-control" id="attributes_new_name" name="attributes[new][name]" value="" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label for="attributes_new_displayname">Anzeigename</label>
|
||||
<input type="text" class="form-control" id="attributes_new_displayname" name="attributes[new][displayname]" value="" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label for="attributes_new_value">Standardwert</label>
|
||||
<input type="text" class="form-control" id="attributes_new_value" name="attributes[new][value]" value="">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="attributes_new_description">Beschreibung</label>
|
||||
<input type="text" class="form-control" id="attributes_new_description" name="attributes[new][description]" value="" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="attributes_new_note">Interne Notiz</label>
|
||||
<input type="text" class="form-control" id="attributes_new_note" name="attributes[new][note]" value="" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="note">Interne Notiz</label>
|
||||
<div class="col-lg-10">
|
||||
<textarea id="note" class="form-control" name="note" rows="5"><?=$product->note?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2"></label>
|
||||
<div class="col-lg-10">
|
||||
<button type="submit" class="btn btn-primary">Speichern</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div> <!-- end container-fluid -->
|
||||
</div>
|
||||
<!-- end wrapper -->
|
||||
|
||||
<script type="text/javascript">
|
||||
$("#productgroup_id").select2({
|
||||
allowClear: true,
|
||||
placeholder: ""
|
||||
});
|
||||
$("#producttech_id").select2({
|
||||
allowClear: true,
|
||||
placeholder: ""
|
||||
});
|
||||
$("#networks").select2({
|
||||
allowClear: true,
|
||||
placeholder: ""
|
||||
});
|
||||
|
||||
$('#productgroup_id').change(function() {
|
||||
var value = $('#productgroup_id option:selected').val();
|
||||
console.log(value);
|
||||
if(value == "new") {
|
||||
$('#productgroup_form').show();
|
||||
} else {
|
||||
$('#productgroup_form').hide();
|
||||
}
|
||||
});
|
||||
|
||||
$('#producttech_id').change(function() {
|
||||
var value = $('#producttech_id option:selected').val();
|
||||
console.log(value);
|
||||
if(value == "new") {
|
||||
$('#producttech_form').show();
|
||||
} else {
|
||||
$('#producttech_form').hide();
|
||||
}
|
||||
});
|
||||
|
||||
// disable mousewheel on input number field when in focus
|
||||
$('form').on('focus', 'input[type=number]', function (e) {
|
||||
$(this).on('wheel.disableScroll', function (e) {
|
||||
e.preventDefault()
|
||||
})
|
||||
});
|
||||
$('form').on('blur', 'input[type=number]', function (e) {
|
||||
$(this).off('wheel.disableScroll')
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/footer.php"); ?>
|
||||
62
Layout/default/Producttech/Index.php
Normal file
62
Layout/default/Producttech/Index.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/header.php"); ?>
|
||||
|
||||
<div class="wrapper">
|
||||
<div class="container-fluid">
|
||||
|
||||
<!-- start page title -->
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="page-title-box">
|
||||
<div class="page-title-right">
|
||||
<ol class="breadcrumb m-0">
|
||||
<li class="breadcrumb-item"><a href="<?=self::getUrl("Dashboard")?>">the-tool</a></li>
|
||||
<li class="breadcrumb-item"><a href="<?=self::getUrl("Product")?>">Produkte</a></li>
|
||||
<li class="breadcrumb-item active">Technologien</li>
|
||||
</ol>
|
||||
</div>
|
||||
<h4 class="page-title">Produkttechnologien</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end page title -->
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body mb-3">
|
||||
<div class="float-left">
|
||||
<h4 class="header-title">Liste aller Technologien</h4>
|
||||
</div>
|
||||
<div class="float-right">
|
||||
<a class="btn btn-primary mb-2" href="<?=self::getUrl("Producttech", "add")?>"><i class="fas fa-plus"></i> Neue Technologie anlegen</a>
|
||||
</div>
|
||||
|
||||
<table class="table table-striped table-hover">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Kundentyp</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
<?php foreach($producttechs as $tech): ?>
|
||||
<tr>
|
||||
<td><?=$tech->name?></td>
|
||||
<td><?=__($tech->customer_type)?></td>
|
||||
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
|
||||
<a href="<?=self::getUrl("Producttech", "edit", ["id" => $tech->id])?>"><i class="far fa-edit" title="Technologie Bearbeiten"></i></a>
|
||||
<a href="<?=self::getUrl("Producttech", "delete", ["id" => $tech->id])?>" class="text-danger" onclick="if(!confirm('Technologie wirklich löschen?')) return false;" title="Technologie Löschen"><i class="fas fa-trash"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div> <!-- end container-fluid -->
|
||||
</div>
|
||||
<!-- end wrapper -->
|
||||
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/footer.php"); ?>
|
||||
@@ -20,9 +20,14 @@
|
||||
<li><a href="<?=self::getUrl("Address", "Index" , ["filter" => ["addresstype" => ["supplier"]]])?>">Lieferanten</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="has-sub-submenu">
|
||||
<a href="<?=self::getUrl("Product")?>">Produkte</a>
|
||||
<ul class="sub-submenu">
|
||||
<li><a href="<?=self::getUrl("Producttech")?>">Technologien</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="<?=self::getUrl("User")?>">Benutzer</a></li>
|
||||
<li><a href="<?=self::getUrl("Network")?>">Netzgebiete</a></li>
|
||||
<li><a href="<?=self::getUrl("Product")?>">Produkte</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@@ -5,6 +5,36 @@ class Product extends mfBaseModel {
|
||||
private $producttech;
|
||||
private $sla;
|
||||
private $networks;
|
||||
private $attributes;
|
||||
|
||||
public function loadAttributes() {
|
||||
if(!$this->producttech_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->attributes = [];
|
||||
|
||||
// get tech attribs
|
||||
$ptattribs = ProducttechAttributeModel::search(['producttech_id' => $this->producttech_id]);
|
||||
// fill atrribs with existing values of product attribs
|
||||
foreach($ptattribs as $pta) {
|
||||
$attrib = ProductAttributeModel::getFirst(['product_id' => $this->id, 'producttechattribute_id' => $pta->id]);
|
||||
if(!$attrib) {
|
||||
$attrib = new ProductAttribute();
|
||||
$attrib->product_id = $this->id;
|
||||
$attrib->producttechattribute_id = $pta->id;
|
||||
$attrib->value = $pta->value;
|
||||
$attrib->note = $pta->note;
|
||||
}
|
||||
$attrib->name = $pta->name;
|
||||
$attrib->displayname = $pta->displayname;
|
||||
$attrib->description = $pta->description;
|
||||
$this->attributes[$attrib->name] = $attrib;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
@@ -18,7 +48,10 @@ class Product extends mfBaseModel {
|
||||
return $this->networks;
|
||||
}
|
||||
|
||||
|
||||
if($name == "attributes") {
|
||||
$this->loadAttributes();
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
|
||||
@@ -35,6 +35,8 @@ class ProductController extends mfBaseController {
|
||||
$this->redirect("Product");
|
||||
}
|
||||
|
||||
//var_dump($product->attributes);exit;
|
||||
|
||||
$this->layout()->set("product", $product);
|
||||
|
||||
return $this->addAction();
|
||||
@@ -49,7 +51,7 @@ class ProductController extends mfBaseController {
|
||||
$product = new Product($id);
|
||||
if(!$product->id) {
|
||||
$this->layout()->setFlash("Produkt nicht gefunden", "error");
|
||||
$this->redirect("Produkt");
|
||||
$this->redirect("Product");
|
||||
}
|
||||
} else {
|
||||
$id = false;
|
||||
@@ -79,10 +81,10 @@ class ProductController extends mfBaseController {
|
||||
$data['productgroup_id'] = null;
|
||||
}
|
||||
|
||||
$data['edit_by'] = 1;
|
||||
$data['edit_by'] = $this->me->id;
|
||||
|
||||
if($mode == "add") {
|
||||
$data['create_by'] = 1;
|
||||
$data['create_by'] = $this->me->id;
|
||||
$product = ProductModel::create($data);
|
||||
} else {
|
||||
$product->update($data);
|
||||
@@ -141,6 +143,22 @@ class ProductController extends mfBaseController {
|
||||
$product->save();
|
||||
}
|
||||
|
||||
if(is_array($r->attributes) && count($r->attributes)) {
|
||||
foreach($r->attributes as $pta_id => $attribute_value) {
|
||||
$attrib = ProductAttributeModel::getFirst(['product_id' => $new_id, 'producttechattribute_id' => $pta_id]);
|
||||
if(!$attrib) {
|
||||
$attrib = ProductAttributeModel::create([
|
||||
'product_id' => $new_id,
|
||||
'producttechattribute_id' => $pta_id,
|
||||
]);
|
||||
//var_dump($attrib);exit;
|
||||
}
|
||||
$attrib->value = $attribute_value;
|
||||
$attrib->edit_by = $this->me->id;
|
||||
$attrib->save();
|
||||
}
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Produkt erfolgreich gespeichert.", "success");
|
||||
$this->redirect("Product", "Edit", ['id' => $new_id]);
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ class ProductModel {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Product", "*", "$where ORDER BY name, owner_id");
|
||||
$res = $db->select("Product", "*", "$where ORDER BY producttech_id, name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Product($data);
|
||||
|
||||
33
application/ProductAttribute/ProductAttribute.php
Normal file
33
application/ProductAttribute/ProductAttribute.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
class ProductAttribute extends mfBaseModel {
|
||||
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if($name == "networks") {
|
||||
$this->networks = [];
|
||||
$productNetworks = ProductNetworkModel::search(['product_id' => $this->id]);
|
||||
foreach($productNetworks as $pnet) {
|
||||
$this->networks[$pnet->network_id] = new Network($pnet->network_id);
|
||||
}
|
||||
return $this->networks;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
|
||||
if($this->$name->id) {
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
}
|
||||
18
application/ProductAttribute/ProductAttributeController.php
Normal file
18
application/ProductAttribute/ProductAttributeController.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
class ProductAttributeController extends mfBaseController {
|
||||
|
||||
protected function init() {
|
||||
$this->needlogin=true;
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
/*
|
||||
if(!$me->isAdmin()) {
|
||||
$this->redirect("Dashboard");
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
121
application/ProductAttribute/ProductAttributeModel.php
Normal file
121
application/ProductAttribute/ProductAttributeModel.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
class ProductAttributeModel {
|
||||
public $product_id = null;
|
||||
public $producttechattribute_id = null;
|
||||
public $value = null;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new ProductAttribute();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
$model->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if($model->create_by === null) {
|
||||
$model->create_by = $me->id;
|
||||
}
|
||||
if($model->edit_by === null) {
|
||||
$model->edit_by = $me->id;
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getOne($id) {
|
||||
if(!is_numeric($id) || !$id) {
|
||||
throw new Exception("Invalid number", 400);
|
||||
}
|
||||
$item = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("ProductAttribute", "*", "id=$id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new ProductAttribute($data);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("ProductAttribute", "*", "1 = 1 ORDER BY product_id, producttechattribute_id");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new ProductAttribute($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("ProductAttribute", "*", "$where ORDER BY product_id, producttechattribute_id");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new ProductAttribute($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function search($filter) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("ProductAttribute", "*", "$where ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new ProductAttribute($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
if(array_key_exists("product_id", $filter)) {
|
||||
$product_id = $filter['product_id'];
|
||||
if(is_numeric($product_id)) {
|
||||
$where .= " AND `product_id` = $product_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("producttechattribute_id", $filter)) {
|
||||
$producttechattribute_id = $filter['producttechattribute_id'];
|
||||
if(is_numeric($producttechattribute_id)) {
|
||||
$where .= " AND `producttechattribute_id` = $producttechattribute_id";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,32 @@
|
||||
<?php
|
||||
|
||||
class Producttech extends mfBaseModel {
|
||||
private $attributes;
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if($name == "attributes") {
|
||||
$this->attributes = [];
|
||||
$producttechAttributes = ProducttechAttributeModel::search(['producttech_id' => $this->id]);
|
||||
foreach($producttechAttributes as $pta) {
|
||||
$this->attributes[$pta->id] = $pta;
|
||||
}
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
|
||||
if($this->$name->id) {
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
}
|
||||
133
application/Producttech/ProducttechController.php
Normal file
133
application/Producttech/ProducttechController.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
class ProducttechController extends mfBaseController {
|
||||
|
||||
protected function init() {
|
||||
$this->needlogin=true;
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
/*
|
||||
if(!$me->isAdmin()) {
|
||||
$this->redirect("Dashboard");
|
||||
}*/
|
||||
}
|
||||
|
||||
protected function indexAction() {
|
||||
$this->layout()->setTemplate("Producttech/Index");
|
||||
$this->layout()->set("producttechs", ProducttechModel::getAll());
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
$this->layout()->setTemplate("Producttech/Form");
|
||||
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
$tech_id = $this->request->id;
|
||||
$tech = new Producttech($tech_id);
|
||||
if(!$tech->id) {
|
||||
$this->layout()->setFlash("Technologie nicht gefunden.", "error");
|
||||
$this->redirect("Producttech");
|
||||
}
|
||||
|
||||
$this->layout()->set("producttech", $tech);
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
//var_dump($r);
|
||||
//var_dump($r->attributes);
|
||||
//exit;
|
||||
$id = $r->id;
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$producttech = new Producttech($id);
|
||||
if(!$producttech->id) {
|
||||
$this->layout()->setFlash("Technologie nicht gefunden", "error");
|
||||
$this->redirect("Producttech");
|
||||
}
|
||||
} else {
|
||||
$id = false;
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['name'] = $r->name;
|
||||
$data['customer_type'] = $r->customer_type;
|
||||
$data['description'] = $r->description;
|
||||
$data['note'] = $r->note;
|
||||
|
||||
$data['edit_by'] = $this->me->id;
|
||||
|
||||
if($mode == "add") {
|
||||
$data['create_by'] = $this->me->id;
|
||||
$producttech = ProducttechModel::create($data);
|
||||
} else {
|
||||
$producttech->update($data);
|
||||
}
|
||||
|
||||
//var_dump($address);exit;
|
||||
|
||||
$new_id = $producttech->save();
|
||||
if(!$new_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
$this->layout()->set("producttech", $producttech);
|
||||
return $this->add();
|
||||
}
|
||||
|
||||
// handle ProductAttributes
|
||||
if(is_array($r->attributes) && count($r->attributes)) {
|
||||
foreach($r->attributes as $aid => $attribute) {
|
||||
if(!trim($attribute['name']) || !trim($attribute['displayname'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$a = [];
|
||||
$a['name'] = $attribute['name'];
|
||||
$a['producttech_id'] = $new_id;
|
||||
$a['displayname'] = $attribute['displayname'];
|
||||
$a['value'] = $attribute['value'];
|
||||
$a['description'] = $attribute['description'];
|
||||
$a['note'] = $attribute['note'];
|
||||
$a['edit_by'] = $this->me->id;
|
||||
|
||||
if($aid == "new") {
|
||||
$attrib = ProducttechAttributeModel::create($a);
|
||||
} elseif(is_numeric($aid) && $aid > 0) {
|
||||
$attrib = new ProducttechAttribute($aid);
|
||||
$attrib->update($a);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
$attrib->save();
|
||||
}
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Technologie erfolgreich gespeichert.", "success");
|
||||
$this->redirect("Producttech", "edit", ['id' => $new_id]);
|
||||
|
||||
}
|
||||
|
||||
protected function delete() {
|
||||
$id = $this->request->id;
|
||||
|
||||
$tech = new Producttech($id);
|
||||
if(!$tech->id || $tech->id != $id) {
|
||||
$this->layout()->setFlash("Technologie nicht gefunden.", "error");
|
||||
$this->redirect("Producttech");
|
||||
}
|
||||
|
||||
if(ProductModel::search(["producttech_id" => $tech->id])) {
|
||||
$this->layout()->setFlash("Technologie kann nicht gelöscht werden, da sie in Verwendung ist.", "error");
|
||||
$this->redirect("Producttech");
|
||||
}
|
||||
|
||||
// check if Product is unused
|
||||
$tech->delete();
|
||||
$this->redirect("Producttech");
|
||||
}
|
||||
}
|
||||
23
application/ProducttechAttribute/ProducttechAttribute.php
Normal file
23
application/ProducttechAttribute/ProducttechAttribute.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
class ProducttechAttribute extends mfBaseModel {
|
||||
private $producttech;
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
|
||||
if($this->$name->id) {
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
class ProducttechAttributeController extends mfBaseController {
|
||||
|
||||
protected function init() {
|
||||
$this->needlogin=true;
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
/*
|
||||
if(!$me->isAdmin()) {
|
||||
$this->redirect("Dashboard");
|
||||
}*/
|
||||
}
|
||||
|
||||
protected function deleteAction() {
|
||||
$id = $this->request->id;
|
||||
|
||||
$ta = new ProducttechAttribute($id);
|
||||
if(!$ta->id || $ta->id != $id) {
|
||||
$this->layout()->setFlash("Attribut nicht gefunden.", "error");
|
||||
$this->redirect("Producttech");
|
||||
}
|
||||
|
||||
/*if(ProductModel::search(["producttech_id" => $tech->id])) {
|
||||
$this->layout()->setFlash("Technologie kann nicht gelöscht werden, da sie in Verwendung ist.", "error");
|
||||
$this->redirect("Producttech");
|
||||
}*/
|
||||
|
||||
$producttech_id = $ta->producttech_id;
|
||||
|
||||
// check if Product is unused
|
||||
$ta->delete();
|
||||
$this->redirect("Producttech", "edit", ['id' => $producttech_id]);
|
||||
}
|
||||
}
|
||||
132
application/ProducttechAttribute/ProducttechAttributeModel.php
Normal file
132
application/ProducttechAttribute/ProducttechAttributeModel.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
class ProducttechAttributeModel {
|
||||
public $producttech_id = null;
|
||||
public $name = null;
|
||||
public $displayname = null;
|
||||
public $value = null;
|
||||
public $description = null;
|
||||
|
||||
public $note = null;
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new ProducttechAttribute();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
$model->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if($model->create_by === null) {
|
||||
$model->create_by = $me->id;
|
||||
}
|
||||
if($model->edit_by === null) {
|
||||
$model->edit_by = $me->id;
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getOne($id) {
|
||||
if(!is_numeric($id) || !$id) {
|
||||
throw new Exception("Invalid number", 400);
|
||||
}
|
||||
$item = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("ProducttechAttribute", "*", "id=$id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new ProducttechAttribute($data);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("ProducttechAttribute", "*", "1 = 1 ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new ProducttechAttribute($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("ProducttechAttribute", "*", "$where ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new ProducttechAttribute($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function search($filter) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("ProducttechAttribute", "*", "$where ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new ProducttechAttribute($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if(array_key_exists("name", $filter)) {
|
||||
$name = $db->escape($filter['name']);
|
||||
if($name) {
|
||||
$where .= " AND `name` like '$name'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("nameLike", $filter)) {
|
||||
$name = $db->escape($filter['nameLike']);
|
||||
if($name) {
|
||||
$where .= " AND `name` like '%$name%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("producttech_id", $filter)) {
|
||||
$producttech_id = $db->escape($filter['producttech_id']);
|
||||
if(is_numeric($producttech_id)) {
|
||||
$where .= " AND `producttech_id` = $producttech_id";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user