boutique_data.module 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <?php
  2. use Drupal\node\Entity\Node;
  3. use Drupal\Core\Url;
  4. use Drupal\Core\Language\Language;
  5. use Drupal\Core\Language\LanguageManager;
  6. use Drupal\Core\Language\LanguageManagerInterface;
  7. use Drupal\Core\Language\LanguageDefault;
  8. function boutique_data_rebuild_json_en() {
  9. $boutiqueGeoJson = '{"type":"FeatureCollection","generator":"overpass-turbo","copyright":"The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.","timestamp":"2016-09-12T19:22:48Z","features":[';
  10. $query = \Drupal::entityQuery('node')
  11. ->condition('status', 1)
  12. ->condition('type', 'boutique');
  13. $result = array_values($query->execute());
  14. $count = count($result);
  15. for ($i = 0; $i < $count; $i++) {
  16. $entity = entity_load('node', $result[$i])->toArray();
  17. $sectorName = '';
  18. if (!empty($entity['field_zone_code'])) {
  19. $zEntityQuery = \Drupal::entityQuery('node')
  20. ->condition('type', 'zone')
  21. ->condition('field_zone_code', $entity['field_zone_code'][0])
  22. ->condition('status', 1)->execute();
  23. if (count($zEntityQuery) > 0) {
  24. $mZone = entity_load('node', array_values($zEntityQuery)[0])->toArray();
  25. if (count($mZone) > 0) {
  26. $sectorName = trim(str_replace('&nbsp;', ' ', (db_query('SELECT description__value FROM taxonomy_term_field_data WHERE tid = :tid', array(
  27. ':tid' => $mZone['field_sector_code'][0]['target_id']
  28. ))->fetchField())));
  29. }
  30. }
  31. }
  32. $nid = $entity['nid'][0]['value'];
  33. $rawUrl = '/node/' . $entity['nid'][0]['value'];
  34. $aliasUrl = db_query('SELECT alias FROM url_alias WHERE source = :source', array(':source' => $rawUrl))->fetchField();
  35. $sTypes = null;
  36. if (!empty($entity['field_boutique_logo'])) {
  37. $imgUrl = str_replace('public://', '/sites/quartierdix30/files/', db_query("SELECT uri FROM file_managed WHERE fid = :fid", array(':fid' => $entity['field_boutique_logo'][0]['target_id']))->fetchField());
  38. } else {
  39. $imgUrl = str_replace('public://', '/sites/quartierdix30/files/', db_query("SELECT uri FROM file_managed WHERE fid = :fid", array(':fid' => 105))->fetchField());
  40. }
  41. $aliasUrl = !$aliasUrl ? $rawUrl : $aliasUrl;
  42. $hoursMarkup = '<div class="boutique-map-hours">';
  43. $todayHours = '<p class="hours-day"><span>Open Today</span>';
  44. $todayFound = false;
  45. if (!empty($entity['field_boutique_hours'])) {
  46. $daysArray = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
  47. $today = date('l');
  48. //ICON REMOVED => <img class="icon" src="/sites/quartierdix30/themes/quartierdix30/images/icons/icon_b-hours.svg" alt="Icon of a clock to display with the hours">
  49. foreach ($entity['field_boutique_hours'] as $day) {
  50. // $hours .= '<p class="hours-day"><span>' . $daysArray[$day['day']] . '</span> <span>' . $day['starthours'] . ' to ' . $day['endhours'] . '</span></p>';
  51. if ($today == $daysArray[$day['day']]) {
  52. $todayHours .= '<span>' . $day['starthours'] . ' to ' . $day['endhours'] . '</span></p>';
  53. $todayFound = true;
  54. }
  55. }
  56. }
  57. if (!$todayFound) {
  58. $todayHours = '<p class="hours-day"><span>Closed Today</span></p>';
  59. }
  60. $hoursMarkup .= $todayHours;
  61. $boutiqueTitle = isset($entity['title'][0]['value']) ? $entity['title'][0]['value'] : 'QD30' . $i;
  62. $description = trim("<div class='boutique-infobox' id='boutique-" . $boutiqueTitle . "'><div id='marker-img'></div><div id='sector'>" . str_replace(array('"', 'è'), array('\"', 'È'), preg_replace('/[\n\r]/', '', strtoupper(strip_tags($sectorName)))) . "</div><h2>". $boutiqueTitle . "</h2><a target='_parent' href='". $aliasUrl . "'><img src='" . $imgUrl . "'></img></a><div id='business-details'>". str_replace('"', '\"', preg_replace('/[\n\r]/', '<br>', $hoursMarkup)) . "</div></div>");
  63. if (!empty($entity['field_store_type'])) {
  64. $storeTypes = array();
  65. foreach ($entity['field_store_type'] as $storeType) {
  66. $typeQ = db_query('SELECT name FROM taxonomy_term_field_data WHERE tid = :tid', array(
  67. ':tid' => $storeType['target_id']
  68. ))->fetchField();
  69. if (strlen($typeQ) > 0) {
  70. $storeTypes[] = $typeQ;
  71. }
  72. }
  73. if (count($storeTypes) > 0) {
  74. $sTypes = '"storetypes":"';
  75. foreach ($storeTypes as $tag) {
  76. $sTypes .= $tag . ',';
  77. }
  78. $sTypes = rtrim($sTypes, ',');
  79. $sTypes .= '",';
  80. }
  81. }
  82. $boutiqueGeoJson .= '{"type":"Feature",';
  83. $boutiqueGeoJson .= '"id":"way/' . $i . '",';
  84. $boutiqueGeoJson .= '"properties":{';
  85. // if (!empty($entity['field_levels'])) {
  86. if (!empty($entity['title'])) {
  87. $boutiqueGeoJson .= '"name":"' . trim($entity['title'][0]['value']) . '",';
  88. }
  89. if ($nid != null && strlen($nid) > 0) {
  90. $boutiqueGeoJson .= '"nid":"' . $nid . '",';
  91. }
  92. if (!empty($entity['field_zone_code']) && !empty($entity['field_levels'])) {
  93. $boutiqueGeoJson .= '"level":"' . trim($entity['field_levels'][0]['value']) . '",';
  94. } else {
  95. $boutiqueGeoJson .= '"level":"1",';
  96. }
  97. // if (!empty($entity['field_boutique_address'])) {
  98. // $boutiqueAddress = trim($entity['field_boutique_address'][0]['value']);
  99. // $boutiqueGeoJson .= '"addr":"'. $boutiqueAddress . '",';
  100. // $description .= "<div class='boutique-info-address'><img class='icon' src='/sites/quartierdix30/modules/custom/qd30map/gfx/icon_mappointer-b.svg' alt='icon'><span>". $boutiqueAddress . "</span></div>";
  101. // }
  102. if (!empty($entity['field_boutique_phone_number'])) {
  103. $phoneNum = trim($entity['field_boutique_phone_number'][0]['value']);
  104. $boutiqueGeoJson .= '"phone":"' . $phoneNum . '",';
  105. //ICON REMOVED => <img class='icon' src='/sites/quartierdix30/themes/quartierdix30/images/icons/icon_b-phone.svg' alt='icon'>
  106. $description .= "<div class='boutique-info-phone'><span>". $phoneNum . "</span></div>";
  107. }
  108. if (!empty($entity['field_boutique_website'])) {
  109. $website = trim($entity['field_boutique_website'][0]['value']);
  110. $boutiqueGeoJson .= '"website":"' . $website . '",';
  111. //ICON REMOVED => <img class='icon' src='/sites/quartierdix30/themes/quartierdix30/images/icons/icon_b-cursor.svg' alt='icon'>
  112. $description .= "<div class='boutique-info-website'><a target='_parent' href='". $website . "'>" . $website . "</a></div>";
  113. }
  114. if ($aliasUrl) {
  115. $description .= "<div class='boutique-view-full'><div class='readmore'><a target='_parent' href='". $aliasUrl . "'>View full listing →</a></div></div>";
  116. }
  117. //This includes a logo property
  118. // if ($imgUrl) {
  119. // $boutiqueGeoJson .= '"logo":"' . $imgUrl .'",';
  120. // }
  121. if (!empty($entity['field_boutique_events'])) {
  122. $boutiqueGeoJson .= '"event":"true",';
  123. //ICON REMOVED => <img class='icon' src='/sites/quartierdix30/modules/custom/qd30map/gfx/icon_calendar-w.svg' alt='icon'>
  124. $description .= "<div id='event-before'></div><div class='event'><div class='readmore'><a target='_parent' href='". $aliasUrl . "'>Event happening now →</a></div></div>";
  125. }
  126. if ($sTypes) {
  127. $boutiqueGeoJson .= $sTypes;
  128. }
  129. if ($description) {
  130. $boutiqueGeoJson .= '"description":"' . $description . '"';
  131. }
  132. if (!empty($entity['field_zone_code'])) {
  133. $zQuery = array_values(\Drupal::entityQuery('node')
  134. ->condition('status', 1)
  135. ->condition('type', 'zone')
  136. ->condition('field_zone_code', $entity['field_zone_code'][0])
  137. ->execute());
  138. if (count($zQuery) > 0) {
  139. $tQuery = db_query("SELECT name FROM taxonomy_term_field_data WHERE tid = :tid", array(
  140. ':tid' => $entity['field_zone_code'][0]['target_id']
  141. ))
  142. ->fetchField();
  143. if (strlen($tQuery) > 0) {
  144. $zoneEntity = entity_load('node', $zQuery[0])->toArray();
  145. if ($zoneEntity != null) {
  146. $sectorQuery = db_query("SELECT field_sector_code_target_id FROM node__field_sector_code
  147. WHERE bundle = :bundle AND entity_id = :nid", array(
  148. ':bundle' => 'zone',
  149. ':nid' => $zoneEntity['nid'][0]['value'],
  150. ))->fetchField();
  151. if (strlen($sectorQuery) > 0) {
  152. $sectorTaxVerify = array_values(\Drupal::entityQuery('taxonomy_term')
  153. ->condition('vid', 'sector')
  154. ->condition('tid', is_array($sectorQuery) ? $sectorQuery[0] : $sectorQuery)
  155. ->execute());
  156. if (count($sectorTaxVerify) > 0) {
  157. $sectorEntityQuery = db_query("SELECT entity_id FROM node__field_sector_code
  158. WHERE bundle = :bundle AND field_sector_code_target_id = :tid", array(
  159. ':bundle' => 'sector',
  160. ':tid' => is_array($sectorQuery) ? $sectorQuery[0] : $sectorQuery,
  161. ))->fetchField();
  162. if (!empty($sectorEntityQuery)) {
  163. $sectorEntity = entity_load('node', is_array($sectorEntityQuery) ? $sectorEntityQuery[0] : $sectorEntityQuery)->toArray();
  164. if (null != $sectorEntity && !empty($sectorEntity['field_zone_colour'])) {
  165. $boutiqueGeoJson .= ',';
  166. $boutiqueGeoJson .= '"colour":"' . $sectorEntity['field_zone_colour'][0]['value'] . '"}';
  167. } else {
  168. $boutiqueGeoJson .= ',';
  169. $boutiqueGeoJson .= '"colour":"' . '#000000' . '"}';
  170. }
  171. }
  172. }
  173. }
  174. if (!empty($zoneEntity['field_feature_data'])) {
  175. $boutiqueGeoJson .= ',';
  176. $boutiqueGeoJson .= '"geometry":' . $zoneEntity['field_feature_data'][0]['value'];
  177. } else {
  178. //Purposely don't set the geometry property so we can choose the default camera view in its absence
  179. $boutiqueGeoJson .= ',';
  180. $boutiqueGeoJson .= '"geometry":' . '{"type":"Polygon","coordinates":[[[1,1]]]}';
  181. }
  182. }
  183. }
  184. }
  185. } else {
  186. $boutiqueGeoJson .= '},';
  187. $boutiqueGeoJson .= '"geometry":' . '{"type":"Polygon","coordinates":[[[1,1]]]}';
  188. }
  189. // $boutiqueGeoJson .= '},';
  190. // $boutiqueGeoJson .= '"geometry":' . '{"type":"Polygon","coordinates":[[[1,1]]]}';
  191. $boutiqueGeoJson .= $i == ($count -1) ? '}' : '},';
  192. }
  193. $boutiqueGeoJson .= ']}';
  194. // print '<pre>'; print_r($boutiqueGeoJson); print '</pre>';
  195. $file = file_save_data($boutiqueGeoJson, "public://geojson/quartier_en.json", FILE_EXISTS_REPLACE);
  196. if ($file != false) {
  197. return $file->id();
  198. } else {
  199. return false;
  200. }
  201. }
  202. function boutique_data_rebuild_json_fr() {
  203. setlocale(LC_TIME, "fr_FR");
  204. $boutiqueGeoJson = '{"type":"FeatureCollection","generator":"overpass-turbo","copyright":"The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.","timestamp":"2016-09-12T19:22:48Z","features":[';
  205. $query = \Drupal::entityQuery('node')
  206. ->condition('status', 1)
  207. ->condition('langcode', 'fr')
  208. ->condition('type', 'boutique');
  209. $result = array_values($query->execute());
  210. $count = count($result);
  211. for ($i = 0; $i < $count; $i++) {
  212. $entity = entity_load('node', $result[$i])->toArray();
  213. $sectorName = '';
  214. if (!empty($entity['field_zone_code'])) {
  215. $zEntityQuery = \Drupal::entityQuery('node')
  216. ->condition('type', 'zone')
  217. ->condition('field_zone_code', $entity['field_zone_code'][0])
  218. ->condition('status', 1)->execute();
  219. if (count($zEntityQuery) > 0) {
  220. $mZone = entity_load('node', array_values($zEntityQuery)[0])->toArray();
  221. if (count($mZone) > 0) {
  222. $sectorName = trim(str_replace('&nbsp;', ' ', (db_query('SELECT description__value FROM taxonomy_term_field_data WHERE tid = :tid', array(
  223. ':tid' => $mZone['field_sector_code'][0]['target_id']
  224. ))->fetchField())));
  225. }
  226. }
  227. }
  228. $nid = $entity['nid'][0]['value'];
  229. $rawUrl = '/node/' . $entity['nid'][0]['value'];
  230. $aliasUrl = db_query('SELECT alias FROM url_alias WHERE source = :source', array(':source' => $rawUrl))->fetchField();
  231. $sTypes = null;
  232. if (!empty($entity['field_boutique_logo'])) {
  233. $imgUrl = str_replace('public://', '/sites/quartierdix30/files/', db_query("SELECT uri FROM file_managed WHERE fid = :fid", array(':fid' => $entity['field_boutique_logo'][0]['target_id']))->fetchField());
  234. } else {
  235. $imgUrl = str_replace('public://', '/sites/quartierdix30/files/', db_query("SELECT uri FROM file_managed WHERE fid = :fid", array(':fid' => 105))->fetchField());
  236. }
  237. $aliasUrl = !$aliasUrl ? $rawUrl : $aliasUrl;
  238. $hoursMarkup = '<div class="boutique-map-hours">';
  239. $todayFound = false;
  240. $todayHours = '<p class="hours-day"><span>Ouvert aujourd\'hui</span>';
  241. if (!empty($entity['field_boutique_hours'])) {
  242. $daysArrayEn = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
  243. $daysArray = array('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi');
  244. $today = date('l');
  245. //ICON REMOVED => <img class="icon" src="/sites/quartierdix30/themes/quartierdix30/images/icons/icon_b-hours.svg" alt="Icon of a clock to display with the hours">
  246. foreach ($entity['field_boutique_hours'] as $day) {
  247. if ($today == $daysArrayEn[$day['day']]) {
  248. $todayHours .= '<span>' . $day['starthours'] . ' à ' . $day['endhours'] . '</span></p>';
  249. $todayFound = true;
  250. }
  251. }
  252. }
  253. $boutiqueTitle = isset($entity['title'][0]['value']) ? $entity['title'][0]['value'] : 'QD30' . $i;
  254. if (!$todayFound) {
  255. $todayHours = '<p class="hours-day"><span>Fermé aujourd\'hui</span></p>';
  256. }
  257. $hoursMarkup .= $todayHours;
  258. $description = trim("<div class='boutique-infobox' id='boutique-" . $boutiqueTitle . "'><div id='marker-img'></div><div id='sector'>" . str_replace(array('"', 'è'), array('\"', 'È'), preg_replace('/[\n\r]/', '', strtoupper(strip_tags($sectorName)))) . "</div><h2>". $boutiqueTitle . "</h2><a target='_parent' href='". $aliasUrl . "'><img src='" . $imgUrl . "'></img></a><div id='business-details'>". str_replace('"', '\"', preg_replace('/[\n\r]/', '<br>', $hoursMarkup)) . "</div></div>");
  259. if (!empty($entity['field_store_type'])) {
  260. $storeTypes = array();
  261. foreach ($entity['field_store_type'] as $storeType) {
  262. $typeQ = db_query('SELECT name FROM taxonomy_term_field_data WHERE tid = :tid', array(
  263. ':tid' => $storeType['target_id']
  264. ))->fetchField();
  265. if (strlen($typeQ) > 0) {
  266. $storeTypes[] = $typeQ;
  267. }
  268. }
  269. if (count($storeTypes) > 0) {
  270. $sTypes = '"storetypes":"';
  271. foreach ($storeTypes as $tag) {
  272. $sTypes .= $tag . ',';
  273. }
  274. $sTypes = rtrim($sTypes, ',');
  275. $sTypes .= '",';
  276. }
  277. }
  278. $boutiqueGeoJson .= '{"type":"Feature",';
  279. $boutiqueGeoJson .= '"id":"way/' . $i . '",';
  280. $boutiqueGeoJson .= '"properties":{';
  281. // if (!empty($entity['field_levels'])) {
  282. if (!empty($entity['title'])) {
  283. $boutiqueGeoJson .= '"name":"' . trim($entity['title'][0]['value']) . '",';
  284. }
  285. if ($nid != null && strlen($nid) > 0) {
  286. $boutiqueGeoJson .= '"nid":"' . $nid . '",';
  287. }
  288. if (!empty($entity['field_zone_code']) && !empty($entity['field_levels'])) {
  289. $boutiqueGeoJson .= '"level":"' . trim($entity['field_levels'][0]['value']) . '",';
  290. } else {
  291. $boutiqueGeoJson .= '"level":"1",';
  292. }
  293. // if (!empty($entity['field_boutique_address'])) {
  294. // $boutiqueAddress = trim($entity['field_boutique_address'][0]['value']);
  295. // $boutiqueGeoJson .= '"addr":"'. $boutiqueAddress . '",';
  296. // $description .= "<div class='boutique-info-address'><img class='icon' src='/sites/quartierdix30/modules/custom/qd30map/gfx/icon_mappointer-b.svg' alt='icon'><span>". $boutiqueAddress . "</span></div>";
  297. // }
  298. if (!empty($entity['field_boutique_phone_number'])) {
  299. $phoneNum = trim($entity['field_boutique_phone_number'][0]['value']);
  300. $boutiqueGeoJson .= '"phone":"' . $phoneNum . '",';
  301. //ICON REMOVED => <img class='icon' src='/sites/quartierdix30/themes/quartierdix30/images/icons/icon_b-phone.svg' alt='icon'>
  302. $description .= "<div class='boutique-info-phone'><span>". $phoneNum . "</span></div>";
  303. }
  304. if (!empty($entity['field_boutique_website'])) {
  305. $website = trim($entity['field_boutique_website'][0]['value']);
  306. $boutiqueGeoJson .= '"website":"' . $website . '",';
  307. //ICON REMOVED => <img class='icon' src='/sites/quartierdix30/themes/quartierdix30/images/icons/icon_b-cursor.svg' alt='icon'>
  308. $description .= "<div class='boutique-info-website'><a target='_parent' href='". $website . "'>" . $website . "</a></div>";
  309. }
  310. if ($aliasUrl) {
  311. $description .= "<div class='boutique-view-full'><div class='readmore'><a target='_parent' href='". $aliasUrl . "'>View full listing →</a></div></div>";
  312. }
  313. if ($imgUrl) {
  314. $boutiqueGeoJson .= '"logo":"' . $imgUrl .'",';
  315. }
  316. if (!empty($entity['field_boutique_events'])) {
  317. $boutiqueGeoJson .= '"event":"true",';
  318. //ICON REMOVED => <img class='icon' src='/sites/quartierdix30/modules/custom/qd30map/gfx/icon_calendar-w.svg' alt='icon'>
  319. $description .= "<div class='event'><div class='readmore'><a target='_parent' href='". $aliasUrl . "'>Event happening now →</a></div></div>";
  320. }
  321. if ($sTypes) {
  322. $boutiqueGeoJson .= $sTypes;
  323. }
  324. if ($description) {
  325. $boutiqueGeoJson .= '"description":"' . $description . '"';
  326. }
  327. if (!empty($entity['field_zone_code'])) {
  328. $zQuery = array_values(\Drupal::entityQuery('node')
  329. ->condition('status', 1)
  330. ->condition('type', 'zone')
  331. ->condition('field_zone_code', $entity['field_zone_code'][0])
  332. ->execute());
  333. if (count($zQuery) > 0) {
  334. $tQuery = db_query("SELECT name FROM taxonomy_term_field_data WHERE tid = :tid", array(
  335. ':tid' => $entity['field_zone_code'][0]['target_id']
  336. ))
  337. ->fetchField();
  338. if (strlen($tQuery) > 0) {
  339. $zoneEntity = entity_load('node', $zQuery[0])->toArray();
  340. if ($zoneEntity != null) {
  341. $sectorQuery = db_query("SELECT field_sector_code_target_id FROM node__field_sector_code
  342. WHERE bundle = :bundle AND entity_id = :nid", array(
  343. ':bundle' => 'zone',
  344. ':nid' => $zoneEntity['nid'][0]['value'],
  345. ))->fetchField();
  346. if (strlen($sectorQuery) > 0) {
  347. $sectorTaxVerify = array_values(\Drupal::entityQuery('taxonomy_term')
  348. ->condition('vid', 'sector')
  349. ->condition('tid', is_array($sectorQuery) ? $sectorQuery[0] : $sectorQuery)
  350. ->execute());
  351. $test = 'test';
  352. if (count($sectorTaxVerify) > 0) {
  353. $sectorEntityQuery = db_query("SELECT entity_id FROM node__field_sector_code
  354. WHERE bundle = :bundle AND field_sector_code_target_id = :tid", array(
  355. ':bundle' => 'sector',
  356. ':tid' => is_array($sectorQuery) ? $sectorQuery[0] : $sectorQuery,
  357. ))->fetchField();
  358. // $sectorEntityQuery = \Drupal::entityQuery('node')
  359. // ->condition('type', 'sector')
  360. // ->condition('field_sector_code', is_array($sectorQuery) ? $sectorQuery[0] : $sectorQuery)
  361. // ->execute();
  362. if (!empty($sectorEntityQuery)) {
  363. $sectorEntity = entity_load('node', is_array($sectorEntityQuery) ? $sectorEntityQuery[0] : $sectorEntityQuery)->toArray();
  364. if (null != $sectorEntity && !empty($sectorEntity['field_zone_colour'])) {
  365. $boutiqueGeoJson .= ',';
  366. $boutiqueGeoJson .= '"colour":"' . $sectorEntity['field_zone_colour'][0]['value'] . '"}';
  367. } else {
  368. $boutiqueGeoJson .= ',';
  369. $boutiqueGeoJson .= '"colour":"' . '#000000' . '"}';
  370. }
  371. }
  372. }
  373. }
  374. if (!empty($zoneEntity['field_feature_data'])) {
  375. $boutiqueGeoJson .= ',';
  376. $boutiqueGeoJson .= '"geometry":' . $zoneEntity['field_feature_data'][0]['value'];
  377. } else {
  378. //Purposely don't set the geometry property so we can choose the default camera view in its absence
  379. $boutiqueGeoJson .= ',';
  380. $boutiqueGeoJson .= '"geometry":' . '{"type":"Polygon","coordinates":[[[1,1]]]}';
  381. }
  382. }
  383. }
  384. }
  385. } else {
  386. $boutiqueGeoJson .= '},';
  387. $boutiqueGeoJson .= '"geometry":' . '{"type":"Polygon","coordinates":[[[1,1]]]}';
  388. }
  389. // $boutiqueGeoJson .= '},';
  390. // $boutiqueGeoJson .= '"geometry":' . '{"type":"Polygon","coordinates":[[[1,1]]]}';
  391. $boutiqueGeoJson .= $i == ($count -1) ? '}' : '},';
  392. }
  393. $boutiqueGeoJson .= ']}';
  394. // print '<pre>'; print_r($boutiqueGeoJson); print '</pre>';
  395. $file = file_save_data($boutiqueGeoJson, "public://geojson/quartier_fr.json", FILE_EXISTS_REPLACE);
  396. if ($file != false) {
  397. return $file->id();
  398. } else {
  399. return false;
  400. }
  401. }
  402. function boutique_data_node_clear() {
  403. $nodeTest = null;
  404. //
  405. // $NboutiqueNode = Drupal\node\Entity\Node::load(216);
  406. // $MboutiqueNode = \Drupal::entityTypeManager()->getStorage('node')->load(216);
  407. // $EboutiqueNode = entity_load('node', 216);
  408. $nResult = \Drupal::entityQuery('node')
  409. ->condition('type', 'zone')
  410. ->execute();
  411. $delAttempt = entity_delete_multiple('node', $nResult);
  412. $tResult = \Drupal::entityQuery('taxonomy_term')
  413. ->condition('vid', 'zone')
  414. ->execute();
  415. $delAttempt = entity_delete_multiple('taxonomy_term', $tResult);
  416. $myvar = 'variability';
  417. return $delAttempt;
  418. }
  419. function boutique_data_boutique_levels_update() {
  420. // $bEntities = \Drupal::entityQuery('node')
  421. // ->condition('type', 'boutique')
  422. // ->condition('status', 1)
  423. // ->execute();
  424. $bEntities = db_query('SELECT nid FROM node_field_data WHERE type = :type AND status = :status AND nid > :min', array(
  425. ':type' => 'boutique',
  426. ':status' => 1,
  427. ':min' => 212,
  428. ));
  429. foreach ($bEntities as $nid) {
  430. $node = Node::load($nid->nid);
  431. $node->field_levels = 1;
  432. $node->save();
  433. }
  434. }