【发布时间】:2015-06-18 21:27:09
【问题描述】:
我已在 TYPO3 6.2 安装中安装了扩展“femanager”,并使用我自己的字段成功扩展了它,这些字段从数据库中存储和读取。
现在控制器中有一个动作,它调用 UserRepository 的 findByUsergroup() 方法来呈现带有过滤器的 fe_users 列表。
我想扩展搜索过滤器,因此我必须更改扩展中的 findByUsergroup() 方法。这可能吗?如果可以,怎么做?
我一直在使用 TYPO3 进行很多开发,但没有使用 extbase。我熟悉钩子和信号/插槽以及这些类型,但我没有让它运行。任何提示如何让 TYPO3 使用我的从 femanager 扩展的存储库?
<?php
namespace NGiB\Ngibmembers\Domain\Repository;
use In2\Femanager\Domain\Repository\UserRepository;
/***************************************************************
* Copyright notice
*
* (c) 2013 Alex Kellner <alexander.kellner@in2code.de>, in2code
*
* 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 3 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!
***************************************************************/
/**
* Member Repository
*
* @package ngibmembers
* @license http://www.gnu.org/licenses/gpl.html
* GNU General Public License, version 3 or later
*/
class MemberRepository extends UserRepository {
/**
* Find users by commaseparated usergroup list
*
* @param string $userGroupList commaseparated list of usergroup uids
* @param array $settings Flexform and TypoScript Settings
* @param array $filter Filter Array
* @return query object
*/
public function findByUsergroups($userGroupList, $settings, $filter) {
$query = $this->createQuery();
// where
$and = array(
$query->greaterThan('uid', 0)
);
if (!empty($userGroupList)) {
$selectedUsergroups = GeneralUtility::trimExplode(',', $userGroupList, TRUE);
$or = array();
foreach ($selectedUsergroups as $group) {
$or[] = $query->contains('usergroup', $group);
}
$and[] = $query->logicalOr($or);
}
if (!empty($filter['searchword'])) {
$searchwords = GeneralUtility::trimExplode(' ', $filter['searchword'], 1);
$fieldsToSearch = GeneralUtility::trimExplode(',', $settings['list']['filter']['searchword']['fieldsToSearch'], TRUE);
foreach ($searchwords as $searchword) {
$or = array();
foreach ($fieldsToSearch as $searchfield) {
$or[] = $query->like($searchfield, '%' . $searchword . '%');
}
$and[] = $query->logicalOr($or);
}
}
if(!empty($filter['ngbl'])){
$and[] = $query->greaterThan('ngbl',1);
}
$query->matching($query->logicalAnd($and));
// sorting
$sorting = QueryInterface::ORDER_ASCENDING;
if ($settings['list']['sorting'] == 'desc') {
$sorting = QueryInterface::ORDER_DESCENDING;
}
$field = preg_replace('/[^a-zA-Z0-9_-]/', '', $settings['list']['orderby']);
$query->setOrderings(
array(
$field => $sorting
)
);
// set limit
if (intval($settings['list']['limit']) > 0) {
$query->setLimit(intval($settings['list']['limit']));
}
$users = $query->execute();
return $users;
}
}
【问题讨论】:
标签: repository typo3 extbase