[Vtigercrm-developers] Registered Event for Invoice module also being used by other modules

Lennart van Ballegoij lennart at egmmedia.nl
Sun Dec 27 00:12:07 GMT 2015


Hi,

I 've used an easyfix by doing this in my handleEvent:

      $modulename = $data->getModuleName();
      if ($data && $modulename == 'Invoice') {}

But i don't think this is the best way of doing this.
Does anyone know the right way of only handling this event on the Invoices
aftersave ?


Thanks in advance!

Kind regards,

Lennart



2015-12-25 2:40 GMT+01:00 Lennart van Ballegoij <lennart at egmmedia.nl>:

> Hi,
>
> I've been working on a Vtiger module that sends the data of a saved
> Invoice to a third party API.
>
> I'm using a Event Handler to retrieve the data from the Invoice module
> and process it to send it to the third party API.
>
> After finishing the module i started testing it and it worked great except
> for returning empty entry's  to the database from time to time.
>
> When i looked into what caused the empty entry's i found out that it was
> caused by the save of other modules.
>
> But i thought the Event Handler will only run for the Module that was
> registered in the Vtiger_Event::register ?
>
> Is this not the case or am i just doing something wrong ?
>
> My Vtiger event register code:
>
>         public function registerInvoiceEvent(){
>             if(Vtiger_Event::hasSupport()) {
>                   Vtiger_Event::register(
>                         'Invoice', 'vtiger.entity.aftersave',
>                         'ReeleezeeHandler',
> 'modules/Reeleezee/ReeleezeeHandler.php'
>                   );
>             }
>         }
>
> My Event handler code:
>
> class ReeleezeeHandler extends VTEventHandler {
>
> public $helper = null;
>
> public function __construct(){
> require 'modules/Reeleezee/Helper.php';
> $this->helper = new Reeleezee_Helper();
> }
>
>  function handleEvent($eventName, $data) {
>
>
>        if($eventName == 'vtiger.entity.aftersave') {
>         if ($data) {
>             $moduledata = $data->getData();
>                         //More code here but don't think it's relevant
>                 }
>           }
> }
>
> Can anybody give me a push in the right direction for why this is
> happening ?
>
>
> Thanks in advance!
>
>
> Kind regards,
>
> Lennart
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20151227/aa816210/attachment.html>


More information about the vtigercrm-developers mailing list