From f7c1203d4cad41e1da12e0c0deba7bacd7b23aa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Fri, 18 Jul 2014 03:29:20 +0200 Subject: [PATCH] Refactored InterfaceNotification class --- ..._50_modNotification_Notification.class.php | 160 ++++++------------ 1 file changed, 56 insertions(+), 104 deletions(-) diff --git a/htdocs/core/triggers/interface_50_modNotification_Notification.class.php b/htdocs/core/triggers/interface_50_modNotification_Notification.class.php index d1677d22065..159b3575855 100644 --- a/htdocs/core/triggers/interface_50_modNotification_Notification.class.php +++ b/htdocs/core/triggers/interface_50_modNotification_Notification.class.php @@ -61,118 +61,70 @@ class InterfaceNotification extends DolibarrTriggers require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php'; - if ($action == 'BILL_VALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("other"); - $ref = dol_sanitizeFileName($object->ref); - $filepdf = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf'; - if (! file_exists($filepdf)) $filepdf=''; - $filepdf=''; // We can't add PDF as it is not generated yet. - $langs->load("other"); - $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$object->ref); + switch ($action) { + case 'BILL_VALIDATE': + $dir_output = $conf->facture->dir_output; + $object_type = 'facture'; + $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$object->ref); + break; + case 'ORDER_VALIDATE': + $dir_output = $conf->commande->dir_output; + $object_type = 'order'; + $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$object->ref); + break; + case 'PROPAL_VALIDATE': + $dir_output = $conf->propal->dir_output; + $object_type = 'propal'; + $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$object->ref); + break; + case 'FICHINTER_VALIDATE': + $dir_output = $conf->facture->dir_output; + $object_type = 'ficheinter'; + $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$object->ref); + break; + case 'ORDER_SUPPLIER_APPROVE': + $dir_output = $conf->fournisseur->dir_output.'/commande/'; + $object_type = 'order_supplier'; + $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; + $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$object->ref,$user->getFullName($langs)); + $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; + break; + case 'ORDER_SUPPLIER_REFUSE': + $dir_output = $conf->fournisseur->dir_output.'/commande/'; + $object_type = 'order_supplier'; + $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; + $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$object->ref,$user->getFullName($langs)); + $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; + break; + case 'SHIPPING_VALIDATE': + $dir_output = $conf->expedition->dir_output.'/sending/'; + $object_type = 'order_supplier'; + $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated",$object->ref); + break; + + default: + return 0; - $notify = new Notify($this->db); - $notify->send($action, $object->socid, $mesg, 'facture', $object->id, $filepdf); } - elseif ($action == 'ORDER_VALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - $ref = dol_sanitizeFileName($object->ref); - $filepdf = $conf->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf'; - if (! file_exists($filepdf)) $filepdf=''; - $filepdf=''; // We can't add PDF as it is not generated yet. - $langs->load("other"); - $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$object->ref); + $ref = dol_sanitizeFileName($object->ref); + $pdf_path = "$dir_output/$ref/$ref.pdf"; - $notify = new Notify($this->db); - $notify->send($action, $object->socid, $mesg, 'order', $object->id, $filepdf); + if (!file_exists($pdf_path)) { + // We can't add PDF as it is not generated yet. + $filepdf = ''; + } else { + $filepdf = $pdf_path; } - elseif ($action == 'PROPAL_VALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $notify = new Notify($this->db); + $notify->send($action, $object->socid, $mesg, $object_type, $object->id, $filepdf); - $ref = dol_sanitizeFileName($object->ref); - $filepdf = $conf->propal->dir_output . '/' . $ref . '/' . $ref . '.pdf'; - if (! file_exists($filepdf)) $filepdf=''; - $filepdf=''; // We can't add PDF as it is not generated yet. - $langs->load("other"); - $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$object->ref); - - $notify = new Notify($this->db); - $notify->send($action, $object->socid, $mesg, 'propal', $object->id, $filepdf); - } - - elseif ($action == 'FICHINTER_VALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - $ref = dol_sanitizeFileName($object->ref); - $filepdf = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf'; - if (! file_exists($filepdf)) $filepdf=''; - $filepdf=''; // We can't add PDF as it is not generated yet. - $langs->load("other"); - $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$object->ref); - - $notify = new Notify($this->db); - $notify->send($action, $object->socid, $mesg, 'ficheinter', $object->id, $filepdf); - } - - elseif ($action == 'ORDER_SUPPLIER_APPROVE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - $ref = dol_sanitizeFileName($object->ref); - $filepdf = $conf->fournisseur->dir_output . '/commande/' . $ref . '/' . $ref . '.pdf'; - if (! file_exists($filepdf)) $filepdf=''; - $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; - $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$object->ref,$user->getFullName($langs)); - $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; - - $notify = new Notify($this->db); - $notify->send($action, $object->socid, $mesg, 'order_supplier', $object->id, $filepdf); - } - - elseif ($action == 'ORDER_SUPPLIER_REFUSE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - $ref = dol_sanitizeFileName($object->ref); - $filepdf = $conf->fournisseur->dir_output . '/commande/' . $ref . '/' . $ref . '.pdf'; - if (! file_exists($filepdf)) $filepdf=''; - $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; - $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$object->ref,$user->getFullName($langs)); - $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; - - $notify = new Notify($this->db); - $notify->send($action, $object->socid, $mesg, 'order_supplier', $object->id, $filepdf); - } - elseif ($action == 'SHIPPING_VALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - $ref = dol_sanitizeFileName($object->ref); - $filepdf = $conf->expedition->dir_output . '/sending/' . $ref . '/' . $ref . '.pdf'; - if (! file_exists($filepdf)) $filepdf=''; - $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated",$object->ref); - - - $notify = new Notify($this->db); - $notify->send($action, $object->socid, $mesg, 'expedition', $object->id, $filepdf); - } - - // If not found -/* - else - { - dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action."); - return -1; - } -*/ - return 0; + return 1; } @@ -183,7 +135,7 @@ class InterfaceNotification extends DolibarrTriggers */ function getListOfManagedEvents() { - global $conf,$langs; + global $conf; $ret=array();