Hi all. I’m sending a link in our application. Made a transport that provides the function of sending messages through Firebase. But I haven’t yet understood the logic of getting the recipient.
My transport:
<?php
namespace Tygh\Notifications\Transports\Firebase;
use Tygh\Exceptions\DeveloperException;
use Tygh\Notifications\Transports\BaseMessageSchema;
use Tygh\Notifications\Transports\ITransport;
class FirebaseTransports implements ITransport
{
protected $firebase;
protected $receiver_finder_factory;
public function __construct(Firebase $firebase)
{
$this->firebase = $firebase;
}
public static function getId()
{
return 'firebase';
}
public function fn_user_fcm_token ($schema, $receivers) {
$body = array(
'title' => $schema->title,
'data' => $schema->data,
);
$message = array(
'to' => $receivers,
'notifications' => $body,
);
return fn_send_notification_firebase(
$message,
$receivers
);
}
public function process(BaseMessageSchema $schema, array $receiver_search_conditions)
{
if (!$schema instanceof FirebaseMessageSchema) {
throw new DeveloperException('Input data should be instance of FirebaseMessageSchema');
}
$receivers = $this->getReceivers($receiver_search_conditions, $schema);
return $this->fn_user_fcm_token($schema, $receivers);
}
protected function getReceivers(array $receiver_search_conditions, FirebaseMessageSchema $schema)
{
$fcmTokens = [];
foreach ($receiver_search_conditions as $condition) {
$finder = $this->receiver_finder_factory->get($condition->getMethod());
$fcmTokens = array_merge($fcmTokens, $finder->find($condition->getCriterion(), $schema));
}
$fcmTokens = array_unique($fcmTokens);
if (!$fcmTokens) {
$fcmTokens = db_get_array("SELECT token FROM ?:fcm_tokens WHERE user_id IN (?a)", array_keys($receiver_search_conditions));
}
$fcmTokens = array_unique(array_column($fcmTokens, 'token'));
// TODO: Сreate function check fcm token
return $fcmTokens;
}
}
Together I made a Firebase diagram.
Events have reached a dead end.
$order_event = [
‘id’ => ‘order.status_changed’,
‘group’ => ‘orders’,
‘name’ => [
‘template’ => ‘event.order.status_changed.name’,
‘params’ => [
‘[status]’ => ‘’,
],
],
‘data_provider’ => [OrderDataProvider::class, ‘factory’],
‘receivers’ => [
UserTypes::CUSTOMER => [
MailTransport::getId() => MailMessageSchema::create([
‘area’ => SiteArea::STOREFRONT,
‘from’ => ‘company_orders_department’,
‘to’ => DataValue::create(‘order_info.email’),
‘template_code’ => DataValue::create(‘template_code’),
‘legacy_template’ => ‘orders/order_notification.tpl’,
‘company_id’ => DataValue::create(‘order_info.company_id’),
‘storefront_id’ => DataValue::create(‘order_info.storefront_id’),
‘language_code’ => DataValue::create(‘order_info.lang_code’, CART_LANGUAGE)
]),
],
UserTypes::ADMIN => [
MailTransport::getId() => MailMessageSchema::create([
‘area’ => SiteArea::ADMIN_PANEL,
‘from’ => ‘default_company_orders_department’,
‘to’ => ‘default_company_orders_department’,
‘reply_to’ => DataValue::create(‘order_info.email’),
‘template_code’ => DataValue::create(‘template_code’),
‘legacy_template’ => ‘orders/order_notification.tpl’,
‘company_id’ => DataValue::create(‘order_info.company_id’),
‘to_company_id’ => DataValue::create(‘order_info.company_id’),
‘storefront_id’ => DataValue::create(‘order_info.storefront_id’),
‘language_code’ => DataValue::create(‘lang_code’, CART_LANGUAGE)
])
],
],
];
From here, as I understand it, I need to pass user_id via:
DataValue::create('order_info.user_id')
And then what should I do to get the user_id in $receiver_search_conditions?