-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Search provider * Search provider * Remove unused classes * Fix meta search for old HumHub version
- Loading branch information
1 parent
cf55fd6
commit 1bcc0c4
Showing
10 changed files
with
255 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
/** | ||
* @link https://www.humhub.org/ | ||
* @copyright Copyright (c) HumHub GmbH & Co. KG | ||
* @license https://www.humhub.com/licences | ||
*/ | ||
|
||
namespace humhub\modules\mail\search; | ||
|
||
use humhub\interfaces\MetaSearchProviderInterface; | ||
use humhub\modules\mail\models\forms\InboxFilterForm; | ||
use humhub\services\MetaSearchService; | ||
use Yii; | ||
|
||
/** | ||
* Mail Meta Search Provider | ||
*/ | ||
class SearchProvider implements MetaSearchProviderInterface | ||
{ | ||
private ?MetaSearchService $service = null; | ||
public ?string $keyword = null; | ||
public string|array|null $route = '/mail/mail/index'; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getName(): string | ||
{ | ||
return Yii::t('MailModule.base', 'Messages'); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getSortOrder(): int | ||
{ | ||
return 400; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getRoute(): string|array | ||
{ | ||
return $this->route; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getAllResultsText(): string | ||
{ | ||
return $this->getService()->hasResults() | ||
? Yii::t('base', 'Show all results') | ||
: Yii::t('MailModule.base', 'Advanced Messages Search'); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getIsHiddenWhenEmpty(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getResults(int $maxResults): array | ||
{ | ||
$filter = new InboxFilterForm(['term' => $this->getKeyword()]); | ||
$filter->apply(); | ||
$totalCount = $filter->query->count(); | ||
$resultsQuery = $filter->query->limit($maxResults); | ||
|
||
$results = []; | ||
foreach ($resultsQuery->all() as $userMessage) { | ||
$results[] = new SearchRecord($userMessage); | ||
} | ||
|
||
return [ | ||
'totalCount' => $totalCount, | ||
'results' => $results, | ||
]; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getService(): MetaSearchService | ||
{ | ||
if ($this->service === null) { | ||
$this->service = new MetaSearchService($this); | ||
} | ||
|
||
return $this->service; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getKeyword(): ?string | ||
{ | ||
return $this->keyword; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* @link https://www.humhub.org/ | ||
* @copyright Copyright (c) HumHub GmbH & Co. KG | ||
* @license https://www.humhub.com/licences | ||
*/ | ||
|
||
namespace humhub\modules\mail\search; | ||
|
||
use humhub\interfaces\MetaSearchResultInterface; | ||
use humhub\modules\mail\helpers\Url; | ||
use humhub\modules\mail\models\UserMessage; | ||
use humhub\modules\mail\widgets\InboxMessagePreview; | ||
use humhub\modules\ui\icon\widgets\Icon; | ||
use humhub\modules\user\models\User; | ||
use humhub\modules\user\widgets\Image; | ||
|
||
/** | ||
* Search Record for Message Entry | ||
*/ | ||
class SearchRecord implements MetaSearchResultInterface | ||
{ | ||
public ?InboxMessagePreview $preview = null; | ||
|
||
public function __construct(UserMessage $userMessage) | ||
{ | ||
$this->preview = new InboxMessagePreview(['userMessage' => $userMessage]); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getImage(): string | ||
{ | ||
$lastParticipant = $this->preview->lastParticipant(); | ||
|
||
if ($lastParticipant instanceof User) { | ||
return Image::widget([ | ||
'user' => $lastParticipant, | ||
'width' => 36, | ||
'link' => false, | ||
'hideOnlineStatus' => true, | ||
]); | ||
} | ||
|
||
return Icon::get('envelope'); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getTitle(): string | ||
{ | ||
return $this->preview->getMessage()->title; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getDescription(): string | ||
{ | ||
return $this->preview->getMessagePreview(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getUrl(): string | ||
{ | ||
return Url::toMessenger($this->preview->getMessage()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.