Proyectos de Subversion Iphone Microlearning - Inconcert

Rev

Rev 17 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
//
2
//  NotificationListViewModel.swift
3
//  twogetskills
4
//
5
//  Created by Efrain Yanez Recanatini on 7/31/22.
6
//
7
 
8
import Foundation
9
import SwiftUI
10
 
11
class NotificationListViewModel: ObservableObject
12
{
13
    @Published public var notifications = [UserNotificationModel]()
14
    private let appData = AppData.sharedInstance
15
 
16
 
17
    init() {
18
 
19
        fetchAll()
20
    }
21
 
22
    func fetchAll()
23
    {
24
        let now = Date()
25
        let yesterday = Calendar.current.date(byAdding: .day, value: -1, to: now)!
26
 
27
 
28
        let dateFormatter = DateFormatter()
29
        dateFormatter.dateFormat = Constants.FORMAT_DATE_YMD
30
 
31
        let sToday = dateFormatter.string(from: now)
32
        let sYesterday = dateFormatter.string(from: yesterday)
33
 
34
        let showFormatter = DateFormatter()
35
        showFormatter.dateFormat = Constants.FORMAT_DATE_DMY
36
 
37
 
38
        let userNotificationDao = UserNotificationDao.sharedInstance
39
 
40
        notifications.removeAll()
41
        notifications = userNotificationDao.selectAllByUserUuid(userUuid: appData.userUuid)
42
 
43
        var i : Int = 0
44
        while i  < notifications.count {
45
 
46
 
47
            switch notifications[i].dateOn
48
            {
49
                case sToday :
50
                    notifications[i].dateOn = Config.LANG_COMMON_TODAY
51
                    break
52
 
53
                case sYesterday :
54
                    notifications[i].dateOn = Config.LANG_COMMON_YESTERDAY
55
                    break
56
 
57
                default :
58
                    let d = dateFormatter.date(from: notifications[i].dateOn) ?? Date()
59
                    notifications[i].dateOn = showFormatter.string(from: d)
60
                    break
61
 
62
            }
63
 
64
            i += 1
65
        }
66
 
67
        /*
68
        let dates = userNotificationDao.selectAllDistinctDateByUserUuid(userUuid: appData.userUuid)
69
 
70
 
71
 
72
        var i : Int = 0
73
        var d : Date
74
        var sDate : String
75
        while i < dates.count {
76
            sDate = dates[i]
77
            userNotificationGroupModel = UserNotificationGroupModel()
78
 
79
            switch sDate
80
            {
81
                case sToday :
82
                    userNotificationGroupModel.label = Config.LANG_COMMON_TODAY
83
                    break
84
 
85
                case sYesterday :
86
                    userNotificationGroupModel.label = Config.LANG_COMMON_YESTERDAY
87
                    break
88
 
89
                default :
90
                    d = dateFormatter.date(from: sDate) ?? Date()
91
                    userNotificationGroupModel.label = showFormatter.string(from: d)
92
                    break
93
 
94
            }
95
 
96
 
97
 
98
            userNotificationGroupModel.notifications = userNotificationDao.selectAllByUserUuidAndDate(userUuid: appData.userUuid, date: sDate)
99
 
100
            groups.append(userNotificationGroupModel)
101
 
102
            i += 1
103
 
104
        }
105
         */
106
    }
107
 
108
 
109
}