0

I have an extension where I need to get all frontend users. I tried this:

    /**
     * @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository $feUserRepository
     */
    $feUserRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( 'TYPO3\\CMS\\Extbase\\Domain\\Repository\\FrontendUserRepository' );
    $allUsers = $feUserRepository->findAll();
    $user = $feUserRepository->findByUid( 1 );

findByUid(1) works, but findAll() returns an empty object. What am I doing wrong here?

UPDATE:

It's about a news extension. I have a mm relation between tx_xxnews_domain_model_news and fe_users, so I can keep track on which users accessed which news.

TCA for News:

'columns' => array(
        ...

        'fe_users' => array(
            'exclude' => 0,
            'label' => 'LLL:EXT:xx_news/Resources/Private/Language/locallang_db.xlf:tx_xxnews_domain_model_news.fe_users',
            'config' => array(
                'type' => 'select',
                'foreign_table' => 'fe_users',
                'MM' => 'tx_xxnews_news_feuser_mm',
                'size' => 10,
                'autoSizeMax' => 30,
                'maxitems' => 9999,
                'multiple' => 0,
            ),
        ),
        ...
),

I have to show the users who accessed the news separately from the ones who did not, so I have 2 more columns which show content from a user defined function:

'reading_users' => array (
    'exclude' => 0,
    'label' => 'LLL:EXT:xx_news/Resources/Private/Language/locallang_db.xlf:tx_xxnews_domain_model_news.user_info',
    'config' => array (
        'type' => 'user',
        'size' => '30',
        'userFunc' => 'EXT:xx_news/Classes/TCA/class.tx_xxnews_tca.php:tx_examples_tca->readersInfo',
        'parameters' => array(
            'read' => TRUE
        )
    )
),
'not_reading_users' => array (
    'exclude' => 0,
    'label' => 'LLL:EXT:xx_news/Resources/Private/Language/locallang_db.xlf:tx_xxnews_domain_model_news.user_info',
    'config' => array (
        'type' => 'user',
        'size' => '30',
        'userFunc' => 'EXT:xx_news/Classes/TCA/class.tx_xxnews_tca.php:tx_examples_tca->readersInfo',
        'parameters' => array(
            'read' => FALSE
        )
    )
),

class.tx_xxnews_tca.php:

class tx_examples_tca {

    /**
     * @var \Vendor\XxNews\Domain\Repository\NewsRepository $newsRepository
     */
    protected $newsRepository;

    /**
     * Class constructor
     */
    public function __construct() {
        $this->newsRepository = new \Vendor\XxNews\Domain\Repository\NewsRepository;
    }

    public function readersInfo($params) {

        /**
         * @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository $feUserRepository
         */
        $feUserRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( 'TYPO3\\CMS\\Extbase\\Domain\\Repository\\FrontendUserRepository' );
        $allUsers = $feUserRepository->findAll();
        $user = $feUserRepository->findByUid( 1 );

        var_dump( $allUsers ); //EMPTY
        var_dump( $user );     //OK
    }
}

Thank you.

cili
  • 1,037
  • 2
  • 19
  • 34

1 Answers1

4

The problem is that when Extbase was introduced by TYPO3, a "record type" for Frontend users was integrated. (This was just done as an example and will be removed in 6.2 BTW).

You must either set the record type of each Frontend User to the record type of your extension (it is defined in the ext_tables.php of your extension) or you can remove (clear) the necessity of the record type

config.tx_extbase.persistence.classes.Vendor/MyExtension/Domain/Model/User.mapping.recordType =

EDIT: By the way, you should inject your repository instead of using makeInstance:

/**
 * @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
 * @inject
 */
protected $feUserRepository;
lorenz
  • 4,538
  • 1
  • 27
  • 45
  • Hi lorenz. I don't extend the FrontendUser model, so I don't have any record type defined. I updated the field tx_extbase_type with 'Tx_Extbase_Domain_Model_FrontendUser', but still nothing is returned by findAll(). I don't extend the model, I just want to get the list of fe users using the core model. Thank you. – cili Jan 22 '14 at 15:16
  • 1
    Is it a Frontend or a Backend extension? Is the storage PID set? – lorenz Jan 22 '14 at 15:24
  • It's a news extension with mm relation to fe_users. Please check the update. – cili Jan 22 '14 at 15:53
  • Injecting does not seem to work in this context. I tried to set the readersInfo method in NewsController, but still the FrontendUser repository was not accessible via @inject. – cili Jan 22 '14 at 16:14
  • Did you clear all caches? If done correctly, it must work; you can insert repositories to a Controller. – lorenz Jan 23 '14 at 08:51
  • Looks like setting: config.tx_extbase.persistence.storagePid = 2 worked (2 is the uid of the sysfolder which keeps frontend users). Isn't this a bit weird? I mean, wouldn't have more sense to set the pid for tx_felogin instead? I tried it, but it had no effect. – cili Jan 23 '14 at 11:38