Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v1.16] Update method of checking friendship humhub/humhub#6745 #442

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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