Commit a8e0c7f1 authored by Stefan Busemann's avatar Stefan Busemann
Browse files

[FEATURE] show user profile

parent 841f2fb1
......@@ -10,8 +10,8 @@
],
"repositories": [
{
"type": "vcs",
"url": "https://github.com/in2code-de/femanager.git"
"type": "path",
"url": "packages/*"
},
{
"type": "composer",
......@@ -36,8 +36,8 @@
"dmitryd/typo3-realurl": "^2.1",
"t3o/t3o_slack": "dev-master",
"t3o/t3olayout": "dev-develop",
"t3o/t3o_ldap":"dev-master",
"in2code/femanager": "dev-develop"
"t3o/t3o_ldap": "dev-master",
"in2code/femanager": "@dev"
},
"config": {
"bin-dir": "bin"
......@@ -55,7 +55,8 @@
"autoload": {
"psr-4": {
"T3o\\T3olayout\\": "html/typo3conf/ext/t3olayout/Classes",
"T3o\\T3omy\\": "html/typo3conf/ext/t3omy/Classes"
"T3o\\T3omy\\": "html/typo3conf/ext/t3omy/Classes",
"T3o\\Userprofile\\": "html/typo3conf/ext/userprofile/Classes"
}
}
}
......@@ -4,7 +4,7 @@ return [
'debug' => true,
'explicitADmode' => 'explicitAllow',
'installToolPassword' => '$pbkdf2-sha256$25000$oRS5QrY6LY0VQWgAxx5hcQ$mM7JqvMgnEfY1FtIW6Ngcj7mJqUNto4kBNJmRv0gUFk',
'loginSecurityLevel' => 'normal',
'loginSecurityLevel' => 'rsa',
],
'DB' => [
'Connections' => [
......@@ -44,6 +44,7 @@ return [
't3olayout' => 'a:0:{}',
't3omy' => 'a:0:{}',
'tstemplate' => 'a:0:{}',
'userprofile' => 'a:0:{}',
],
],
'FE' => [
......
<?php
declare(strict_types=1);
namespace T3o\Userprofile\Controller;
use T3o\Userprofile\Domain\Model\UserProfile;
use T3o\Userprofile\Domain\Repository\UserProfileRepository;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
/**
* Class UserController
*/
class UserProfileController extends ActionController
{
/**
* @var UserProfileRepository
* */
public $userProfileRepository;
/**
* @param UserProfileRepository $userProfileRepository
*/
public function injectUserProfileRepository(UserProfileRepository $userProfileRepository)
{
$this->userProfileRepository = $userProfileRepository;
}
/**
* @param \T3o\Userprofile\Domain\Userprofile $userProfile
*
* @return void
*
* @ignoevalidation $userProfile
*/
public function showAction(UserProfile $userProfile = NULL)
{
if (!$userProfile) {
if ($GLOBALS['TSFE']->fe_user->user['uid']>0) {
$userProfile = $this->userProfileRepository->findByUid($GLOBALS['TSFE']->fe_user->user['uid']);
if (!$userProfile) {
$this->addFlashMessage('Something went wrong. We were not able to find your profile found!','Profile can not be shown',AbstractMessage::ERROR);
}
$this->view->assign('showEditButton',true);
} else {
$this->addFlashMessage('You need to be logged in!','Profile can not be shown',AbstractMessage::ERROR);
}
}
// display a profile of a user
$this->view->assign('userProfile',$userProfile);
// render an edit button, if the current user is logged in
}
/**
*
*/
public function editAction()
{
}
/**
* @param \T3o\Userprofile\Domain\Userprofile $userProfile
*
* @return void
*
* @ignoevalidation $userProfile
*/
public function updateAction(UserProfile $userProfile)
{
// store changes in database
$this->userProfileRepository->update($userProfile);
// clear cache entry for this entry
}
}
<?php
declare(strict_types=1);
namespace T3o\Userprofile\Controller;
use T3o\Userprofile\Domain\Model\UserProfile;
use T3o\Userprofile\Domain\Repository\UserProfileRepository;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
/**
* Class ListUserProfileController
*/
class UserProfileListController extends ActionController
{
/**
* @var UserProfileRepository
* */
public $userProfileRepository;
/**
* @param UserProfileRepository $userProfileRepository
*/
public function injectUserProfileRepository(UserProfileRepository $userProfileRepository)
{
$this->userProfileRepository = $userProfileRepository;
}
/**
*
*/
public function listAction()
{
$allUsers = $this->userProfileRepository->findAll();
$this->view->assign('frontendUsers', $allUsers);
}
}
<?php
declare(strict_types=1);
namespace T3o\Userprofile\Domain\Model;
use In2code\Femanager\Domain\Model\User;
/**
* Class UserProfile
*/
class UserProfile extends User
{
/**
* $privacySettings
*
* @var string
*/
public $privacySettings;
/**
* $realName
*
* @var string
*/
public $aboutMe;
/**
* $publicProfile
*
* @var boolean
*/
public $publicProfile=false;
/**
* @return string
*/
public function getPrivacySettings()
{
return $this->privacySettings;
}
/**
* @param $defaultPrivacySettings
* @return array
*/
public function getCompilledPrivacySettings($defaultPrivacySettings)
{
#$defaultSettings = $defaultPrivacySettings['_default'];
##$this->getPrivacySettings();
#return $this->privacySettings;
}
/**
* @param string $privacySettings
*/
public function setPrivacySettings($privacySettings)
{
$this->privacySettings = $privacySettings;
}
/**
* @return string
*/
public function getAboutMe()
{
return $this->aboutMe;
}
/**
* @param string $aboutMe
*/
public function setAboutme($aboutMe)
{
$this->aboutMe = $aboutMe;
}
/**
* @return bool
*/
public function isPublicProfile(): bool
{
return $this->publicProfile;
}
/**
* @param bool $publicProfile
*/
public function setPublicProfile(bool $publicProfile=false)
{
$this->publicProfile = $publicProfile;
}
}
<?php
declare(strict_types=1);
namespace T3o\Userprofile\Domain\Repository;
use T3o\userprofile\Domain\Model\UserProfile;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3\CMS\Extbase\Persistence\Repository;
/**
* Class UserProfileRepository
*/
class UserProfileRepository extends Repository
{
/**
* Overload Find by UID to also get hidden records
*
* @param int $uid fe_users UID
* @return UserProfile
*/
public function findByUid($uid)
{
$query = $this->createQuery();
$and = [$query->equals('uid', $uid)];
/** @var UserProfile $user */
$user = $query->matching($query->logicalAnd($and))->execute()->getFirst();
return $user;
}
/**
* 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 QueryResultInterface|array
*/
public function findByUsergroups($userGroupList, $settings, $filter)
{
$query = $this->createQuery();
// where
$and = [
$query->greaterThan('uid', 0)
];
if (!empty($userGroupList)) {
$selectedUsergroups = GeneralUtility::trimExplode(',', $userGroupList, true);
$logicalOr = [];
foreach ($selectedUsergroups as $group) {
$logicalOr[] = $query->contains('usergroup', $group);
}
$and[] = $query->logicalOr($logicalOr);
}
if (!empty($filter['searchword'])) {
$searchwords = GeneralUtility::trimExplode(' ', $filter['searchword'], true);
$fieldsToSearch = GeneralUtility::trimExplode(
',',
$settings['list']['filter']['searchword']['fieldsToSearch'],
true
);
foreach ($searchwords as $searchword) {
$logicalOr = [];
foreach ($fieldsToSearch as $searchfield) {
$logicalOr[] = $query->like($searchfield, '%' . $searchword . '%');
}
$and[] = $query->logicalOr($logicalOr);
}
}
$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([$field => $sorting]);
// set limit
if ((int)$settings['list']['limit'] > 0) {
$query->setLimit((int)$settings['list']['limit']);
}
$users = $query->execute();
return $users;
}
}
<?php
/**
* Table configuration fe_users
*/
$feUsersColumns = [
'privacy_settings' => [
'exclude' => 0,
'label' => 'Privacy settings',
'config' => [
'type' => 'text',
]
],
'about_me' => [
'exclude' => 0,
'label' => 'about me',
'config' => [
'type' => 'text',
]
],
'public_profile' => [
'exclude' => 0,
'label' => 'show user profile',
'config' => [
'type' => 'check',
]
],
];
$fields = 'privacy_settings,about_me,';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'fe_users',
'privacy_settings,about_me,public_profile',
'',
'after:name'
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('fe_users', $feUsersColumns);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'fe_users',
'--div--;LLL:EXT:femanager/Resources/Private/Language/locallang_db.xlf:fe_users.tab, ' . $fields
);
plugin.tx_userprofile {
view {
# cat=plugin.tx_userprofile/file; type=string; label=Path to template root (FE)
templateRootPath = EXT:tx_userprofile/Resources/Private/Templates/
# cat=plugin.tx_userprofile/file; type=string; label=Path to template partials (FE)
partialRootPath = EXT:tx_userprofile/Resources/Private/Partials/
# cat=plugin.tx_userprofile/file; type=string; label=Path to template layouts (FE)
layoutRootPath = EXT:tx_userprofile/Resources/Private/Layouts/
}
persistence {
# cat=plugin.tx_userprofile//a; type=string; label=Default storage PID
storagePid =
}
}
plugin.tx_userprofile {
view {
templateRootPath = {$plugin.tx_userprofile.view.templateRootPath}
partialRootPath = {$plugin.tx_userprofile.view.partialRootPath}
layoutRootPath = {$plugin.tx_userprofile.view.layoutRootPath}
}
persistence {
storagePid = {$plugin.tx_userprofile.persistence.storagePid}
}
features {
# uncomment the following line to enable the new Property Mapper.
# rewrittenPropertyMapper = 1
}
settings {
pricacy {
_default {
public = 0
authenticated = 0
groups = 0
}
#column_name = 1 activates the setting for the user
#column_name {
# public = 0 => sets the default value for element
# authenticated = 0
# groups = 0
# }
about_me = 1
email = 1
name = 1
image = 1
slack_id = 1
}
}
}
<section class="container">
<h1>{userProfile.name}</h1>
<ul>
<li>Name: {userProfile.name}</li>
<li>Email: {userProfile.email}</li>
<li>About me: {userProfile.aboutMe}</li>
<f:if condition="{showEditButton}" >
<li>my privacy settings: {userProfile.privacySettings}</li>
<f:link.action action="edit" arguments="{userProfile:userProfile}">Edit</f:link.action>
<f:form action="update" name="userProfile" object="{userProfile}">
<f:form.checkbox value="{userProfile.publicProfile}" property="publicProfile"></f:form.checkbox>
<label for="publicProfile">show my profile page</label></br>
<f:form.submit class="btn btn-primary" value="update your profile" />
</f:form>
</f:if>
</ul>
</section>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
</html>
<section class="container">
<h1>my user profile</h1>
<table>
<f:for each="{frontendUsers}" as="frontendUser">
<f:if condition="{frontendUser.publicProfile}">
<tr>
<td><f:link.action controller="UserProfile" action="show" arguments="{userProfile:frontendUser}">{frontendUser.username}</f:link.action></td>
<td>{frontendUser.uid}</td>
</tr>
</f:if>
</f:for>
</table>
</section>
......@@ -27,6 +27,7 @@ $EM_CONF[$_EXTKEY] = [
'depends' => [
'typo3' => '8.7.0-8.99.99',
'php' => '7.0.0-7.99.99',
'femanager' => '3.1.0-'
],
'conflicts' => [],
'suggests' => [],
......
......@@ -2,6 +2,30 @@
if (!defined('TYPO3_MODE')) {
die('Access denied.');
}
call_user_func(function () {
});
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'T3o.' . $_EXTKEY,
'Pi1',
[
'UserProfile' => 'show, edit, update',
'UserProfileList' => 'list',
],
[
'UserProfile' => 'edit, update',
'UserProfileList' => '',
]
);
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'T3o.' . $_EXTKEY,
'Pi2',
[
'UserProfileList' => 'list',
'UserProfile' => 'show, edit, update',
],
[
'UserProfileList' => '',
'UserProfile' => 'show, edit, update',
]
);
......@@ -3,10 +3,22 @@ if (!defined('TYPO3_MODE')) {
die('Access denied.');
}
call_user_func(function () {
/**
* FE Plugin
*/
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin('userprofile', 'Pi1', 'User Profile');
});
/**
* FE Plugin
*/
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin('T3o.' . $_EXTKEY, 'Pi1', 'Show profile for a Frontend User');
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin('T3o.' . $_EXTKEY, 'Pi2', 'List profile for Frontend Users');
/**
* Static TypoScript
*/
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript',
'Main settings for userprofile');
/**
* Disable non needed fields in tt_content
*/
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist']['userprofile_pi1'] = 'select_key';
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist']['userprofile_pi2'] = 'select_key';
#
# Table structure for table 'fe_users'
#
CREATE TABLE fe_users (
privacy_settings text,
about_me text,
public_profile TINYINT,
);
......@@ -4,7 +4,7 @@ TYPO3 Frontend User Profile
## Quick installation
Please look at the manual for a big documentation at
Please look at the manual for a detailed documentation at