Proyectos de Subversion Iphone Microlearning - Inconcert

Rev

Rev 17 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

//
//  NotificationListViewModel.swift
//  twogetskills
//
//  Created by Efrain Yanez Recanatini on 7/31/22.
//

import Foundation
import SwiftUI

class NotificationListViewModel: ObservableObject
{
    @Published public var notifications = [UserNotificationModel]()
    private var appData = Environment(\.appData).wrappedValue
    
    
    init() {

        fetchAll()
    }

    func fetchAll()
    {
        let now = Date()
        let yesterday = Calendar.current.date(byAdding: .day, value: -1, to: now)!
        
        
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = Constants.FORMAT_DATE_YMD
        
        let sToday = dateFormatter.string(from: now)
        let sYesterday = dateFormatter.string(from: yesterday)
        
        let showFormatter = DateFormatter()
        showFormatter.dateFormat = Constants.FORMAT_DATE_DMY
        
        
        let userNotificationDao = UserNotificationDao()
        
        notifications.removeAll()
        notifications = userNotificationDao.selectAllByUserUuid(userUuid: appData.userUuid)

        var i : Int = 0
        while i  < notifications.count {
            
            
            switch notifications[i].dateOn
            {
                case sToday :
                    notifications[i].dateOn = Config.LANG_COMMON_TODAY
                    break
                
                case sYesterday :
                    notifications[i].dateOn = Config.LANG_COMMON_YESTERDAY
                    break
                
                default :
                    let d = dateFormatter.date(from: notifications[i].dateOn) ?? Date()
                    notifications[i].dateOn = showFormatter.string(from: d)
                    break
                
            }
            
            i += 1
        }
        
        /*
        let dates = userNotificationDao.selectAllDistinctDateByUserUuid(userUuid: appData.userUuid)
        
        

        var i : Int = 0
        var d : Date
        var sDate : String
        while i < dates.count {
            sDate = dates[i]
            userNotificationGroupModel = UserNotificationGroupModel()
            
            switch sDate
            {
                case sToday :
                    userNotificationGroupModel.label = Config.LANG_COMMON_TODAY
                    break
                
                case sYesterday :
                    userNotificationGroupModel.label = Config.LANG_COMMON_YESTERDAY
                    break
                
                default :
                    d = dateFormatter.date(from: sDate) ?? Date()
                    userNotificationGroupModel.label = showFormatter.string(from: d)
                    break
                
            }
           
            
           
            userNotificationGroupModel.notifications = userNotificationDao.selectAllByUserUuidAndDate(userUuid: appData.userUuid, date: sDate)
            
            groups.append(userNotificationGroupModel)
            
            i += 1
            
        }
         */
    }
    

}