WIP Ivt Import 2024-05-02

This commit is contained in:
Frank Schubert
2024-05-06 13:24:25 +02:00
parent df108dca2d
commit 6002876343
17 changed files with 1298 additions and 404 deletions
@@ -0,0 +1,67 @@
<?php
class IvtCustomerTelephoneNr extends mfBaseModel {
protected $forcestr = [];
private $customer;
/**
* Takes ID or DB row as arguments
* @param id or table row $_
*/
public function __construct($_ = NULL) {
$this->log = mfLoghandler::singleton();
$this->data = new stdClass();
$this->table = "products";
$this->db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
if(is_numeric($_)) {
$this->fetch($_);
} elseif(is_object($_)) {
$this->load($_);
}
}
public function save() {
return true;
}
public function getProperty($name) {
if($this->$name == null) {
if($name == "customer") {
$ivtcustomer = new IvtCustomer($this->cid);
if($ivtcustomer->id) {
$this->ivtcustomer = $ivtcustomer;
}
return $this->ivtcustomer;
}
$classname = ucfirst($name);
$idfield = $name . "_id";
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-" . $this->$idfield);
if(!$this->$name) {
$this->$name = new $classname($this->$idfield);
}
if($this->$name->id) {
mfValuecache::singleton()->set("mfObjectmodel-$name-" . $this->$name->id, $this->$name);
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
public function __debugInfo() {
$vars = get_object_vars($this);
if(is_object($vars['db'])) $vars['db'] = "object(FronkDB)";
if(is_object($vars['log'])) $vars['log'] = 'object(mfLoghandler)';
return $vars;
}
}
@@ -0,0 +1,115 @@
<?php
class IvtCustomerTelephoneNrModel {
public static function getAll($order = false) {
$items = [];
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
if(!$order) {
$order = "id";
}
$res = $db->select("customer_telephone_nr", "*", "1=1 ORDER BY $order");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new IvtCustomerTelephoneNr($data);
}
}
return $items;
}
public static function getFirst($filter = []) {
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
$where = self::getSqlFilter($filter);
$res = $db->select("customer_telephone_nr", "*", "$where ORDER BY id LIMIT 1");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new IvtCustomerTelephoneNr($data);
if($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function count($filter) {
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
$where = self::getSqlFilter($filter);
$sql = "SELECT COUNT(*) cnt FROM customer_telephone_nr WHERE $where ORDER by id";
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
return $data->cnt;
}
return 0;
}
public static function search($filter, $limit = false) {
$items = [];
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM customer_telephone_nr WHERE $where ORDER by cid,pid,sid,id";
mfLoghandler::singleton()->debug($sql);
if(is_array($limit) && count($limit)) {
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
} elseif(is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['count'];
}
}
$res = $db->query($sql);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new IvtCustomerTelephoneNr($data);
}
}
return $items;
}
private static function getSqlFilter($filter) {
$where = "1=1 ";
if(array_key_exists("cid", $filter)) {
$cid = $filter['cid'];
if(is_numeric($cid)) {
$where .= " AND cid=$cid";
}
}
if(array_key_exists("pid", $filter)) {
$pid = $filter['pid'];
if(is_numeric($pid)) {
$where .= " AND pid=$pid";
}
}
if(array_key_exists("number", $filter)) {
$number = (string)FronkDB::singleton()->escape($filter['number']);
if($number) {
$where .= " AND number='$number'";
}
}
if(array_key_exists("number%", $filter)) {
$number = (string)FronkDB::singleton()->escape($filter['number']);
if($number) {
$where .= " AND number LIKE '%$number%'";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}