Skip to content

Commit

Permalink
#247 [Attendant] add: attendance field for signatory
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Mar 21, 2023
1 parent ce525d4 commit 2e29f48
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 33 deletions.
25 changes: 19 additions & 6 deletions class/saturnesignature.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class SaturneSignature extends CommonObject
const STATUS_UNSIGNED = 6;
const STATUS_ABSENT = 7;
const STATUS_JUSTIFIED_ABSENT = 8;
const STATUS_DELAY = 9;

/**
* @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 @@ -118,6 +119,7 @@ class SaturneSignature extends CommonObject
'signature_url' => ['type' => 'varchar(255)', 'label' => 'SignatureUrl', 'enabled' => 1, 'position' => 170, 'notnull' => 0, 'visible' => 1],
'transaction_url' => ['type' => 'varchar(255)', 'label' => 'TransactionUrl', 'enabled' => 1, 'position' => 180, 'notnull' => 0, 'visible' => 1],
'last_email_sent_date' => ['type' => 'datetime', 'label' => 'SendMailDate', 'enabled' => 1, 'position' => 190, 'notnull' => 0, 'visible' => 3],
'attendance' => ['type' => 'smallint', 'label' => 'Attendance', 'enabled' => 1, 'position' => 194, 'notnull' => 0, 'visible' => 3],
'object_type' => ['type' => 'varchar(255)', 'label' => 'object_type', 'enabled' => 1, 'position' => 195, 'notnull' => 0, 'visible' => 0],
'fk_object' => ['type' => 'integer', 'label' => 'FKObject', 'enabled' => 1, 'position' => 200, 'notnull' => 1, 'visible' => 0, 'index' => 1],
];
Expand Down Expand Up @@ -293,11 +295,7 @@ public function __construct(DoliDB $db)
*/
public function create(User $user, bool $notrigger = false): int
{
$result = $this->createCommon($user, $notrigger);
if ($result > 0) {
$this->call_trigger('SESSION_ADDATTENDANT',$user);
}
return $result;
return $this->createCommon($user, $notrigger);
}

/**
Expand Down Expand Up @@ -463,6 +461,18 @@ 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
*
Expand Down Expand Up @@ -509,7 +519,6 @@ public function LibStatut(int $status, int $mode = 0): string
{
if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
global $langs;
$langs->load('signature@dolimeet');
$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');
Expand All @@ -519,6 +528,7 @@ public function LibStatut(int $status, int $mode = 0): string
$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;
Expand Down Expand Up @@ -777,6 +787,9 @@ public function createFromClone(User $user, int $fromid, int $objectID): int
if (property_exists($object, 'status')) {
$object->status = 1;
}
if (property_exists($object, 'attendance')) {
$object->attendance = 0;
}
if (property_exists($object, 'signature')) {
$object->signature = '';
}
Expand Down
10 changes: 10 additions & 0 deletions core/triggers/interface_99_modDoliMeet_DoliMeetTriggers.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,16 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
$actioncomm->fk_element = $object->fk_object;
$actioncomm->create($user);
break;
case 'SATURNESIGNATURE_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);
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' :
$actioncomm->elementtype = $object->object_type . '@dolimeet';
$actioncomm->code = 'AC_SATURNESIGNATURE_ABSENT';
Expand Down
1 change: 1 addition & 0 deletions sql/signature/llx_saturne_object_signature.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ CREATE TABLE llx_saturne_object_signature(
last_email_sent_date datetime DEFAULT NULL,
signature_url varchar(255),
transaction_url varchar(255),
attendance smallint,
object_type varchar(255),
fk_object integer NOT NULL
) ENGINE=innodb;
3 changes: 2 additions & 1 deletion sql/update.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ ALTER TABLE `llx_dolimeet_session` CHANGE `date_start` `date_start` DATETIME NOT
ALTER TABLE `llx_dolimeet_session` CHANGE `date_end` `date_end` DATETIME NOT NULL;
ALTER TABLE `llx_dolimeet_session` CHANGE `tms` `tms` TIMESTAMP on update CURRENT_TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP;
ALTER TABLE `llx_dolimeet_session` CHANGE `status` `status` INT(11) NOT NULL;
ALTER TABLE `llx_dolimeet_session` CHANGE `import_key` `import_key` VARCHAR(14) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL;
ALTER TABLE `llx_dolimeet_session` CHANGE `import_key` `import_key` VARCHAR(14) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL;
ALTER TABLE `llx_saturne_object_signature` ADD `attendance` SMALLINT NULL AFTER `transaction_url`;
75 changes: 49 additions & 26 deletions view/saturne_attendants.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,29 +134,35 @@
$action = '';
}

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

$signatoryID = $data['signatoryID'];
$attendance = $data['attendance'];

$signatory->fetch($signatoryID);

if ($signatoryStatus != $signatory::STATUS_ABSENT) {
$result = $signatory->setAbsent($user);
} else {
$result = $signatory->setRegistered($user);
switch ($attendance) {
case 1:
$result = $signatory->setDelay($user);
$signatory->attendance = 1;
break;
case 2:
$result = $signatory->setAbsent($user);
$signatory->attendance = 2;
break;
default:
$result = $signatory->setRegistered($user);
$signatory->attendance = 0;
break;
}

if ($result > 0) {
// Toggle absent OK
if ($signatoryStatus != $signatory::STATUS_ABSENT) {
setEventMessages($langs->trans('AbsentAttendantMessage', $langs->trans($signatory->role) . ' ' . strtoupper($signatory->lastname) . ' ' . $signatory->firstname), []);
}
// Prevent form reloading page
header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $id . '&module_name=' . $moduleName . '&object_type=' . $object->element);
exit;
// Set attendance OK
$signatory->update($user, true);
} elseif (!empty($signatory->errors)) {
// Toggle absent KO
// Set attendance KO
setEventMessages('', $signatory->errors, 'errors');
} else {
setEventMessages($signatory->error, [], 'errors');
Expand Down Expand Up @@ -423,21 +429,38 @@
print '</td><td>';
print dol_print_date($element->signature_date, 'dayhour');
print '</td><td class="center">';
print $element->getLibStatut(5);
if ($element->attendance == 0) {
print $element->getLibStatut(5);
}
print '</td><td class="center">';
switch ($element->attendance) {
case 1:
$cssButton = '';
$userIcon = 'fa-user-clock';
break;
case 2:
$cssButton = 'button-red';
$userIcon = 'fa-user-slash';
break;
default:
$cssButton = 'button-green';
$userIcon = 'fa-user';
break;
}
if ($object->status == $object::STATUS_VALIDATED && $permissiontoadd) {
if (empty($element->signature)) {
print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '?id=' . $id . '&module_name=' . $moduleName . '&object_type=' . $object->element . '">';
print '<input type="hidden" name="token" value="' . newToken() . '">';
print '<input type="hidden" name="action" value="toggle_absent">';
print '<div class="wpeo-dropdown dropdown-right attendance-container">';
print '<input type="hidden" name="signatoryID" value="' . $element->id . '">';
print '<input type="hidden" name="signatoryStatus" value="' . $element->status . '">';
print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
print '<button type="submit" class="signature-absent wpeo-button ' . (($element->status != $element::STATUS_ABSENT) ? 'button-green' : 'button-red') . '"" value="' . $element->id . '">';
print '<i class="fas ' . (($element->status != $element::STATUS_ABSENT) ? 'fa-user' : 'fa-user-slash') . '"></i>';
print '</button>';
print '</form>';
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>';
}
print '</td><td class="center">';
if ($object->status < $object::STATUS_LOCKED && $permissiontoadd) {
Expand Down

0 comments on commit 2e29f48

Please sign in to comment.