mirror of
https://github.com/humhub/humhub.git
synced 2025-02-12 03:26:25 +01:00
Merge pull request #4165 from humhub/feature/show-user-email
Show users email in profile (#4003)
This commit is contained in:
commit
b24cc27add
@ -32,25 +32,39 @@ use yii\helpers\Url;
|
||||
'class' => CheckboxColumn::class,
|
||||
'label' => Yii::t('UserModule.profile', 'Required'),
|
||||
'attribute' => 'required',
|
||||
|
||||
'content' => function (ProfileField $model, $key, $index, $that) {
|
||||
if ($model->getFieldType()->isVirtual) {
|
||||
return '';
|
||||
}
|
||||
return $that->getDataCellValue($model, $key, $index);
|
||||
}
|
||||
],
|
||||
[
|
||||
'class' => CheckboxColumn::class,
|
||||
'label' => Yii::t('UserModule.profile', 'Visible'),
|
||||
'attribute' => 'visible',
|
||||
|
||||
],
|
||||
[
|
||||
'class' => CheckboxColumn::class,
|
||||
'label' => Yii::t('UserModule.profile', 'Editable'),
|
||||
'attribute' => 'editable',
|
||||
|
||||
'content' => function (ProfileField $model, $key, $index, $that) {
|
||||
if ($model->getFieldType()->isVirtual) {
|
||||
return '';
|
||||
}
|
||||
return $that->getDataCellValue($model, $key, $index);
|
||||
}
|
||||
],
|
||||
[
|
||||
'class' => CheckboxColumn::class,
|
||||
'label' => Yii::t('UserModule.profile', 'Searchable'),
|
||||
'attribute' => 'searchable',
|
||||
|
||||
'content' => function (ProfileField $model, $key, $index, $that) {
|
||||
if ($model->getFieldType()->isVirtual) {
|
||||
return '';
|
||||
}
|
||||
return $that->getDataCellValue($model, $key, $index);
|
||||
}
|
||||
],
|
||||
[
|
||||
'header' => Yii::t('base', 'Actions'),
|
||||
|
@ -279,6 +279,16 @@ class InitialData
|
||||
$field->fieldType->save();
|
||||
}
|
||||
|
||||
$field = new ProfileField();
|
||||
$field->internal_name = "email_virtual";
|
||||
$field->title = 'E-Mail';
|
||||
$field->sort_order = 350;
|
||||
$field->profile_field_category_id = $cCommunication->id;
|
||||
$field->field_type_class = \humhub\modules\user\models\fieldtype\UserEmail::class;
|
||||
if ($field->save()) {
|
||||
$field->fieldType->save();
|
||||
}
|
||||
|
||||
$field = new ProfileField();
|
||||
$field->internal_name = "fax";
|
||||
$field->title = 'Fax';
|
||||
|
@ -80,6 +80,9 @@ class Profile extends ActiveRecord
|
||||
];
|
||||
|
||||
foreach (ProfileField::find()->all() as $profileField) {
|
||||
if ($profileField->getFieldType()->isVirtual) {
|
||||
continue;
|
||||
}
|
||||
$rules = array_merge($rules, $profileField->getFieldType()->getFieldRules());
|
||||
}
|
||||
|
||||
@ -154,6 +157,7 @@ class Profile extends ActiveRecord
|
||||
Yii::t('UserModule.profile', 'Phone Private');
|
||||
Yii::t('UserModule.profile', 'Phone Work');
|
||||
Yii::t('UserModule.profile', 'Mobile');
|
||||
Yii::t('UserModule.profile', 'E-Mail');
|
||||
Yii::t('UserModule.profile', 'Fax');
|
||||
Yii::t('UserModule.profile', 'Skype Nickname');
|
||||
Yii::t('UserModule.profile', 'MSN');
|
||||
@ -167,7 +171,6 @@ class Profile extends ActiveRecord
|
||||
Yii::t('UserModule.profile', 'Vimeo URL');
|
||||
Yii::t('UserModule.profile', 'Flickr URL');
|
||||
Yii::t('UserModule.profile', 'MySpace URL');
|
||||
Yii::t('UserModule.profile', 'Google+ URL');
|
||||
Yii::t('UserModule.profile', 'Twitter URL');
|
||||
}
|
||||
|
||||
@ -256,6 +259,10 @@ class Profile extends ActiveRecord
|
||||
public function beforeSave($insert)
|
||||
{
|
||||
foreach (ProfileField::find()->all() as $profileField) {
|
||||
/** @var ProfileField $profileField */
|
||||
if ($profileField->getFieldType()->isVirtual) {
|
||||
continue;
|
||||
}
|
||||
$key = $profileField->internal_name;
|
||||
$this->$key = $profileField->getFieldType()->beforeProfileSave($this->$key);
|
||||
}
|
||||
|
@ -166,8 +166,11 @@ class ProfileField extends ActiveRecord
|
||||
*/
|
||||
public function getFormDefinition()
|
||||
{
|
||||
|
||||
$categories = ProfileFieldCategory::find()->orderBy('sort_order')->all();
|
||||
$profileFieldTypes = new fieldtype\BaseType();
|
||||
$isVirtualField = (!$this->isNewRecord && $this->getFieldType()->isVirtual);
|
||||
|
||||
$definition = [
|
||||
'ProfileField' => [
|
||||
'type' => 'form',
|
||||
@ -203,21 +206,26 @@ class ProfileField extends ActiveRecord
|
||||
'type' => 'text',
|
||||
'maxlength' => 255,
|
||||
'class' => 'form-control',
|
||||
'isVisible' => (!$isVirtualField)
|
||||
],
|
||||
'required' => [
|
||||
'type' => 'checkbox',
|
||||
'isVisible' => (!$isVirtualField)
|
||||
],
|
||||
'visible' => [
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
'show_at_registration' => [
|
||||
'type' => 'checkbox',
|
||||
'isVisible' => (!$isVirtualField)
|
||||
],
|
||||
'editable' => [
|
||||
'type' => 'checkbox',
|
||||
'isVisible' => (!$isVirtualField)
|
||||
],
|
||||
'searchable' => [
|
||||
'type' => 'checkbox',
|
||||
'isVisible' => (!$isVirtualField)
|
||||
],
|
||||
'profile_field_category_id' => [
|
||||
'type' => 'dropdownlist',
|
||||
|
@ -22,6 +22,9 @@ use yii\helpers\Json;
|
||||
*
|
||||
* @package humhub.modules_core.user.models
|
||||
* @since 0.5
|
||||
*
|
||||
* @property array $fieldFormDefinition
|
||||
* @property array $labels
|
||||
*/
|
||||
class BaseType extends Model
|
||||
{
|
||||
@ -43,6 +46,14 @@ class BaseType extends Model
|
||||
*/
|
||||
public $profileField = null;
|
||||
|
||||
|
||||
/**
|
||||
* @var boolean is a virtual field (readonly)
|
||||
* @see BaseTypeVirtual
|
||||
* @since 1.6
|
||||
*/
|
||||
public $isVirtual = false;
|
||||
|
||||
/**
|
||||
* Links a ProfileField to the ProfileFieldType.
|
||||
*
|
||||
@ -73,6 +84,7 @@ class BaseType extends Model
|
||||
MarkdownEditor::class => Yii::t('UserModule.profile', 'Markdown'),
|
||||
Checkbox::class => Yii::t('UserModule.profile', 'Checkbox'),
|
||||
CheckboxList::class => Yii::t('UserModule.profile', 'Checkbox List'),
|
||||
UserEmail::class => Yii::t('UserModule.profile', 'E-mail address of the user'),
|
||||
], $this->fieldTypes);
|
||||
|
||||
return $fieldTypes;
|
||||
@ -113,16 +125,13 @@ class BaseType extends Model
|
||||
*/
|
||||
public function getFieldFormDefinition()
|
||||
{
|
||||
|
||||
$definition = [
|
||||
return [
|
||||
$this->profileField->internal_name => [
|
||||
'type' => 'text',
|
||||
'class' => 'form-control',
|
||||
'readonly' => (!$this->profileField->editable)
|
||||
]
|
||||
];
|
||||
|
||||
return $definition;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2020 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
namespace humhub\modules\user\models\fieldtype;
|
||||
|
||||
use humhub\modules\user\models\User;
|
||||
|
||||
/**
|
||||
* Base type for virtual profile fields
|
||||
*
|
||||
* Virtual profile fields are read-only and can be used to display content
|
||||
* from other sources (e.g. user table).
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
abstract class BaseTypeVirtual extends BaseType
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $isVirtual = true;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
final public function getUserValue($user, $raw = true)
|
||||
{
|
||||
return $this->getVirtualUserValue($user, $raw);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getFormDefinition($definition = [])
|
||||
{
|
||||
return parent::getFormDefinition([
|
||||
get_class($this) => [
|
||||
'type' => 'form',
|
||||
'title' => '',
|
||||
'elements' => []
|
||||
]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getFieldFormDefinition()
|
||||
{
|
||||
return [$this->profileField->internal_name => [
|
||||
'type' => 'hidden',
|
||||
'isVisible' => false,
|
||||
]];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the readonly virutal value for the given User
|
||||
*
|
||||
* @param User $user
|
||||
* @param bool $raw
|
||||
* @return mixed
|
||||
*/
|
||||
abstract protected function getVirtualUserValue($user, $raw = true);
|
||||
}
|
37
protected/humhub/modules/user/models/fieldtype/UserEmail.php
Normal file
37
protected/humhub/modules/user/models/fieldtype/UserEmail.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2020 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
namespace humhub\modules\user\models\fieldtype;
|
||||
|
||||
use humhub\libs\Html;
|
||||
|
||||
/**
|
||||
* UserEmail is a virtual profile field
|
||||
* that displays the current email address of the user.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class UserEmail extends BaseTypeVirtual
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getVirtualUserValue($user, $raw = true)
|
||||
{
|
||||
if (empty($user->email)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($raw) {
|
||||
return Html::encode($user->email);
|
||||
} else {
|
||||
return Html::a(Html::encode($user->email), 'mailto:' . $user->email);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user