$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 getOne($id) { if (!is_numeric($id) || !$id) { throw new Exception("Invalid number", 400); } $item = []; $db = FronkDB::singleton(); $res = $db->select("Timerecording", "*", "id=$id LIMIT 1"); if ($db->num_rows($res)) { $data = $db->fetch_object($res); $item = new Timerecording($data); } return $item; } public static function getAllHours($user_id) { $items = []; $db = FronkDB::singleton(); $sql = "SELECT SUM(`end` - `start`) AS gesamt_summe FROM Timerecording where user_id=$user_id AND `timerecordingCategory_id` =1"; $res = $db->query($sql); if ($db->num_rows($res)) { while ($data = $db->fetch_object($res)) { $items[] = new Timerecording($data); } } return $items; } public static function getAll() { $items = []; $db = FronkDB::singleton(); $res = $db->select("Timerecording", "*", "1=1"); if ($db->num_rows($res)) { while ($data = $db->fetch_object($res)) { $items[] = new Timerecording($data); } } return $items; } public static function getAllPermits() { $items = []; $db = FronkDB::singleton(); $sql = "SELECT Timerecording.* FROM `Timerecording` INNER JOIN `TimerecordingCategory` ON (`Timerecording`.`timerecordingCategory_id` = `TimerecordingCategory`.`id`) WHERE `TimerecordingCategory`.`approval`='1'"; $res = $db->query($sql); if ($db->num_rows($res)) { while ($data = $db->fetch_object($res)) { $items[] = new Timerecording($data); } } return $items; } public static function getAllPermitsFibu() { $items = []; $db = FronkDB::singleton(); $sql = "SELECT Timerecording.* FROM `Timerecording` INNER JOIN `TimerecordingCategory` ON (`Timerecording`.`timerecordingCategory_id` = `TimerecordingCategory`.`id`) WHERE `TimerecordingCategory`.`approval_fibu`='1'"; $res = $db->query($sql); if ($db->num_rows($res)) { while ($data = $db->fetch_object($res)) { $items[] = new Timerecording($data); } } return $items; } public static function getFirst() { $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); $res = $db->select("Timerecording", "*", "$where "); if ($db->num_rows($res)) { $data = $db->fetch_object($res); $item = new Timerecording($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("Timerecording", "*", "$where "); if ($db->num_rows($res)) { while ($data = $db->fetch_object($res)) { $items[] = new Timerecording($data); } } return $items; } private static function getSqlFilter($filter) { $where = "1=1"; if (array_key_exists("user_id", $filter)) { $userid = $filter['user_id']; if (is_numeric($userid)) { $where .= " AND user_id=$userid"; } } if (array_key_exists("start", $filter) && array_key_exists("end", $filter)) { $start = $filter['start']; $end = $filter['end']; if (is_numeric($start) && is_numeric($end)) { $where .= " AND ((`start` >= $start AND `start` <= $end) OR (`end` >= $start AND `end` <= $end) OR `end` is NULL) ORDER by user_id,start ASC"; } } if (array_key_exists("start", $filter) && array_key_exists("timerecordingCategory_id", $filter)) { $start = $filter['start']; $timerecordingCategory_id = $filter['timerecordingCategory_id']; if (is_numeric($start) && is_numeric($timerecordingCategory_id)) { $where .= " AND `start` >= $start AND `timerecordingCategory_id` = $timerecordingCategory_id ORDER by start ASC"; } } if (array_key_exists("start", $filter) && array_key_exists("hours", $filter)) { $start = $filter['start']; if (is_numeric($start)) { $where .= " AND `start` >= $start AND (`hours`>0 or `hours`<0 or `hours_overtime`>0) ORDER by start ASC"; } } if (array_key_exists("start", $filter) && array_key_exists("days", $filter)) { $days = $filter['days']; $start = $filter['start']; $end= $filter['endsdate']; if ($days === 1) { $where .= " AND `start` >= $start AND `days` !=0 "; } if ($end) { if (is_numeric($end)) { $where .= " AND `start` <= $end "; } } $where.=" ORDER by start ASC"; } if (array_key_exists("timerecordingCar_id", $filter)) { $timerecordingCar = $filter['timerecordingCar_id']; if (is_numeric($timerecordingCar)) { $where .= " AND `timerecordingCar_id` = $timerecordingCar ORDER by mileage_end DESC LIMIT 1"; } } if (array_key_exists("timerecordingCar_id_all", $filter)) { $timerecordingCar = $filter['timerecordingCar_id_all']; if (is_numeric($timerecordingCar)) { $where .= " AND `timerecordingCar_id` = $timerecordingCar ORDER by mileage_start ASC"; } } if (array_key_exists("starttime", $filter) && array_key_exists("endtime", $filter)) { $starttime = $filter['starttime']; $endtime = $filter['endtime']; $id = $filter['id']; if (is_numeric($starttime) && is_numeric($endtime)) { if ($id && is_numeric($id)) { $where .= " AND `id` != $id "; } $where .= " AND (((`start` <= $starttime AND `end` > $starttime ) OR (`start` > $endtime AND `end` < $endtime) OR (`start` > $starttime AND `end` > $starttime AND `start` <= $endtime AND `end` <= $endtime) OR (`start` > $starttime AND `end` > $starttime AND `start` < $endtime AND `end` > $endtime) OR (`start` = $starttime AND `end` = $endtime )) OR ( `start` <= $starttime AND `end` IS NULL)) AND `days` = 0 ORDER by user_id,start ASC"; //echo ($where);die(); } } if (array_key_exists("type", $filter)) { $type = $filter['type']; if ($type === "opentimerecording") { $where .= " AND `end` IS NULL ORDER by start DESC LIMIT 1"; } } // // var_dump($filter, $where);exit; return $where; } }