From 1700ac937a33c69ef007a4d4361f8f66dcbe8eb8 Mon Sep 17 00:00:00 2001 From: Dorian Vabre Date: Wed, 21 Apr 2021 17:25:28 +0200 Subject: [PATCH] wip on looking for existing attendees instead of creating them each time --- .../attendee_subscription.php | 51 ++++++++----------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/htdocs/public/eventorganization/attendee_subscription.php b/htdocs/public/eventorganization/attendee_subscription.php index 2bacd3a1951..d88a1ddd55a 100644 --- a/htdocs/public/eventorganization/attendee_subscription.php +++ b/htdocs/public/eventorganization/attendee_subscription.php @@ -228,10 +228,26 @@ if (empty($reshook) && $action == 'add') { } if (!$error) { - // Vérifier si client existe par l'email + // Check if attendee already exists (by email) + $confattendee = new ConferenceOrBoothAttendee($db); + $resultfetchconfattendee = $confattendee->fetchAll('', '', 0, 0, array('t.fk_actioncomm'=>$id, 't.email'=>$email)); + if ($resultfetchconfattendee != 0 && count($resultfetchconfattendee)>0) { + // Found confattendee + $confattendee = $resultfetchconfattendee[0]; + } else { + // Need to create a confattendee + } + $confattendee->date_subscription = dol_now(); + $confattendee->email = GETPOST("email"); + $confattendee->fk_actioncomm = $id; + $resultconfattendee = $confattendee->create($user); + if ($resultconfattendee < 0) { + $error++; + $errmsg .= $confattendee->error; + } + // Getting the thirdparty or creating it $thirdparty = new Societe($db); - $resultfetchthirdparty = $thirdparty->fetch('', '', '', '', '', '', '', '', '', '', $email); - + $resultfetchthirdparty = $thirdparty->fetch($confattendee->fk_soc); if ($resultfetchthirdparty<0) { $error++; $errmsg .= $thirdparty->error; @@ -277,33 +293,8 @@ if (empty($reshook) && $action == 'add') { // We have an existing thirdparty ready to use $readythirdparty = 1; } - - if ($readythirdparty < 0) { - $error++; - $errmsg .= $thirdparty->error; - } else { - // creation of an attendee - $confattendee = new ConferenceOrBoothAttendee($db); - $resultfetchattendee = $confattendee->fetchAll('','', 1, 0, array('t.fk_soc'=>$thirdparty->id, 't.fk_actioncomm'=>$id)); - if ($resultfetchattendee == 0 || count($resultfetchattendee) == 0) { - // Need to create an attendee - $confattendee->fk_soc = $thirdparty->id; - $confattendee->date_subscription = dol_now(); - $confattendee->email = GETPOST("email"); - $confattendee->fk_actioncomm = $id; - $resultconfattendee = $confattendee->create($user); - if ($resultconfattendee < 0) { - $error++; - $errmsg .= $confattendee->error; - } - print 'created attendee'; - } else { - // Found an attendee - print 'found attendee'; - var_dump($resultfetchattendee); - $confattendee = $resultfetchattendee[0]; - } - } + // Updating the fk_soc associated to the confattendee to match the ready to use thirdparty we have got + $confattendee->fk_soc = $thirdparty->id; } if (!$error) {