mirror of
https://github.com/humhub/humhub.git
synced 2025-01-29 12:28:06 +01:00
Template optimization directory "Members"
This commit is contained in:
parent
19fb4f40e3
commit
f7fc790eb5
@ -1,116 +1,71 @@
|
||||
<?php
|
||||
/* @var $this \yii\web\View */
|
||||
/* @var $keyword string */
|
||||
/* @var $group humhub\modules\user\models\Group */
|
||||
/* @var $users humhub\modules\user\models\User[] */
|
||||
/* @var $pagination yii\data\Pagination */
|
||||
|
||||
use yii\helpers\Url;
|
||||
use yii\helpers\Html;
|
||||
use humhub\modules\friendship\models\Friendship;
|
||||
use humhub\modules\user\widgets\Image;
|
||||
use humhub\modules\directory\widgets\MemberActionsButton;
|
||||
use humhub\modules\directory\widgets\UserTagList;
|
||||
use humhub\modules\directory\widgets\UserGroupList;
|
||||
?>
|
||||
<div class="panel panel-default">
|
||||
|
||||
<div class="panel-heading">
|
||||
<?php if ($group === null) : ?>
|
||||
<?php echo Yii::t('DirectoryModule.base', '<strong>Member</strong> directory'); ?>
|
||||
<?= Yii::t('DirectoryModule.base', '<strong>Member</strong> directory'); ?>
|
||||
<?php else: ?>
|
||||
<?php echo Yii::t('DirectoryModule.base', '<strong>Group</strong> members - {group}', ['{group}' => $group->name]); ?>
|
||||
<?= Yii::t('DirectoryModule.base', '<strong>Group</strong> members - {group}', ['{group}' => Html::encode($group->name)]); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="panel-body">
|
||||
|
||||
<!-- search form -->
|
||||
<?php echo Html::beginForm(Url::to(['/directory/directory/members']), 'get', array('class' => 'form-search')); ?>
|
||||
<?= Html::beginForm('', 'get', ['class' => 'form-search']); ?>
|
||||
<div class="row">
|
||||
<div class="col-md-3"></div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group form-group-search">
|
||||
<?php echo Html::textInput("keyword", $keyword, array("class" => "form-control form-search", "placeholder" => Yii::t('DirectoryModule.base', 'search for members'))); ?>
|
||||
<?php echo Html::submitButton(Yii::t('DirectoryModule.base', 'Search'), array('class' => 'btn btn-default btn-sm form-button-search')); ?>
|
||||
<?= Html::textInput("keyword", $keyword, ['class' => 'form-control form-search', 'placeholder' => Yii::t('DirectoryModule.base', 'search for members')]); ?>
|
||||
<?= Html::submitButton(Yii::t('DirectoryModule.base', 'Search'), ['class' => 'btn btn-default btn-sm form-button-search']); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3"></div>
|
||||
</div>
|
||||
<?php echo Html::endForm(); ?>
|
||||
<?= Html::endForm(); ?>
|
||||
|
||||
<?php if (count($users) == 0): ?>
|
||||
<p><?php echo Yii::t('DirectoryModule.base', 'No members found!'); ?></p>
|
||||
<p><?= Yii::t('DirectoryModule.base', 'No members found!'); ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<ul class="media-list">
|
||||
<!-- BEGIN: Results -->
|
||||
<?php foreach ($users as $user) : ?>
|
||||
<li>
|
||||
<div class="media">
|
||||
|
||||
<!-- Follow Handling -->
|
||||
<div class="pull-right">
|
||||
<?=
|
||||
\humhub\modules\user\widgets\UserFollowButton::widget([
|
||||
'user' => $user,
|
||||
'followOptions' => ['class' => 'btn btn-primary btn-sm'],
|
||||
'unfollowOptions' => ['class' => 'btn btn-info btn-sm']
|
||||
]);
|
||||
?>
|
||||
|
||||
<?php
|
||||
if (!Yii::$app->user->isGuest && !$user->isCurrentUser() && Yii::$app->getModule('friendship')->getIsEnabled()) {
|
||||
$friendShipState = Friendship::getStateForUser(Yii::$app->user->getIdentity(), $user);
|
||||
if ($friendShipState === Friendship::STATE_NONE) {
|
||||
echo Html::a('<span class="glyphicon glyphicon-plus"></span> ' . Yii::t("FriendshipModule.base", "Add Friend"), Url::to(['/friendship/request/add', 'userId' => $user->id]), array('class' => 'btn btn-primary btn-sm', 'data-method' => 'POST'));
|
||||
} elseif ($friendShipState === Friendship::STATE_FRIENDS) {
|
||||
echo Html::a('<span class="glyphicon glyphicon-ok"></span> ' . Yii::t("FriendshipModule.base", "Friends"), $user->getUrl(), ['class' => 'btn btn-info btn-sm']);
|
||||
}
|
||||
}
|
||||
?>
|
||||
<div class="pull-right memberActions">
|
||||
<?= MemberActionsButton::widget(['user' => $user]); ?>
|
||||
</div>
|
||||
|
||||
<a href="<?php echo $user->getUrl(); ?>" class="pull-left">
|
||||
<img class="media-object img-rounded"
|
||||
src="<?php echo $user->getProfileImage()->getUrl(); ?>" width="50"
|
||||
height="50" alt="50x50" data-src="holder.js/50x50"
|
||||
style="width: 50px; height: 50px;">
|
||||
</a>
|
||||
|
||||
|
||||
<?= Image::widget(['user' => $user, 'htmlOptions' => ['class' => 'pull-left']]); ?>
|
||||
<div class="media-body">
|
||||
<h4 class="media-heading"><a
|
||||
href="<?php echo $user->getUrl(); ?>"><?php echo Html::encode($user->displayName); ?></a>
|
||||
<?php if ($user->hasGroup()) : ?>
|
||||
<small>(<?=
|
||||
implode(', ', array_map(function($g) {
|
||||
return Html::encode($g->name);
|
||||
}, $user->groups));
|
||||
?>)</small>
|
||||
<?php endif; ?>
|
||||
<h4 class="media-heading">
|
||||
<a href="<?= $user->getUrl(); ?>"><?= Html::encode($user->displayName); ?></a>
|
||||
<?= UserGroupList::widget(['user' => $user]); ?>
|
||||
</h4>
|
||||
<h5><?php echo Html::encode($user->profile->title); ?></h5>
|
||||
|
||||
<?php $tag_count = 0; ?>
|
||||
<?php if ($user->hasTags()) : ?>
|
||||
<?php foreach ($user->getTags() as $tag): ?>
|
||||
<?php if ($tag_count <= 5) { ?>
|
||||
<?php echo Html::a(Html::encode($tag), Url::to(['/directory/directory/members', 'keyword' => $tag]), array('class' => 'label label-default')); ?>
|
||||
<?php
|
||||
$tag_count++;
|
||||
}
|
||||
?>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<h5><?= Html::encode($user->profile->title); ?></h5>
|
||||
<?= UserTagList::widget(['user' => $user]); ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<?php endforeach; ?>
|
||||
<!-- END: Results -->
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="pagination-container">
|
||||
<?php echo \humhub\widgets\LinkPager::widget(['pagination' => $pagination]); ?>
|
||||
<?= \humhub\widgets\LinkPager::widget(['pagination' => $pagination]); ?>
|
||||
</div>
|
||||
|
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
namespace humhub\modules\directory\widgets;
|
||||
|
||||
use humhub\components\Widget;
|
||||
|
||||
/**
|
||||
* MemberActionsButton shows directory options (following or friendship) for listed users
|
||||
*
|
||||
* @since 1.2
|
||||
* @author Luke
|
||||
*/
|
||||
class MemberActionsButton extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \humhub\modules\user\models\User
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
return $this->render('memberActionsButton', [
|
||||
'user' => $this->user
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
54
protected/humhub/modules/directory/widgets/UserGroupList.php
Normal file
54
protected/humhub/modules/directory/widgets/UserGroupList.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
namespace humhub\modules\directory\widgets;
|
||||
|
||||
use humhub\libs\Html;
|
||||
use humhub\components\Widget;
|
||||
|
||||
/**
|
||||
* UserGroupList displays a comma separated list of user groups
|
||||
*
|
||||
* @since 1.2
|
||||
* @author Luke
|
||||
*/
|
||||
class UserGroupList extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \humhub\modules\user\models\User
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* @var string Tag name for base HTML tag
|
||||
*/
|
||||
public $tagName = 'small';
|
||||
|
||||
/**
|
||||
* @var array the HTML Options fo the base Tag
|
||||
*/
|
||||
public $htmlOptions = [];
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
if (!$this->user->hasGroup()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$groupList = implode(', ', array_map(function($g) {
|
||||
return Html::encode($g->name);
|
||||
}, $this->user->groups));
|
||||
|
||||
return Html::tag($this->tagName, $groupList, $this->htmlOptions);
|
||||
}
|
||||
|
||||
}
|
58
protected/humhub/modules/directory/widgets/UserTagList.php
Normal file
58
protected/humhub/modules/directory/widgets/UserTagList.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
namespace humhub\modules\directory\widgets;
|
||||
|
||||
use humhub\libs\Html;
|
||||
use yii\helpers\Url;
|
||||
use humhub\components\Widget;
|
||||
|
||||
/**
|
||||
* UserTagList displays the user tags on the directory page
|
||||
*
|
||||
* @since 1.2
|
||||
* @author Luke
|
||||
*/
|
||||
class UserTagList extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \humhub\modules\user\models\User
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* @var int number of max. displayed tags
|
||||
*/
|
||||
public $maxTags = 5;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
|
||||
$tags = $this->user->getTags();
|
||||
|
||||
$count = count($tags);
|
||||
|
||||
if ($count === 0) {
|
||||
return;
|
||||
} elseif ($count > $this->maxTags) {
|
||||
$tags = array_slice($tags, 0, $this->maxTags);
|
||||
}
|
||||
|
||||
$html = '';
|
||||
foreach ($tags as $tag) {
|
||||
$html .= Html::a(Html::encode($tag), Url::to(['/directory/directory/members', 'keyword' => $tag]), ['class' => 'label label-default']) . " ";
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/* @var $this \yii\web\View */
|
||||
/* @var $user humhub\modules\user\models\User */
|
||||
|
||||
use humhub\modules\friendship\models\Friendship;
|
||||
use humhub\modules\user\widgets\UserFollowButton;
|
||||
use humhub\libs\Html;
|
||||
use yii\helpers\Url;
|
||||
?>
|
||||
<?=
|
||||
|
||||
UserFollowButton::widget([
|
||||
'user' => $user,
|
||||
'followOptions' => ['class' => 'btn btn-primary btn-sm'],
|
||||
'unfollowOptions' => ['class' => 'btn btn-info btn-sm']
|
||||
]);
|
||||
?>
|
||||
|
||||
<?php
|
||||
|
||||
if (!Yii::$app->user->isGuest && !$user->isCurrentUser() && Yii::$app->getModule('friendship')->getIsEnabled()) {
|
||||
$friendShipState = Friendship::getStateForUser(Yii::$app->user->getIdentity(), $user);
|
||||
if ($friendShipState === Friendship::STATE_NONE) {
|
||||
echo Html::a('<span class="glyphicon glyphicon-plus"></span> ' . Yii::t("FriendshipModule.base", "Add Friend"), Url::to(['/friendship/request/add', 'userId' => $user->id]), array('class' => 'btn btn-primary btn-sm', 'data-method' => 'POST'));
|
||||
} elseif ($friendShipState === Friendship::STATE_FRIENDS) {
|
||||
echo Html::a('<span class="glyphicon glyphicon-ok"></span> ' . Yii::t("FriendshipModule.base", "Friends"), $user->getUrl(), ['class' => 'btn btn-info btn-sm']);
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user