Guest User

Untitled

a guest
Aug 10th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * @file
  5. * Helpers for vim_integration_bios.
  6. */
  7.  
  8. /**
  9. * Custom function to import wholesalers.
  10. *
  11. * @param bool $all
  12. * Flag to indicate whether to import all or updated bios.
  13. * @param string $as_of_date
  14. * Optional lookback period for bios updates. Defaults to -1 day.
  15. */
  16. function _vim_integration_bios_import_biographies($all, $as_of_date = NULL) {
  17. $bios_service = \Drupal::service('vim_integration_bios.service');
  18. $team_ids = \Drupal::config('vim_integration_bios.settings')->get('teams_to_import');
  19.  
  20. $bios = $all ? $bios_service->getAllBiographies() : $bios_service->getUpdatedBiographies($as_of_date);
  21. // Let's assume if we have team ids, we're ONLY managing teams.
  22. if (!empty($team_ids)) {
  23. $team_bios_ids = [];
  24. foreach ($team_ids as $team_id) {
  25. $team_members = \Drupal::service('vim_person.team_service')->getTeamMembers($team_id);
  26. foreach ($team_members as $member) {
  27. $team_bios_ids[] = $member->idEmployee;
  28. }
  29. }
  30.  
  31. // Unpublish the person if not in the team.
  32. $persons = \Drupal::entityTypeManager()
  33. ->getStorage('node')
  34. ->getQuery()
  35. ->condition('type', 'person')
  36. ->condition('status', '1')
  37. ->execute();
  38.  
  39. if (!empty($persons)) {
  40. $nodes = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple($persons);
  41. foreach ($nodes as $node) {
  42. if ($node->hasField('field_external_id')) {
  43. if (!in_array($node->get('field_external_id')->value, $team_bios_ids)) {
  44. $node->status = 0;
  45. $node->save();
  46. }
  47. }
  48. }
  49. }
  50.  
  51. $bios = array_filter($bios, function ($bio) use ($team_bios_ids) {
  52. return in_array($bio->id, $team_bios_ids);
  53. });
  54. }
  55.  
  56. \Drupal::service('vim_integration_bios.integration')->process($bios);
  57. }
Add Comment
Please, Sign In to add comment