Skip to content

Commit

Permalink
Mail: Code cleanup (unused "ns" imports, code style)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansenDatabay committed Sep 19, 2024
1 parent 99fb6df commit ffed431
Show file tree
Hide file tree
Showing 10 changed files with 256 additions and 187 deletions.
12 changes: 7 additions & 5 deletions components/ILIAS/Mail/classes/Folder/MailFilterUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
class MailFilterUI
{
private FilterComponent $filter;
private ?string $sender;

public function __construct(
private readonly string $target_url,
Expand All @@ -48,7 +47,9 @@ public function __construct(
if ($this->folder->hasIncomingMails()) {
$inputs['sender'] = $this->ui_factory->input()->field()->text($this->lng->txt('mail_filter_sender'));
} else {
$inputs['recipients'] = $this->ui_factory->input()->field()->text($this->lng->txt('mail_filter_recipients'));
$inputs['recipients'] = $this->ui_factory->input()->field()->text(
$this->lng->txt('mail_filter_recipients')
);
}

$inputs['subject'] = $this->ui_factory->input()->field()->text($this->lng->txt('mail_filter_subject'));
Expand All @@ -66,16 +67,17 @@ public function __construct(
'with_attachment' => $this->lng->txt('mail_filter_show_with_attachments'),
'without_attachment' => $this->lng->txt('mail_filter_show_without_attachment')
]);
$inputs['period'] = $this->ui_factory->input()->field()->duration($this->lng->txt('mail_filter_period'))
->withTimezone($this->user_time_zone->getName());
$inputs['period'] = $this->ui_factory
->input()->field()->duration($this->lng->txt('mail_filter_period'))
->withTimezone($this->user_time_zone->getName());

$this->filter = $this->filter_service->standard(
self::class,
$this->target_url,
//elements
$inputs,
// initially rendered
array_map(fn($value) => true, $inputs),
array_map(fn($value): bool => true, $inputs),
false,
false
);
Expand Down
1 change: 1 addition & 0 deletions components/ILIAS/Mail/classes/Folder/MailFolderData.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function isSent(): bool
{
return $this->type === MailFolderType::SENT;
}

public function isTrash(): bool
{
return $this->type === MailFolderType::TRASH;
Expand Down
12 changes: 5 additions & 7 deletions components/ILIAS/Mail/classes/Folder/MailFolderSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

namespace ILIAS\Mail\Folder;

use Exception;
use ilSearchSettings;
use ilMailSearchResult;
use ilMailLuceneSearcher;
use ilMailLuceneQueryParser;
Expand Down Expand Up @@ -65,10 +63,10 @@ public function __construct(

if ($this->lucene_enabled && (
($this->filter->getSender() ?? '') !== '' ||
($this->filter->getRecipients() ?? '') !== '' ||
($this->filter->getSubject() ?? '') !== '' ||
($this->filter->getBody() ?? '') !== '' ||
($this->filter->getAttachment() ?? '') !== ''
($this->filter->getRecipients() ?? '') !== '' ||
($this->filter->getSubject() ?? '') !== '' ||
($this->filter->getBody() ?? '') !== '' ||
($this->filter->getAttachment() ?? '') !== ''
)) {
$query_parser = new ilMailLuceneQueryParser('');
$query_parser->setFields([
Expand Down Expand Up @@ -141,7 +139,6 @@ public function getPagedRecords(
?MailBoxOrderColumn $order_column,
?string $order_direction
): array {

return $this->mailbox_query
->withFilteredIds($this->getFilteredIds())
->withLimit($limit)
Expand All @@ -154,6 +151,7 @@ public function getPagedRecords(
/**
* Get the cached mail ids from a lucene search for selected filter criteria
* These will be used as additional filter for the mailbox query
* @return null|list<int>
*/
private function getFilteredIds(): ?array
{
Expand Down
54 changes: 33 additions & 21 deletions components/ILIAS/Mail/classes/Folder/MailFolderTableUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
use Psr\Http\Message\ServerRequestInterface;
use DateTimeImmutable;
use DateTimeZone;
use ILIAS\UI\Component\Symbol\Symbol;

class MailFolderTableUI implements \ILIAS\UI\Component\Table\DataRetrieval
{
Expand All @@ -64,7 +63,7 @@ class MailFolderTableUI implements \ILIAS\UI\Component\Table\DataRetrieval
private array $avatars = [];

/**
* @param MailFolderData[] $user_folders
* @param MailFolderData[] $user_folders
*/
public function __construct(
private readonly URLBuilder $url_builder,
Expand Down Expand Up @@ -216,13 +215,21 @@ private function getActions(): array

foreach ($this->user_folders as $target_folder) {
if ($target_folder->getFolderId() !== $this->current_folder->getFolderId()) {
$actions[self::ACTION_MOVE_TO . (string) $target_folder->getFolderId()] = $this->ui_factory->table()->action()->multi(
$this->lng->txt('mail_move_to') . ' ' . $target_folder->getTitle()
. ($target_folder->isTrash() ? ' (' . $this->lng->txt('delete') . ')' : ''),
$this->url_builder->withParameter($this->action_token, self::ACTION_MOVE_TO)
->withParameter($this->folder_token, (string) $target_folder->getFolderId()),
$this->row_id_token
);
$action_title = $this->lng->txt('mail_move_to') . ' ' . $target_folder->getTitle();
if ($target_folder->isTrash()) {
$action_title .= ' (' . $this->lng->txt('delete') . ')';
}

$actions[self::ACTION_MOVE_TO . $target_folder->getFolderId()] = $this->ui_factory
->table()
->action()
->multi(
$action_title,
$this->url_builder
->withParameter($this->action_token, self::ACTION_MOVE_TO)
->withParameter($this->folder_token, (string) $target_folder->getFolderId()),
$this->row_id_token
);
}
}

Expand Down Expand Up @@ -251,7 +258,6 @@ public function getRows(
?array $filter_data, // not used, because data is filtered by MailDataSearch
?array $additional_parameters // not used
): \Generator {

// mapping of table columns to allowed order columns of the mailbox query
$order_columns = [
'status' => MailBoxOrderColumn::STATUS,
Expand Down Expand Up @@ -304,9 +310,10 @@ public function getRows(
yield $row_builder->buildDataRow(
(string) $record->getMailId(),
$data
)
->withDisabledAction(self::ACTION_REPLY, !$record->hasPersonalSender())
->withDisabledAction(self::ACTION_DOWNLOAD_ATTACHMENT, !$record->hasAttachments());
)->withDisabledAction(self::ACTION_REPLY, !$record->hasPersonalSender())->withDisabledAction(
self::ACTION_DOWNLOAD_ATTACHMENT,
!$record->hasAttachments()
);
}
}

Expand Down Expand Up @@ -365,13 +372,15 @@ private function getSender(MailRecordData $record): string

if (!empty($user = ilMailUserCache::getUserObjectById($record->getSenderId()))) {
if ($user->hasPublicProfile()) {
return $this->ui_renderer->render($this->ui_factory->link()->standard(
$user->getPublicName(),
(string) $this->url_builder
->withParameter($this->action_token, self::ACTION_PROFILE)
->withParameter($this->row_id_token, (string) $record->getMailId())
->buildURI()
));
return $this->ui_renderer->render(
$this->ui_factory->link()->standard(
$user->getPublicName(),
(string) $this->url_builder
->withParameter($this->action_token, self::ACTION_PROFILE)
->withParameter($this->row_id_token, (string) $record->getMailId())
->buildURI()
)
);
}

return $user->getPublicName();
Expand All @@ -392,7 +401,10 @@ private function getSubject(MailRecordData $record): Link
return $this->ui_factory->link()->standard(
$this->refinery->encode()->htmlSpecialCharsAsEntities()->transform($record->getSubject()),
(string) $this->url_builder
->withParameter($this->action_token, $this->current_folder->isDrafts() ? self::ACTION_EDIT : self::ACTION_SHOW)
->withParameter(
$this->action_token,
$this->current_folder->isDrafts() ? self::ACTION_EDIT : self::ACTION_SHOW
)
->withParameter($this->row_id_token, (string) $record->getMailId())
->buildURI()
);
Expand Down
24 changes: 12 additions & 12 deletions components/ILIAS/Mail/classes/Message/MailBoxQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@
namespace ILIAS\Mail\Message;

use ilDBInterface;
use ilMail;
use ilDBConstants;
use DateTimeImmutable;
use DateTimeZone;
use ilTimeZone;
use ILIAS\Data\Order;
use ilUserSearchOptions;

Expand Down Expand Up @@ -269,10 +267,10 @@ public function query($short): array

if ($this->order_column === MailBoxOrderColumn::FROM) {
$query .= ' ORDER BY '
. ' u.firstname ' . $this->order_direction . ', '
. ' u.lastname ' . $this->order_direction . ', '
. ' u.login ' . $this->order_direction . ', '
. ' m.import_name ' . $this->order_direction;
. ' u.firstname ' . $this->order_direction . ', '
. ' u.lastname ' . $this->order_direction . ', '
. ' u.login ' . $this->order_direction . ', '
. ' m.import_name ' . $this->order_direction;
} else {
$query .= ' ORDER BY ' . $this->order_column->value . ' ' . $this->order_direction;
}
Expand Down Expand Up @@ -379,26 +377,28 @@ private function getWhere(): string

if ($this->has_attachment === true) {
$parts[] = '(m.attachments != ' . $this->db->quote(serialize(null), ilDBConstants::T_TEXT)
. ' AND m.attachments != ' . $this->db->quote(serialize([]), ilDBConstants::T_TEXT) . ')';
. ' AND m.attachments != ' . $this->db->quote(serialize([]), ilDBConstants::T_TEXT) . ')';
} elseif ($this->has_attachment === false) {
$parts[] = '(m.attachments = ' . $this->db->quote(serialize(null), ilDBConstants::T_TEXT)
. ' OR m.attachments = ' . $this->db->quote(serialize([]), ilDBConstants::T_TEXT) . ')';
. ' OR m.attachments = ' . $this->db->quote(serialize([]), ilDBConstants::T_TEXT) . ')';
}

if ($this->period_start !== null) {
$parts[] = 'm.send_time >= ' . $this->db->quote(
// convert to server time zone (set by ilias initialisation)
$this->period_start->setTimezone(new DateTimeZone(date_default_timezone_get()))
->format('Y-m-d H:i:s'),
$this->period_start
->setTimezone(new DateTimeZone(date_default_timezone_get()))
->format('Y-m-d H:i:s'),
ilDBConstants::T_TIMESTAMP
);
}

if ($this->period_end !== null) {
$parts[] = 'm.send_time <= ' . $this->db->quote(
// convert to server time zone (set by ilias initialisation)
$this->period_end->setTimezone(new DateTimeZone(date_default_timezone_get()))
->format('Y-m-d H:i:s'),
$this->period_end
->setTimezone(new DateTimeZone(date_default_timezone_get()))
->format('Y-m-d H:i:s'),
ilDBConstants::T_TIMESTAMP
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

namespace ILIAS\Mail\Placeholder;

use ilObjUser;
use ilLanguage;
use ilUserUtil;

Expand Down
Loading

0 comments on commit ffed431

Please sign in to comment.