Skip to content

Commit

Permalink
Added default image for recommendation without own image and redirect…
Browse files Browse the repository at this point in the history
… issue
  • Loading branch information
eki89 committed Apr 17, 2019
1 parent 1bc98dd commit 8135a91
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 87 deletions.
14 changes: 14 additions & 0 deletions src/Resources/contao/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
'tables' => array('tl_recommendation_archive', 'tl_recommendation')
)
));
array_insert($GLOBALS['BE_MOD']['system'], 3, array
(
'recommendation_settings' => array
(
'tables' => array('tl_recommendation_settings'),
'hideInNavigation' => true
)
));

// Front end modules
array_insert($GLOBALS['FE_MOD'], 2, array
Expand All @@ -28,3 +36,9 @@
// Add permissions
$GLOBALS['TL_PERMISSIONS'][] = 'recommendations';
$GLOBALS['TL_PERMISSIONS'][] = 'recommendationp';

// Style sheet
if (TL_MODE == 'BE')
{
$GLOBALS['TL_CSS'][] = 'bundles/contaorecommendation/style.css|static';
}
9 changes: 8 additions & 1 deletion src/Resources/contao/dca/tl_recommendation_archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
),
'global_operations' => array
(
'settings' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_recommendation_archive']['settings'],
'href' => 'do=recommendation_settings',
'icon' => 'edit.svg',
'attributes' => 'onclick="Backend.getScrollOffset()" accesskey="e"'
),
'all' => array
(
'label' => &$GLOBALS['TL_LANG']['MSC']['all'],
Expand Down Expand Up @@ -132,7 +139,7 @@
'exclude' => true,
'inputType' => 'pageTree',
'foreignKey' => 'tl_page.title',
'eval' => array('mandatory'=>true, 'fieldType'=>'radio', 'tl_class'=>'clr'),
'eval' => array('fieldType'=>'radio', 'tl_class'=>'clr'),
'sql' => "int(10) unsigned NOT NULL default '0'",
'relation' => array('type'=>'hasOne', 'load'=>'eager')
),
Expand Down
35 changes: 35 additions & 0 deletions src/Resources/contao/dca/tl_recommendation_settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of Oveleon Recommendation Bundle.
*
* (c) https://www.oveleon.de/
*/

$GLOBALS['TL_DCA']['tl_recommendation_settings'] = array
(

// Config
'config' => array
(
'dataContainer' => 'File',
'closed' => true
),

// Palettes
'palettes' => array
(
'default' => '{image_legend},recommendationDefaultImage;'
),

// Fields
'fields' => array
(
'recommendationDefaultImage' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_recommendation_settings']['recommendationDefaultImage'],
'inputType' => 'fileTree',
'eval' => array('fieldType'=>'radio', 'filesOnly'=>true, 'isGallery'=>true, 'extensions'=>Config::get('validImageTypes'), 'tl_class'=>'clr')
)
)
);
8 changes: 8 additions & 0 deletions src/Resources/contao/languages/de/modules.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
<source>Manage recommendations</source>
<target>Bewertungen verwalten</target>
</trans-unit>
<trans-unit id="MOD.recommendation_settings.0">
<source>Recommendation settings</source>
<target>Bewertungs-Einstellungen</target>
</trans-unit>
<trans-unit id="MOD.recommendation_settings.1">
<source>Configure recommendation settings</source>
<target>Bewertungs-Einstellungen vornehmen</target>
</trans-unit>
<trans-unit id="FMD.recommendation">
<source>Recommendations</source>
<target>Bewertungen</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@
<source>Access protection</source>
<target>Zugriffsschutz</target>
</trans-unit>
<trans-unit id="tl_recommendation_archive.settings.0">
<source>Settings</source>
<target>Einstellungen</target>
</trans-unit>
<trans-unit id="tl_recommendation_archive.settings.1">
<source>Recommendation settings</source>
<target>Bewertungen-Einstellungen</target>
</trans-unit>
<trans-unit id="tl_recommendation_archive.new.0">
<source>New archive</source>
<target>Neues Archiv</target>
Expand Down
18 changes: 18 additions & 0 deletions src/Resources/contao/languages/de/tl_recommendation_settings.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" ?><xliff version="1.1">
<file datatype="php" original="src/Resources/contao/languages/en/tl_recommendation_settings.php" source-language="en" target-language="de">
<body>
<trans-unit id="tl_recommendation_settings.recommendationDefaultImage.0">
<source>Default image</source>
<target>Standard-Bild</target>
</trans-unit>
<trans-unit id="tl_recommendation_settings.recommendationDefaultImage.1">
<source>The default image is displayed for recommendations that have not set their own image.</source>
<target>Das Standard-Bild wird bei Bewertungen angezeigt, die keinen eigenes Bild gesetzt haben.</target>
</trans-unit>#
<trans-unit id="tl_recommendation_settings.image_legend">
<source>Image settings</source>
<target>Bild-Einstellungen</target>
</trans-unit>
</body>
</file>
</xliff>
90 changes: 56 additions & 34 deletions src/Resources/contao/modules/ModuleRecommendation.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

namespace Oveleon\ContaoRecommendationBundle;

use Contao\FilesModel;
use Contao\Image\ResizeCoordinates;

/**
* Parent class for recommendation modules.
*
Expand Down Expand Up @@ -69,13 +66,14 @@ protected function sortOutProtected($arrArchives)
/**
* Parse an item and return it as string
*
* @param RecommendationModel $objRecommendation
* @param string $strClass
* @param integer $intCount
* @param RecommendationModel $objRecommendation
* @param RecommendationArchiveModel $objRecommendationArchive
* @param string $strClass
* @param integer $intCount
*
* @return string
*/
protected function parseRecommendation($objRecommendation, $strClass='', $intCount=0)
protected function parseRecommendation($objRecommendation, $objRecommendationArchive, $strClass='', $intCount=0)
{
/** @var \FrontendTemplate|object $objTemplate */
$objTemplate = new \FrontendTemplate($this->recommendation_template);
Expand All @@ -92,17 +90,20 @@ protected function parseRecommendation($objRecommendation, $strClass='', $intCou
}

$objTemplate->class = $strClass;
$objTemplate->archiveId = $objRecommendationArchive->id;

if ($objRecommendationArchive->jumpTo)
{
$objTemplate->allowRedirect = true;
$objTemplate->more = $this->generateLink($GLOBALS['TL_LANG']['MSC']['more'], $objRecommendation, $objRecommendation->title, true);
}

if ($objRecommendation->title)
{
$objTemplate->hasTitle = true;
$objTemplate->linkHeadline = $this->generateLink($objRecommendation->title, $objRecommendation, $objRecommendation->title);
$objTemplate->headlineLink = $objRecommendationArchive->jumpTo ? $this->generateLink($objRecommendation->title, $objRecommendation, $objRecommendation->title) : $objRecommendation->title;
$objTemplate->headline = $objRecommendation->title;
}

$objTemplate->more = $this->generateLink($GLOBALS['TL_LANG']['MSC']['more'], $objRecommendation, $strTitle, true);
$objTemplate->archiveId = $objRecommendation->pid;

$arrMeta = $this->getMetaFields($objRecommendation);

// Add the meta information
Expand Down Expand Up @@ -131,29 +132,15 @@ protected function parseRecommendation($objRecommendation, $strClass='', $intCou
{
$objModel = \FilesModel::findByPath($objRecommendation->imageUrl);

if ($objModel !== null && is_file(TL_ROOT . '/' . $objModel->path))
{
$objTemplate->addInternalImage = true;

// Do not override the field now that we have a model registry (see #6303)
$arrRecommendation = $objRecommendation->row();

// Override the default image size
if ($this->imgSize != '')
{
$size = \StringUtil::deserialize($this->imgSize);

if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2]))
{
$arrRecommendation['size'] = $this->imgSize;
}
}

$arrRecommendation['singleSRC'] = $objModel->path;
$this->addImageToTemplate($objTemplate, $arrRecommendation, null, null, $objModel);
}
$this->addInternalImage($objModel, $objRecommendation, $objTemplate);
}
}
elseif (\Config::get('recommendationDefaultImage'))
{
$objModel = \FilesModel::findByUuid(\Config::get('recommendationDefaultImage'));

$this->addInternalImage($objModel, $objRecommendation, $objTemplate);
}

// HOOK: add custom logic
if (isset($GLOBALS['TL_HOOKS']['parseRecommendation']) && \is_array($GLOBALS['TL_HOOKS']['parseRecommendation']))
Expand Down Expand Up @@ -192,7 +179,10 @@ protected function parseRecommendations($objRecommendations)
/** @var RecommendationModel $objRecommendation */
$objRecommendation = $objRecommendations->current();

$arrRecommendations[] = $this->parseRecommendation($objRecommendation, ((++$count == 1) ? ' first' : '') . (($count == $limit) ? ' last' : '') . ((($count % 2) == 0) ? ' odd' : ' even'), $count);
/** @var RecommendationArchiveModel $objRecommendationArchive */
$objRecommendationArchive = $objRecommendation->getRelated('pid');

$arrRecommendations[] = $this->parseRecommendation($objRecommendation, $objRecommendationArchive, ((++$count == 1) ? ' first' : '') . (($count == $limit) ? ' last' : '') . ((($count % 2) == 0) ? ' odd' : ' even'), $count);
}

return $arrRecommendations;
Expand Down Expand Up @@ -289,4 +279,36 @@ protected function isExternal($strPath)

return false;
}

/**
* Add an internal image to template
*
* @param \FilesModel $objModel The files model
* @param RecommendationModel $objRecommendation The recommendation model
* @param \FrontendTemplate $objTemplate The frontend template
*/
protected function addInternalImage($objModel, $objRecommendation, &$objTemplate)
{
if ($objModel !== null && is_file(TL_ROOT . '/' . $objModel->path))
{
$objTemplate->addInternalImage = true;

// Do not override the field now that we have a model registry (see #6303)
$arrRecommendation = $objRecommendation->row();

// Override the default image size
if ($this->imgSize != '')
{
$size = \StringUtil::deserialize($this->imgSize);

if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2]))
{
$arrRecommendation['size'] = $this->imgSize;
}
}

$arrRecommendation['singleSRC'] = $objModel->path;
$this->addImageToTemplate($objTemplate, $arrRecommendation, null, null, $objModel);
}
}
}
5 changes: 4 additions & 1 deletion src/Resources/contao/modules/ModuleRecommendationReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ protected function compile()
throw new PageNotFoundException('Page not found: ' . \Environment::get('uri'));
}

$arrRecommendation = $this->parseRecommendation($objRecommendation);
/** @var RecommendationArchiveModel $objRecommendationArchive */
$objRecommendationArchive = $objRecommendation->getRelated('pid');

$arrRecommendation = $this->parseRecommendation($objRecommendation, $objRecommendationArchive);
$this->Template->recommendation = $arrRecommendation;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<div class="layout_full block<?= $this->class ?>">

<?php if ($this->hasTitle): ?>
<?php if ($this->headline): ?>
<h1 itemprop="name"><?= $this->headline ?></h1>
<?php endif; ?>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<?php endif; ?>

<div class="layout_container">
<?php if ($this->hasTitle): ?>
<h4 itemprop="name"><?= $this->linkHeadline ?></h4>
<?php if ($this->headlineLink): ?>
<h4 itemprop="name"><?= $this->headlineLink ?></h4>
<?php endif; ?>

<?php if ($this->addAuthor || $this->addDate || $this->addRating): ?>
Expand All @@ -35,14 +35,16 @@
<?php endif; ?>

<div class="text" itemprop="description">
<?php if ($this->teaser): ?>
<?php if ($this->teaser && $this->allowRedirect): ?>
<?= $this->teaser ?>
<?php else: ?>
<?= $this->text ?>
<?php endif; ?>
</div>

<p class="more"><?= $this->more ?></p>
<?php if ($this->allowRedirect): ?>
<p class="more"><?= $this->more ?></p>
<?php endif; ?>
</div>

</div>

This file was deleted.

3 changes: 3 additions & 0 deletions src/Resources/public/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.navigation.recommendation_settings {
display: none !important;
}

0 comments on commit 8135a91

Please sign in to comment.