Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

Rev 11 | Rev 22 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 17
Línea 8... Línea 8...
8
import Foundation
8
import Foundation
9
import SwiftyJSON
9
import SwiftyJSON
Línea 10... Línea 10...
10
 
10
 
11
class DataService
11
class DataService
12
{
12
{
13
    let appDao = AppDao.sharedInstance
-
 
14
    
-
 
15
    func completeCapsule(topicModel : TopicModel, capsuleModel : CapsuleModel)
-
 
16
    {
-
 
17
        let appData = appDao.selectOne()
-
 
18
        
-
 
19
        let now = Date()
-
 
20
        let dateFormatter = DateFormatter()
-
 
21
        dateFormatter.dateFormat = Constants.FORMAT_DATETIME_SERVICE
-
 
22
        let dateOn = dateFormatter.string(from: now)
-
 
Línea 23... Línea -...
23
        
-
 
24
 
-
 
25
        let userUuid = appData.userUuid
-
 
26
        var json : [String: Any]
-
 
27
        var sync : SyncModel
-
 
28
        var userLog : UserLogModel
-
 
29
 
-
 
30
        let syncDao = SyncDao.sharedInstance
-
 
31
        let progressDao = ProgressDao.sharedInstance
-
 
32
        let userLogDao = UserLogDao.sharedInstance
-
 
33
            
-
 
34
        var progressCapsule = progressDao.selectByCapsuleUuidAndUserUuid(capsuleUuid: capsuleModel.uuid, userUuid: userUuid)
-
 
35
        if progressCapsule.id > 0 && progressCapsule.progress >= 100 {
-
 
36
            progressCapsule.completed = 1
-
 
37
            progressCapsule.updatedOn = dateOn
-
 
38
            progressDao.update(record: progressCapsule)
-
 
39
            
-
 
40
            json = progressCapsule.toJson()
-
 
41
            json[Constants.SYNC_ADAPTER_DATA_TYPE_FIELD_NAME] = Constants.SYNC_ADAPTER_DATA_TYPE_MICROLEARNING_PROGRESS
-
 
42
                        
-
 
43
            sync = SyncModel();
-
 
44
            sync.type = Constants.SYNC_ADAPTER_TYPE_SYNC
-
 
45
            if let theJSONData = try?  JSONSerialization.data(withJSONObject: json, options: .prettyPrinted),
-
 
46
               let data = String(data: theJSONData, encoding: String.Encoding.ascii) {
-
 
47
                    sync.data = data
-
 
48
                }
-
 
49
                      
-
 
50
            syncDao.insert(record : sync);
-
 
51
            
-
 
52
            userLog = UserLogModel()
-
 
53
            userLog.userUuid = userUuid
-
 
54
            userLog.companyUuid = topicModel.companyUuid
-
 
55
            userLog.topicUuid = topicModel.uuid
-
 
56
            userLog.capsuleUuid = capsuleModel.uuid
-
 
57
            userLog.activity = Constants.USER_LOG_ACTIVITY_COMPLETED_CAPSULE
-
 
58
            userLog.addedOn = dateOn
-
 
59
            userLogDao.insert(record: userLog)
-
 
60
            
-
 
61
            json = userLog.toJson()
-
 
62
            json[Constants.SYNC_ADAPTER_DATA_TYPE_FIELD_NAME] = Constants.SYNC_ADAPTER_DATA_TYPE_MICROLEARNING_USER_LOG
-
 
63
                    
-
 
64
            sync = SyncModel();
-
 
65
            sync.type = Constants.SYNC_ADAPTER_TYPE_SYNC
-
 
66
            if let theJSONData = try?  JSONSerialization.data(withJSONObject: json, options: .prettyPrinted),
-
 
67
                let data = String(data: theJSONData, encoding: String.Encoding.ascii) {
-
 
68
                    sync.data = data
-
 
69
                }
-
 
70
                      
-
 
71
            syncDao.insert(record : sync);
-
 
72
        }
-
 
73
 
-
 
Línea 74... Línea 13...
74
        
13
    private var appData = AppData.sharedInstance
75
    }
14
 
76
    
-
 
77
    
-
 
78
    func completeTopic(topicModel : TopicModel, capsuleModel : CapsuleModel)
15
    
79
    {
16
    
80
        let appData = appDao.selectOne()
17
    func complete(topicModel : TopicModel, capsuleModel : CapsuleModel)
81
        
18
    {
Línea 93... Línea 30...
93
        let syncDao = SyncDao.sharedInstance
30
        let syncDao = SyncDao.sharedInstance
94
        let progressDao = ProgressDao.sharedInstance
31
        let progressDao = ProgressDao.sharedInstance
95
        let userLogDao = UserLogDao.sharedInstance
32
        let userLogDao = UserLogDao.sharedInstance
Línea 96... Línea 33...
96
            
33
            
-
 
34
        var progressCapsule = progressDao.selectByCapsuleUuidAndUserUuid(capsuleUuid: capsuleModel.uuid, userUuid: userUuid)
97
        var progressCapsule = progressDao.selectByCapsuleUuidAndUserUuid(capsuleUuid: capsuleModel.uuid, userUuid: userUuid)
35
        
98
        if progressCapsule.id > 0 && progressCapsule.progress >= 100 {
36
        if progressCapsule.id > 0 && progressCapsule.progress >= 100 {
99
            progressCapsule.completed = 1
37
            progressCapsule.completed = 1
100
            progressCapsule.updatedOn = dateOn
38
            progressCapsule.updatedOn = dateOn
Línea 133... Línea 71...
133
                      
71
                      
134
            syncDao.insert(record : sync);
72
            syncDao.insert(record : sync);
Línea 135... Línea 73...
135
        }
73
        }
-
 
74
 
136
 
75
        var progressTopic = progressDao.selectByTopicUuidAndUserUuid(topicUuid: topicModel.uuid, userUuid: userUuid)
137
        var progressTopic = progressDao.selectByTopicUuidAndUserUuid(topicUuid: topicModel.uuid, userUuid: userUuid)
76
        
138
        if progressTopic.id > 0 && progressTopic.progress >= 100 {
77
        if progressTopic.id > 0 && progressTopic.progress >= 100 {
139
            progressTopic.completed = 1
78
            progressTopic.completed = 1
140
            progressTopic.updatedOn = dateOn
79
            progressTopic.updatedOn = dateOn
141
            progressDao.update(record: progressTopic)
80
            progressDao.update(record: progressTopic)
142
            
81
 
Línea 143... Línea 82...
143
            json = progressCapsule.toJson()
82
            json = progressTopic.toJson()
144
            json[Constants.SYNC_ADAPTER_DATA_TYPE_FIELD_NAME] = Constants.SYNC_ADAPTER_DATA_TYPE_MICROLEARNING_PROGRESS
83
            json[Constants.SYNC_ADAPTER_DATA_TYPE_FIELD_NAME] = Constants.SYNC_ADAPTER_DATA_TYPE_MICROLEARNING_PROGRESS
145
                        
84
                        
Línea 175... Línea 114...
175
    }
114
    }
Línea 176... Línea 115...
176
    
115
    
177
    func incompleteSlide (slide: SlideModel)
116
    func incompleteSlide (slide: SlideModel)
178
    {
117
    {
179
        //print("Notification: \(Constants.NOTIFICATION_NAME_INCOMPLETED_SLIDE) ")
118
        //print("Notification: \(Constants.NOTIFICATION_NAME_INCOMPLETED_SLIDE) ")
180
        NotificationCenter.default.post(name:Constants.NOTIFICATION_NAME_INCOMPLETED_SLIDE,
119
       // NotificationCenter.default.post(name:Constants.NOTIFICATION_NAME_INCOMPLETED_SLIDE,
181
                                        object: nil, userInfo: ["slideUuid": slide.uuid])
120
       //                                 object: nil, userInfo: ["slideUuid": slide.uuid])
Línea 182... Línea 121...
182
    }
121
    }
183
    
122
    
184
    func completeSlide( slide : SlideModel)
-
 
185
    {
-
 
186
        var appData = appDao.selectOne()
123
    func completeSlide( slide : SlideModel)
187
        
124
    {
188
        var changeProgress = false
125
        var changeProgress = false
189
        let now = Date()
126
        let now = Date()
190
        let dateFormatter = DateFormatter()
127
        let dateFormatter = DateFormatter()
Línea 365... Línea 302...
365
                    progressDao.update(record: progressCapsule)
302
                    progressDao.update(record: progressCapsule)
Línea 366... Línea 303...
366
                                
303
                                
367
                    
-
 
368
           
-
 
369
                    appData.capsuleUuidOld = slide.capsuleUuid
304
                    
Línea 370... Línea 305...
370
                    
305
           
371
                    print("update query : 2")
306
                    appData.capsuleUuidOld = slide.capsuleUuid
372
                    appDao.update(model: appData)
307
                    appData.save()
373
                    
308
                    
Línea 435... Línea 370...
435
            syncDao.insert(record : sync);
370
            syncDao.insert(record : sync);
436
        }
371
        }
Línea 437... Línea 372...
437
        
372
        
438
        
373
        
439
       // print("Notification: \(Constants.NOTIFICATION_NAME_COMPLETED_SLIDE) ")
374
       // print("Notification: \(Constants.NOTIFICATION_NAME_COMPLETED_SLIDE) ")
Línea 440... Línea 375...
440
        NotificationCenter.default.post(name:Constants.NOTIFICATION_NAME_COMPLETED_SLIDE,
375
       // NotificationCenter.default.post(name:Constants.NOTIFICATION_NAME_COMPLETED_SLIDE,
Línea 441... Línea 376...
441
                                        object: nil, userInfo: ["slideUuid": slide.uuid])
376
       //                                 object: nil, userInfo: ["slideUuid": slide.uuid])
442
        
377
        
Línea 443... Línea 378...
443
        if (changeProgress) {
378
       // if (changeProgress) {
444
            
379
            
Línea 445... Línea 380...
445
            //print("Notification: \(Constants.NOTIFICATION_NAME_CHANGE_PERCENTAJE_COMPLETED_CAPSULE) ")
380
            //print("Notification: \(Constants.NOTIFICATION_NAME_CHANGE_PERCENTAJE_COMPLETED_CAPSULE) ")
Línea 446... Línea 381...
446
            NotificationCenter.default.post(name: Constants.NOTIFICATION_NAME_CHANGE_PERCENTAJE_COMPLETED_CAPSULE, object: nil, userInfo:["capsuleUuid": slide.capsuleUuid])
381
            //NotificationCenter.default.post(name: Constants.NOTIFICATION_NAME_CHANGE_PERCENTAJE_COMPLETED_CAPSULE, object: nil, userInfo:["capsuleUuid": slide.capsuleUuid])
Línea 447... Línea 382...
447
            
382
            
448
            
383
            
449
            //print("Notification: \(Constants.NOTIFICATION_NAME_CHANGE_PERCENTAJE_COMPLETED_TOPIC) ")
-
 
450
            NotificationCenter.default.post(name: Constants.NOTIFICATION_NAME_CHANGE_PERCENTAJE_COMPLETED_TOPIC, object: nil, userInfo:["topicUuid": slide.topicUuid])
384
            //print("Notification: \(Constants.NOTIFICATION_NAME_CHANGE_PERCENTAJE_COMPLETED_TOPIC) ")
451
            
385
            //NotificationCenter.default.post(name: Constants.NOTIFICATION_NAME_CHANGE_PERCENTAJE_COMPLETED_TOPIC, object: nil, userInfo:["topicUuid": slide.topicUuid])
452
        }
386
            
453
          
387
        //}
454
    }
388
          
Línea 477... Línea 411...
477
                                
411
                                
478
        slideDao.removeAll()
412
        slideDao.removeAll()
479
        capsuleDao.removeAll()
413
        capsuleDao.removeAll()
480
        topicDao.removeAll()
414
        topicDao.removeAll()
481
        companyDao.removeAll()
415
        companyDao.removeAll()
482
                                
-
 
483
        userLogDao.removeAll()
-
 
484
        progressDao.removeAll()
416
                        
485
        userExtendedDao.removeAll()
-
 
486
        userNotificationDao.removeAll()
-
 
Línea -... Línea 417...
-
 
417
        userExtendedDao.removeAll()
-
 
418
        
-
 
419
        //userLogDao.removeAll()
-
 
420
        //progressDao.removeAll()
487
        
421
        //userNotificationDao.removeAll()
488
        
422
 
489
        var companyModel : CompanyModel
423
        var companyModel : CompanyModel
490
        let now = Date()
424
        let now = Date()
491
        let dateFormatter = DateFormatter()
-
 
492
        dateFormatter.dateFormat = Constants.FORMAT_DATETIME_SERVICE
-
 
-
 
425
        let dateFormatter = DateFormatter()
Línea 493... Línea 426...
493
 
426
        dateFormatter.dateFormat = Constants.FORMAT_DATETIME_SERVICE
494
 
427
        let dateOn = dateFormatter.string(from: now)
Línea 495... Línea 428...
495
            
428
            
496
        if json?["data"]["max_date_changes"] != ""  {
-
 
497
            let maxDateChanges = json?["data"]["max_date_changes"].string ?? ""
429
        if json?["data"]["max_date_changes"] != ""  {
498
            
430
            let maxDateChanges = json?["data"]["max_date_changes"].string ?? ""
Línea 499... Línea 431...
499
            //print("maxDateChanges : \(maxDateChanges)")
431
            
500
            
432
            //print("maxDateChanges : \(maxDateChanges)")
Línea 515... Línea 447...
515
            let userUuid = json?["data"]["user"]["uuid"].string ?? ""
447
            let userUuid = json?["data"]["user"]["uuid"].string ?? ""
516
            let userFirstName = json?["data"]["user"]["first_name"].string ?? ""
448
            let userFirstName = json?["data"]["user"]["first_name"].string ?? ""
517
            let userLastName = json?["data"]["user"]["last_name"].string ?? ""
449
            let userLastName = json?["data"]["user"]["last_name"].string ?? ""
518
            let userEmail = json?["data"]["user"]["email"].string ?? ""
450
            let userEmail = json?["data"]["user"]["email"].string ?? ""
519
            let userImage = json?["data"]["user"]["image"].string ?? ""
451
            let userImage = json?["data"]["user"]["image"].string ?? ""
520
            
-
 
Línea 521... Línea 452...
521
   
452
   
522
            //print("userUuid : \(userUuid)")
453
            //print("userUuid : \(userUuid)")
523
            //print("userFirstName : \(userFirstName)")
454
            //print("userFirstName : \(userFirstName)")
524
            //print("userLastName: \(userLastName)")
455
            //print("userLastName: \(userLastName)")
525
            //print("userEmail : \(userEmail)")
456
            //print("userEmail : \(userEmail)")
526
            //print("userImage : \(userImage)")
-
 
Línea 527... Línea 457...
527
     
457
            //print("userImage : \(userImage)")
528
                 
458
                 
529
            appData.userUuid = userUuid
459
            appData.userUuid = userUuid
530
            appData.userFirstname = userFirstName
460
            appData.userFirstname = userFirstName
531
            appData.userLastname =  userLastName
461
            appData.userLastname =  userLastName
532
            appData.userEmail = userEmail
-
 
533
            appData.userImage = userImage
-
 
534
            
-
 
535
 
462
            appData.userEmail = userEmail
Línea -... Línea 463...
-
 
463
            appData.userImage = userImage
536
                    
464
        }
537
        }
465
    
538
    
466
        appData.lastCheckChanges = dateOn
539
        appData.topicUuidActive = ""
467
        appData.topicUuidActive = ""
-
 
468
        appData.capsuleUuidActive = ""
Línea 540... Línea 469...
540
        appData.capsuleUuidActive = ""
469
        appData.capsuleUuidOld = ""
541
        appData.capsuleUuidOld = ""
470
        appData.slideUuidActive = ""
542
        appData.slideUuidActive = ""
-
 
-
 
471
        appData.save()
Línea 543... Línea 472...
543
        
472
        
544
        print("update query : 3")
473
        userLogDao.removeAllUserUuidNotEqual(userUuid: appData.userUuid)
545
        appDao.update(model: appData)
474
        progressDao.removeAllUserUuidNotEqual(userUuid: appData.userUuid)
546
 
475
        userNotificationDao.removeAllUserUuidNotEqual(userUuid: appData.userUuid)