<commit_before>//
//  WhosNextVC.swift
//  Perspective
//
//  Created by Apprentice on 2/17/15.
//  Copyright (c) 2015 Dev Bootcamp. All rights reserved.
//

import UIKit

class WhosNextVC: UIViewController {
    
    @IBOutlet weak var submitButton: UIButton!
    
    var url: String!
    var perspectiveId: String!
    var toUser : String!

    override func viewDidLoad() {
        super.viewDidLoad()

//        instructionsText.text = "Pick the next collaborator"
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    @IBAction func gotoPickCollaborator(sender: UIButton) {
        let vc = self.storyboard?.instantiateViewControllerWithIdentifier("PickCollaboratorVC") as PickCollaboratorVC
        self.navigationController?.pushViewController(vc, animated: true)
    }
    
    func setPerspectiveComplete(perspective: PFObject) {
        perspective["complete"] = true
        perspective.saveInBackground()
    }
    
    @IBAction func queryPerspective (sender: UIButton) {
        var query = PFQuery(className: "Perspective")
        query.getObjectInBackgroundWithId(self.perspectiveId) {
            (perspective: PFObject!, error: NSError!) -> Void in
            if error != nil {
                NSLog("%@", error)
                println("Error, Perspective not retrieved.")
            } else {
                perspective.addObject(PFUser.currentUser().username, forKey: "collaborators")
                perspective.addObject(self.url, forKey: "videos")
                perspective.saveInBackgroundWithBlock {
                    (success: Bool, error: NSError!) -> Void in
                    if (success) {
                        var perspectiveId = perspective.objectId
                        var collaborators: NSArray = perspective["collaborators"] as NSArray
                        let videosArray:NSArray = perspective["videos"] as NSArray
                        let videosArrayCount: Int = videosArray.count
                        println(videosArrayCount)
                        let perspectiveNumOfClips: Int = perspective["numOfClips"] as Int
                        println(perspectiveNumOfClips)
                        if perspectiveNumOfClips == videosArrayCount {
                            self.createCompleteNotification(perspectiveId, collaborators: collaborators)
                            self.setPerspectiveComplete(perspective)
                          } else {
                            println("Inside completion check - else")
                            self.createNextNotification(perspectiveId)
                          }
                    } else {
                        NSLog("%@", error)
                        println("Error, Perspective not updated.")
                    }
                }
            }
                self.navigationController?.popToRootViewControllerAnimated(true)
                println("Perspective updating in background, pop to root VC.")
        }
    }
    
    func createNextNotification(perspectiveId: String) {
        var notification = PFObject(className: "Notification")
        notification["fromUser"] = PFUser.currentUser().username
        notification["toUser"] = "darrin"
        notification["notificationType"] = "invite"
        notification["perspectiveId"] = perspectiveId
        notification.saveInBackgroundWithBlock {
            (success: Bool, error: NSError!) -> Void in
            if (success) {
                println("Sucessfully saved Notification")
            } else {
                println("Notification did not save")
            }
        }
        
    }
    
    func createCompleteNotification(perspectiveId: String, collaborators: NSArray) {
        var users: NSArray = ["Dick", "John", "Harry"]
        
        for user in users {
            var notification = PFObject(className: "Notification")
            notification["fromUser"] = PFUser.currentUser().username
            notification["toUser"] = user as String
            notification["notificationType"] = "invite"
            notification["perspectiveId"] = perspectiveId
            notification.saveInBackgroundWithBlock {
                (success: Bool, error: NSError!) -> Void in
                if (success) {
                    println("Sucessfully saved Notification")
                } else {
                    println("Notification did not save")
                }
            }
            println("Perspective complete notification successfully created.")
        }
    }
}
<commit_msg>Notification functions created for whosnext vc.<commit_after>//
//  WhosNextVC.swift
//  Perspective
//
//  Created by Apprentice on 2/17/15.
//  Copyright (c) 2015 Dev Bootcamp. All rights reserved.
//

import UIKit

class WhosNextVC: UIViewController {
    
    @IBOutlet weak var submitButton: UIButton!
    
    var url: String!
    var perspectiveId: String!
    var toUser : String!

    override func viewDidLoad() {
        super.viewDidLoad()

//        instructionsText.text = "Pick the next collaborator"
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    @IBAction func gotoPickCollaborator(sender: UIButton) {
        let vc = self.storyboard?.instantiateViewControllerWithIdentifier("PickCollaboratorVC") as PickCollaboratorVC
        self.navigationController?.pushViewController(vc, animated: true)
    }
    
    func setPerspectiveComplete(perspective: PFObject) {
        perspective["complete"] = true
        perspective.saveInBackground()
    }
    
    @IBAction func queryPerspective (sender: UIButton) {
        var query = PFQuery(className: "Perspective")
        query.getObjectInBackgroundWithId(self.perspectiveId) {
            (perspective: PFObject!, error: NSError!) -> Void in
            if error != nil {
                NSLog("%@", error)
                println("Error, Perspective not retrieved.")
            } else {
                perspective.addObject(PFUser.currentUser().username, forKey: "collaborators")
                perspective.addObject(self.url, forKey: "videos")
                perspective.saveInBackgroundWithBlock {
                    (success: Bool, error: NSError!) -> Void in
                    if (success) {
                        var perspectiveId = perspective.objectId
                        var collaborators: NSArray = perspective["collaborators"] as NSArray
                        let videosArray:NSArray = perspective["videos"] as NSArray
                        let videosArrayCount: Int = videosArray.count
                        println(videosArrayCount)
                        let perspectiveNumOfClips: Int = perspective["numOfClips"] as Int
                        println(perspectiveNumOfClips)
                        if perspectiveNumOfClips == videosArrayCount {
                            self.createCompleteNotification(perspectiveId, collaborators: collaborators)
                            self.setPerspectiveComplete(perspective)
                          } else {
                            println("Inside completion check - else")
                            self.createNextNotification(perspectiveId)
                          }
                    } else {
                        NSLog("%@", error)
                        println("Error, Perspective not updated.")
                    }
                }
            }
                self.navigationController?.popToRootViewControllerAnimated(true)
                println("Perspective updating in background, pop to root VC.")
        }
    }
    
    func createNextNotification(perspectiveId: String) {
        var notification = PFObject(className: "Notification")
        notification["fromUser"] = PFUser.currentUser().username
        notification["toUser"] = perspectiveId
        notification["notificationType"] = "invite"
        notification["perspectiveId"] = perspectiveId
        notification.saveInBackgroundWithBlock {
            (success: Bool, error: NSError!) -> Void in
            if (success) {
                println("Sucessfully saved Notification")
            } else {
                println("Notification did not save")
            }
        }
        
    }
    
    func createCompleteNotification(perspectiveId: String, collaborators: NSArray) {
        for user in collaborators {
            var notification = PFObject(className: "Notification")
            notification["fromUser"] = PFUser.currentUser().username
            notification["toUser"] = user as String
            notification["notificationType"] = "invite"
            notification["perspectiveId"] = perspectiveId
            notification.saveInBackgroundWithBlock {
                (success: Bool, error: NSError!) -> Void in
                if (success) {
                    println("Sucessfully saved Notification")
                } else {
                    println("Notification did not save")
                }
            }
            println("Perspective complete notification successfully created.")
        }
    }
}

{'fraction_non_alphanumeric': 0.0844261406741086, 'fraction_numerical': 0.0019507965752682346, 'mean_word_length': 1.829806807727691, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3211259', 'n_tokens_mistral': 2274, 'n_tokens_neox': 2098, 'n_words': 505}