-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathopeny_daxko_gxp_syncer.module
45 lines (43 loc) · 1.28 KB
/
openy_daxko_gxp_syncer.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* @file
* Main module's file.
*/
/**
* Implements hook_openy_repeat_results_alter().
*/
function openy_daxko_gxp_syncer_openy_repeat_results_alter(&$results, $request, $date = NULL) {
if (empty($results)) {
return;
}
/** @var \Drupal\openy_daxko_gxp_syncer\DaxkoGroupexMappingRepository $mappingRepository*/
$mappingRepository = \Drupal::service('openy_daxko_gxp_syncer.mapping');
$storage = $mappingRepository->getStorage();
$query = $storage->getQuery()->accessCheck(FALSE);
$sessionIds = [];
foreach ($results as $schedule) {
if (empty($schedule->productid)) {
continue;
}
$sessionIds[] = $schedule->nid;
}
if (empty($sessionIds)) {
return;
}
$query->condition('session', $sessionIds, 'IN');
$mappingIds = $query->execute();
$mappings = $storage->loadMultiple($mappingIds);
$mappingNormalize = [];
foreach ($mappings as $mapping) {
/** @var \Drupal\openy_daxko_gxp_syncer\DaxkoGroupexMappingInterface $mapping */
$mappingNormalize[$mapping->session->target_id] = $mapping->getAvailabilty();
}
foreach ($results as &$schedule) {
if (empty($schedule->productid)) {
continue;
}
if (isset($mappingNormalize[$schedule->nid])) {
$schedule->spottext = $mappingNormalize[$schedule->nid];
}
}
}