Refactored InterfaceNotification class

This commit is contained in:
Marcos García de La Fuente 2014-07-18 03:29:20 +02:00
parent cbd10106b8
commit f7c1203d4c

View File

@ -61,118 +61,70 @@ class InterfaceNotification extends DolibarrTriggers
require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php'; 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);
$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"); $langs->load("other");
switch ($action) {
case 'BILL_VALIDATE':
$dir_output = $conf->facture->dir_output;
$object_type = 'facture';
$mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$object->ref); $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$object->ref);
break;
$notify = new Notify($this->db); case 'ORDER_VALIDATE':
$notify->send($action, $object->socid, $mesg, 'facture', $object->id, $filepdf); $dir_output = $conf->commande->dir_output;
} $object_type = 'order';
elseif ($action == 'ORDER_VALIDATE')
{
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); $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$object->ref);
break;
$notify = new Notify($this->db); case 'PROPAL_VALIDATE':
$notify->send($action, $object->socid, $mesg, 'order', $object->id, $filepdf); $dir_output = $conf->propal->dir_output;
} $object_type = 'propal';
elseif ($action == 'PROPAL_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$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); $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$object->ref);
break;
$notify = new Notify($this->db); case 'FICHINTER_VALIDATE':
$notify->send($action, $object->socid, $mesg, 'propal', $object->id, $filepdf); $dir_output = $conf->facture->dir_output;
} $object_type = 'ficheinter';
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); $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$object->ref);
break;
$notify = new Notify($this->db); case 'ORDER_SUPPLIER_APPROVE':
$notify->send($action, $object->socid, $mesg, 'ficheinter', $object->id, $filepdf); $dir_output = $conf->fournisseur->dir_output.'/commande/';
} $object_type = 'order_supplier';
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("Hello").",\n\n";
$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$object->ref,$user->getFullName($langs)); $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$object->ref,$user->getFullName($langs));
$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
break;
$notify = new Notify($this->db); case 'ORDER_SUPPLIER_REFUSE':
$notify->send($action, $object->socid, $mesg, 'order_supplier', $object->id, $filepdf); $dir_output = $conf->fournisseur->dir_output.'/commande/';
} $object_type = 'order_supplier';
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("Hello").",\n\n";
$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$object->ref,$user->getFullName($langs)); $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$object->ref,$user->getFullName($langs));
$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; $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, 'order_supplier', $object->id, $filepdf);
} }
elseif ($action == 'SHIPPING_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); $ref = dol_sanitizeFileName($object->ref);
$filepdf = $conf->expedition->dir_output . '/sending/' . $ref . '/' . $ref . '.pdf'; $pdf_path = "$dir_output/$ref/$ref.pdf";
if (! file_exists($filepdf)) $filepdf='';
$mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated",$object->ref);
if (!file_exists($pdf_path)) {
// We can't add PDF as it is not generated yet.
$filepdf = '';
} else {
$filepdf = $pdf_path;
}
$notify = new Notify($this->db); $notify = new Notify($this->db);
$notify->send($action, $object->socid, $mesg, 'expedition', $object->id, $filepdf); $notify->send($action, $object->socid, $mesg, $object_type, $object->id, $filepdf);
}
// If not found return 1;
/*
else
{
dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action.");
return -1;
}
*/
return 0;
} }
@ -183,7 +135,7 @@ class InterfaceNotification extends DolibarrTriggers
*/ */
function getListOfManagedEvents() function getListOfManagedEvents()
{ {
global $conf,$langs; global $conf;
$ret=array(); $ret=array();