github.com/benoitkugler/goacve@v0.0.0-20201217100549-151ce6e55dc8/server/directeurs/simple.go (about) 1 package directeurs 2 3 import ( 4 "bytes" 5 "errors" 6 "sort" 7 8 dm "github.com/benoitkugler/goACVE/server/core/datamodel" 9 rd "github.com/benoitkugler/goACVE/server/core/rawdata" 10 "github.com/benoitkugler/goACVE/server/core/utils/table" 11 "github.com/benoitkugler/goACVE/server/documents" 12 ) 13 14 func (d DriverCampSimple) loadDataInscrits() error { 15 participantsimples, err := rd.SelectParticipantsimplesByIdCamps(d.DB, d.camp.Id) 16 if err != nil { 17 return err 18 } 19 20 rows, err := d.DB.Query(`SELECT personnes.* FROM personnes 21 JOIN participantsimples ON participantsimples.id_personne = personnes.id 22 WHERE participantsimples.id = ANY($1)`, participantsimples.Ids().AsSQL()) 23 if err != nil { 24 return err 25 } 26 personnes, err := rd.ScanPersonnes(rows) 27 if err != nil { 28 return err 29 } 30 31 d.camp.Base.Personnes = personnes 32 d.camp.Base.Participantsimples = participantsimples 33 return nil 34 } 35 36 func (d DriverCampSimple) loadDataEquipiers() error { 37 // no op 38 return nil 39 } 40 41 func (d DriverCampSimple) exportListeInscrits(options optionsExportExcel) (*bytes.Buffer, error) { 42 inscrits, _ := d.camp.GetListes(false, "", true, false) 43 return table.GenereListeParticipants(HeaderExportInscrits, nil, inscrits, nil, options.showColors) 44 } 45 46 func (d DriverCampSimple) getInscrits(host string) ([]Inscrit, error) { 47 insc := d.camp.GetParticipantsimples(nil) 48 out := make([]Inscrit, len(insc)) 49 for index, part := range insc { 50 pers := part.GetPersonne() 51 partFields := part.AsItem().Fields 52 out[index] = Inscrit{ 53 Id: part.Id, 54 InscritWritable: InscritWritable{ 55 Mail: pers.RawData().Mail.String(), 56 }, 57 // puisque la table participantsimple n'a pas de critère liste d'attente 58 // on considère une personne non vérifiée comme étant en liste d'attente 59 IsAttente: bool(pers.RawData().IsTemporaire), 60 AgeDebutCamp: part.AgeDebutCamp().Age(), 61 HasAnniversaire: part.HasAnniversaire(), 62 Nom: partFields.Data(dm.PersonneNom).String(), 63 Prenom: partFields.Data(dm.PersonnePrenom).String(), 64 Sexe: pers.RawData().Sexe, 65 DateNaissance: pers.RawData().DateNaissance, 66 Info: part.RawData().Info, 67 } 68 } 69 sort.Slice(out, func(i, j int) bool { 70 return out[i].Nom+out[i].Prenom < out[j].Nom+out[j].Prenom 71 }) 72 return out, nil 73 } 74 75 func (d DriverCampSimple) modifieInscrit(modif InscritWritable, id int64) error { 76 row := d.DB.QueryRow(`SELECT personnes.* FROM personnes 77 JOIN participantsimples ON participantsimples.id_personne = personnes.id 78 WHERE participantsimples = $1`, id) 79 personne, err := rd.ScanPersonne(row) 80 if err != nil { 81 return err 82 } 83 84 personne.Mail = rd.String(modif.Mail) 85 personne, err = personne.Update(d.DB) 86 // mise à jour locale 87 d.camp.Base.Personnes[personne.Id] = personne 88 return err 89 } 90 91 var ecs = errors.New("Ce séjour ne supporte pas cette opération") 92 93 func (DriverCampSimple) exportListeFinances() (*bytes.Buffer, error) { return nil, ecs } 94 func (DriverCampSimple) exportListeEquipiers() (*bytes.Buffer, error) { return nil, ecs } 95 func (DriverCampSimple) updateEnvois(env rd.Envois) error { return ecs } 96 func (DriverCampSimple) getBonusDocs(host string) ([]documents.PublicDocument, error) { 97 return nil, ecs 98 }