condition('status', 1)
->condition('type', 'boutique');
$result = array_values($query->execute());
$count = count($result);
for ($i = 0; $i < $count; $i++) {
$entity = entity_load('node', $result[$i])->toArray();
$sectorName = '';
if (!empty($entity['field_zone_code'])) {
$zEntityQuery = \Drupal::entityQuery('node')
->condition('type', 'zone')
->condition('field_zone_code', $entity['field_zone_code'][0])
->condition('status', 1)->execute();
if (count($zEntityQuery) > 0) {
$mZone = entity_load('node', array_values($zEntityQuery)[0])->toArray();
if (count($mZone) > 0) {
$sectorName = trim(str_replace(' ', ' ', (db_query('SELECT description__value FROM taxonomy_term_field_data WHERE tid = :tid', array(
':tid' => $mZone['field_sector_code'][0]['target_id']
))->fetchField())));
}
}
}
$nid = $entity['nid'][0]['value'];
$rawUrl = '/node/' . $entity['nid'][0]['value'];
$aliasUrl = db_query('SELECT alias FROM url_alias WHERE source = :source', array(':source' => $rawUrl))->fetchField();
$sTypes = null;
if (!empty($entity['field_boutique_logo'])) {
$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());
} else {
$imgUrl = str_replace('public://', '/sites/quartierdix30/files/', db_query("SELECT uri FROM file_managed WHERE fid = :fid", array(':fid' => 105))->fetchField());
}
$aliasUrl = !$aliasUrl ? $rawUrl : $aliasUrl;
$hoursMarkup = '
';
$todayHours = '
Open Today';
$todayFound = false;
if (!empty($entity['field_boutique_hours'])) {
$daysArray = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
$today = date('l');
//ICON REMOVED =>
foreach ($entity['field_boutique_hours'] as $day) {
// $hours .= '
' . $daysArray[$day['day']] . ' ' . $day['starthours'] . ' to ' . $day['endhours'] . '
';
if ($today == $daysArray[$day['day']]) {
$todayHours .= '
' . $day['starthours'] . ' to ' . $day['endhours'] . '';
$todayFound = true;
}
}
}
if (!$todayFound) {
$todayHours = '
Closed Today
';
}
$hoursMarkup .= $todayHours;
$boutiqueTitle = isset($entity['title'][0]['value']) ? $entity['title'][0]['value'] : 'QD30' . $i;
$description = trim("
" . str_replace(array('"', 'è'), array('\"', 'È'), preg_replace('/[\n\r]/', '', strtoupper(strip_tags($sectorName)))) . "
". $boutiqueTitle . "
". str_replace('"', '\"', preg_replace('/[\n\r]/', '
', $hoursMarkup)) . "
");
if (!empty($entity['field_store_type'])) {
$storeTypes = array();
foreach ($entity['field_store_type'] as $storeType) {
$typeQ = db_query('SELECT name FROM taxonomy_term_field_data WHERE tid = :tid', array(
':tid' => $storeType['target_id']
))->fetchField();
if (strlen($typeQ) > 0) {
$storeTypes[] = $typeQ;
}
}
if (count($storeTypes) > 0) {
$sTypes = '"storetypes":"';
foreach ($storeTypes as $tag) {
$sTypes .= $tag . ',';
}
$sTypes = rtrim($sTypes, ',');
$sTypes .= '",';
}
}
$boutiqueGeoJson .= '{"type":"Feature",';
$boutiqueGeoJson .= '"id":"way/' . $i . '",';
$boutiqueGeoJson .= '"properties":{';
// if (!empty($entity['field_levels'])) {
if (!empty($entity['title'])) {
$boutiqueGeoJson .= '"name":"' . trim($entity['title'][0]['value']) . '",';
}
if ($nid != null && strlen($nid) > 0) {
$boutiqueGeoJson .= '"nid":"' . $nid . '",';
}
if (!empty($entity['field_zone_code']) && !empty($entity['field_levels'])) {
$boutiqueGeoJson .= '"level":"' . trim($entity['field_levels'][0]['value']) . '",';
} else {
$boutiqueGeoJson .= '"level":"1",';
}
// if (!empty($entity['field_boutique_address'])) {
// $boutiqueAddress = trim($entity['field_boutique_address'][0]['value']);
// $boutiqueGeoJson .= '"addr":"'. $boutiqueAddress . '",';
// $description .= "
". $boutiqueAddress . " ";
// }
if (!empty($entity['field_boutique_phone_number'])) {
$phoneNum = trim($entity['field_boutique_phone_number'][0]['value']);
$boutiqueGeoJson .= '"phone":"' . $phoneNum . '",';
//ICON REMOVED =>
$description .= "
". $phoneNum . "
";
}
if (!empty($entity['field_boutique_website'])) {
$website = trim($entity['field_boutique_website'][0]['value']);
$boutiqueGeoJson .= '"website":"' . $website . '",';
//ICON REMOVED =>
$description .= "
";
}
if ($aliasUrl) {
$description .= "
";
}
//This includes a logo property
// if ($imgUrl) {
// $boutiqueGeoJson .= '"logo":"' . $imgUrl .'",';
// }
if (!empty($entity['field_boutique_events'])) {
$boutiqueGeoJson .= '"event":"true",';
//ICON REMOVED =>
$description .= "
";
}
if ($sTypes) {
$boutiqueGeoJson .= $sTypes;
}
if ($description) {
$boutiqueGeoJson .= '"description":"' . $description . '"';
}
if (!empty($entity['field_zone_code'])) {
$zQuery = array_values(\Drupal::entityQuery('node')
->condition('status', 1)
->condition('type', 'zone')
->condition('field_zone_code', $entity['field_zone_code'][0])
->execute());
if (count($zQuery) > 0) {
$tQuery = db_query("SELECT name FROM taxonomy_term_field_data WHERE tid = :tid", array(
':tid' => $entity['field_zone_code'][0]['target_id']
))
->fetchField();
if (strlen($tQuery) > 0) {
$zoneEntity = entity_load('node', $zQuery[0])->toArray();
if ($zoneEntity != null) {
$sectorQuery = db_query("SELECT field_sector_code_target_id FROM node__field_sector_code
WHERE bundle = :bundle AND entity_id = :nid", array(
':bundle' => 'zone',
':nid' => $zoneEntity['nid'][0]['value'],
))->fetchField();
if (strlen($sectorQuery) > 0) {
$sectorTaxVerify = array_values(\Drupal::entityQuery('taxonomy_term')
->condition('vid', 'sector')
->condition('tid', is_array($sectorQuery) ? $sectorQuery[0] : $sectorQuery)
->execute());
if (count($sectorTaxVerify) > 0) {
$sectorEntityQuery = db_query("SELECT entity_id FROM node__field_sector_code
WHERE bundle = :bundle AND field_sector_code_target_id = :tid", array(
':bundle' => 'sector',
':tid' => is_array($sectorQuery) ? $sectorQuery[0] : $sectorQuery,
))->fetchField();
if (!empty($sectorEntityQuery)) {
$sectorEntity = entity_load('node', is_array($sectorEntityQuery) ? $sectorEntityQuery[0] : $sectorEntityQuery)->toArray();
if (null != $sectorEntity && !empty($sectorEntity['field_zone_colour'])) {
$boutiqueGeoJson .= ',';
$boutiqueGeoJson .= '"colour":"' . $sectorEntity['field_zone_colour'][0]['value'] . '"}';
} else {
$boutiqueGeoJson .= ',';
$boutiqueGeoJson .= '"colour":"' . '#000000' . '"}';
}
}
}
}
if (!empty($zoneEntity['field_feature_data'])) {
$boutiqueGeoJson .= ',';
$boutiqueGeoJson .= '"geometry":' . $zoneEntity['field_feature_data'][0]['value'];
} else {
//Purposely don't set the geometry property so we can choose the default camera view in its absence
$boutiqueGeoJson .= ',';
$boutiqueGeoJson .= '"geometry":' . '{"type":"Polygon","coordinates":[[[1,1]]]}';
}
}
}
}
} else {
$boutiqueGeoJson .= '},';
$boutiqueGeoJson .= '"geometry":' . '{"type":"Polygon","coordinates":[[[1,1]]]}';
}
// $boutiqueGeoJson .= '},';
// $boutiqueGeoJson .= '"geometry":' . '{"type":"Polygon","coordinates":[[[1,1]]]}';
$boutiqueGeoJson .= $i == ($count -1) ? '}' : '},';
}
$boutiqueGeoJson .= ']}';
// print '
'; print_r($boutiqueGeoJson); print '
';
$file = file_save_data($boutiqueGeoJson, "public://geojson/quartier_en.json", FILE_EXISTS_REPLACE);
if ($file != false) {
return $file->id();
} else {
return false;
}
}
function boutique_data_rebuild_json_fr() {
setlocale(LC_TIME, "fr_FR");
$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":[';
$query = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('langcode', 'fr')
->condition('type', 'boutique');
$result = array_values($query->execute());
$count = count($result);
for ($i = 0; $i < $count; $i++) {
$entity = entity_load('node', $result[$i])->toArray();
$sectorName = '';
if (!empty($entity['field_zone_code'])) {
$zEntityQuery = \Drupal::entityQuery('node')
->condition('type', 'zone')
->condition('field_zone_code', $entity['field_zone_code'][0])
->condition('status', 1)->execute();
if (count($zEntityQuery) > 0) {
$mZone = entity_load('node', array_values($zEntityQuery)[0])->toArray();
if (count($mZone) > 0) {
$sectorName = trim(str_replace(' ', ' ', (db_query('SELECT description__value FROM taxonomy_term_field_data WHERE tid = :tid', array(
':tid' => $mZone['field_sector_code'][0]['target_id']
))->fetchField())));
}
}
}
$nid = $entity['nid'][0]['value'];
$rawUrl = '/node/' . $entity['nid'][0]['value'];
$aliasUrl = db_query('SELECT alias FROM url_alias WHERE source = :source', array(':source' => $rawUrl))->fetchField();
$sTypes = null;
if (!empty($entity['field_boutique_logo'])) {
$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());
} else {
$imgUrl = str_replace('public://', '/sites/quartierdix30/files/', db_query("SELECT uri FROM file_managed WHERE fid = :fid", array(':fid' => 105))->fetchField());
}
$aliasUrl = !$aliasUrl ? $rawUrl : $aliasUrl;
$hoursMarkup = '
';
$todayFound = false;
$todayHours = '
Ouvert aujourd\'hui';
if (!empty($entity['field_boutique_hours'])) {
$daysArrayEn = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
$daysArray = array('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi');
$today = date('l');
//ICON REMOVED =>
foreach ($entity['field_boutique_hours'] as $day) {
if ($today == $daysArrayEn[$day['day']]) {
$todayHours .= '' . $day['starthours'] . ' à ' . $day['endhours'] . '
';
$todayFound = true;
}
}
}
$boutiqueTitle = isset($entity['title'][0]['value']) ? $entity['title'][0]['value'] : 'QD30' . $i;
if (!$todayFound) {
$todayHours = '
Fermé aujourd\'hui
';
}
$hoursMarkup .= $todayHours;
$description = trim("
" . str_replace(array('"', 'è'), array('\"', 'È'), preg_replace('/[\n\r]/', '', strtoupper(strip_tags($sectorName)))) . "
". $boutiqueTitle . "
". str_replace('"', '\"', preg_replace('/[\n\r]/', '
', $hoursMarkup)) . "
");
if (!empty($entity['field_store_type'])) {
$storeTypes = array();
foreach ($entity['field_store_type'] as $storeType) {
$typeQ = db_query('SELECT name FROM taxonomy_term_field_data WHERE tid = :tid', array(
':tid' => $storeType['target_id']
))->fetchField();
if (strlen($typeQ) > 0) {
$storeTypes[] = $typeQ;
}
}
if (count($storeTypes) > 0) {
$sTypes = '"storetypes":"';
foreach ($storeTypes as $tag) {
$sTypes .= $tag . ',';
}
$sTypes = rtrim($sTypes, ',');
$sTypes .= '",';
}
}
$boutiqueGeoJson .= '{"type":"Feature",';
$boutiqueGeoJson .= '"id":"way/' . $i . '",';
$boutiqueGeoJson .= '"properties":{';
// if (!empty($entity['field_levels'])) {
if (!empty($entity['title'])) {
$boutiqueGeoJson .= '"name":"' . trim($entity['title'][0]['value']) . '",';
}
if ($nid != null && strlen($nid) > 0) {
$boutiqueGeoJson .= '"nid":"' . $nid . '",';
}
if (!empty($entity['field_zone_code']) && !empty($entity['field_levels'])) {
$boutiqueGeoJson .= '"level":"' . trim($entity['field_levels'][0]['value']) . '",';
} else {
$boutiqueGeoJson .= '"level":"1",';
}
// if (!empty($entity['field_boutique_address'])) {
// $boutiqueAddress = trim($entity['field_boutique_address'][0]['value']);
// $boutiqueGeoJson .= '"addr":"'. $boutiqueAddress . '",';
// $description .= "
". $boutiqueAddress . " ";
// }
if (!empty($entity['field_boutique_phone_number'])) {
$phoneNum = trim($entity['field_boutique_phone_number'][0]['value']);
$boutiqueGeoJson .= '"phone":"' . $phoneNum . '",';
//ICON REMOVED =>
$description .= "
". $phoneNum . "
";
}
if (!empty($entity['field_boutique_website'])) {
$website = trim($entity['field_boutique_website'][0]['value']);
$boutiqueGeoJson .= '"website":"' . $website . '",';
//ICON REMOVED =>
$description .= "
";
}
if ($aliasUrl) {
$description .= "
";
}
if ($imgUrl) {
$boutiqueGeoJson .= '"logo":"' . $imgUrl .'",';
}
if (!empty($entity['field_boutique_events'])) {
$boutiqueGeoJson .= '"event":"true",';
//ICON REMOVED =>
$description .= "
";
}
if ($sTypes) {
$boutiqueGeoJson .= $sTypes;
}
if ($description) {
$boutiqueGeoJson .= '"description":"' . $description . '"';
}
if (!empty($entity['field_zone_code'])) {
$zQuery = array_values(\Drupal::entityQuery('node')
->condition('status', 1)
->condition('type', 'zone')
->condition('field_zone_code', $entity['field_zone_code'][0])
->execute());
if (count($zQuery) > 0) {
$tQuery = db_query("SELECT name FROM taxonomy_term_field_data WHERE tid = :tid", array(
':tid' => $entity['field_zone_code'][0]['target_id']
))
->fetchField();
if (strlen($tQuery) > 0) {
$zoneEntity = entity_load('node', $zQuery[0])->toArray();
if ($zoneEntity != null) {
$sectorQuery = db_query("SELECT field_sector_code_target_id FROM node__field_sector_code
WHERE bundle = :bundle AND entity_id = :nid", array(
':bundle' => 'zone',
':nid' => $zoneEntity['nid'][0]['value'],
))->fetchField();
if (strlen($sectorQuery) > 0) {
$sectorTaxVerify = array_values(\Drupal::entityQuery('taxonomy_term')
->condition('vid', 'sector')
->condition('tid', is_array($sectorQuery) ? $sectorQuery[0] : $sectorQuery)
->execute());
$test = 'test';
if (count($sectorTaxVerify) > 0) {
$sectorEntityQuery = db_query("SELECT entity_id FROM node__field_sector_code
WHERE bundle = :bundle AND field_sector_code_target_id = :tid", array(
':bundle' => 'sector',
':tid' => is_array($sectorQuery) ? $sectorQuery[0] : $sectorQuery,
))->fetchField();
// $sectorEntityQuery = \Drupal::entityQuery('node')
// ->condition('type', 'sector')
// ->condition('field_sector_code', is_array($sectorQuery) ? $sectorQuery[0] : $sectorQuery)
// ->execute();
if (!empty($sectorEntityQuery)) {
$sectorEntity = entity_load('node', is_array($sectorEntityQuery) ? $sectorEntityQuery[0] : $sectorEntityQuery)->toArray();
if (null != $sectorEntity && !empty($sectorEntity['field_zone_colour'])) {
$boutiqueGeoJson .= ',';
$boutiqueGeoJson .= '"colour":"' . $sectorEntity['field_zone_colour'][0]['value'] . '"}';
} else {
$boutiqueGeoJson .= ',';
$boutiqueGeoJson .= '"colour":"' . '#000000' . '"}';
}
}
}
}
if (!empty($zoneEntity['field_feature_data'])) {
$boutiqueGeoJson .= ',';
$boutiqueGeoJson .= '"geometry":' . $zoneEntity['field_feature_data'][0]['value'];
} else {
//Purposely don't set the geometry property so we can choose the default camera view in its absence
$boutiqueGeoJson .= ',';
$boutiqueGeoJson .= '"geometry":' . '{"type":"Polygon","coordinates":[[[1,1]]]}';
}
}
}
}
} else {
$boutiqueGeoJson .= '},';
$boutiqueGeoJson .= '"geometry":' . '{"type":"Polygon","coordinates":[[[1,1]]]}';
}
// $boutiqueGeoJson .= '},';
// $boutiqueGeoJson .= '"geometry":' . '{"type":"Polygon","coordinates":[[[1,1]]]}';
$boutiqueGeoJson .= $i == ($count -1) ? '}' : '},';
}
$boutiqueGeoJson .= ']}';
// print '
'; print_r($boutiqueGeoJson); print '
';
$file = file_save_data($boutiqueGeoJson, "public://geojson/quartier_fr.json", FILE_EXISTS_REPLACE);
if ($file != false) {
return $file->id();
} else {
return false;
}
}
function boutique_data_node_clear() {
$nodeTest = null;
//
// $NboutiqueNode = Drupal\node\Entity\Node::load(216);
// $MboutiqueNode = \Drupal::entityTypeManager()->getStorage('node')->load(216);
// $EboutiqueNode = entity_load('node', 216);
$nResult = \Drupal::entityQuery('node')
->condition('type', 'zone')
->execute();
$delAttempt = entity_delete_multiple('node', $nResult);
$tResult = \Drupal::entityQuery('taxonomy_term')
->condition('vid', 'zone')
->execute();
$delAttempt = entity_delete_multiple('taxonomy_term', $tResult);
$myvar = 'variability';
return $delAttempt;
}
function boutique_data_boutique_levels_update() {
// $bEntities = \Drupal::entityQuery('node')
// ->condition('type', 'boutique')
// ->condition('status', 1)
// ->execute();
$bEntities = db_query('SELECT nid FROM node_field_data WHERE type = :type AND status = :status AND nid > :min', array(
':type' => 'boutique',
':status' => 1,
':min' => 212,
));
foreach ($bEntities as $nid) {
$node = Node::load($nid->nid);
$node->field_levels = 1;
$node->save();
}
}