扩展外部TYPO3 extbase扩展的存储库 [英] Extend Repository of a foreign TYPO3 extbase extension
问题描述
我已经在TYPO3 6.2安装中安装了扩展名'femanager',并成功地使用我自己的字段对其进行了扩展,这些字段可以从数据库中存储和读取.
I have installed the extension 'femanager' on a TYPO3 6.2 installation and successfully extended it with my own fields that get stored and read from the database.
现在,Controller中有一个操作,该操作调用UserRepository的findByUsergroup()方法,以使用过滤器呈现fe_users列表.
Now there is an action in a Controller that calls upon the UserRepository for the findByUsergroup() method to render a list of fe_users with a filter.
我想扩展搜索过滤器,因此必须从扩展名中更改方法findByUsergroup().这可能吗?如果可以,怎么办?
I want to extend the search filter, and therefore I must alter the method findByUsergroup() from my extension. Is this possible, and if so, how?
我一直在使用TYPO3进行很多开发,但没有使用extbase进行开发.我对钩子和信号/插槽以及这些种类很熟悉,但是我没有让它运行.有什么提示如何使TYPO3使用我的存储库来扩展femanager的存储库吗?
I have been developing a lot with TYPO3, but not with extbase. I am familiar with hooks and signal/slots and these kinds, but I don't get this running. Any hints how to make TYPO3 use my Repository that extends the one from 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;
}
}
推荐答案
您可以使用TypoScript告诉extbase加载您的类,而不是原来的类
You can tell extbase to load your class instead of the original one with TypoScript
config.tx_extbase {
objects {
In2\Femanager\Domain\Repository\UserRepository {
className = NGiB\Ngibmembers\Domain\Repository\MemberRepository
}
}
}
您仍然必须扩展原始类,但是现在应该调用您的repo.
You still have to extend the original class, but your repo should be called now.
这篇关于扩展外部TYPO3 extbase扩展的存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!