Skip to content

Commit

Permalink
Allow to profile search by year of birth
Browse files Browse the repository at this point in the history
  • Loading branch information
digedag committed Mar 31, 2024
1 parent 1fcffca commit a501e98
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 59 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Änderungen
==========

## v1.12.0 (??.04.2024)
* Support for Judo added
* (BC) types of sports registered by compiler pass
* Some refactoring in person search backend module
* Allow to search for year if birth in person search (e.g. "1985") Every number between 1000 and 3000 is interpreted as year.

## v1.11.7 (01.03.2024)
* Add fields for video assists (#74)

Expand Down
51 changes: 18 additions & 33 deletions Classes/Controller/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
use Sys25\RnBase\Backend\Utility\BackendUtility;
use Sys25\RnBase\Backend\Utility\Tables;
use Sys25\RnBase\Database\Connection;
use Sys25\RnBase\Domain\Collection\BaseCollection;
use Sys25\RnBase\Utility\T3General;
use Sys25\RnBase\Utility\TYPO3;
use System25\T3sports\Controller\Profile\ProfileMerger;
use System25\T3sports\Controller\Profile\ShowItem;
use System25\T3sports\Controller\Profile\ShowItem87;
use System25\T3sports\Module\Searcher\IProfileListRenderer;
use System25\T3sports\Module\Searcher\ProfileSearcher;
use System25\T3sports\Module\Utility\Selector;
use Throwable;
use tx_rnbase;
Expand Down Expand Up @@ -46,7 +49,7 @@
* Das Modul wurde relativ schnell runterprogrammiert und ist daher nicht auf Erweiterbarkeit
* ausgelegt.
*/
class Profile extends BaseModFunc
class Profile extends BaseModFunc implements IProfileListRenderer
{
private $doc;

Expand Down Expand Up @@ -96,27 +99,19 @@ protected function getContent($template, &$configurations, &$formatter, $formToo
'searchterm' => '',
], $data, $this->getModule()->getName());

$content .= $this->doc->section($lang->getLL('msg_search_person'), $this->createSearchForm($settings), 0, 1);

// Haben wir Daten im Request?
if (is_array($data)) {
// Soll ein Profil bearbeitet werden?
$content .= $this->handleProfileUpdate($data);
$content .= $this->handleProfileMerge($data);
}
// Wir zeigen die Liste an

$searcher = tx_rnbase::makeInstance(ProfileSearcher::class, $this->mod, $settings);

$content .= $this->doc->section($lang->getLL('msg_search_person'), $searcher->getSearchForm(), 0, 1);

if (!$this->hideResults) {
$searchterm = trim($settings['searchterm']);
if (strlen($searchterm) && strlen($searchterm) < 3) {
$content .= $this->doc->section($lang->getLL('message').':', $lang->getLL('msg_string_too_short'), 0, 1, IModFunc::ICON_INFO);
} elseif (strlen($searchterm) >= 3) {
$profiles = $this->searchProfiles($searchterm);
if (!empty($profiles)) {
$content .= $this->doc->section($lang->getLL('msg_found_person'), $this->buildProfileTable($profiles), 0, 1);
} else {
$content .= $this->doc->section($lang->getLL('msg_no_person_found'), '', 0, 1, IModFunc::ICON_WARN);
}
}
$content .= $searcher->getResultList($this);
}

return $content;
Expand Down Expand Up @@ -335,10 +330,15 @@ protected function searchProfiles($searchterm, $uid = 0)

/**
* Erstellt eine Tabelle mit den gefundenen Personen.
*
* @implements IProfileListRenderer
*/
protected function buildProfileTable(&$profiles)
public function renderProfiles(string $headline, BaseCollection $profiles)
{
$lang = $this->getModule()->getLanguageService();
if ($profiles->isEmpty()) {
return $this->doc->section($lang->getLL('msg_no_person_found'), '', 0, 1, IModFunc::ICON_WARN);
}

$out = '';
$arr = [
Expand All @@ -359,7 +359,7 @@ protected function buildProfileTable(&$profiles)
$row = [];
$row[] = $this->formTool->createRadio('data[merge1]', $profile['uid']).$this->formTool->createRadio('data[merge2]', $profile['uid']);
$row[] = $profile['uid'];
$row[] = $profile['last_name'];
$row[] = $profile['last_name'].'-'.$profile['birthday'];
$row[] = $profile['first_name'] ? $profile['first_name'] : '&nbsp;';
$row[] = date('j.n.Y', $profile['birthday']).' <input type="submit" name="data[edit_profile]['.$profile['uid'].']" value="'.$lang->getLL('btn_edit').'"';
// Die Zusatzinfos zusammenstellen
Expand Down Expand Up @@ -394,21 +394,6 @@ protected function buildProfileTable(&$profiles)
]);
}

return $out;
}

protected function createSearchForm(array $settings)
{
$lang = $this->getModule()->getLanguageService();
$out = '<div class="form-inline">';
$out .= $lang->getLL('label_searchterm').': ';
$out .= $this->formTool->createTxtInput('data[searchterm]', $settings['searchterm'] ?? '', 20, [
'class' => 'form-control input-sm',
]);
// Den Update-Button einfügen
$out .= $this->formTool->createSubmit('search', $lang->getLL('btn_search'));
$out .= '</div>';

return $out;
return $this->doc->section($lang->getLL('msg_found_person'), $out, 0, 1);
}
}
34 changes: 34 additions & 0 deletions Classes/Module/Searcher/IProfileListRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace System25\T3sports\Module\Searcher;

use Sys25\RnBase\Domain\Collection\BaseCollection;

/**************************************************************
* Copyright notice
*
* (c) 2008-2024 Rene Nitzsche ([email protected])
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
* *************************************************************
*/

interface IProfileListRenderer
{
public function renderProfiles(string $headline, BaseCollection $profiles);
}
34 changes: 22 additions & 12 deletions Classes/Module/Searcher/ProfileSearcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
use Sys25\RnBase\Backend\Module\IModule;
use Sys25\RnBase\Backend\Utility\BackendUtility;
use Sys25\RnBase\Backend\Utility\Tables;
use Sys25\RnBase\Domain\Collection\BaseCollection;
use Sys25\RnBase\Utility\Misc;
use Sys25\RnBase\Utility\T3General;
use System25\T3sports\Module\Decorator\ProfileDecorator;
use System25\T3sports\Utility\ServiceRegistry;
use tx_rnbase;
use tx_rnbase_mod_IModFunc;

/*
* *************************************************************
Expand Down Expand Up @@ -107,33 +107,43 @@ public function getSearchForm($label = '')
return $out;
}

public function getResultList()
public function getResultList(?IProfileListRenderer $renderer = null)
{
$content = '';
$lang = $this->module->getLanguageService();
$searchTerm = Misc::validateSearchString($this->SEARCH_SETTINGS['searchterm'] ?? '');
if (!$searchTerm) {
return $this->module->getDoc()->section($lang->getLL('message').':', $lang->getLL('msg_searchhelp'), 0, 1, tx_rnbase_mod_IModFunc::ICON_INFO);
return $this->module->getDoc()->section($lang->getLL('message').':', $lang->getLL('msg_searchhelp'), 0, 1, IModFunc::ICON_INFO);
}

$profiles = $this->searchProfiles($searchTerm);
$content .= $this->showProfiles('###LABEL_SEARCHRESULTS###', $profiles);
$content .= null !== $renderer ? $renderer->renderProfiles('###LABEL_SEARCHRESULTS###', $profiles) : $this->showProfiles('###LABEL_SEARCHRESULTS###', $profiles);

return $content;
}

/**
* @return BaseCollection<Profile>
*/
private function searchProfiles($searchterm)
{
$isYearSearch = (ctype_digit($searchterm) && (int) $searchterm > 1000 && (int) $searchterm < 3000);

$joined = $fields = [];
if (strlen($searchterm)) {
$joined['value'] = trim($searchterm);
$joined['cols'] = [
'PROFILE.LAST_NAME',
'PROFILE.FIRST_NAME',
'PROFILE.UID',
];
$joined['operator'] = OP_LIKE;
$fields[SEARCH_FIELD_JOINED][] = $joined;
if ($isYearSearch) {
$fields['PROFILE.BIRTHDAY'][OP_GTEQ_INT] = strtotime(sprintf('01.01.%d 00:00:00', $searchterm));
$fields['PROFILE.BIRTHDAY'][OP_LT_INT] = strtotime(sprintf('31.12.%d 23:59:59', $searchterm));
} else {
$joined['value'] = trim($searchterm);
$joined['cols'] = [
'PROFILE.LAST_NAME',
'PROFILE.FIRST_NAME',
'PROFILE.UID',
];
$joined['operator'] = OP_LIKE;
$fields[SEARCH_FIELD_JOINED][] = $joined;
}
}

$options = [];
Expand Down
5 changes: 3 additions & 2 deletions Classes/Service/ProfileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace System25\T3sports\Service;

use Sys25\RnBase\Database\Connection;
use Sys25\RnBase\Domain\Collection\BaseCollection;
use Sys25\RnBase\Domain\Model\RecordInterface;
use Sys25\RnBase\Typo3Wrapper\Service\AbstractService;
use Sys25\RnBase\Utility\Misc;
Expand All @@ -14,7 +15,7 @@
/***************************************************************
* Copyright notice
*
* (c) 2009-2023 Rene Nitzsche ([email protected])
* (c) 2009-2024 Rene Nitzsche ([email protected])
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
Expand Down Expand Up @@ -227,7 +228,7 @@ public function getProfileTypeItems4TCA($uids)
* @param array $fields
* @param array $options
*
* @return Profile[]
* @return BaseCollection<Profile>
*/
public function search($fields, $options)
{
Expand Down
12 changes: 0 additions & 12 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,11 @@

Sys25\RnBase\Utility\Extensions::addUserTSConfig('
options.saveDocNew.tx_cfcleague_group=1
');
Sys25\RnBase\Utility\Extensions::addUserTSConfig('
options.saveDocNew.tx_cfcleague_saison=1
');
Sys25\RnBase\Utility\Extensions::addUserTSConfig('
options.saveDocNew.tx_cfcleague_competition=1
');
Sys25\RnBase\Utility\Extensions::addUserTSConfig('
options.saveDocNew.tx_cfcleague_club=1
');
Sys25\RnBase\Utility\Extensions::addUserTSConfig('
options.saveDocNew.tx_cfcleague_teams=1
');
Sys25\RnBase\Utility\Extensions::addUserTSConfig('
options.saveDocNew.tx_cfcleague_profiles=1
');
Sys25\RnBase\Utility\Extensions::addUserTSConfig('
options.saveDocNew.tx_cfcleague_team_notes=1
');

Expand Down

0 comments on commit a501e98

Please sign in to comment.