diff --git a/src/Resources/contao/config/config.php b/src/Resources/contao/config/config.php index abcafdd..fd17a73 100644 --- a/src/Resources/contao/config/config.php +++ b/src/Resources/contao/config/config.php @@ -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 @@ -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'; +} diff --git a/src/Resources/contao/dca/tl_recommendation_archive.php b/src/Resources/contao/dca/tl_recommendation_archive.php index 43fec32..fac9f9f 100644 --- a/src/Resources/contao/dca/tl_recommendation_archive.php +++ b/src/Resources/contao/dca/tl_recommendation_archive.php @@ -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'], @@ -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') ), diff --git a/src/Resources/contao/dca/tl_recommendation_settings.php b/src/Resources/contao/dca/tl_recommendation_settings.php new file mode 100644 index 0000000..f025b52 --- /dev/null +++ b/src/Resources/contao/dca/tl_recommendation_settings.php @@ -0,0 +1,35 @@ + 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') + ) + ) +); diff --git a/src/Resources/contao/languages/de/modules.xlf b/src/Resources/contao/languages/de/modules.xlf index fa884ba..5a82bbe 100644 --- a/src/Resources/contao/languages/de/modules.xlf +++ b/src/Resources/contao/languages/de/modules.xlf @@ -9,6 +9,14 @@ Manage recommendations Bewertungen verwalten + + Recommendation settings + Bewertungs-Einstellungen + + + Configure recommendation settings + Bewertungs-Einstellungen vornehmen + Recommendations Bewertungen diff --git a/src/Resources/contao/languages/de/tl_recommendation_archive.xlf b/src/Resources/contao/languages/de/tl_recommendation_archive.xlf index e09be72..6647544 100644 --- a/src/Resources/contao/languages/de/tl_recommendation_archive.xlf +++ b/src/Resources/contao/languages/de/tl_recommendation_archive.xlf @@ -49,6 +49,14 @@ Access protection Zugriffsschutz + + Settings + Einstellungen + + + Recommendation settings + Bewertungen-Einstellungen + New archive Neues Archiv diff --git a/src/Resources/contao/languages/de/tl_recommendation_settings.xlf b/src/Resources/contao/languages/de/tl_recommendation_settings.xlf new file mode 100644 index 0000000..494032e --- /dev/null +++ b/src/Resources/contao/languages/de/tl_recommendation_settings.xlf @@ -0,0 +1,18 @@ + + + + + Default image + Standard-Bild + + + The default image is displayed for recommendations that have not set their own image. + Das Standard-Bild wird bei Bewertungen angezeigt, die keinen eigenes Bild gesetzt haben. + # + + Image settings + Bild-Einstellungen + + + + diff --git a/src/Resources/contao/modules/ModuleRecommendation.php b/src/Resources/contao/modules/ModuleRecommendation.php index 750a3aa..c35060b 100644 --- a/src/Resources/contao/modules/ModuleRecommendation.php +++ b/src/Resources/contao/modules/ModuleRecommendation.php @@ -8,9 +8,6 @@ namespace Oveleon\ContaoRecommendationBundle; -use Contao\FilesModel; -use Contao\Image\ResizeCoordinates; - /** * Parent class for recommendation modules. * @@ -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); @@ -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 @@ -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'])) @@ -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; @@ -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); + } + } } diff --git a/src/Resources/contao/modules/ModuleRecommendationReader.php b/src/Resources/contao/modules/ModuleRecommendationReader.php index 9417481..9c49684 100644 --- a/src/Resources/contao/modules/ModuleRecommendationReader.php +++ b/src/Resources/contao/modules/ModuleRecommendationReader.php @@ -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; } } diff --git a/src/Resources/contao/templates/recommendation/recommendation_full.html5 b/src/Resources/contao/templates/recommendation/recommendation_full.html5 index 330ce68..11b4492 100644 --- a/src/Resources/contao/templates/recommendation/recommendation_full.html5 +++ b/src/Resources/contao/templates/recommendation/recommendation_full.html5 @@ -1,7 +1,7 @@
- hasTitle): ?> + headline): ?>

headline ?>

diff --git a/src/Resources/contao/templates/recommendation/recommendation_latest.html5 b/src/Resources/contao/templates/recommendation/recommendation_latest.html5 index 9c8be38..87e5fda 100644 --- a/src/Resources/contao/templates/recommendation/recommendation_latest.html5 +++ b/src/Resources/contao/templates/recommendation/recommendation_latest.html5 @@ -10,8 +10,8 @@
- hasTitle): ?> -

linkHeadline ?>

+ headlineLink): ?> +

headlineLink ?>

addAuthor || $this->addDate || $this->addRating): ?> @@ -35,14 +35,16 @@
- teaser): ?> + teaser && $this->allowRedirect): ?> teaser ?> text ?>
-

more ?>

+ allowRedirect): ?> +

more ?>

+
diff --git a/src/Resources/contao/templates/recommendation/recommendation_simple.html5 b/src/Resources/contao/templates/recommendation/recommendation_simple.html5 deleted file mode 100644 index ad9dadf..0000000 --- a/src/Resources/contao/templates/recommendation/recommendation_simple.html5 +++ /dev/null @@ -1,46 +0,0 @@ - -
- - addInternalImage): ?> - insert('image', $this->arrData); ?> - addExternalImage): ?> -
- -
- - -
- hasTitle): ?> -

headline ?>

- - - addAuthor || $this->addDate || $this->addRating): ?> -
- addAuthor): ?> -

author ?>

- - - addDate): ?> -

- - - addRating): ?> -
- - - -
- -
- - -
- teaser): ?> - teaser ?> - - text ?> - -
-
- -
diff --git a/src/Resources/public/style.css b/src/Resources/public/style.css new file mode 100644 index 0000000..ec6318c --- /dev/null +++ b/src/Resources/public/style.css @@ -0,0 +1,3 @@ +.navigation.recommendation_settings { + display: none !important; +}