diff --git a/CHANGELOG.md b/CHANGELOG.md index 646bbba..6d9169b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 1.0.4 + +- Microdata added to template (@cdigruttola) +- Phone and price level added to place (@cdigruttola) +- Author URL added to review (@cdigruttola) + ## 1.0.3 - Custom widget template diff --git a/README.md b/README.md index a0236b2..25909fd 100644 --- a/README.md +++ b/README.md @@ -55,12 +55,13 @@ It is only possible to retrieve the last 5 reviews. Import often to accumulate t In any template, add the following Widget: ```smarty -{widget name='pixel_googlemybusiness' display='name,rating,opening-hours,reviews'} +{widget name='pixel_googlemybusiness' display='name,phone,rating,opening-hours,reviews'} ``` **Display excepted options:** * name: Place name (Eiffel tower) +* phone: International phone number (+33 1 22 33 44 55) * rating: Average Rating (4/5) * opening-hours: Opening hours (Monday: 12:00 – 19:00, Tuesday: 10:00 – 19:00...) * review: the last reviews diff --git a/pixel_googlemybusiness.php b/pixel_googlemybusiness.php index ca19c64..03405bf 100644 --- a/pixel_googlemybusiness.php +++ b/pixel_googlemybusiness.php @@ -22,7 +22,7 @@ class Pixel_googlemybusiness extends Module implements WidgetInterface public function __construct() { $this->name = 'pixel_googlemybusiness'; - $this->version = '1.0.3'; + $this->version = '1.0.4'; $this->author = 'Pixel Open'; $this->tab = 'front_office_features'; $this->need_instance = 0; @@ -102,7 +102,7 @@ public function getWidgetVariables($hookName, array $configuration): array explode(',', $configuration['place_ids'] ?? '') ); $display = array_filter( - explode(',', $configuration['display'] ?? 'name,rating,opening-hours,reviews') + explode(',', $configuration['display'] ?? 'name,phone,rating,opening-hours,reviews') ); $reviewNumber = $configuration['review_number'] ?? 5; $reviewMinRating = $configuration['review_min_rating'] ?? 0; @@ -282,10 +282,12 @@ protected function createTables(): bool `place_id` VARCHAR(255) NOT NULL, `language` VARCHAR(2) NULL, `name` VARCHAR(255) NOT NULL, + `phone` VARCHAR(255) DEFAULT NULL, `opening_hours_periods` TEXT DEFAULT NULL, `opening_hours_weekday_text` TEXT DEFAULT NULL, `rating` NUMERIC(4, 2) DEFAULT NULL, `user_ratings_total` INT DEFAULT NULL, + `price_level` INT DEFAULT NULL, PRIMARY KEY(`id`), UNIQUE KEY(`place_id`, `language`) ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=UTF8; @@ -294,6 +296,7 @@ protected function createTables(): bool `id` INT(11) AUTO_INCREMENT NOT NULL, `place_id` VARCHAR(255) NOT NULL, `author_name` VARCHAR(255) DEFAULT NULL, + `author_url` VARCHAR(255) DEFAULT NULL, `language` VARCHAR(2) NULL, `original_language` VARCHAR(2) DEFAULT NULL, `profile_photo_url` VARCHAR(255) DEFAULT NULL, diff --git a/pixel_googlemybusiness.tpl b/pixel_googlemybusiness.tpl index daaea23..18dfc35 100644 --- a/pixel_googlemybusiness.tpl +++ b/pixel_googlemybusiness.tpl @@ -1,12 +1,17 @@
{foreach from=$places item=place} -
+
{if 'name'|in_array:$display} -
{$place->getName()}
+
{$place->getName()}
+ {/if} + {if 'phone'|in_array:$display and $place->getPhone()} + {/if} {if 'rating'|in_array:$display} -
+
{if $place->getUserRatingsTotal()} + + {l s='Note:' d='Modules.Pixelgooglemybusiness.Shop'} {$place->getRating()}/5 ({$place->getUserRatingsTotal()} {l s='reviews' d='Modules.Pixelgooglemybusiness.Shop'}) {else} @@ -18,19 +23,26 @@ {if 'opening-hours'|in_array:$display}
    {foreach from=$place->getOpeningHoursWeekdayText()|json_decode:1 item=hour} -
  • {$hour}
  • +
  • {$hour}
  • {/foreach}
{/if} {if 'reviews'|in_array:$display}
{foreach from=$place->getReviews() item=review} -
- {$review->getAuthorName()} - {$review->getTime()|date_format:"%e %B %Y"} - {$review->getRating()}/5 +
+ + + + + + {$review->getRating()}/5 + + + + {if $review->getComment()} -
+
{$review->getComment()}
{/if} diff --git a/src/Command/ImportPlace.php b/src/Command/ImportPlace.php index d1ad2f2..ee395dc 100644 --- a/src/Command/ImportPlace.php +++ b/src/Command/ImportPlace.php @@ -49,7 +49,7 @@ protected function execute(InputInterface $input, OutputInterface $output) foreach ($placeIds as $placeId) { $params = [ - 'fields' => 'name,rating,opening_hours,user_ratings_total,reviews', + 'fields' => 'name,international_phone_number,rating,opening_hours,user_ratings_total,reviews,price_level', 'reviews_sort' => 'newest', 'key' => Configuration::get('GOOGLE_MY_BUSINESS_API_KEY'), 'placeid' => $placeId, @@ -81,10 +81,12 @@ protected function execute(InputInterface $input, OutputInterface $output) ->setPlaceId($placeId) ->setLanguage($language) ->setName($result['name']) + ->setPhone($result['international_phone_number'] ?? null) ->setOpeningHoursPeriods(json_encode($result['opening_hours']['periods'] ?? [])) ->setOpeningHoursWeekdayText(json_encode($result['opening_hours']['weekday_text'] ?? [])) ->setRating((float)($result['rating'] ?? 5)) - ->setUserRatingsTotal((int)($result['user_ratings_total'] ?? 0)); + ->setUserRatingsTotal((int)($result['user_ratings_total'] ?? 0)) + ->setPriceLevel((int)($result['price_level'] ?? 0)); $entityManager->persist($googlePlace); $entityManager->flush(); @@ -107,6 +109,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $googleReview ->setPlaceId($placeId) ->setAuthorName($review['author_name']) + ->setAuthorUrl($review['author_url'] ?? '') ->setLanguage($review['language'] ?? null) ->setOriginalLanguage($review['original_language'] ?? null) ->setProfilePhotoUrl($review['profile_photo_url']) diff --git a/src/Entity/GooglePlace.php b/src/Entity/GooglePlace.php index e1f3a31..0dbc216 100644 --- a/src/Entity/GooglePlace.php +++ b/src/Entity/GooglePlace.php @@ -42,6 +42,13 @@ class GooglePlace */ private $name; + /** + * @var string + * + * @ORM\Column(name="phone", type="text", nullable=true) + */ + private $phone; + /** * @var string * @@ -70,6 +77,13 @@ class GooglePlace */ private $userRatingsTotal; + /** + * @var int + * + * @ORM\Column(name="price_level", type="integer", nullable=true) + */ + private $priceLevel; + /** * @var GoogleReview[] */ @@ -155,6 +169,26 @@ public function setName(string $name): GooglePlace return $this; } + /** + * @return string + */ + public function getPhone(): ?string + { + return $this->phone; + } + + /** + * @param string $phone + * + * @return GooglePlace + */ + public function setPhone(?string $phone): GooglePlace + { + $this->phone = $phone; + + return $this; + } + /** * @return string|null */ @@ -235,6 +269,26 @@ public function setUserRatingsTotal(?int $userRatingsTotal): GooglePlace return $this; } + /** + * @return int|null + */ + public function getPriceLevel(): ?int + { + return $this->priceLevel; + } + + /** + * @param int|null $priceLevel + * + * @return GooglePlace + */ + public function setPriceLevel(?int $priceLevel): GooglePlace + { + $this->priceLevel = $priceLevel; + + return $this; + } + /** * @return GoogleReview[] */ @@ -263,11 +317,15 @@ public function toArray(): array return [ 'id' => $this->getId(), 'place_id' => $this->getPlaceId(), + 'name' => $this->getName(), + 'phone' => $this->getPhone(), 'opening_hours_periods' => $this->getOpeningHoursPeriods(), 'opening_hours_weekday_text' => $this->getOpeningHoursWeekdayText(), 'rating' => $this->getRating(), 'user_ratings_total' => $this->getUserRatingsTotal(), 'reviews' => $this->getReviews(), + 'price_level' => $this->getPriceLevel(), + 'language' => $this->getLanguage(), ]; } } diff --git a/src/Entity/GoogleReview.php b/src/Entity/GoogleReview.php index d008434..c99b9d9 100644 --- a/src/Entity/GoogleReview.php +++ b/src/Entity/GoogleReview.php @@ -33,6 +33,12 @@ class GoogleReview * @ORM\Column(name="author_name", type="string", length=255, nullable=true) */ private $authorName; + /** + * @var string + * + * @ORM\Column(name="author_url", type="string", length=255, nullable=true) + */ + private $authorUrl; /** * @var string @@ -157,6 +163,26 @@ public function setAuthorName(?string $authorName): GoogleReview return $this; } + /** + * @return string|null + */ + public function getAuthorUrl(): ?string + { + return $this->authorUrl; + } + + /** + * @param string|null $authorUrl + * + * @return GoogleReview + */ + public function setAuthorUrl(?string $authorUrl): GoogleReview + { + $this->authorUrl = $authorUrl; + + return $this; + } + /** * @return string|null */ @@ -346,6 +372,7 @@ public function toArray(): array 'id' => $this->getId(), 'place_id' => $this->getPlaceId(), 'author_name' => $this->getAuthorName(), + 'author_url' => $this->getAuthorUrl(), 'language' => $this->getLanguage(), 'original_language' => $this->getOriginalLanguage(), 'profile_photo_url' => $this->getProfilePhotoUrl(), diff --git a/upgrade/upgrade-1.0.4.php b/upgrade/upgrade-1.0.4.php new file mode 100644 index 0000000..e6c6528 --- /dev/null +++ b/upgrade/upgrade-1.0.4.php @@ -0,0 +1,19 @@ +execute(' + ALTER TABLE `' . _DB_PREFIX_ . 'google_place` + ADD COLUMN `phone` VARCHAR(255) DEFAULT NULL; + + ALTER TABLE `' . _DB_PREFIX_ . 'google_place` + ADD COLUMN `price_level` INT DEFAULT NULL; + + ALTER TABLE `' . _DB_PREFIX_ . 'google_review` + ADD COLUMN `author_url` VARCHAR(255) DEFAULT NULL; + '); +} diff --git a/views/css/gmb.css b/views/css/gmb.css index 3284e97..b55f122 100644 --- a/views/css/gmb.css +++ b/views/css/gmb.css @@ -8,6 +8,10 @@ font-size: 1.1rem; } +.google-places .place .phone { + margin-bottom: 1rem; +} + .google-places .place .rating { margin-bottom: 1rem; }