fields = ['amountMoney', 'amountTime', 'content']; //with title, list fields we can search in } public function limitUnsettled(string $type) { if ($type == Criminal::TYPE_FINE) { $column = 'd.amountMoney'; } elseif ($type == Criminal::TYPE_JAIL) { $column = 'd.amountTime'; } elseif ($type == Criminal::TYPE_COMMUNITY_WORK) { $column = 'd.amountCommunityWork'; } else { throw new \OutOfRangeException($type); } $settledColumn = $column . 'Settled'; $this->qb->andWhere("$column <> $settledColumn OR ($column IS NOT NULL AND $settledColumn IS NULL)"); return $this; } }