扩展外国TYPO3 extbase扩展的存储库

时间:2015-06-18 21:27:10

标签: repository typo3 extbase

我已经安装了扩展程序' femanager'在TYPO3 6.2安装上,并使用我自己的字段成功扩展它,这些字段可以存储并从数据库中读取。

现在Controller中有一个动作,它调用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;
    }
}

1 个答案:

答案 0 :(得分:2)

你可以告诉extbase加载你的类,而不是使用TypoScript加载你的类

config.tx_extbase {
   objects {
      In2\Femanager\Domain\Repository\UserRepository {
         className = NGiB\Ngibmembers\Domain\Repository\MemberRepository
      }
   }
}

您仍需要扩展原始类,但现在应该调用您的回购。