Merge branch 'master' of code.fronk.at:fronk/thetool
This commit is contained in:
@@ -56,7 +56,7 @@ class NetworkController extends mfBaseController {
|
||||
$mode = "edit";
|
||||
$network = new Network($id);
|
||||
if(!$network->id) {
|
||||
$this->layout()->setFlash("Netzgebie tnicht gefunden", "error");
|
||||
$this->layout()->setFlash("Netzgebiet nicht gefunden", "error");
|
||||
$this->redirect("Network");
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -20,6 +20,16 @@ class NetworkModel {
|
||||
}
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
@@ -100,4 +100,42 @@ class NetworkAddressController extends mfBaseController {
|
||||
|
||||
$this->redirect("Network", "Index", [],"view=roles&net=$network_id");
|
||||
}
|
||||
|
||||
protected function deleteAction() {
|
||||
$r = $this->request;
|
||||
//var_dump($r->roles);exit;
|
||||
if(!is_numeric($r->network_id) && $r->network_id <= 0) {
|
||||
$this->layout()->setFlash("Netzgebiet nicht gefunden.", "error");
|
||||
$this->redirect("Network");
|
||||
}
|
||||
if(!is_numeric($r->address_id) && $r->address_id <= 0) {
|
||||
$this->layout()->setFlash("Person/Firma nicht gefunden.", "error");
|
||||
$this->redirect("Network");
|
||||
}
|
||||
|
||||
$network_id = $r->network_id;
|
||||
$address_id = $r->address_id;
|
||||
|
||||
$network = new Network($network_id);
|
||||
if(!$network->id) {
|
||||
$this->layout()->setFlash("Netzgebiet nicht gefunden.", "error");
|
||||
$this->redirect("Network");
|
||||
}
|
||||
|
||||
$address = new Address($address_id);
|
||||
if(!$address->id) {
|
||||
$this->layout()->setFlash("Person/Firma nicht gefunden.", "error");
|
||||
$this->redirect("Network", "Index", [], "view=roles&net=$network_id");
|
||||
}
|
||||
|
||||
$roles = NetworkAddressModel::search(["network_id" => $network_id, "address_id" => $address_id]);
|
||||
//var_dump($roles);exit;
|
||||
|
||||
foreach($roles as $role) {
|
||||
$role->delete();
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Berechtigungen erfolgreich gelöscht.", "success");
|
||||
$this->redirect("Network", "Index", [], "view=roles&net=$network_id");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
class Product extends mfBaseModel {
|
||||
private $productgroup;
|
||||
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) {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if($name == "attributes") {
|
||||
$this->loadAttributes();
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
class ProductController 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()->set("products", ProductModel::getAll());
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
$this->layout()->setTemplate("Product/Form");
|
||||
$this->layout()->set("productgroups", ProductgroupModel::getAll());
|
||||
$this->layout()->set("producttechs", ProducttechModel::getAll());
|
||||
$this->layout()->set("slas", SlaModel::getAll());
|
||||
$this->layout()->set("networks", NetworkModel::getAll());
|
||||
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
$product_id = $this->request->id;
|
||||
$product = new Product($product_id);
|
||||
if(!$product->id) {
|
||||
$this->layout()->setFlash("Produkt nicht gefunden.", "error");
|
||||
$this->redirect("Product");
|
||||
}
|
||||
|
||||
//var_dump($product->attributes);exit;
|
||||
|
||||
$this->layout()->set("product", $product);
|
||||
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
//var_dump($r);exit;
|
||||
$id = $r->id;
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$product = new Product($id);
|
||||
if(!$product->id) {
|
||||
$this->layout()->setFlash("Produkt nicht gefunden", "error");
|
||||
$this->redirect("Product");
|
||||
}
|
||||
} else {
|
||||
$id = false;
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['name'] = $r->name;
|
||||
$data['description'] = $r->description;
|
||||
$data['sla_id'] = $r->sla_id;
|
||||
$data['external'] = ($r->external == 1) ? "1" : "0";
|
||||
$data['price_nne'] = Layout::commaToDot($r->price_nne);
|
||||
$data['price_nbe'] = Layout::commaToDot($r->price_nbe);
|
||||
$data['price'] = Layout::commaToDot($r->price);
|
||||
$data['price_setup'] = Layout::commaToDot($r->price_setup);
|
||||
$data['billing_period'] = $r->billing_period;
|
||||
$data['billing_delay'] = $r->billing_delay;
|
||||
$data['ivt_id'] = ($r->ivt_id) ? $r->ivt_id : null;
|
||||
$data['note'] = $r->note;
|
||||
|
||||
if(is_numeric($r->producttech_id)) {
|
||||
$data['producttech_id'] = $r->producttech_id;
|
||||
} else {
|
||||
$data['producttech_id'] = null;
|
||||
}
|
||||
if(is_numeric($r->productgroup_id)) {
|
||||
$data['productgroup_id'] = $r->productgroup_id;
|
||||
} else {
|
||||
$data['productgroup_id'] = null;
|
||||
}
|
||||
|
||||
$data['edit_by'] = $this->me->id;
|
||||
|
||||
if($mode == "add") {
|
||||
$data['create_by'] = $this->me->id;
|
||||
$product = ProductModel::create($data);
|
||||
} else {
|
||||
$product->update($data);
|
||||
}
|
||||
|
||||
//var_dump($address);exit;
|
||||
|
||||
$new_id = $product->save();
|
||||
if(!$new_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
$this->layout()->set("product", $product);
|
||||
return $this->add();
|
||||
}
|
||||
|
||||
// delete all networks to save networks
|
||||
$pnets = ProductNetworkModel::search(['product_id' => $new_id]);
|
||||
foreach($pnets as $pnet) {
|
||||
$pnet->delete();
|
||||
}
|
||||
|
||||
if(is_array($r->networks) && count($r->networks)) {
|
||||
foreach($r->networks as $network_id) {
|
||||
$network = new Network($network_id);
|
||||
if(!$network->id) {
|
||||
// ignore non-existing networks
|
||||
continue;
|
||||
}
|
||||
$pnet = ProductNetworkModel::create(['product_id' => $new_id, 'network_id' => $network_id]);
|
||||
$pnet->save();
|
||||
}
|
||||
}
|
||||
|
||||
// create new product group and tech
|
||||
|
||||
if($r->productgroup_id == "new") {
|
||||
$ng = [];
|
||||
$ng['name'] = $r->productgroup_new_name;
|
||||
$ng['description'] = $r->productgroup_new_description;
|
||||
$ng['note'] = $r->productgroup_new_note;
|
||||
$group = ProductgroupModel::create($ng);
|
||||
$group_id = $group->save();
|
||||
$product->productgroup_id = $group_id;
|
||||
$product->save();
|
||||
}
|
||||
|
||||
if($r->producttech_id == "new") {
|
||||
$nt = [];
|
||||
$nt['name'] = $r->producttech_new_name;
|
||||
$nt['rtrcode'] = $r->producttech_new_rtrcode;
|
||||
$nt['customer_type'] = ($r->producttech_new_customer_type == "business") ? "business" : "residential";
|
||||
$nt['description'] = $r->producttech_new_description;
|
||||
$nt['note'] = $r->producttech_new_note;
|
||||
$tech = ProducttechModel::create($nt);
|
||||
$tech_id = $tech->save();
|
||||
$product->producttech_id = $tech_id;
|
||||
$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]);
|
||||
}
|
||||
|
||||
protected function delete() {
|
||||
$id = $this->request->id;
|
||||
|
||||
$product = new Product($id);
|
||||
if(!$product->id || $product->id != $id) {
|
||||
$this->layout()->setFlash("Produkt nicht gefunden.", "error");
|
||||
$this->redirect("Product");
|
||||
}
|
||||
|
||||
// check if Product is unused
|
||||
$product->delete();
|
||||
$this->redirect("Product");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
class ProductModel {
|
||||
public $name = null;
|
||||
public $description = null;
|
||||
public $sla_id = null;
|
||||
public $external = null;
|
||||
public $productgroup_id = null;
|
||||
public $producttech_id = null;
|
||||
public $price = null;
|
||||
public $price_nne = null;
|
||||
public $price_nbe = null;
|
||||
public $billing_period = null;
|
||||
public $ivt_id = 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 Product();
|
||||
|
||||
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("Product", "*", "id=$id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Product($data);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Product", "*", "1 = 1 ORDER BY producttech_id, name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Product($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Product", "*", "$where ORDER BY producttech_id, name LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Product($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("Product", "*", "$where ORDER BY producttech_id, name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Product($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if(array_key_exists("productgroup_id", $filter)) {
|
||||
$productgroup_id = $filter['productgroup_id'];
|
||||
if(is_numeric($productgroup_id)) {
|
||||
$where .= " AND productgroup_id=$productgroup_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("producttech_id", $filter)) {
|
||||
$producttech_id = $filter['producttech_id'];
|
||||
if(is_numeric($producttech_id)) {
|
||||
$where .= " AND producttech_id=$producttech_id";
|
||||
}
|
||||
}
|
||||
|
||||
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%'";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class ProductNetwork extends mfBaseModel {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
class ProductNetworkModel {
|
||||
public $product_id = null;
|
||||
public $network_id = null;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new ProductNetwork();
|
||||
|
||||
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("ProductNetwork", "*", "id=$id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new ProductNetwork($data);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("ProductNetwork", "*", "1 = 1 ORDER BY product_id, network_id");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new ProductNetwork($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("ProductNetwork", "*", "$where ORDER BY product_id, network_id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new ProductNetwork($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("ProductNetwork", "*", "$where ORDER BY product_id, network_id");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new ProductNetwork($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
//var_dump($filter);exit;
|
||||
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("network_id", $filter)) {
|
||||
$network_id = $filter['network_id'];
|
||||
if(is_numeric($network_id)) {
|
||||
$where .= " AND network_id=$network_id";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class Productgroup extends mfBaseModel {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
class ProductgroupController 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() {
|
||||
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
class ProductgroupModel {
|
||||
public $name = 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 Productgroup();
|
||||
|
||||
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("Productgroup", "*", "id=$id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Productgroup($data);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Productgroup", "*", "1 = 1 ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new Productgroup($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Productgroup", "*", "$where ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Productgroup($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("Productgroup", "*", "$where ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new Productgroup($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%'";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +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;
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
class ProducttechModel {
|
||||
public $name = null;
|
||||
public $rtrcode = null;
|
||||
public $customer_type = 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 Producttech();
|
||||
|
||||
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("Producttech", "*", "id=$id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Producttech($data);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Producttech", "*", "1 = 1 ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new Producttech($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Producttech", "*", "$where ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Producttech($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("Producttech", "*", "$where ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new Producttech($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("rtrcode", $filter)) {
|
||||
$rtrcode = $db->escape($filter['rtrcode']);
|
||||
if($rtrcode) {
|
||||
$where .= " AND `code` like '$rtrcode'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("customer_type", $filter)) {
|
||||
$customer_type = ($customer_type == "business") ? "business" : "residential";
|
||||
$where .= " AND `customer_type`='$customer_type'";
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class Sla extends mfBaseModel {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
class SlaModel {
|
||||
public $name = 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 Sla();
|
||||
|
||||
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("Sla", "*", "id=$id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Sla($data);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Sla", "*", "1 = 1 ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Sla($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Sla", "*", "$where ORDER BY name LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Sla($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("Sla", "*", "$where ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Sla($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%'";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user