Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @file
- * Helpers for vim_integration_bios.
- */
- /**
- * Custom function to import wholesalers.
- *
- * @param bool $all
- * Flag to indicate whether to import all or updated bios.
- * @param string $as_of_date
- * Optional lookback period for bios updates. Defaults to -1 day.
- */
- function _vim_integration_bios_import_biographies($all, $as_of_date = NULL) {
- $bios_service = \Drupal::service('vim_integration_bios.service');
- $team_ids = \Drupal::config('vim_integration_bios.settings')->get('teams_to_import');
- $bios = $all ? $bios_service->getAllBiographies() : $bios_service->getUpdatedBiographies($as_of_date);
- // Let's assume if we have team ids, we're ONLY managing teams.
- if (!empty($team_ids)) {
- $team_bios_ids = [];
- foreach ($team_ids as $team_id) {
- $team_members = \Drupal::service('vim_person.team_service')->getTeamMembers($team_id);
- foreach ($team_members as $member) {
- $team_bios_ids[] = $member->idEmployee;
- }
- }
- // Unpublish the person if not in the team.
- $persons = \Drupal::entityTypeManager()
- ->getStorage('node')
- ->getQuery()
- ->condition('type', 'person')
- ->condition('status', '1')
- ->execute();
- if (!empty($persons)) {
- $nodes = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple($persons);
- foreach ($nodes as $node) {
- if ($node->hasField('field_external_id')) {
- if (!in_array($node->get('field_external_id')->value, $team_bios_ids)) {
- $node->status = 0;
- $node->save();
- }
- }
- }
- }
- $bios = array_filter($bios, function ($bio) use ($team_bios_ids) {
- return in_array($bio->id, $team_bios_ids);
- });
- }
- \Drupal::service('vim_integration_bios.integration')->process($bios);
- }
Add Comment
Please, Sign In to add comment