206 lines
5.2 KiB
PHP
206 lines
5.2 KiB
PHP
<?php
|
|
|
|
class PreorderModel {
|
|
public $ucode;
|
|
public $preordercampaign_id;
|
|
public $adb_hausnummer_id;
|
|
public $adb_wohneinheit_id;
|
|
public $address_info;
|
|
public $building_id;
|
|
public $termination_id;
|
|
public $connection_type;
|
|
public $connection_count;
|
|
public $product_id;
|
|
public $setup_product_id;
|
|
public $type;
|
|
public $order_id;
|
|
public $price;
|
|
public $price_setup;
|
|
public $price_nne;
|
|
public $price_nbe;
|
|
public $billing_delay;
|
|
public $billing_period;
|
|
public $partner_id;
|
|
public $accept_agb;
|
|
public $accept_dsgvo;
|
|
public $accept_marketing;
|
|
public $accept_withdrawal;
|
|
public $company;
|
|
public $uid;
|
|
public $firstname;
|
|
public $lastname;
|
|
public $street;
|
|
public $zip;
|
|
public $city;
|
|
public $phone;
|
|
public $email;
|
|
public $submit_type;
|
|
public $submit_request;
|
|
|
|
public $note;
|
|
|
|
public $create_by;
|
|
public $edit_by;
|
|
public $create;
|
|
public $edit;
|
|
|
|
public static function create(Array $data) {
|
|
$model = new Preorder();
|
|
|
|
foreach($data as $field => $value) {
|
|
if(property_exists(get_called_class(), $field)) {
|
|
if(substr($field, 0, 5) == "vlan_" && !$value) {
|
|
$model->$field = null;
|
|
continue;
|
|
}
|
|
$model->$field = $value;
|
|
}
|
|
}
|
|
|
|
$me = mfValuecache::singleton()->get("me");
|
|
if(!$me) {
|
|
$me = new User();
|
|
$me->loadMe();
|
|
mfValuecache::singleton()->set("me", $me);
|
|
}
|
|
|
|
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 getAll() {
|
|
$items = [];
|
|
|
|
$db = FronkDB::singleton();
|
|
|
|
$res = $db->select("Preorder", "*");
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new Preorder($data);
|
|
}
|
|
}
|
|
return $items;
|
|
|
|
}
|
|
|
|
public static function getFirst() {
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$res = $db->select("Preorder", "*", "$where ORDER BY lastname, firstname");
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new Preorder($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("Preorder", "*", "$where ORDER BY lastname, firstname");
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new Preorder($data);
|
|
}
|
|
}
|
|
return $items;
|
|
}
|
|
|
|
private static function getSqlFilter($filter) {
|
|
$where = "1=1 ";
|
|
|
|
//var_dump($filter);exit;
|
|
|
|
if(array_key_exists("deleted", $filter)) {
|
|
$deleted = $filter['deleted'];
|
|
if(is_numeric($deleted)) {
|
|
$where .= " AND deleted=$deleted";
|
|
}
|
|
/*if($deleted === null) {
|
|
$where .= " AND deleted IS NULL";
|
|
}*/
|
|
}
|
|
|
|
if(array_key_exists("preordercampaign_id", $filter)) {
|
|
$preordercampaign_id = $filter['preordercampaign_id'];
|
|
if(is_numeric($preordercampaign_id)) {
|
|
$where .= " AND preordercampaign_id=$preordercampaign_id";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("building_id", $filter)) {
|
|
$building_id = $filter['building_id'];
|
|
if(is_numeric($building_id)) {
|
|
$where .= " AND building_id=$building_id";
|
|
} elseif(is_array($building_id)) {
|
|
$where .= " AND building_id IN (".implode(",",$building_id).")";
|
|
} elseif($building_id === null) {
|
|
$where .= " AND building_id IS NULL";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("adb_hausnummer_id", $filter)) {
|
|
$adb_hausnummer_id = $filter['adb_hausnummer_id'];
|
|
if(is_numeric($adb_hausnummer_id)) {
|
|
$where .= " AND adb_hausnummer_id=$adb_hausnummer_id";
|
|
} elseif(is_array($adb_hausnummer_id)) {
|
|
$where .= " AND adb_hausnummer_id IN (".implode(",",$adb_hausnummer_id).")";
|
|
} elseif($adb_hausnummer_id === null) {
|
|
$where .= " AND adb_hausnummer_id IS NULL";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("adb_wohneinheit_id", $filter)) {
|
|
$adb_wohneinheit_id = $filter['adb_wohneinheit_id'];
|
|
if(is_numeric($adb_wohneinheit_id)) {
|
|
$where .= " AND adb_wohneinheit_id=$adb_wohneinheit_id";
|
|
} elseif(is_array($adb_wohneinheit_id)) {
|
|
$where .= " AND adb_wohneinheit_id IN (".implode(",",$adb_wohneinheit_id).")";
|
|
} elseif($adb_wohneinheit_id === null) {
|
|
$where .= " AND adb_wohneinheit_id IS NULL";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("type", $filter)) {
|
|
$type = $filter['type'];
|
|
if(is_array($type) && count($type)) {
|
|
$where .= " AND type IN ('".implode("','",$type)."')";
|
|
} else {
|
|
$type = FronkDB::singleton()->escape($filter['type']);
|
|
if($type) {
|
|
$where .= " AND type like '%$type%'";
|
|
}
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("ucode", $filter)) {
|
|
$ucode = FronkDB::singleton()->escape($filter['ucode']);
|
|
if($ucode) {
|
|
$where .= " AND ucode like '%$ucode%'";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
//var_dump($filter, $where);exit;
|
|
return $where;
|
|
}
|
|
|
|
}
|