extcode / contacts

Contacts is an extension to handle contacts (e.g. companies, persons, addresses) and add relations to each other.
GNU General Public License v2.0
7 stars 2 forks source link

How to get Contact person from assigned fe_user #80

Open X-Tender opened 4 years ago

X-Tender commented 4 years ago

Hi,

When I create a Person I can assign it to a fe_user. But how do I get the Person from the fe_user? I hoped to find an additional option in the fe_user wehre I can assign a Person so when I get the currently logged in fe_user I can also access the Person data.

extcode commented 4 years ago

Hi. Can you explain what you're trying to solve? Do you need the contact data in the controller or a view?

X-Tender commented 4 years ago

Yes, I achieved it currently via a extended FrontUser Model whre I add a custom field with the foreign table tx_contacts_domain_model_contact so now I can do:

$user = $this->frontendUserRepository->findByUid($GLOBALS['TSFE']->fe_user->user['uid']);
 \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($user->getContact()->getAddresses());

I thought this would be already included in the extension. Or how would you get the assigned contact from a FrontendUser?

X-Tender commented 4 years ago

I ran into an another problem. I create a new Contact in my controller and now I would like to assign a fe_user to the contact. In the typo3 BE its not a problem, there's the Dropdown but there is no setUser method in the Contact model. Is it possible without building a sql and set the uid of the fe_user column manualy?

X-Tender commented 4 years ago

So thats how I make this currently happen

$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_contacts_domain_model_contact');
$queryBuilder
    ->update('tx_contacts_domain_model_contact')
    ->where(
        $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($newContact->getUid()))
    )
    ->set('fe_user', $user->getUid())
    ->execute();