2
votes

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.

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.

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?

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 <[email protected]>, 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

1 Answers

3
votes

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
      }
   }
}

You still have to extend the original class, but your repo should be called now.