Skip to content

Commit 869f651

Browse files
author
Neil Crookes
committed
Adding updates from events package
1 parent a0f5582 commit 869f651

1 file changed

Lines changed: 74 additions & 15 deletions

File tree

src/models/Place.php

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ class Place extends \Eloquent {
1414
*/
1515
protected $table = 'fbf_places';
1616

17+
/**
18+
* The prefix string for config options.
19+
*
20+
* Defaults to the package's config prefix string
21+
*
22+
* @var string
23+
*/
24+
protected $configPrefix = 'laravel-places::';
25+
1726
/**
1827
* Used for Cviebrock/EloquentSluggable
1928
* @var array
@@ -93,7 +102,7 @@ public function getImageSrc($type, $size)
93102
{
94103
return null;
95104
}
96-
return self::getImageConfig($type, $size, 'dir') . $this->$type;
105+
return $this->getImageConfig($type, $size, 'dir') . $this->$type;
97106
}
98107

99108
/**
@@ -109,15 +118,15 @@ public function getImageWidth($type, $size)
109118
{
110119
return null;
111120
}
112-
$method = self::getImageConfig($type, $size, 'method');
121+
$method = $this->getImageConfig($type, $size, 'method');
113122

114123
// Width varies for images that are 'portrait', 'auto', 'fit', 'crop'
115124
if (in_array($method, array('portrait', 'auto', 'fit', 'crop')))
116125
{
117126
list($width) = $this->getImageDimensions($type, $size);
118127
return $width;
119128
}
120-
return self::getImageConfig($type, $size, 'width');
129+
return $this->getImageConfig($type, $size, 'width');
121130
}
122131

123132
/**
@@ -133,15 +142,15 @@ public function getImageHeight($type, $size)
133142
{
134143
return null;
135144
}
136-
$method = self::getImageConfig($type, $size, 'method');
145+
$method = $this->getImageConfig($type, $size, 'method');
137146

138147
// Height varies for images that are 'landscape', 'auto', 'fit', 'crop'
139148
if (in_array($method, array('landscape', 'auto', 'fit', 'crop')))
140149
{
141150
list($width, $height) = $this->getImageDimensions($type, $size);
142151
return $height;
143152
}
144-
return self::getImageConfig($type, $size, 'height');
153+
return $this->getImageConfig($type, $size, 'height');
145154
}
146155

147156
/**
@@ -153,7 +162,7 @@ public function getImageHeight($type, $size)
153162
*/
154163
protected function getImageDimensions($type, $size)
155164
{
156-
$pathToImage = public_path(self::getImageConfig($type, $size, 'dir') . $this->$type);
165+
$pathToImage = public_path($this->getImageConfig($type, $size, 'dir') . $this->$type);
157166
if (is_file($pathToImage) && file_exists($pathToImage))
158167
{
159168
list($width, $height) = getimagesize($pathToImage);
@@ -174,9 +183,9 @@ protected function getImageDimensions($type, $size)
174183
* @internal param $type
175184
* @return mixed
176185
*/
177-
public static function getImageConfig($imageType, $size, $property)
186+
public function getImageConfig($imageType, $size, $property)
178187
{
179-
$config = 'laravel-places::images.' . $imageType . '.';
188+
$config = $this->getConfigPrefix().'images.' . $imageType . '.';
180189
if ($size == 'original')
181190
{
182191
$config .= 'original.';
@@ -189,28 +198,48 @@ public static function getImageConfig($imageType, $size, $property)
189198
return \Config::get($config);
190199
}
191200

201+
/**
202+
* Helper function to determine whether the item has a YouTube video
203+
*
204+
* @return bool
205+
*/
206+
public function hasYouTubeVideo()
207+
{
208+
return !empty($this->you_tube_video_id);
209+
}
210+
211+
/**
212+
* Returns the thumbnail image code defined in the config, for the current item's you tube video id
213+
*
214+
* @return string
215+
*/
192216
public function getYouTubeThumbnailImage()
193217
{
194-
return str_replace('%YOU_TUBE_VIDEO_ID%', $this->you_tube_video_id, \Config::get('laravel-places::you_tube.thumbnail_code'));
218+
return str_replace('%YOU_TUBE_VIDEO_ID%', $this->you_tube_video_id, \Config::get($this->getConfigPrefix().'you_tube.thumbnail_code'));
195219
}
196220

221+
/**
222+
* Returns the embed code defined in the config, for the current item's you tube video id
223+
*
224+
* @return string
225+
*/
197226
public function getYouTubeEmbedCode()
198227
{
199-
return str_replace('%YOU_TUBE_VIDEO_ID%', $this->you_tube_video_id, \Config::get('laravel-places::you_tube.embed_code'));
228+
return str_replace('%YOU_TUBE_VIDEO_ID%', $this->you_tube_video_id, \Config::get($this->getConfigPrefix().'you_tube.embed_code'));
200229
}
201230

202231
public function getMapZoom()
203232
{
204-
if (\Config::get('laravel-places::map.variable_map_zoom'))
233+
if (\Config::get($this->getConfigPrefix().'map.variable_map_zoom'))
205234
{
206235
return $this->map_zoom;
207236
}
208-
return \Config::get('laravel-places::map.default_map_zoom');
237+
return \Config::get($this->getConfigPrefix().'map.default_map_zoom');
209238
}
210239

211240
public function getMapLatitude()
212241
{
213-
if (\Config::get('laravel-places::map.map_centre_different_to_marker'))
242+
if (\Config::get($this->getConfigPrefix().'map.map_centre_different_to_marker'))
214243
{
215244
return $this->map_latitude;
216245
}
@@ -219,7 +248,7 @@ public function getMapLatitude()
219248

220249
public function getMapLongitude()
221250
{
222-
if (\Config::get('laravel-places::map.map_centre_different_to_marker'))
251+
if (\Config::get($this->getConfigPrefix().'map.map_centre_different_to_marker'))
223252
{
224253
return $this->map_longitude;
225254
}
@@ -241,13 +270,43 @@ public function hasMap()
241270
return $this->marker_latitude != 0 && $this->marker_longitude != 0;
242271
}
243272

273+
/**
274+
* Help function to determine whether the item has a link
275+
* @return bool
276+
*/
277+
public function hasLink()
278+
{
279+
return !empty($this->link_text) && !empty($this->link_url);
280+
}
281+
244282
/**
245283
* Returns the published date formatted according to the config setting
246284
* @return string
247285
*/
248286
public function getDate()
249287
{
250-
return date(\Config::get('laravel-places::views.published_date_format'), strtotime($this->published_date));
288+
return date(\Config::get($this->getConfigPrefix().'views.published_date_format'), strtotime($this->published_date));
289+
}
290+
291+
/**
292+
* Returns the config prefix
293+
*
294+
* @return string
295+
*/
296+
public function getConfigPrefix()
297+
{
298+
return $this->configPrefix;
299+
}
300+
301+
/**
302+
* Sets the config prefix string
303+
*
304+
* @param $configBase string
305+
* @return string
306+
*/
307+
public function setConfigPrefix($configBase)
308+
{
309+
return $this->configPrefix = $configBase;
251310
}
252311

253312
}

0 commit comments

Comments
 (0)