Skip to content

Commit

Permalink
#247 [Attendant] add: rework attendance with status
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Mar 22, 2023
1 parent 68d61d4 commit e036cdb
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 73 deletions.
59 changes: 16 additions & 43 deletions class/saturnesignature.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,12 @@ class SaturneSignature extends CommonObject
const STATUS_DELETED = -1;
const STATUS_DRAFT = 0;
const STATUS_REGISTERED = 1;
const STATUS_SIGNATURE_REQUEST = 2;
const STATUS_PENDING_SIGNATURE = 3;
const STATUS_DENIED = 4;
const STATUS_SIGNED = 5;
const STATUS_UNSIGNED = 6;
const STATUS_ABSENT = 7;
const STATUS_JUSTIFIED_ABSENT = 8;
const STATUS_DELAY = 9;

const ATTENDANCE_PRESENT = 0;
const ATTENDANCE_DELAY = 1;
const ATTENDANCE_ABSENT = 2;

/**
* @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
Expand Down Expand Up @@ -239,6 +237,11 @@ class SaturneSignature extends CommonObject
*/
public string $last_email_sent_date;

/**
* @var int|null Attendance
*/
public ?int $attendance;

/**
* @var string Object type
*/
Expand Down Expand Up @@ -461,30 +464,6 @@ public function setSigned(User $user, int $notrigger = 0, string $zone = 'privat
return $this->setStatusCommon($user, self::STATUS_SIGNED, $notrigger, 'SATURNESIGNATURE_SIGNED' . (($zone == 'public') ? '_PUBLIC' : ''));
}

/**
* Set delay status
*
* @param User $user Object user that modify
* @param int $notrigger 1 = Does not execute triggers, 0 = Execute triggers
* @return int 0 < if KO, > 0 if OK
*/
public function setDelay(User $user, int $notrigger = 0): int
{
return $this->setStatusCommon($user, self::STATUS_DELAY, $notrigger, 'SATURNESIGNATURE_DELAY');
}

/**
* Set absent status
*
* @param User $user Object user that modify
* @param int $notrigger 1 = Does not execute triggers, 0 = Execute triggers
* @return int 0 < if KO, > 0 if OK
*/
public function setAbsent(User $user, int $notrigger = 0): int
{
return $this->setStatusCommon($user, self::STATUS_ABSENT, $notrigger, 'SATURNESIGNATURE_ABSENT');
}

/**
* Set deleted status
*
Expand Down Expand Up @@ -521,23 +500,14 @@ public function LibStatut(int $status, int $mode = 0): string
global $langs;
$this->labelStatus[self::STATUS_DELETED] = $langs->transnoentities('Deleted');
$this->labelStatus[self::STATUS_REGISTERED] = $langs->transnoentities('Registered');
$this->labelStatus[self::STATUS_SIGNATURE_REQUEST] = $langs->transnoentities('SignatureRequest');
$this->labelStatus[self::STATUS_PENDING_SIGNATURE] = $langs->transnoentities('PendingSignature');
$this->labelStatus[self::STATUS_DENIED] = $langs->transnoentities('Denied');
$this->labelStatus[self::STATUS_SIGNED] = $langs->transnoentities('Signed');
$this->labelStatus[self::STATUS_UNSIGNED] = $langs->transnoentities('Unsigned');
$this->labelStatus[self::STATUS_ABSENT] = $langs->transnoentities('Absent');
$this->labelStatus[self::STATUS_JUSTIFIED_ABSENT] = $langs->transnoentities('JustifiedAbsent');
$this->labelStatus[self::STATUS_DELAY] = $langs->transnoentities('Delay');
}

$statusType = 'status' . $status;
if ($status == self::STATUS_SIGNED) {
$statusType = 'status4';
}
if ($status == self::STATUS_ABSENT) {
$statusType = 'status8';
}

return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
}
Expand Down Expand Up @@ -606,6 +576,8 @@ public function setSignatory($fk_object, $object_type, $element_type, $element_i

$this->signature_url = generate_random_id(16);

$this->attendance = self::ATTENDANCE_PRESENT;

$this->object_type = $object_type;
$this->fk_object = $fk_object;
$this->module_name = $this->module;
Expand Down Expand Up @@ -684,7 +656,7 @@ public function checkSignatoriesSignatures($fk_object, $object_type)

if ( ! empty($signatories) && $signatories > 0) {
foreach ($signatories as $signatory) {
if ($signatory->status == 5 || $signatory->status == 7) {
if ($signatory->status == self::STATUS_SIGNED || $signatory->attendance == self::ATTENDANCE_ABSENT) {
continue;
} else {
return 0;
Expand Down Expand Up @@ -715,7 +687,8 @@ public function deleteSignatoriesSignatures($fk_object, $object_type)
if (dol_strlen($signatory->signature)) {
$signatory->signature = '';
$signatory->signature_date = '';
$signatory->status = 1;
$signatory->status = self::STATUS_REGISTERED;
$signatory->attendance = self::ATTENDANCE_PRESENT;
$signatory->update($user);
}
}
Expand Down Expand Up @@ -785,10 +758,10 @@ public function createFromClone(User $user, int $fromid, int $objectID): int
$object->fk_object = $objectID;
}
if (property_exists($object, 'status')) {
$object->status = 1;
$object->status = self::STATUS_REGISTERED;
}
if (property_exists($object, 'attendance')) {
$object->attendance = 0;
$object->attendance = self::ATTENDANCE_PRESENT;
}
if (property_exists($object, 'signature')) {
$object->signature = '';
Expand Down
2 changes: 1 addition & 1 deletion core/tpl/signature/signature_view.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
exit;
}

if (empty($element->signature) && ($object->status == $object::STATUS_VALIDATED || $element->signature == $langs->transnoentities('FileGenerated')) && $element->status != $element::STATUS_ABSENT && $permissiontoadd) : ?>
if (empty($element->signature) && ($object->status == $object::STATUS_VALIDATED || $element->signature == $langs->transnoentities('FileGenerated')) && $element->attendance != SaturneSignature::ATTENDANCE_ABSENT && $permissiontoadd) : ?>
<div class="wpeo-button button-blue wpeo-modal-event modal-signature-open modal-open" value="<?php echo $element->id ?>">
<input type="hidden" class="modal-to-open" value="modal-signature<?php echo $element->id ?>">
<input type="hidden" class="from-id" value="<?php echo $element->id ?>">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,20 +236,20 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
$actioncomm->fk_element = $object->fk_object;
$actioncomm->create($user);
break;
case 'SATURNESIGNATURE_DELAY' :
case 'SATURNESIGNATURE_ATTENDANCE_DELAY' :
$actioncomm->elementtype = $object->object_type . '@dolimeet';
$actioncomm->code = 'AC_SATURNESIGNATURE_DELAY';
$actioncomm->label = $langs->transnoentities('DelayTrigger', $langs->trans($object->role) . ' ' . strtoupper($object->lastname) . ' ' . $object->firstname);
$actioncomm->code = 'AC_SATURNESIGNATURE_ATTENDANCE_DELAY';
$actioncomm->label = $langs->transnoentities('AttendanceDelayTrigger', $langs->trans($object->role) . ' ' . strtoupper($object->lastname) . ' ' . $object->firstname);
if ($object->element_type == 'socpeople') {
$actioncomm->socpeopleassigned = [$object->element_id => $object->element_id];
}
$actioncomm->fk_element = $object->fk_object;
$actioncomm->create($user);
break;
case 'SATURNESIGNATURE_ABSENT' :
case 'SATURNESIGNATURE_ATTENDANCE_ABSENT' :
$actioncomm->elementtype = $object->object_type . '@dolimeet';
$actioncomm->code = 'AC_SATURNESIGNATURE_ABSENT';
$actioncomm->label = $langs->transnoentities('AbsentTrigger', $langs->trans($object->role) . ' ' . strtoupper($object->lastname) . ' ' . $object->firstname);
$actioncomm->code = 'AC_SATURNESIGNATURE_ATTENDANCE_ABSENT';
$actioncomm->label = $langs->transnoentities('AttendanceAbsentTrigger', $langs->trans($object->role) . ' ' . strtoupper($object->lastname) . ' ' . $object->firstname);
if ($object->element_type == 'socpeople') {
$actioncomm->socpeopleassigned = [$object->element_id => $object->element_id];
}
Expand Down
44 changes: 21 additions & 23 deletions view/saturne_attendants.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
$action = '';
}

// Action to set attendance and status STATUS_REGISTERED / STATUS_DELAY / STATUS_ABSENT
// Action to set attendance
if ($action == 'set_attendance') {
$data = json_decode(file_get_contents('php://input'), true);

Expand All @@ -145,22 +145,24 @@

switch ($attendance) {
case 1:
$result = $signatory->setDelay($user);
$signatory->attendance = 1;
$signatory->attendance = SaturneSignature::ATTENDANCE_DELAY;
$triggerName = 'ATTENDANCE_DELAY';
break;
case 2:
$result = $signatory->setAbsent($user);
$signatory->attendance = 2;
$signatory->attendance = SaturneSignature::ATTENDANCE_ABSENT;
$triggerName = 'ATTENDANCE_ABSENT';
break;
default:
$result = $signatory->setRegistered($user);
$signatory->attendance = 0;
$signatory->attendance = SaturneSignature::ATTENDANCE_PRESENT;
$triggerName = 'ATTENDANCE_PRESENT';
break;
}

$result = $signatory->update($user, true);

if ($result > 0) {
// Set attendance OK
$signatory->update($user, true);
$signatory->call_trigger('SATURNESIGNATURE_' . $triggerName, $user);
} elseif (!empty($signatory->errors)) {
// Set attendance KO
setEventMessages('', $signatory->errors, 'errors');
Expand Down Expand Up @@ -374,7 +376,7 @@
}
}
print '</td><td class="center copy-signatureurl-container">';
if ($object->status == $object::STATUS_VALIDATED && $element->status != $element::STATUS_ABSENT) {
if ($object->status == $object::STATUS_VALIDATED && $element->attendance != SaturneSignature::ATTENDANCE_ABSENT) {
if ((!$user->rights->$moduleNameLowerCase->$objectType->read && $user->rights->$moduleNameLowerCase->assignedtome->$objectType && ($element->element_id == $user->id || $element->element_id == $user->contact_id)) || $permissiontoadd) {
$signatureUrl = dol_buildpath('/custom/dolimeet/public/signature/add_signature.php?track_id=' . $element->signature_url . '&object_type=' . $object->element, 3);
print '<a href=' . $signatureUrl . ' target="_blank"><div class="wpeo-button button-primary"><i class="fas fa-signature"></i></div></a>';
Expand Down Expand Up @@ -429,9 +431,7 @@
print '</td><td>';
print dol_print_date($element->signature_date, 'dayhour');
print '</td><td class="center">';
if ($element->attendance == 0) {
print $element->getLibStatut(5);
}
print $element->getLibStatut(5);
print '</td><td class="center">';
switch ($element->attendance) {
case 1:
Expand All @@ -448,17 +448,15 @@
break;
}
if ($object->status == $object::STATUS_VALIDATED && $permissiontoadd) {
if (empty($element->signature)) {
print '<div class="wpeo-dropdown dropdown-right attendance-container">';
print '<input type="hidden" name="signatoryID" value="' . $element->id . '">';
print '<div class="dropdown-toggle wpeo-button ' . $cssButton . '"><i class="fas ' . $userIcon . '"></i></div>';
print '<ul class="dropdown-content wpeo-gridlayout grid-3">';
print '<li class="dropdown-item set-attendance" style="padding: 0" value="0"><div class="wpeo-button button-green"><i class="fas fa-user"></i></div></li>';
print '<li class="dropdown-item set-attendance" style="padding: 0" value="1"><div class="wpeo-button"><i class="fas fa-user-clock"></i></div></li>';
print '<li class="dropdown-item set-attendance" style="padding: 0" value="2"><div class="wpeo-button button-red"><i class="fas fa-user-slash"></i></div></li>';
print '</ul>';
print '</div>';
}
print '<div class="wpeo-dropdown dropdown-right attendance-container">';
print '<input type="hidden" name="signatoryID" value="' . $element->id . '">';
print '<div class="dropdown-toggle wpeo-button ' . $cssButton . '"><i class="fas ' . $userIcon . '"></i></div>';
print '<ul class="dropdown-content wpeo-gridlayout grid-3">';
print '<li class="dropdown-item set-attendance" style="padding: 0" value="0"><div class="wpeo-button button-green"><i class="fas fa-user"></i></div></li>';
print '<li class="dropdown-item set-attendance" style="padding: 0" value="1"><div class="wpeo-button"><i class="fas fa-user-clock"></i></div></li>';
print '<li class="dropdown-item set-attendance" style="padding: 0" value="2"><div class="wpeo-button button-red"><i class="fas fa-user-slash"></i></div></li>';
print '</ul>';
print '</div>';
} else {
print '<div class="dropdown-toggle wpeo-button ' . $cssButton . '"><i class="fas ' . $userIcon . '"></i></div>';
}
Expand Down

0 comments on commit e036cdb

Please sign in to comment.