Extend Repository of a foreign TYPO3 extbase 扩展
Extend Repository of a foreign TYPO3 extbase extension
我已经在 TYPO3 6.2 安装上安装了扩展程序 'femanager',并成功地使用我自己的从数据库中存储和读取的字段对其进行了扩展。
现在 Controller 中有一个操作调用 UserRepository 的 findByUsergroup() 方法来呈现带有过滤器的 fe_users 列表。
我想扩展搜索过滤器,因此我必须更改我的扩展中的 findByUsergroup() 方法。这可能吗?如果可能,怎么做?
我用 TYPO3 进行了很多开发,但没有使用 extbase。我熟悉钩子和 signal/slots 以及这些种类,但我不明白这个 运行。有什么提示可以让 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;
}
}
您可以告诉 extbase 使用 TypoScript
加载您的 class 而不是原始的
config.tx_extbase {
objects {
In2\Femanager\Domain\Repository\UserRepository {
className = NGiB\Ngibmembers\Domain\Repository\MemberRepository
}
}
}
你仍然需要扩展原来的 class,但你的 repo 现在应该被调用。
我已经在 TYPO3 6.2 安装上安装了扩展程序 'femanager',并成功地使用我自己的从数据库中存储和读取的字段对其进行了扩展。
现在 Controller 中有一个操作调用 UserRepository 的 findByUsergroup() 方法来呈现带有过滤器的 fe_users 列表。
我想扩展搜索过滤器,因此我必须更改我的扩展中的 findByUsergroup() 方法。这可能吗?如果可能,怎么做?
我用 TYPO3 进行了很多开发,但没有使用 extbase。我熟悉钩子和 signal/slots 以及这些种类,但我不明白这个 运行。有什么提示可以让 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;
}
}
您可以告诉 extbase 使用 TypoScript
加载您的 class 而不是原始的config.tx_extbase {
objects {
In2\Femanager\Domain\Repository\UserRepository {
className = NGiB\Ngibmembers\Domain\Repository\MemberRepository
}
}
}
你仍然需要扩展原来的 class,但你的 repo 现在应该被调用。