map_coordinates.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Show the map coordinates of all users geo extra field.
  5. *
  6. * @author José Loguercio Silva <jose.loguercio@beeznest.com>
  7. *
  8. * @package chamilo.plugin.google_maps
  9. */
  10. $cidReset = true;
  11. require_once __DIR__.'/../../../main/inc/global.inc.php';
  12. api_protect_admin_script();
  13. $plugin = GoogleMapsPlugin::create();
  14. $apiIsEnable = $plugin->get('enable_api') === 'true';
  15. $extraFieldName = $plugin->get('extra_field_name');
  16. $extraFieldName = array_map('trim', explode(',', $extraFieldName));
  17. if ($apiIsEnable) {
  18. $gmapsApiKey = $plugin->get('api_key');
  19. $htmlHeadXtra[] = '<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?key='.$gmapsApiKey.'" ></script>';
  20. }
  21. $em = Database::getManager();
  22. $extraField = $em->getRepository('ChamiloCoreBundle:ExtraField');
  23. $extraFieldNames = [];
  24. foreach ($extraFieldName as $field) {
  25. $extraFieldNames[] = $extraField->findOneBy(['variable' => $field]);
  26. }
  27. $extraFieldValues = [];
  28. foreach ($extraFieldNames as $index => $fieldName) {
  29. if ($fieldName) {
  30. $extraFieldRepo = $em->getRepository('ChamiloCoreBundle:ExtraFieldValues');
  31. $extraFieldValues[] = $extraFieldRepo->findBy(['field' => $fieldName->getId()]);
  32. }
  33. }
  34. $templateName = $plugin->get_lang('UsersCoordinatesMap');
  35. $tpl = new Template($templateName);
  36. $formattedExtraFieldValues = [];
  37. foreach ($extraFieldValues as $index => $extra) {
  38. foreach ($extra as $yandex => $field) {
  39. $thisUserExtraField = api_get_user_info($field->getItemId());
  40. $formattedExtraFieldValues[$index][$yandex]['address'] = $field->getValue();
  41. $formattedExtraFieldValues[$index][$yandex]['user_complete_name'] = $thisUserExtraField['complete_name'];
  42. }
  43. }
  44. $tpl->assign('extra_field_values_formatted', $formattedExtraFieldValues);
  45. $tpl->assign('extra_field_values', $extraFieldValues);
  46. $content = $tpl->fetch('google_maps/view/map_coordinates.tpl');
  47. $tpl->assign('header', $templateName);
  48. $tpl->assign('content', $content);
  49. $tpl->display_one_col_template();