Skip to content

Commit

Permalink
Merge pull request #3 from jweiland-net/mkBaseSearchOnClubdirectory
Browse files Browse the repository at this point in the history
[Feature] Added Search with Categories and Sorting
  • Loading branch information
Crontis authored Apr 18, 2019
2 parents 415bf4c + a0aad7a commit 7a0cc3e
Show file tree
Hide file tree
Showing 12 changed files with 529 additions and 42 deletions.
66 changes: 66 additions & 0 deletions Classes/Configuration/ExtConf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace JWeiland\Socialservices\Configuration;

/*
* This file is part of the socialservices project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\CMS\Core\SingletonInterface;

/**
* Class ExtConf
*/
class ExtConf implements SingletonInterface
{
/**
* root category.
*
* @var int
*/
protected $rootCategory = 0;

/**
* constructor of this class
* This method reads the global configuration and calls the setter methods.
*/
public function __construct()
{
// get global configuration
$extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['socialservices'], ['allowed_classes' => false]);
if (is_array($extConf) && count($extConf)) {
// call setter method foreach configuration entry
foreach ($extConf as $key => $value) {
$methodName = 'set' . ucfirst($key);
if (method_exists($this, $methodName)) {
$this->$methodName($value);
}
}
}
}

/**
* @return int
*/
public function getRootCategory(): int
{
return $this->rootCategory;
}

/**
* @param string $rootCategory
*/
public function setRootCategory(string $rootCategory)
{
$this->rootCategory = (int)$rootCategory;
}
}
91 changes: 65 additions & 26 deletions Classes/Controller/HelpdeskController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace JWeiland\Socialservices\Controller;

/*
Expand All @@ -14,17 +15,21 @@
* The TYPO3 project - inspiring people to share!
*/

use JWeiland\Socialservices\Configuration\ExtConf;
use JWeiland\Socialservices\Domain\Model\Helpdesk;
use JWeiland\Socialservices\Domain\Model\Search;
use JWeiland\Socialservices\Domain\Repository\HelpdeskRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Extbase\Domain\Repository\CategoryRepository;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

/**
* Class HelpdeskController
*
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class HelpdeskController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
class HelpdeskController extends ActionController
{
/**
* HelpdeskRepository
Expand All @@ -33,6 +38,20 @@ class HelpdeskController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
*/
protected $helpdeskRepository;

/**
* CategoryRepository
*
* @var CategoryRepository
*/
protected $categoryRepository;

/**
* ExtConf
*
* @var ExtConf
*/
protected $extConf;

/**
* Letters
*
Expand All @@ -41,9 +60,7 @@ class HelpdeskController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
protected $letters = '0-9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z';

/**
* preprocessing of all actions
*
* @return void
* Pre processing of all actions.
*/
public function initializeAction()
{
Expand All @@ -52,27 +69,55 @@ public function initializeAction()
if (empty($this->settings['pidOfDetailPage'])) {
$this->settings['pidOfDetailPage'] = null;
}
if ($this->arguments->hasArgument('search')) {
$this->arguments->getArgument('search')
->getPropertyMappingConfiguration()
->allowProperties(
'searchWord',
'letter',
'category',
'subCategory'
);
}
}

/**
* inject helpdeskRepository
*
* @param HelpdeskRepository $helpdeskRepository
* @return void
*/
public function injectHelpdeskRepository(HelpdeskRepository $helpdeskRepository)
{
$this->helpdeskRepository = $helpdeskRepository;
}

/**
* inject categoryRepository
*
* @param CategoryRepository $categoryRepository
*/
public function injectCategoryRepository(CategoryRepository $categoryRepository)
{
$this->categoryRepository = $categoryRepository;
}

/**
* inject extConf
*
* @param ExtConf $extConf
*/
public function injectExtConf(ExtConf $extConf)
{
$this->extConf = $extConf;
}

/**
* action list
*
* @param string $letter Show only records starting with this letter
* @validate $letter String, StringLength(minimum=0,maximum=1)
* @return void
*/
public function listAction($letter = null)
public function listAction(string $letter = null)
{
if ($letter === null) {
$helpdesks = $this->helpdeskRepository->findAll();
Expand All @@ -81,6 +126,7 @@ public function listAction($letter = null)
}
$this->view->assign('helpdesks', $helpdesks);
$this->view->assign('glossar', $this->getGlossar());
$this->view->assign('categories', $this->categoryRepository->findByParent($this->extConf->getRootCategory()));
}

/**
Expand Down Expand Up @@ -121,37 +167,30 @@ protected function getGlossar() : array
* action show
*
* @param Helpdesk $helpdesk
* @return void
*/
public function showAction(Helpdesk $helpdesk)
{
$this->view->assign('helpdesk', $helpdesk);
}

/**
* secure search parameter
* search show.
*
* @return void
* @param Search $search
*/
public function initializeSearchAction()
public function searchAction(Search $search = null)
{
if ($this->request->hasArgument('search')) {
$search = $this->request->getArgument('search');
$this->request->setArgument('search', htmlentities($search));
if ($search instanceof Search) {
$helpdesks = $this->helpdeskRepository->searchHelpdesks($search);
if ($search->getCategory()) {
$this->view->assign('subCategories', $this->categoryRepository->findByParent($search->getCategory()));
}
} else {
$helpdesks = $this->helpdeskRepository->findAll();
}
}

/**
* search show
*
* @param string $search
* @return void
*/
public function searchAction($search)
{
$helpdesks = $this->helpdeskRepository->searchHelpdesks($search);
$this->view->assign('helpdesks', $helpdesks);
$this->view->assign('categories', $this->categoryRepository->findByParent($this->extConf->getRootCategory()));
$this->view->assign('search', $search);
$this->view->assign('glossar', $this->getGlossar());
$this->view->assign('helpdesks', $helpdesks);
}
}
Loading

0 comments on commit 7a0cc3e

Please sign in to comment.