Skip to content

Commit

Permalink
[Session] add: clone attendants with object
Browse files Browse the repository at this point in the history
  • Loading branch information
Théo David committed Aug 18, 2022
1 parent df3c810 commit 59a1098
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 3 deletions.
144 changes: 144 additions & 0 deletions class/session.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,4 +572,148 @@ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hided

return $result;
}

/**
* Clone an object into another one
*
* @param User $user User that creates
* @param int $fromid Id of object to clone
* @param $options
* @return mixed New object created, <0 if KO
* @throws Exception
*/
public function createFromClone(User $user, $fromid, $options)
{
global $conf, $langs;
$error = 0;

require_once __DIR__ . '/meeting.class.php';
require_once __DIR__ . '/trainingsession.class.php';
require_once __DIR__ . '/audit.class.php';


switch ($this->type) {
case 'meeting':
$signatory = new TrainingSessionSignature($this->db);
break;
case 'trainingsession':
$signatory = new MeetingSignature($this->db);
break;
case 'audit':
$signatory = new AuditSignature($this->db);
break;
}

$conf_mod = "DOLIMEET_" . strtoupper($this->type) . '_ADDON';
$refObjectMod = new $conf->global->$conf_mod($this->db);

dol_syslog(__METHOD__, LOG_DEBUG);

$object = new self($this->db);

$this->db->begin();

// Load source object
$result = $object->fetchCommon($fromid);
if ($result > 0 && ! empty($object->table_element_line)) {
$object->fetchLines();
}

// Load signatory and ressources from source object
$signatories = $signatory->fetchSignatory("", $fromid, $this->type);

if ( ! empty($signatories) && $signatories > 0) {
foreach ($signatories as $arrayRole) {
foreach ($arrayRole as $signatoryRole) {
$signatoriesID[$signatoryRole->role] = $signatoryRole->id;
if ($signatoryRole->role == strtoupper($this->type) . '_EXTERNAL_ATTENDANT') {
$extintervenant_ids[] = $signatoryRole->id;
}
}
}
}

// Reset some properties
unset($object->id);
unset($object->fk_user_creat);
unset($object->import_key);

// Clear fields
if (property_exists($object, 'ref')) {
$object->ref = $refObjectMod->getNextValue($object);
}
if (property_exists($object, 'ref_ext')) {
$object->ref_ext = 'dolimeet_' . $object->ref;
}
if (property_exists($object, 'label')) {
$object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf") . " " . $object->label : $this->fields['label']['default'];
}
if (property_exists($object, 'date_creation')) {
$object->date_creation = dol_now();
}
if (property_exists($object, 'status')) {
$object->status = 1;
}

// Create clone
$object->context['createfromclone'] = 'createfromclone';
$object_id = $object->create($user);

if ($object_id > 0) {
if (!empty($signatoriesID)) {
$signatory->createFromClone($user, $signatoriesID[strtoupper($this->type) . '_EXTERNAL_ATTENDANT'], $object_id);
$signatory->createFromClone($user, $signatoriesID[strtoupper($this->type) . '_SOCIETY_ATTENDANT'], $object_id);
}

if ( ! empty($options['schedule'])) {
if ( ! empty($openinghours)) {
$openinghours->element_id = $object_id;
$openinghours->create($user);
}
}

if ( ! empty($options['attendants'])) {
if ( ! empty($extintervenant_ids) && $extintervenant_ids > 0) {
foreach ($extintervenant_ids as $extintervenant_id) {
$signatory->createFromClone($user, $extintervenant_id, $object_id);
}
}
}

if ( ! empty($options['preventionplan_risk'])) {
$num = (!empty($object->lines) ? count($object->lines) : 0);
for ($i = 0; $i < $num; $i++) {
$line = $object->lines[$i];
if (property_exists($line, 'ref')) {
$line->ref = $refPreventionPlanDetMod->getNextValue($line);
}
$line->category = empty($line->category) ? 0 : $line->category;
$line->fk_preventionplan = $object_id;

$result = $line->insert($user, 1);
if ($result < 0) {
$this->error = $this->db->lasterror();
$this->db->rollback();
return -1;
}
}
}
} else {
$error++;
$this->error = $object->error;
$this->errors = $object->errors;
}

unset($object->context['createfromclone']);

// End
if ( ! $error) {
$this->db->commit();
return $object_id;
} else {
$this->db->rollback();
return -1;
}
}

}
4 changes: 2 additions & 2 deletions core/tpl/session/dolimeet_session_attendants.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@
print '<tr class="oddeven"><td class="minwidth200">';
print $usertmp->getNomUrl(1);
print '</td><td>';
print $langs->trans("SocietyAttendants") . ' ' . $j;
print $langs->trans("SocietyAttendant") . ' ' . $j;
print '</td><td class="center">';
if ($object->status == 2) {
$signatureUrl = dol_buildpath('/custom/dolimeet/public/signature/add_signature.php?track_id=' . $element->signature_url . '&type=' . $object->element, 3);
Expand Down Expand Up @@ -400,7 +400,7 @@
print '<tr class="oddeven"><td class="maxwidth200">';
print $form->select_dolusers('', 'user_attendant', 1, $already_added_users);
print '</td>';
print '<td>' . $langs->trans("SocietyAttendants") . '</td>';
print '<td>' . $langs->trans("SocietyAttendant") . '</td>';
print '<td class="center">';
print '-';
print '</td><td class="center">';
Expand Down
3 changes: 2 additions & 1 deletion core/tpl/session/dolimeet_session_card.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,9 @@

// Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes') {
$options = array();
$object->ref = $refMod->getNextValue($object);
$result = $object->create($user);
$result = $object->createFromClone($user, $object->id, $options);

if ($result > 0) {
header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $result);
Expand Down
15 changes: 15 additions & 0 deletions langs/fr_FR/dolimeet.lang
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ SessionList = Liste des sessions
SessionTypes = Types de session
SessionNumberingModule = Numérotation des sessions
SessionConfig = Configuration des sessions
Deleted = Supprimé
ValidatePendingSignature = Validé (en attente de signature)
Signed = Signé
Locked = Verrouillé
SentByLetter = Envoyé par courrier
SentByMail = Envoyé par email
ReceivedAndSignedByMail = Reçu par mail et signé
ReceivedAndSignedByLetter = Reçu par courrier et signé
Registered = Inscrit
SignatureRequest = Demande de signature envoyée
PendingSignature = En attente de signature
Denied = Refusé
Unsigned = Non signé
Absent = Absent
JustifiedAbsent = Absence justifiée


#
Expand Down

0 comments on commit 59a1098

Please sign in to comment.