There is a handler in Bitrix that I want to use to collect reports:

RegisterModuleDependences("iblock", "OnAfterIBlockElementAdd", "OnWeekAfterReviewAdded"); 

When sending messages, he must write to the database and then output a certain period. In essence, the report is annual, monthly, weekly. However, it is not clear where this hook is writing these events. Unfortunately did not find this in the documentation. .. There are recall messages generated by the array:

 AddEventHandler("iblock", "OnAfterIBlockElementAdd", "OnWeekAfterReviewAdded"); function OnWeekAfterReviewAdded($arFields) { if($arFields['IBLOCK_ID'] == IBLOCK_REVIEWS_ID) { $arEventFields = array( 'LINK_TO_REVIEW' => $arFields['PROPERTY_VALUES']['LINK'], 'TEXT' => $arFields['DETAIL_TEXT'], 'NAME' => $arFields['NAME'], 'DATE' => $arFields['DATE_ACTIVE_FROM'], 'IP' => $arFields['PROPERTY_VALUES']['IP'], 'EMAIL' => $arFields['PROPERTY_VALUES']['EMAIL'], 'ID' => $arFields['IBLOCK_ID'], 'TEST' => $arFields, ); CEvent::Send('EMAIL_WEEK_REPORT', 's1', $arEventFields); } } 

I also need to send this event once a month on the first day and on Monday.

1 answer 1

Here is a link to the RegisterModuleDependences documentation. As the name suggests, this function registers the dependencies of a module. It should be used when you are developing your module for bitrix.

In essence, calling this method creates an entry in the b_module_to_module table.

Most likely, you need the AddEventHandler method, which registers an event handler on the fly (without writing to the database).

The difference of these approaches:

  • RegisterModuleDependences - called 1 time during the project, for example, when installing a module. The handler is registered in the database with the indication of the module in which the handler is defined. Triggering the event will lead to the connection of the module.
  • AddEventHandler - executed on every hit, complements the array of handlers collected from the database.

The OnAfterIBlockElementAdd handler you use works on every change of an information block element, but it is not guaranteed to be called when the properties change.

If you want to collect the fact of changes of information block elements, this can be done on the information block settings page, Event Log tab.

  • The problem is that I need to write to the database and make selections for sending. - Basil Jimmy
  • But Bitrix positions itself as: "Newbies need to swear on the manual that they will forget about direct requests, they will forget about DB in general. When a little experience appears and it seems that you are a beast in Beatrix, then you can read about communication with DB, but still do not touch, wait another year or two of active work with the system. And only then you can make friends with the database completely, but remember that first of all it is necessary to make Berix using standard methods by hook or by crook. : " - Basil Jimmy
  • Until I have enough success, there is not enough knowledge how to write through create, write with a database. - Basil Jimmy
  • > how to write through create I do not understand what I mean. - Dmitry