Skip to content

Commit

Permalink
#1 [Certificate] add: trigger file
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Oct 11, 2022
1 parent d42edac commit 1574459
Showing 1 changed file with 71 additions and 3 deletions.
74 changes: 71 additions & 3 deletions core/triggers/interface_99_modDolisirh_DolisirhTriggers.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

/**
* \file core/triggers/interface_99_modDolisirh_DolisirhTriggers.class.php
* \file core/triggers/interface_99_modDoliSIRH_DoliSIRHTriggers.class.php
* \ingroup dolisirh
* \brief DoliSIRH trigger.
*/
Expand All @@ -26,7 +26,7 @@
/**
* Class of triggers for DoliSIRH module
*/
class InterfaceDolisirhTriggers extends DolibarrTriggers
class InterfaceDoliSIRHTriggers extends DolibarrTriggers
{
/**
* @var DoliDB Database handler
Expand All @@ -44,7 +44,7 @@ public function __construct(DoliDB $db)

$this->name = preg_replace('/^Interface/i', '', get_class($this));
$this->family = "demo";
$this->description = "Dolisirh triggers.";
$this->description = "DoliSIRH triggers.";
// 'development', 'experimental', 'dolibarr' or version
$this->version = '1.0.0';
$this->picto = 'dolisirh@dolisirh';
Expand Down Expand Up @@ -335,6 +335,74 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
$actioncomm->create($user);
break;

// Certificate
case 'CERTIFICATE_CREATE' :
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';

require_once __DIR__ . '/../../class/certificate.class.php';

$signatory = new CertificateSignature($this->db);
$usertmp = new User($this->db);
$actioncomm = new ActionComm($this->db);

if (!empty($object->fk_user_assign)) {
$usertmp->fetch($object->fk_user_assign);
$signatory->setSignatory($object->id, 'timesheet', 'user', array($object->fk_user_assign), 'CERTIFICATE_SOCIETY_ATTENDANT');
$signatory->setSignatory($object->id, 'timesheet', 'user', array($usertmp->fk_user), 'CERTIFICATE_SOCIETY_RESPONSIBLE');
}

$now = dol_now();

$actioncomm->elementtype = 'certificate@dolisirh';
$actioncomm->code = 'AC_CERTIFICATE_CREATE';
$actioncomm->type_code = 'AC_OTH_AUTO';
$actioncomm->label = $langs->trans('CertificateCreateTrigger');
$actioncomm->datep = $now;
$actioncomm->fk_element = $object->id;
$actioncomm->userownerid = $user->id;
$actioncomm->percentage = -1;

$actioncomm->create($user);
break;

case 'CERTIFICATE_MODIFY' :
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
$now = dol_now();
$actioncomm = new ActionComm($this->db);

$actioncomm->elementtype = 'certificate@dolisirh';
$actioncomm->code = 'AC_CERTIFICATE_MODIFY';
$actioncomm->type_code = 'AC_OTH_AUTO';
$actioncomm->label = $langs->trans('CertificateModifyTrigger');
$actioncomm->datep = $now;
$actioncomm->fk_element = $object->id;
$actioncomm->userownerid = $user->id;
$actioncomm->percentage = -1;

$actioncomm->create($user);
break;

case 'CERTIFICATE_DELETE' :
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
$now = dol_now();
$actioncomm = new ActionComm($this->db);

$actioncomm->elementtype = 'certificate@dolisirh';
$actioncomm->code = 'AC_CERTIFICATE_DELETE';
$actioncomm->type_code = 'AC_OTH_AUTO';
$actioncomm->label = $langs->trans('CertificateDeleteTrigger');
$actioncomm->datep = $now;
$actioncomm->fk_element = $object->id;
$actioncomm->userownerid = $user->id;
$actioncomm->percentage = -1;

$actioncomm->create($user);
break;

case 'ECMFILES_CREATE' :
if ($object->src_object_type == 'dolisirh_timesheet') {
dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id);
Expand Down

0 comments on commit 1574459

Please sign in to comment.