Skip to content

Commit

Permalink
Adding updates from events package
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Crookes committed Mar 7, 2014
1 parent a0f5582 commit 869f651
Showing 1 changed file with 74 additions and 15 deletions.
89 changes: 74 additions & 15 deletions src/models/Place.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ class Place extends \Eloquent {
*/
protected $table = 'fbf_places';

/**
* The prefix string for config options.
*
* Defaults to the package's config prefix string
*
* @var string
*/
protected $configPrefix = 'laravel-places::';

/**
* Used for Cviebrock/EloquentSluggable
* @var array
Expand Down Expand Up @@ -93,7 +102,7 @@ public function getImageSrc($type, $size)
{
return null;
}
return self::getImageConfig($type, $size, 'dir') . $this->$type;
return $this->getImageConfig($type, $size, 'dir') . $this->$type;
}

/**
Expand All @@ -109,15 +118,15 @@ public function getImageWidth($type, $size)
{
return null;
}
$method = self::getImageConfig($type, $size, 'method');
$method = $this->getImageConfig($type, $size, 'method');

// Width varies for images that are 'portrait', 'auto', 'fit', 'crop'
if (in_array($method, array('portrait', 'auto', 'fit', 'crop')))
{
list($width) = $this->getImageDimensions($type, $size);
return $width;
}
return self::getImageConfig($type, $size, 'width');
return $this->getImageConfig($type, $size, 'width');
}

/**
Expand All @@ -133,15 +142,15 @@ public function getImageHeight($type, $size)
{
return null;
}
$method = self::getImageConfig($type, $size, 'method');
$method = $this->getImageConfig($type, $size, 'method');

// Height varies for images that are 'landscape', 'auto', 'fit', 'crop'
if (in_array($method, array('landscape', 'auto', 'fit', 'crop')))
{
list($width, $height) = $this->getImageDimensions($type, $size);
return $height;
}
return self::getImageConfig($type, $size, 'height');
return $this->getImageConfig($type, $size, 'height');
}

/**
Expand All @@ -153,7 +162,7 @@ public function getImageHeight($type, $size)
*/
protected function getImageDimensions($type, $size)
{
$pathToImage = public_path(self::getImageConfig($type, $size, 'dir') . $this->$type);
$pathToImage = public_path($this->getImageConfig($type, $size, 'dir') . $this->$type);
if (is_file($pathToImage) && file_exists($pathToImage))
{
list($width, $height) = getimagesize($pathToImage);
Expand All @@ -174,9 +183,9 @@ protected function getImageDimensions($type, $size)
* @internal param $type
* @return mixed
*/
public static function getImageConfig($imageType, $size, $property)
public function getImageConfig($imageType, $size, $property)
{
$config = 'laravel-places::images.' . $imageType . '.';
$config = $this->getConfigPrefix().'images.' . $imageType . '.';
if ($size == 'original')
{
$config .= 'original.';
Expand All @@ -189,28 +198,48 @@ public static function getImageConfig($imageType, $size, $property)
return \Config::get($config);
}

/**
* Helper function to determine whether the item has a YouTube video
*
* @return bool
*/
public function hasYouTubeVideo()
{
return !empty($this->you_tube_video_id);
}

/**
* Returns the thumbnail image code defined in the config, for the current item's you tube video id
*
* @return string
*/
public function getYouTubeThumbnailImage()
{
return str_replace('%YOU_TUBE_VIDEO_ID%', $this->you_tube_video_id, \Config::get('laravel-places::you_tube.thumbnail_code'));
return str_replace('%YOU_TUBE_VIDEO_ID%', $this->you_tube_video_id, \Config::get($this->getConfigPrefix().'you_tube.thumbnail_code'));
}

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

public function getMapZoom()
{
if (\Config::get('laravel-places::map.variable_map_zoom'))
if (\Config::get($this->getConfigPrefix().'map.variable_map_zoom'))
{
return $this->map_zoom;
}
return \Config::get('laravel-places::map.default_map_zoom');
return \Config::get($this->getConfigPrefix().'map.default_map_zoom');
}

public function getMapLatitude()
{
if (\Config::get('laravel-places::map.map_centre_different_to_marker'))
if (\Config::get($this->getConfigPrefix().'map.map_centre_different_to_marker'))
{
return $this->map_latitude;
}
Expand All @@ -219,7 +248,7 @@ public function getMapLatitude()

public function getMapLongitude()
{
if (\Config::get('laravel-places::map.map_centre_different_to_marker'))
if (\Config::get($this->getConfigPrefix().'map.map_centre_different_to_marker'))
{
return $this->map_longitude;
}
Expand All @@ -241,13 +270,43 @@ public function hasMap()
return $this->marker_latitude != 0 && $this->marker_longitude != 0;
}

/**
* Help function to determine whether the item has a link
* @return bool
*/
public function hasLink()
{
return !empty($this->link_text) && !empty($this->link_url);
}

/**
* Returns the published date formatted according to the config setting
* @return string
*/
public function getDate()
{
return date(\Config::get('laravel-places::views.published_date_format'), strtotime($this->published_date));
return date(\Config::get($this->getConfigPrefix().'views.published_date_format'), strtotime($this->published_date));
}

/**
* Returns the config prefix
*
* @return string
*/
public function getConfigPrefix()
{
return $this->configPrefix;
}

/**
* Sets the config prefix string
*
* @param $configBase string
* @return string
*/
public function setConfigPrefix($configBase)
{
return $this->configPrefix = $configBase;
}

}

0 comments on commit 869f651

Please sign in to comment.