Commit 21dfba7e authored by Sebastian Castro's avatar Sebastian Castro

Element import openhours

parent 1b99206a
......@@ -9,7 +9,7 @@
* @license MIT License
* @Last Modified time: 2018-01-19 13:05:00
*/
namespace Biopen\GeoDirectoryBundle\Document;
......@@ -19,26 +19,29 @@ use JMS\Serializer\Annotation\Expose;
/** @MongoDB\EmbeddedDocument */
class DailyTimeSlot
{
/**
/**
* @Expose
* @MongoDB\Field(type="date") */
private $slot1start;
/**
/**
* @Expose
* @MongoDB\Field(type="date") */
private $slot1end;
/**
/**
* @Expose
* @MongoDB\Field(type="date") */
private $slot2start;
/**
/**
* @Expose
* @MongoDB\Field(type="date") */
private $slot2end;
public function __construct()
public function __construct($slot1start = null, $slot1end = null, $slot2start = null, $slot2end = null)
{
$this->slot1start = $slot1start;
$this->slot1end = $slot1end;
$this->slot2start = $slot2start;
$this->slot2end = $slot2end;
}
public function toJson()
......@@ -55,7 +58,7 @@ class DailyTimeSlot
//return date_format($this->slot1start, 'H:i');
return $this->slot1start;
}
public function getSlot2Start()
{
......@@ -68,7 +71,7 @@ class DailyTimeSlot
//return date_format($this->slot1end, 'H:i');
return $this->slot1end;
}
public function getSlot2End()
{
......@@ -84,7 +87,7 @@ class DailyTimeSlot
$this->slot1start = $slot;
return $this;
}
public function setSlot2Start($slot)
{
......@@ -97,7 +100,7 @@ class DailyTimeSlot
$this->slot1end = $slot;
return $this;
}
public function setSlot2End($slot)
{
......
......@@ -9,7 +9,7 @@
* @license MIT License
* @Last Modified time: 2018-01-19 13:04:59
*/
namespace Biopen\GeoDirectoryBundle\Document;
......@@ -19,35 +19,60 @@ use JMS\Serializer\Annotation\Expose;
/** @MongoDB\EmbeddedDocument */
class OpenHours
{
/**
protected $days = ['Mo' => 'Monday', 'Tu' => 'Tuesday', 'We' => 'Wednesday', 'Th' => 'Thursday', 'Fr' => 'Friday', 'Sa' => 'Saturday', 'Sun' => 'Sunday'];
/**
* @Expose
* @MongoDB\EmbedOne(targetDocument="Biopen\GeoDirectoryBundle\Document\DailyTimeSlot") */
private $Monday;
/**
/**
* @Expose
* @MongoDB\EmbedOne(targetDocument="Biopen\GeoDirectoryBundle\Document\DailyTimeSlot") */
private $Tuesday;
/**
/**
* @Expose
* @MongoDB\EmbedOne(targetDocument="Biopen\GeoDirectoryBundle\Document\DailyTimeSlot") */
private $Wednesday;
/**
/**
* @Expose
* @MongoDB\EmbedOne(targetDocument="Biopen\GeoDirectoryBundle\Document\DailyTimeSlot") */
private $Thursday;
/**
/**
* @Expose
* @MongoDB\EmbedOne(targetDocument="Biopen\GeoDirectoryBundle\Document\DailyTimeSlot") */
private $Friday;
/**
/**
* @Expose
* @MongoDB\EmbedOne(targetDocument="Biopen\GeoDirectoryBundle\Document\DailyTimeSlot") */
private $Saturday;
/**
/**
* @Expose
* @MongoDB\EmbedOne(targetDocument="Biopen\GeoDirectoryBundle\Document\DailyTimeSlot") */
private $Sunday;
public function __construct($openHours)
{
foreach ($openHours as $day => $timeSlotString) {
$slot1start = null; $slot1end = null; $slot2start = null; $slot2end = null;
$slots = explode(',', $timeSlotString);
if (count($slots) > 0) list($slot1start, $slot1end) = $this->buildSlotsFrom($slots[0]);
if (count($slots) == 2) list($slot2start, $slot2end) = $this->buildSlotsFrom($slots[1]);
$dailySlot = new DailyTimeSlot($slot1start, $slot1end, $slot2start, $slot2end);
$method = 'set' . $this->days[$day];
$this->$method($dailySlot);
}
dump($this);
}
private function buildSlotsFrom($string)
{
$times = explode('-',$string);
$start = date_create_from_format('H:i', $times[0]);
$end = date_create_from_format('H:i', $times[1]);
return [$start, $end];
}
public function toJson() {
$result = '{';
if ($this->Monday) $result .= '"Mo":' . $this->Monday->toJson() . ',';
......@@ -141,7 +166,7 @@ class OpenHours
}
/*public function __construct()
{
{
}
public setDailyTimeSlot($day,$plage1,$plage2)
......
......@@ -64,6 +64,7 @@
coreData.push({id: 'email', text: "Email de l'élement"});
coreData.push({id: 'owner', text: "Email de l'utilisateur propriétaire de la fiche"});
coreData.push({id: 'source', text: "Origine de l'élément (source)"});
coreData.push({id: 'openHours', text: "Horaire d'ouvertues (format GoGoCarto)"});
allProperties = $.map(coreData, function(el) { return el.id });
......
......@@ -7,6 +7,7 @@ use Biopen\GeoDirectoryBundle\Document\Element;
use Biopen\GeoDirectoryBundle\Document\ElementStatus;
use Biopen\GeoDirectoryBundle\Document\ModerationState;
use Biopen\GeoDirectoryBundle\Document\Coordinates;
use Biopen\GeoDirectoryBundle\Document\OpenHours;
use Biopen\GeoDirectoryBundle\Document\Option;
use Biopen\GeoDirectoryBundle\Document\OptionValue;
use Biopen\GeoDirectoryBundle\Document\UserInteractionContribution;
......@@ -21,7 +22,7 @@ class ElementImportOneService
protected $optionIdsToAddToEachElement = [];
protected $coreFields = ['id', 'name', 'categories', 'streetAddress', 'addressLocality', 'postalCode', 'addressCountry', 'latitude', 'longitude', 'images', 'owner', 'source'];
protected $coreFields = ['id', 'name', 'categories', 'streetAddress', 'addressLocality', 'postalCode', 'addressCountry', 'latitude', 'longitude', 'images', 'owner', 'source', 'openHours'];
protected $privateDataProps;
/**
......@@ -125,6 +126,7 @@ class ElementImportOneService
$this->createCategories($element, $row, $import);
$this->createImages($element, $row);
$this->createOpenHours($element, $row);
$this->saveCustomFields($element, $row);
if ($import->isDynamicImport()) { // keep the same status for the one who were deleted
......@@ -158,7 +160,6 @@ class ElementImportOneService
private function saveCustomFields($element, $raw_data)
{
$customFields = array_diff(array_keys($raw_data), $this->coreFields);
$customFields = array_diff($customFields, ['lat', 'long', 'lon', 'lng', 'title', 'nom', 'categories', 'address']);
$customData = [];
foreach ($customFields as $customField) {
if ($customField && is_string($customField)) $customData[$customField] = $raw_data[$customField];
......@@ -193,6 +194,20 @@ class ElementImportOneService
}
}
private function createOpenHours($element, $row)
{
if (!isset($row['openHours']) || !$this->isAssociativeArray($row['openHours'])) return;
$element->setOpenHours(new OpenHours($row['openHours']));
}
private function isAssociativeArray($a) {
if (!is_array($a)) return false;
foreach(array_keys($a) as $key)
if (!is_int($key)) return true;
return false;
}
function startsWith($haystack, $needle)
{
$length = strlen($needle);
......
{
"licence": "https://opendatacommons.org/licenses/odbl/summary/",
"source": "Cap ou pas Cap",
"graph":[{
"data":[{
"id":"Rhm",
"name":"Entropie",
"coord":{"latitude":45.18679,"longitude":5.70548},
......@@ -12,7 +12,14 @@
{ "name": "Numérique", "index": 1}
],
"website": "https:\/\/www.asso-entropie.fr\/",
"images": ["https:\/\/www.capoupascap.info\/wp-content\/uploads\/2018\/12\/entropie.png"]
"images": ["https:\/\/www.capoupascap.info\/wp-content\/uploads\/2018\/12\/entropie.png"],
"openHours": {
"Tu": "09:30-19:30",
"We": "09:30-19:30",
"Th": "09:30-13:00,15:00-19:30",
"Fr": "09:30-19:30",
"Sa": "09:30-19:30"
}
},
{
"id":"Ki",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment