Skip to content

Commit

Permalink
Update method of checking friendship humhub/humhub#6745
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-rueegg committed Jan 17, 2024
1 parent 9a43a5c commit 076326c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
30 changes: 19 additions & 11 deletions integration/BirthdayCalendarQuery.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2018 HumHub GmbH & Co. KG
Expand All @@ -19,6 +20,7 @@
use humhub\modules\calendar\interfaces\event\FilterNotSupportedException;
use humhub\modules\calendar\models\SnippetModuleSettings;
use humhub\modules\content\components\ActiveQueryContent;
use humhub\modules\friendship\Module as FriendshipModule;
use humhub\modules\space\models\Membership;
use humhub\modules\space\models\Space;
use humhub\modules\user\models\User;
Expand All @@ -45,8 +47,8 @@ class BirthdayCalendarQuery extends AbstractCalendarQuery

protected function setupDateCriteria()
{
$from = $this->_from ?: (new \DateTime())->setTime(0,0,0);
$to = $this->_to ?: (new \DateTime())->setTime(0,0,0)->modify('+2 year');
$from = $this->_from ?: (new \DateTime())->setTime(0, 0, 0);
$to = $this->_to ?: (new \DateTime())->setTime(0, 0, 0)->modify('+2 year');

$fromYear = (int)$from->format('Y');
$toYear = (int)$to->format('Y');
Expand All @@ -65,23 +67,28 @@ protected function setupDateCriteria()
$this->_query->joinWith('profile');
$this->_query->addSelect(['profile.*', 'user.*']);
$this->_query->addSelect(new Expression($toOrFromBirthday . ' AS next_birthday'));
$this->_query->andWhere(new Expression($toOrFromBirthday . ' BETWEEN :fromDate AND :toDate'),
$this->_query->andWhere(
new Expression($toOrFromBirthday . ' BETWEEN :fromDate AND :toDate'),
[
':fromDate' => $from->format('Y-m-d'),
':toDate' => $to->format('Y-m-d')
]);

]
);
}

protected function filterDashboard()
{
if(SnippetModuleSettings::instance()->includeBirthdayToDashboard()) {
if (SnippetModuleSettings::instance()->includeBirthdayToDashboard()) {
return;
}

if (!Yii::$app->user->isGuest && Yii::$app->getModule('friendship')->isEnabled) {
$this->_query->innerJoin('user_friendship', 'user.id=user_friendship.friend_user_id AND user_friendship.user_id=:userId',
[':userId' => Yii::$app->user->id]);
$module = Yii::$app->getModule('friendship');
if (!Yii::$app->user->isGuest && $module instanceof FriendshipModule && $module->isFriendshipEnabled()) {
$this->_query->innerJoin(
'user_friendship',
'user.id=user_friendship.friend_user_id AND user_friendship.user_id=:userId',
[':userId' => Yii::$app->user->id]
);
} else {
throw new FilterNotSupportedException('Global filter not supported for this query');
}
Expand Down Expand Up @@ -115,7 +122,8 @@ protected function filterFollowedUsersCondition(&$conditions = [])
$friendshipSubQuery = (new Query())->select('user_friendship.friend_user_id')->from('user_friendship')->where(['user_friendship.user_id' => Yii::$app->user->id]);
$followerSubQuery = (new Query())->select('user_follow.object_id')->from('user_follow')->where(['user_follow.user_id' => Yii::$app->user->id])->andWhere(['object_model' => User::class]);

if (!Yii::$app->user->isGuest && Yii::$app->getModule('friendship')->isEnabled) {
$module = Yii::$app->getModule('friendship');
if (!Yii::$app->user->isGuest && $module instanceof FriendshipModule && $module->isFriendshipEnabled()) {
$conditions[] = ['in', 'profile.user_id', $friendshipSubQuery];
$conditions[] = ['in', 'profile.user_id', $followerSubQuery];
} else {
Expand Down Expand Up @@ -145,4 +153,4 @@ public function filterMine()
{
$this->_query->andWhere(['profile.user_id' => Yii::$app->user->id]);
}
}
}
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"keywords": ["calendar"],
"version": "1.5.7",
"humhub": {
"minVersion": "1.14"
"minVersion": "1.16"
},
"homepage": "https://github.com/humhub/calendar",
"authors": [
Expand Down

0 comments on commit 076326c

Please sign in to comment.