Skip to content

Commit

Permalink
wip1
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Jul 9, 2024
1 parent 41f671c commit f94be8f
Show file tree
Hide file tree
Showing 30 changed files with 119 additions and 216 deletions.
3 changes: 1 addition & 2 deletions application/controllers/ChannelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public function init()

public function indexAction()
{
$channels = Channel::on($this->db)
->filter(Filter::equal('deleted', 'n'));
$channels = Channel::on($this->db);
$this->mergeTabs($this->Module()->getConfigTabs());
$this->getTabs()->activate('channels');

Expand Down
10 changes: 2 additions & 8 deletions application/controllers/ContactGroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ public function indexAction(): void

$query = Contactgroup::on(Database::get())
->columns(['id', 'name'])
->filter(Filter::all(
Filter::equal('id', $groupId),
Filter::equal('deleted', 'n')
));
->filter(Filter::equal('id', $groupId));

$group = $query->first();
if ($group === null) {
Expand All @@ -51,10 +48,7 @@ public function indexAction(): void

$contacts = $group
->contact
->filter(Filter::all(
Filter::equal('contactgroup_member.deleted', 'n'),
Filter::equal('deleted', 'n')
));
->filter(Filter::equal('contactgroup_member.deleted', 'n'));

$this->addControl($this->createPaginationControl($contacts));
$this->addControl($this->createLimitControl());
Expand Down
3 changes: 1 addition & 2 deletions application/controllers/ContactGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public function init(): void

public function indexAction(): void
{
$groups = Contactgroup::on(Database::get())
->filter(Filter::equal('deleted', 'n'));
$groups = Contactgroup::on(Database::get());

$limitControl = $this->createLimitControl();
$paginationControl = $this->createPaginationControl($groups);
Expand Down
3 changes: 1 addition & 2 deletions application/controllers/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public function init()
public function indexAction()
{
$contacts = Contact::on($this->db)
->withColumns('has_email')
->filter(Filter::equal('deleted', 'n'));
->withColumns('has_email');

$limitControl = $this->createLimitControl();
$paginationControl = $this->createPaginationControl($contacts);
Expand Down
11 changes: 3 additions & 8 deletions application/controllers/EventRuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,7 @@ public function fromDb(int $ruleId): array
{
$query = Rule::on(Database::get())
->columns(['id', 'name', 'object_filter'])
->filter(Filter::all(
Filter::equal('id', $ruleId),
Filter::equal('deleted', 'n')
));
->filter(Filter::equal('id', $ruleId));

$rule = $query->first();
if ($rule === null) {
Expand All @@ -165,8 +162,7 @@ public function fromDb(int $ruleId): array

$ruleEscalations = $rule
->rule_escalation
->withoutColumns(['changed_at', 'deleted'])
->filter(Filter::equal('deleted', 'n'));
->withoutColumns(['changed_at', 'deleted']);

foreach ($ruleEscalations as $re) {
foreach ($re as $k => $v) {
Expand All @@ -175,8 +171,7 @@ public function fromDb(int $ruleId): array

$escalationRecipients = $re
->rule_escalation_recipient
->withoutColumns(['changed_at', 'deleted'])
->filter(Filter::equal('deleted', 'n'));
->withoutColumns(['changed_at', 'deleted']);

foreach ($escalationRecipients as $recipient) {
$config[$re->getTableName()][$re->position]['recipient'][] = iterator_to_array($recipient);
Expand Down
3 changes: 1 addition & 2 deletions application/controllers/EventRulesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public function init()

public function indexAction(): void
{
$eventRules = Rule::on(Database::get())
->filter(Filter::equal('deleted', 'n'));
$eventRules = Rule::on(Database::get());

$limitControl = $this->createLimitControl();
$paginationControl = $this->createPaginationControl($eventRules);
Expand Down
5 changes: 1 addition & 4 deletions application/controllers/IncidentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ public function indexAction(): void

$contact = Contact::on(Database::get())
->columns('id')
->filter(Filter::all(
Filter::equal('username', $this->Auth()->getUser()->getUsername()),
Filter::equal('deleted', 'n')
))
->filter(Filter::equal('username', $this->Auth()->getUser()->getUsername()))
->first();

if ($contact !== null) {
Expand Down
33 changes: 1 addition & 32 deletions application/controllers/ScheduleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Icinga\Module\Notifications\Controllers;

use Icinga\Exception\Http\HttpNotFoundException;
use Icinga\Module\Notifications\Common\Database;
use Icinga\Module\Notifications\Common\Links;
use Icinga\Module\Notifications\Forms\MoveRotationForm;
Expand All @@ -27,10 +26,7 @@ public function indexAction(): void
$id = (int) $this->params->getRequired('id');

$query = Schedule::on(Database::get())
->filter(Filter::all(
Filter::equal('schedule.id', $id),
Filter::equal('schedule.deleted', 'n')
));
->filter(Filter::equal('schedule.id', $id));

/** @var ?Schedule $schedule */
$schedule = $query->first();
Expand Down Expand Up @@ -116,7 +112,6 @@ public function addAction(): void
public function addRotationAction(): void
{
$scheduleId = (int) $this->params->getRequired('schedule');
$this->assertScheduleExists($scheduleId);

$form = new RotationConfigForm($scheduleId, Database::get());
$form->setAction($this->getRequest()->getUrl()->setParam('showCompact')->getAbsoluteUrl());
Expand Down Expand Up @@ -150,7 +145,6 @@ public function editRotationAction(): void
{
$id = (int) $this->params->getRequired('id');
$scheduleId = (int) $this->params->getRequired('schedule');
$this->assertScheduleExists($scheduleId);

$form = new RotationConfigForm($scheduleId, Database::get());
$form->disableModeSelection();
Expand Down Expand Up @@ -214,29 +208,4 @@ public function suggestRecipientAction(): void

$this->getDocument()->addHtml($suggestions);
}

/**
* Assert that a schedule with the given ID exists
*
* @param int $id
*
* @return void
*
* @throws HttpNotFoundException If the schedule with the given ID does not exist
*/
private function assertScheduleExists(int $id): void
{
$query = Schedule::on(Database::get())
->columns('1')
->filter(Filter::all(
Filter::equal('schedule.id', $id),
Filter::equal('schedule.deleted', 'n')
));

/** @var ?Schedule $schedule */
$schedule = $query->first();
if ($schedule === null) {
$this->httpNotFound(t('Schedule not found'));
}
}
}
3 changes: 1 addition & 2 deletions application/controllers/SchedulesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class SchedulesController extends CompatController

public function indexAction(): void
{
$schedules = Schedule::on(Database::get())
->filter(Filter::equal('deleted', 'n'));
$schedules = Schedule::on(Database::get());

$limitControl = $this->createLimitControl();
$sortControl = $this->createSortControl(
Expand Down
3 changes: 1 addition & 2 deletions application/controllers/SourcesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public function init()
public function indexAction(): void
{
$sources = Source::on(Database::get())
->columns(['id', 'type', 'name'])
->filter(Filter::equal('deleted', 'n'));
->columns(['id', 'type', 'name']);

$limitControl = $this->createLimitControl();
$paginationControl = $this->createPaginationControl($sources);
Expand Down
14 changes: 4 additions & 10 deletions application/forms/ChannelForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,9 @@ protected function assemble()
if ($this->channelId !== null) {
$isInUse = RuleEscalationRecipient::on($this->db)
->columns('1')
->filter(Filter::all(
Filter::equal('deleted', 'n'),
Filter::any(
Filter::equal('channel_id', $this->channelId),
Filter::equal('contact.default_channel_id', $this->channelId)
)
->filter(Filter::any(
Filter::equal('channel_id', $this->channelId),
Filter::equal('contact.default_channel_id', $this->channelId)
))
->first();

Expand Down Expand Up @@ -418,10 +415,7 @@ private function fetchDbValues(): array
{
/** @var Channel $channel */
$channel = Channel::on($this->db)
->filter(Filter::all(
Filter::equal('id', $this->channelId),
Filter::equal('deleted', 'n')
))
->filter(Filter::equal('id', $this->channelId))
->first();

if ($channel === null) {
Expand Down
15 changes: 3 additions & 12 deletions application/forms/ContactGroupForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,7 @@ public function removeContactgroup(): void
->filter(
Filter::all(
Filter::equal('rotation_id', $rotationIds),
Filter::unequal('contactgroup_id', $this->contactgroupId),
Filter::equal('deleted', 'n')
Filter::unequal('contactgroup_id', $this->contactgroupId)
)
)->assembleSelect()
);
Expand Down Expand Up @@ -353,22 +352,14 @@ private function fetchDbValues(): array
{
$query = Contactgroup::on($this->db)
->columns(['id', 'name'])
->filter(Filter::all(
Filter::equal('id', $this->contactgroupId),
Filter::equal('deleted', 'n')
));
->filter(Filter::equal('id', $this->contactgroupId));

$group = $query->first();
if ($group === null) {
throw new HttpNotFoundException($this->translate('Contact group not found'));
}

$contacts = Contact::on(Database::get())
->filter(Filter::all(
Filter::equal('contactgroup_member.contactgroup_id', $group->id),
Filter::equal('contactgroup_member.deleted', 'n'),
Filter::equal('deleted', 'n')
));
$contacts = $group->contact->filter(Filter::equal('contactgroup_member.deleted', 'n'));

$groupMembers = [];
foreach ($contacts as $contact) {
Expand Down
6 changes: 3 additions & 3 deletions application/forms/EscalationRecipientForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public function __construct(?int $count)
protected function fetchOptions(): array
{
$options = [];
foreach (Contact::on(Database::get())->filter(Filter::equal('deleted', 'n')) as $contact) {
foreach (Contact::on(Database::get()) as $contact) {
$options['Contacts']['contact_' . $contact->id] = $contact->full_name;
}

foreach (Contactgroup::on(Database::get())->filter(Filter::equal('deleted', 'n')) as $contactgroup) {
foreach (Contactgroup::on(Database::get()) as $contactgroup) {
$options['Contact Groups']['contactgroup_' . $contactgroup->id] = $contactgroup->name;
}

foreach (Schedule::on(Database::get())->filter(Filter::equal('deleted', 'n')) as $schedule) {
foreach (Schedule::on(Database::get()) as $schedule) {
$options['Schedules']['schedule_' . $schedule->id] = $schedule->name;
}

Expand Down
7 changes: 1 addition & 6 deletions application/forms/MoveRotationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ protected function onSuccess()
/** @var ?Rotation $rotation */
$rotation = Rotation::on($this->db)
->columns(['schedule_id', 'priority'])
->filter(Filter::all(
Filter::equal('id', $rotationId),
Filter::equal('deleted', 'n')
))
->filter(Filter::equal('id', $rotationId))
->first();
if ($rotation === null) {
throw new HttpNotFoundException('Rotation not found');
Expand All @@ -114,7 +111,6 @@ protected function onSuccess()
->columns('id')
->from('rotation')
->where([
'deleted = ?' => 'n',
'schedule_id = ?' => $rotation->schedule_id,
'priority >= ?' => $newPriority,
'priority < ?' => $rotation->priority
Expand All @@ -134,7 +130,6 @@ protected function onSuccess()
->columns('id')
->from('rotation')
->where([
'deleted = ?' => 'n',
'schedule_id = ?' => $rotation->schedule_id,
'priority > ?' => $rotation->priority,
'priority <= ?' => $newPriority
Expand Down
Loading

0 comments on commit f94be8f

Please sign in to comment.