From 177b07438d28ab2755b16221517559cf5fb2ee9b Mon Sep 17 00:00:00 2001 From: Tomek Stach Date: Wed, 31 Aug 2022 14:25:03 +0200 Subject: [PATCH] Add Joomla! Twig to the mod_finder module --- modules/mod_finder/mod_finder.php | 109 +++++++++++++++++- .../mod_finder/src/Module/FinderModule.php | 59 ++++++++++ modules/mod_finder/tmpl/default.html.twig | 37 ++++++ modules/mod_finder/tmpl/default.md | 56 +++++++++ modules/mod_finder/tmpl/default.php | 74 +----------- .../mod_finder/tmpl/default/default.html.twig | 37 ++++++ modules/mod_finder/tmpl/default/default.md | 56 +++++++++ modules/mod_finder/tmpl/navigation.php | 57 +++++++++ 8 files changed, 406 insertions(+), 79 deletions(-) create mode 100644 modules/mod_finder/src/Module/FinderModule.php create mode 100644 modules/mod_finder/tmpl/default.html.twig create mode 100644 modules/mod_finder/tmpl/default.md create mode 100644 modules/mod_finder/tmpl/default/default.html.twig create mode 100644 modules/mod_finder/tmpl/default/default.md create mode 100644 modules/mod_finder/tmpl/navigation.php diff --git a/modules/mod_finder/mod_finder.php b/modules/mod_finder/mod_finder.php index 30a80bdea6312..a1255640817ae 100644 --- a/modules/mod_finder/mod_finder.php +++ b/modules/mod_finder/mod_finder.php @@ -11,13 +11,16 @@ defined('_JEXEC') or die; use Joomla\CMS\Component\ComponentHelper; -use Joomla\CMS\Helper\ModuleHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\Router\Route; use Joomla\CMS\Uri\Uri; use Joomla\Component\Finder\Administrator\Helper\LanguageHelper; use Joomla\Component\Finder\Site\Helper\RouteHelper; use Joomla\Module\Finder\Site\Helper\FinderHelper; +// TS change - start +// use Joomla\Component\Videos\Site\Helper\Videos; +use Joomla\Module\Finder\Site\Module\FinderModule; +// TS change - end $cparams = ComponentHelper::getParams('com_finder'); @@ -36,11 +39,11 @@ // Get the route. $route = RouteHelper::getSearchRoute($params->get('searchfilter', null)); -if ($params->get('set_itemid')) { - $uri = Uri::getInstance($route); - $uri->setVar('Itemid', $params->get('set_itemid')); - $route = $uri->toString(array('path', 'query')); +// TS change - start +if ((int) $params->get('set_itemid') > 0) { + $route = 'index.php?Itemid=' . $params->get('set_itemid'); } +// TS change - end // Load component language file. LanguageHelper::loadComponentLanguage(); @@ -51,4 +54,98 @@ // Get Smart Search query object. $query = FinderHelper::getQuery($params); -require ModuleHelper::getLayoutPath('mod_finder', $params->get('layout', 'default')); +// TS change - start +// $videos = VideosFrontendHelper::getModel('Frontend'); +// $subjects = $videos->getSubjects(); +// $levels = $videos->getLevels(); +// $types = $videos->getTypes(); + +// To remove - start +$subjects = [ + (object) [ + 'id' => '1', + 'subject_title' => 'Matematyka', + 'state' => '1', + 'ordering' => '1', + ], + (object) [ + 'id' => '2', + 'subject_title' => 'Fizyka', + 'state' => '1', + 'ordering' => '2', + ], + (object) [ + 'id' => '3', + 'subject_title' => 'Chemia', + 'state' => '1', + 'ordering' => '3', + ], + (object) [ + 'id' => '4', + 'subject_title' => 'Biologia', + 'state' => '1', + 'ordering' => '4', + ], +]; + +$levels = [ + (object) [ + 'id' => '2', + 'level_title' => 'Szkoła Podstawowa IV-VI', + 'state' => '1', + 'ordering' => '2', + ], + (object) [ + 'id' => '5', + 'level_title' => 'Szkoła Podstawowa VII-VIII', + 'state' => '1', + 'ordering' => '5', + ], + (object) [ + 'id' => '6', + 'level_title' => 'Szkoła Ponadpodstawowa', + 'state' => '1', + 'ordering' => '6', + ], +]; + +$types = [ + (object) [ + 'id' => '1', + 'type_title' => 'Film', + 'state' => '1', + ], + (object) [ + 'id' => '2', + 'type_title' => 'Playlista', + 'state' => '1', + ], + (object) [ + 'id' => '3', + 'type_title' => 'Zadanie', + 'state' => '1', + ], + (object) [ + 'id' => '4', + 'type_title' => 'Riddle', + 'state' => '1', + ], +]; +// To remove - end + +$data = [ + 'route' => $route, + 'query' => $query, + 'search' => htmlspecialchars(JFactory::getApplication()->input->get('q', '', 'string')), + 'subjects' => $subjects, + 'levels' => $levels, + 'types' => $types, +]; + +$modInstance = new FinderModule($params, $module); +$modInstance->setData($data); + +$layout = '@module/mod_finder/' . explode(':', $params->get('layout', 'default'))[1] . '/' . explode(':', $params->get('layout', 'default'))[1] . '.html.twig'; + +echo $modInstance->render($layout); +// TS change - end diff --git a/modules/mod_finder/src/Module/FinderModule.php b/modules/mod_finder/src/Module/FinderModule.php new file mode 100644 index 0000000000000..ec486fa01dc98 --- /dev/null +++ b/modules/mod_finder/src/Module/FinderModule.php @@ -0,0 +1,59 @@ + - http://katalysteducation.org + */ + +namespace Joomla\Module\Finder\Site\Module; + +defined('_JEXEC') || die; + +\JLoader::import('twig.library'); + +use Phproberto\Joomla\Twig\Module\BaseTwigModule; + +/** + * Finder module. + * + * @since 3.0.0 + */ +class FinderModule extends BaseTwigModule +{ + /** + * Module created by module + * + * @var string + */ + protected $data; + + /** + * Method to set data from module. + * + * @param array $data + */ + public function setData(array $data): void + { + $this->data = $data; + } + + /** + * Load layout data. + * + * @return array + */ + protected function loadLayoutData(): array + { + return [ + 'cssClass' => $this->getCssClass(), + 'cssId' => $this->getCssId(), + 'moduleInstance' => $this, + 'params' => $this->getParams(), + 'data' => $this->data, + ]; + } +} diff --git a/modules/mod_finder/tmpl/default.html.twig b/modules/mod_finder/tmpl/default.html.twig new file mode 100644 index 0000000000000..1fc167a33a055 --- /dev/null +++ b/modules/mod_finder/tmpl/default.html.twig @@ -0,0 +1,37 @@ +

moduleInstance

+
{{ dump(moduleInstance) }}
+ +

params

+
{{ dump(params) }}
+ +

route

+
{{ dump(data.route) }}
+ +

query

+
{{ dump(data.query) }}
+ +

search

+
{{ dump(data.search) }}
+ +

subjects

+
{{ dump(data.subjects) }}
+ +

levels

+
{{ dump(data.levels) }}
+ +

types

+
{{ dump(data.types) }}
+ + +
+ search + +
+ diff --git a/modules/mod_finder/tmpl/default.md b/modules/mod_finder/tmpl/default.md new file mode 100644 index 0000000000000..c63ea73b8d4c5 --- /dev/null +++ b/modules/mod_finder/tmpl/default.md @@ -0,0 +1,56 @@ +## Info + +**Module:** mod_finder + +**Template:** default + +**Description:** This is the view which we use to display a searchbox. + +## Data + +### {{ data.route }} + +This is a url for the form action. + +### {{ data.query }} + +This is a query object. + +### {{ data.search }} + +This is a searched phrase. + +### {{ data.subjects }} + +This is a list of available subjects. + +### {{ data.levels }} + +This is a list of available levels. + +### {{ data.types }} + +This is a list of available types. + +### {{ class_sfx }} + +CSS class suffix. + +**Tips:** + + - old version of searchbox: + ``` + +
+ search + +
+ + ``` diff --git a/modules/mod_finder/tmpl/default.php b/modules/mod_finder/tmpl/default.php index 2ec2c11e96100..1a47f8d9bcfcc 100644 --- a/modules/mod_finder/tmpl/default.php +++ b/modules/mod_finder/tmpl/default.php @@ -1,73 +1 @@ - - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ - -defined('_JEXEC') or die; - -use Joomla\CMS\HTML\HTMLHelper; -use Joomla\CMS\Language\Text; -use Joomla\CMS\Router\Route; -use Joomla\Module\Finder\Site\Helper\FinderHelper; - -// Load the smart search component language file. -$lang = $app->getLanguage(); -$lang->load('com_finder', JPATH_SITE); - -$input = ''; - -$showLabel = $params->get('show_label', 1); -$labelClass = (!$showLabel ? 'visually-hidden ' : '') . 'finder'; -$label = ''; - -$output = ''; - -if ($params->get('show_button', 0)) { - $output .= $label; - $output .= ''; -} else { - $output .= $label; - $output .= $input; -} - -Text::script('MOD_FINDER_SEARCH_VALUE', true); - -/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */ -$wa = $app->getDocument()->getWebAssetManager(); -$wa->getRegistry()->addExtensionRegistryFile('com_finder'); - -/* - * This segment of code sets up the autocompleter. - */ -if ($params->get('show_autosuggest', 1)) { - $wa->usePreset('awesomplete'); - $app->getDocument()->addScriptOptions('finder-search', array('url' => Route::_('index.php?option=com_finder&task=suggestions.suggest&format=json&tmpl=component', false))); -} - -$wa->useScript('com_finder.finder'); - -?> - - + diff --git a/modules/mod_finder/tmpl/default/default.html.twig b/modules/mod_finder/tmpl/default/default.html.twig new file mode 100644 index 0000000000000..1fc167a33a055 --- /dev/null +++ b/modules/mod_finder/tmpl/default/default.html.twig @@ -0,0 +1,37 @@ +

moduleInstance

+
{{ dump(moduleInstance) }}
+ +

params

+
{{ dump(params) }}
+ +

route

+
{{ dump(data.route) }}
+ +

query

+
{{ dump(data.query) }}
+ +

search

+
{{ dump(data.search) }}
+ +

subjects

+
{{ dump(data.subjects) }}
+ +

levels

+
{{ dump(data.levels) }}
+ +

types

+
{{ dump(data.types) }}
+ + +
+ search + +
+ diff --git a/modules/mod_finder/tmpl/default/default.md b/modules/mod_finder/tmpl/default/default.md new file mode 100644 index 0000000000000..c63ea73b8d4c5 --- /dev/null +++ b/modules/mod_finder/tmpl/default/default.md @@ -0,0 +1,56 @@ +## Info + +**Module:** mod_finder + +**Template:** default + +**Description:** This is the view which we use to display a searchbox. + +## Data + +### {{ data.route }} + +This is a url for the form action. + +### {{ data.query }} + +This is a query object. + +### {{ data.search }} + +This is a searched phrase. + +### {{ data.subjects }} + +This is a list of available subjects. + +### {{ data.levels }} + +This is a list of available levels. + +### {{ data.types }} + +This is a list of available types. + +### {{ class_sfx }} + +CSS class suffix. + +**Tips:** + + - old version of searchbox: + ``` + +
+ search + +
+ + ``` diff --git a/modules/mod_finder/tmpl/navigation.php b/modules/mod_finder/tmpl/navigation.php new file mode 100644 index 0000000000000..33e5711557272 --- /dev/null +++ b/modules/mod_finder/tmpl/navigation.php @@ -0,0 +1,57 @@ +getTemplate(); +$menu = $app->getMenu(); +// Load the smart search component language file. +$lang = JFactory::getLanguage(); +$lang->load('com_finder', JPATH_SITE); + +if (JFactory::getApplication()->input->get('option') == 'com_videos') { + $search_mode = 'slim'; +} +elseif ($menu->getActive() == $menu->getDefault($lang->getTag())) { + $search_mode = 'big'; +} +else { + $search_mode = 'regular'; +} + +$videos = VideosFrontendHelper::getModel('Frontend'); +$subjects = $videos->getSubjects(); +$levels = $videos->getLevels(); +$types = $videos->getTypes(); + +if ((int) $params->get('set_itemid') > 0) { + $route = 'index.php?Itemid='.$params->get('set_itemid'); +} + +$logo_url = $app->get('logo'); +$desktop_bg = $app->get('dektop'); + +?> +
+ search + + +
+