245 lines
8.6 KiB
Swift
245 lines
8.6 KiB
Swift
|
//
|
||
|
// Settings.swift
|
||
|
// Befund
|
||
|
//
|
||
|
// Created by Irakli Abetschkhrischwili on 29.05.22.
|
||
|
// Copyright © 2022 MVZ Dr. Stein und Kollegen. All rights reserved.
|
||
|
|
||
|
import Foundation
|
||
|
|
||
|
extension Core.Models
|
||
|
{
|
||
|
public class Settings
|
||
|
{
|
||
|
public var public_key: String? = nil
|
||
|
public var hashed_private_key: String? = nil
|
||
|
public var verificator_hash: String? = nil
|
||
|
public var password_hash: String? = nil
|
||
|
public var password_reset_hash: String? = nil
|
||
|
public var zip: String? = nil
|
||
|
public var birthday: String? = nil
|
||
|
public var udid: String? = nil
|
||
|
public var lang: Core.Lang.Languages = Core.Lang.Languages.DE
|
||
|
public var labor: Core.Models.Labor? = nil
|
||
|
public var pushNotificationExplained: Bool = false
|
||
|
public var pushNotificationAccepted: Bool = false
|
||
|
public var policyAGBExplained: Bool = false
|
||
|
|
||
|
/**
|
||
|
* Loads settings from the file
|
||
|
*/
|
||
|
public static func loadFromFile(atPath: String) -> Core.Models.Settings?
|
||
|
{
|
||
|
var result: Core.Models.Settings? = nil
|
||
|
|
||
|
if(Core.System.FileExists(atPath: atPath))
|
||
|
{
|
||
|
let dic = NSMutableDictionary(contentsOfFile: atPath)
|
||
|
|
||
|
if(dic != nil)
|
||
|
{
|
||
|
result = Core.Models.Settings()
|
||
|
|
||
|
let public_key = dic!.value(forKey: "public_key")
|
||
|
|
||
|
if(public_key != nil)
|
||
|
{
|
||
|
result!.public_key = public_key as? String
|
||
|
}
|
||
|
|
||
|
let hashed_private_key = dic!.value(forKey: "hashed_private_key")
|
||
|
|
||
|
if(hashed_private_key != nil)
|
||
|
{
|
||
|
result!.hashed_private_key = hashed_private_key as? String
|
||
|
}
|
||
|
|
||
|
let verificator_hash = dic!.value(forKey: "verificator_hash")
|
||
|
|
||
|
if(verificator_hash != nil)
|
||
|
{
|
||
|
result!.verificator_hash = verificator_hash as? String
|
||
|
}
|
||
|
|
||
|
let password_hash = dic!.value(forKey: "password_hash")
|
||
|
|
||
|
if(password_hash != nil)
|
||
|
{
|
||
|
result!.password_hash = password_hash as? String
|
||
|
}
|
||
|
|
||
|
let password_reset_hash = dic!.value(forKey: "password_reset_hash")
|
||
|
|
||
|
if(password_reset_hash != nil)
|
||
|
{
|
||
|
result!.password_reset_hash = password_reset_hash as? String
|
||
|
}
|
||
|
|
||
|
|
||
|
let zip = dic!.value(forKey: "zip")
|
||
|
|
||
|
if(zip != nil)
|
||
|
{
|
||
|
result!.zip = zip as? String
|
||
|
}
|
||
|
|
||
|
let birthday = dic!.value(forKey: "birthday")
|
||
|
|
||
|
if(birthday != nil)
|
||
|
{
|
||
|
result!.birthday = birthday as? String
|
||
|
}
|
||
|
|
||
|
let udid = dic!.value(forKey: "udid")
|
||
|
|
||
|
if(udid != nil)
|
||
|
{
|
||
|
result!.udid = udid as? String
|
||
|
}
|
||
|
|
||
|
let lang = dic!.value(forKey: "lang") as? String
|
||
|
switch(lang)
|
||
|
{
|
||
|
case "EN":
|
||
|
result!.lang = Core.Lang.Languages.EN
|
||
|
break;
|
||
|
default:
|
||
|
result!.lang = Core.Lang.Languages.DE
|
||
|
break;
|
||
|
|
||
|
}
|
||
|
|
||
|
let labor_id = dic!.value(forKey: "labor")
|
||
|
if(labor_id != nil)
|
||
|
{
|
||
|
result!.labor = Core.Models.Labor.GetLaborByName(id: (labor_id as? String)!)
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
result!.labor = nil //Core.Models.Labor.GetLaborByName(id: "LABOR_HANNOVER")
|
||
|
}
|
||
|
//result!.labor!.host = .LABOR_HANNOVER
|
||
|
|
||
|
|
||
|
let pushExplained = dic!.value(forKey: "push_explained")
|
||
|
if (pushExplained != nil)
|
||
|
{
|
||
|
result?.pushNotificationExplained = ((pushExplained as? NSNumber)!).boolValue
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
result?.pushNotificationExplained = false
|
||
|
}
|
||
|
|
||
|
let pushAccepted = dic!.value(forKey: "push_accepted")
|
||
|
if (pushAccepted != nil)
|
||
|
{
|
||
|
result?.pushNotificationAccepted = ((pushAccepted as? NSNumber)!).boolValue
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
result?.pushNotificationAccepted = false
|
||
|
}
|
||
|
|
||
|
let AGBAccepted = dic!.value(forKey: "agb_accepted")
|
||
|
if (AGBAccepted != nil)
|
||
|
{
|
||
|
result?.policyAGBExplained = ((AGBAccepted as? NSNumber)!).boolValue
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
result?.policyAGBExplained = false
|
||
|
}
|
||
|
|
||
|
//let host = dic!.value(forKey: "host")
|
||
|
|
||
|
//if(host != nil)
|
||
|
//{
|
||
|
//result!.host = Core.Https.Servers(rawValue: host as! String)!
|
||
|
//}
|
||
|
//result!.host = .LABOR_HANNOVER
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//if(result != nil &&
|
||
|
// (result!.public_key == nil || result!.hashed_private_key == nil || result!.verificator_hash == nil))
|
||
|
//{
|
||
|
// result = nil
|
||
|
//}
|
||
|
|
||
|
return result
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Saves the settings to the file
|
||
|
*/
|
||
|
public func save(atPath: String) -> Bool
|
||
|
{
|
||
|
let dic = NSMutableDictionary()
|
||
|
dic.setValue(self.public_key, forKey: "public_key")
|
||
|
dic.setValue(self.hashed_private_key, forKey: "hashed_private_key")
|
||
|
dic.setValue(self.verificator_hash, forKey: "verificator_hash")
|
||
|
dic.setValue(self.password_hash, forKey: "password_hash")
|
||
|
dic.setValue(self.password_reset_hash, forKey: "password_reset_hash")
|
||
|
dic.setValue(self.zip, forKey: "zip")
|
||
|
dic.setValue(self.birthday, forKey: "birthday")
|
||
|
dic.setValue(self.udid, forKey: "udid")
|
||
|
dic.setValue((self.lang == Core.Lang.Languages.DE ? "DE": "EN"), forKey: "lang")
|
||
|
dic.setValue(self.labor?.id, forKey: "labor")
|
||
|
dic.setValue(self.pushNotificationExplained, forKey: "push_explained")
|
||
|
dic.setValue(self.pushNotificationAccepted, forKey: "push_accepted")
|
||
|
dic.setValue(self.policyAGBExplained, forKey: "agb_accepted")
|
||
|
|
||
|
dic.write(toFile: atPath, atomically: true)
|
||
|
|
||
|
return Core.System.FileExists(atPath: atPath)
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Returns formated birthday as date
|
||
|
*/
|
||
|
public func GetBirthday() -> Date?
|
||
|
{
|
||
|
var result: Date? = nil
|
||
|
|
||
|
if(self.birthday != nil)
|
||
|
{
|
||
|
let dateFormatter = DateFormatter()
|
||
|
dateFormatter.dateFormat = "yyyy-MM-dd"
|
||
|
result = dateFormatter.date(from: self.birthday!)
|
||
|
}
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Returns formated birthday as string
|
||
|
*/
|
||
|
public func GetFormatedBirthday() -> String?
|
||
|
{
|
||
|
var result: String? = nil
|
||
|
|
||
|
let date = self.GetBirthday()
|
||
|
|
||
|
if(date != nil)
|
||
|
{
|
||
|
let dateFormatter = DateFormatter()
|
||
|
dateFormatter.dateFormat = "dd.MM.yyyy"
|
||
|
result = dateFormatter.string(from: date!)
|
||
|
}
|
||
|
|
||
|
return result
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Sets the birthday to the settings
|
||
|
*/
|
||
|
public func SetBirthday(date: Date)
|
||
|
{
|
||
|
let dateFormatter = DateFormatter()
|
||
|
dateFormatter.dateFormat = "yyyy-MM-dd"
|
||
|
self.birthday = dateFormatter.string(from: date)
|
||
|
}
|
||
|
}
|
||
|
}
|