Skip to content

Commit

Permalink
Update the certificate with the new PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
AurelTyson committed Oct 30, 2020
1 parent 503bc98 commit aefad99
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 22 deletions.
40 changes: 21 additions & 19 deletions AttestationCovid/Certificate/CertificateDocumentBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,43 +28,45 @@ struct CertificateDocumentBuilder {
let mainPage = document.page(at: 0)
let pageWidth = mainPage?.bounds(for: .mediaBox).width ?? 600

mainPage?.addAnnotation(makeTextAnnotation(text: attestation.displayName, x: 123, y: 686, width: .fittingPage(pageWidth)))
mainPage?.addAnnotation(makeTextAnnotation(text: attestation.birthdate, x: 123, y: 661, width: .fittingPage(pageWidth)))
mainPage?.addAnnotation(makeTextAnnotation(text: attestation.birthplace, x: 92, y: 638, width: .fittingPage(pageWidth)))
mainPage?.addAnnotation(makeTextAnnotation(text: attestation.fullAddress, x: 134, y: 613, width: .fittingPage(pageWidth)))
mainPage?.addAnnotation(makeTextAnnotation(text: attestation.displayName, x: 115, y: 698, width: .fittingPage(pageWidth)))
mainPage?.addAnnotation(makeTextAnnotation(text: attestation.birthdate, x: 115, y: 675, width: .fittingPage(pageWidth)))
mainPage?.addAnnotation(makeTextAnnotation(text: attestation.birthplace, x: 295, y: 675, width: .fittingPage(pageWidth)))
mainPage?.addAnnotation(makeTextAnnotation(text: attestation.fullAddress, x: 130, y: 653, width: .fittingPage(pageWidth)))

if attestation.motives.contains(.pro) {
mainPage?.addAnnotation(makeCheckmarkAnnotation(x: 74, y: 527))
mainPage?.addAnnotation(makeCheckmarkAnnotation(x: 80, y: 577))
}
if attestation.motives.contains(.shop) {
mainPage?.addAnnotation(makeCheckmarkAnnotation(x: 74, y: 478))
mainPage?.addAnnotation(makeCheckmarkAnnotation(x: 80, y: 532))
}
if attestation.motives.contains(.health) {
mainPage?.addAnnotation(makeCheckmarkAnnotation(x: 74, y: 436))
mainPage?.addAnnotation(makeCheckmarkAnnotation(x: 80, y: 477))
}
if attestation.motives.contains(.family) {
mainPage?.addAnnotation(makeCheckmarkAnnotation(x: 74, y: 400))
mainPage?.addAnnotation(makeCheckmarkAnnotation(x: 80, y: 435))
}
if attestation.motives.contains(.disabledPeopleTransport) {
mainPage?.addAnnotation(makeCheckmarkAnnotation(x: 80, y: 395))
}
if attestation.motives.contains(.brief) {
mainPage?.addAnnotation(makeCheckmarkAnnotation(x: 74, y: 345))
mainPage?.addAnnotation(makeCheckmarkAnnotation(x: 80, y: 355))
}
if attestation.motives.contains(.administrative) {
mainPage?.addAnnotation(makeCheckmarkAnnotation(x: 74, y: 298))
mainPage?.addAnnotation(makeCheckmarkAnnotation(x: 80, y: 295))
}
if attestation.motives.contains(.tig) {
mainPage?.addAnnotation(makeCheckmarkAnnotation(x: 74, y: 260))
mainPage?.addAnnotation(makeCheckmarkAnnotation(x: 80, y: 254))
}
if attestation.motives.contains(.school) {
mainPage?.addAnnotation(makeCheckmarkAnnotation(x: 80, y: 210))
}

mainPage?.addAnnotation(makeTextAnnotation(text: attestation.city, x: 111, y: 226, width: .fittingPage(pageWidth)))
mainPage?.addAnnotation(makeTextAnnotation(text: attestation.formattedDate, x: 92, y: 200, width: .width(80)))
mainPage?.addAnnotation(makeTextAnnotation(text: attestation.formattedHour, x: 198, y: 201, width: .width(20)))
mainPage?.addAnnotation(makeTextAnnotation(text: attestation.formattedMinute, x: 218, y: 201, width: .width(20)))

let qrImage = try CertificateQRCodeBuilder.build(from: attestation, creationDate: creationDate)
mainPage?.addAnnotation(makeImageAnnotation(image: qrImage, x: pageWidth - 170, y: 157, width: 100, height: 100))
makeCreationDateAnnotations(creationDate: creationDate).forEach { mainPage?.addAnnotation($0) }
mainPage?.addAnnotation(makeTextAnnotation(text: attestation.city, x: 106, y: 175, width: .fittingPage(pageWidth)))
mainPage?.addAnnotation(makeTextAnnotation(text: attestation.formattedDate, x: 92, y: 153, width: .width(80)))
mainPage?.addAnnotation(makeTextAnnotation(text: attestation.formattedTime, x: 255, y: 153, width: .width(80)))

let qrPage = PDFPage()
let qrImage = try CertificateQRCodeBuilder.build(from: attestation, creationDate: creationDate)
let qrPageHeight = qrPage.bounds(for: .mediaBox).height
qrPage.addAnnotation(makeImageAnnotation(image: qrImage, x: 50, y: qrPageHeight - 350, width: 300, height: 300))
document.insert(qrPage, at: 1)
Expand Down
20 changes: 20 additions & 0 deletions AttestationCovid/Form/FormViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ final class FormViewController: UITableViewController {
}
}
return cell
case (.motives, FormSection.MotivesContent.disabledPeopleTransport.rawValue):
let cell = self.checkCell(tableView, indexPath: indexPath)
cell.configure(content: NSLocalizedString("motive.disabledPeopleTransport", comment: ""), selected: attestation.motives.contains(.disabledPeopleTransport)) { [weak self] value in
if value {
self?.attestation.motives.insert(.disabledPeopleTransport)
} else {
self?.attestation.motives.remove(.disabledPeopleTransport)
}
}
return cell
case (.motives, FormSection.MotivesContent.brief.rawValue):
let cell = self.checkCell(tableView, indexPath: indexPath)
cell.configure(content: NSLocalizedString("motive.brief", comment: ""), selected: attestation.motives.contains(.brief)) { [weak self] value in
Expand Down Expand Up @@ -180,6 +190,16 @@ final class FormViewController: UITableViewController {
}
}
return cell
case (.motives, FormSection.MotivesContent.school.rawValue):
let cell = self.checkCell(tableView, indexPath: indexPath)
cell.configure(content: NSLocalizedString("motive.school", comment: ""), selected: attestation.motives.contains(.school)) { [weak self] value in
if value {
self?.attestation.motives.insert(.school)
} else {
self?.attestation.motives.remove(.school)
}
}
return cell

// DATE section
case (.date, FormSection.DateContent.date.rawValue):
Expand Down
2 changes: 2 additions & 0 deletions AttestationCovid/Form/FormViewModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ enum FormSection: Int, CaseIterable {
case shop
case health
case family
case disabledPeopleTransport
case brief
case administrative
case tig
case school
}

enum DateContent: Int, CaseIterable {
Expand Down
14 changes: 11 additions & 3 deletions AttestationCovid/Models/Certificate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,23 @@ struct Certificate: Codable {
static let shop = Motive(rawValue: 1 << 1)
static let health = Motive(rawValue: 1 << 2)
static let family = Motive(rawValue: 1 << 3)
static let brief = Motive(rawValue: 1 << 4)
static let administrative = Motive(rawValue: 1 << 5)
static let tig = Motive(rawValue: 1 << 6)
static let disabledPeopleTransport = Motive(rawValue: 1 << 4)
static let brief = Motive(rawValue: 1 << 5)
static let administrative = Motive(rawValue: 1 << 6)
static let tig = Motive(rawValue: 1 << 7)
static let school = Motive(rawValue: 1 << 8)

var displayableValue: String {
var values: [String] = []
if contains(.pro) { values.append("travail") }
if contains(.shop) { values.append("courses") }
if contains(.health) { values.append("sante") }
if contains(.family) { values.append("famille") }
if contains(.disabledPeopleTransport) { values.append("déplacement des personnes en situtation de handicap") }
if contains(.brief) { values.append("sport") }
if contains(.administrative) { values.append("judiciaire") }
if contains(.tig) { values.append("missions") }
if contains(.school) { values.append("école") }

return values.joined(separator: "-")
}
Expand All @@ -68,6 +72,10 @@ struct Certificate: Codable {
var formattedDate: String {
return DateFormatter.date.string(from: date)
}

var formattedTime: String {
return DateFormatter.time.string(from: date)
}

var formattedHour: String {
return DateFormatter.hour.string(from: date)
Expand Down
Binary file modified AttestationCovid/certificate.pdf
Binary file not shown.
2 changes: 2 additions & 0 deletions AttestationCovid/fr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
"motive.shop" = "Déplacements pour effectuer des achats de fournitures nécessaires à l’activité professionnelle et des achats de première nécessité dans des établissements dont les activités demeurent autorisées (liste sur gouvernement.fr).";
"motive.health" = "Consultations et soins ne pouvant être assurés à distance et ne pouvant être différés ; consultations et soins des patients atteints d'une affection de longue durée.";
"motive.family" = "Déplacements pour motif familial impérieux, pour l’assistance aux personnes vulnérables ou la garde d’enfants.";
"motive.disabledPeopleTransport" = "Déplacement des personnes en situation de handicap et leur accompagnant.";
"motive.brief" = "Déplacements brefs, dans la limite d'une heure quotidienne et dans un rayon maximal d'un kilomètre autour du domicile, liés soit à l'activité physique individuelle des personnes, à l'exclusion de toute pratique sportive collective et de toute proximité avec d'autres personnes, soit à la promenade avec les seules personnes regroupées dans un même domicile, soit aux besoins des animaux de compagnie.";
"motive.administrative" = "Convocation judiciaire ou administrative.";
"motive.tig" = "Participation à des missions d’intérêt général sur demande de l’autorité administrative.";
"motive.school" = "Déplacement pour chercher les enfants à l’école et à l’occasion de leurs activités périscolaire.";

"date" = "Date de sortie";
"time" = "Heure de sortie";
Expand Down

0 comments on commit aefad99

Please sign in to comment.