Skip to content

Commit

Permalink
Merge pull request #22 from helpfulrobot/convert-to-psr-2
Browse files Browse the repository at this point in the history
Converted to PSR-2
  • Loading branch information
colymba committed Dec 21, 2015
2 parents c9e7eb2 + f2e5c54 commit 32bbe9f
Showing 1 changed file with 65 additions and 65 deletions.
130 changes: 65 additions & 65 deletions code/GridFieldGalleryTheme.php
Expand Up @@ -8,7 +8,7 @@
*/
class GridFieldGalleryTheme implements GridField_HTMLProvider, GridField_ColumnProvider
{
/** @var string */
/** @var string */
protected $thumbnailField;

/** @var array */
Expand All @@ -30,106 +30,106 @@ class GridFieldGalleryTheme implements GridField_HTMLProvider, GridField_ColumnP
/**
* @param String $thumbnailField has_one relation on DO to use for thumbnail preview
*/
public function __construct($thumbnailField) {
$this->thumbnailField = $thumbnailField;
public function __construct($thumbnailField)
{
$this->thumbnailField = $thumbnailField;
}

/* *********************************************************************** */
// GridField_HTMLProvider

public function getHTMLFragments($gridField)
{
Requirements::css(GRIDFIELD_GALLERY_THEME_PATH . '/css/GridFieldGalleryTheme.css');
Requirements::javascript(GRIDFIELD_GALLERY_THEME_PATH . '/js/GridFieldGalleryTheme.js');
{
Requirements::css(GRIDFIELD_GALLERY_THEME_PATH . '/css/GridFieldGalleryTheme.css');
Requirements::javascript(GRIDFIELD_GALLERY_THEME_PATH . '/js/GridFieldGalleryTheme.js');
}

/* *********************************************************************** */
// GridField_ColumnProvider
function augmentColumns($gridField, &$columns)

public function augmentColumns($gridField, &$columns)
{
if(!in_array('GalleryThumbnail', $columns))
$columns[] = 'GalleryThumbnail';
if (!in_array('GalleryThumbnail', $columns)) {
$columns[] = 'GalleryThumbnail';
}
}

function getColumnsHandled($gridField)
public function getColumnsHandled($gridField)
{
return array('GalleryThumbnail');
return array('GalleryThumbnail');
}

function getColumnContent($gridField, $record, $columnName)
public function getColumnContent($gridField, $record, $columnName)
{
$previewObj = $record->{$this->thumbnailField}();
$imgFile = GRIDFIELD_GALLERY_THEME_PATH . '/img/icons/missing.png';
$previewObj = $record->{$this->thumbnailField}();
$imgFile = GRIDFIELD_GALLERY_THEME_PATH . '/img/icons/missing.png';

if ( $previewObj->ID )
{
if ( $previewObj instanceof Image )
{
$croppedImage = $previewObj->CroppedImage( 150, 150 );
if ($croppedImage)
{
$url = $croppedImage->URL;
if ($url) $imgFile = $url;
}
}
else if ( $previewObj instanceof File )
{
if ( is_dir( BASE_PATH.'/'.$previewObj->Filename ) ) $imgFile = GRIDFIELD_GALLERY_THEME_PATH . '/img/icons/folder.png';
else $imgFile = $this->getFileTypeIcon( $previewObj );
if ($previewObj->ID) {
if ($previewObj instanceof Image) {
$croppedImage = $previewObj->CroppedImage(150, 150);
if ($croppedImage) {
$url = $croppedImage->URL;
if ($url) {
$imgFile = $url;
}
}
} elseif ($previewObj instanceof File) {
if (is_dir(BASE_PATH.'/'.$previewObj->Filename)) {
$imgFile = GRIDFIELD_GALLERY_THEME_PATH . '/img/icons/folder.png';
} else {
$imgFile = $this->getFileTypeIcon($previewObj);
}
}
}
}

return '<img src="'.$imgFile.'" />';
return '<img src="'.$imgFile.'" />';
}

/**
* Return the icon to display for the fileobject
* @param File $file
* @return string icon path
*/
function getFileTypeIcon ( $file )
public function getFileTypeIcon($file)
{
$imgFile = GRIDFIELD_GALLERY_THEME_PATH . '/img/icons/file.png';
$ext = strtolower( pathinfo($file->Filename, PATHINFO_EXTENSION) );
$imgFile = GRIDFIELD_GALLERY_THEME_PATH . '/img/icons/file.png';
$ext = strtolower(pathinfo($file->Filename, PATHINFO_EXTENSION));

if ($ext)
{
$tempFile = GRIDFIELD_GALLERY_THEME_PATH . '/img/icons/'.$ext.'.png';
if ( !file_exists(BASE_PATH.'/'.$tempFile) )
{
foreach ( $this->fileTypeMapping as $icon => $extensions)
{
if ( in_array($ext, $extensions) )
{
$imgFile = GRIDFIELD_GALLERY_THEME_PATH . '/img/icons/'.$icon;
break;
if ($ext) {
$tempFile = GRIDFIELD_GALLERY_THEME_PATH . '/img/icons/'.$ext.'.png';
if (!file_exists(BASE_PATH.'/'.$tempFile)) {
foreach ($this->fileTypeMapping as $icon => $extensions) {
if (in_array($ext, $extensions)) {
$imgFile = GRIDFIELD_GALLERY_THEME_PATH . '/img/icons/'.$icon;
break;
}
}
} else {
$imgFile = $tempFile;
}
}
}else{
$imgFile = $tempFile;
}
}

return $imgFile;
return $imgFile;
}

function getColumnAttributes($gridField, $record, $columnName)
public function getColumnAttributes($gridField, $record, $columnName)
{
$class = 'galleryThumbnail';
$previewObj = $record->{$this->thumbnailField}();
if ( $previewObj )
{
if ( $previewObj instanceof Image ) $class .= ' image';
else if ( $previewObj instanceof File ) $class .= ' icon';
}
return array('class' => $class);
$class = 'galleryThumbnail';
$previewObj = $record->{$this->thumbnailField}();
if ($previewObj) {
if ($previewObj instanceof Image) {
$class .= ' image';
} elseif ($previewObj instanceof File) {
$class .= ' icon';
}
}
return array('class' => $class);
}

function getColumnMetadata($gridField, $columnName)
public function getColumnMetadata($gridField, $columnName)
{
if($columnName == 'GalleryThumbnail') {
return array('title' => 'Thumbnail');
}
if ($columnName == 'GalleryThumbnail') {
return array('title' => 'Thumbnail');
}
}
}

0 comments on commit 32bbe9f

Please sign in to comment.