$newRow = $this->db->table(self::TABLE_NAME);
$rows = $this->db->table(self::TABLE_NAME);
$newRow = $this->db->table(self::TABLE_NAME);
$rows = $this->db->table(self::TABLE_NAME);
if ($showActiveOnly == 1) {
$newRow = $rows->where(array('status' => 'dodano'));
}
$rows = $this->db->table(self::TABLE_NAME);
if($showNotAdded == 1){
$newRow = $rows->where(array('status' => 'nedodano'));
}
$rows = $this->db->table(self::TABLE_NAME);
if($showHalfAdded == 1){
$newRow = $rows->where(array('status' => 'casdodano'));
}
$rows = $this->db->table(self::TABLE_NAME);
if($showDeclined == 1){
$newRow = $rows->where(array('status' => 'storno'));
}
return $newRow;
public function filter($showActiveOnly, $showNotAdded, $showHalfAdded, $showDeclined)
{
$newRow = $this->db->table(self::TABLE_NAME);
$rows = $this->db->table(self::TABLE_NAME);
if ($showActiveOnly == 1) {
$newRow = $rows->where(array('status' => 'dodano'));
}
$rows = $this->db->table(self::TABLE_NAME);
if($showNotAdded == 1){
$newRow = $rows->where(array('status' => 'nedodano'));
}
$rows = $this->db->table(self::TABLE_NAME);
if($showHalfAdded == 1){
$newRow = $rows->where(array('status' => 'casdodano'));
}
$rows = $this->db->table(self::TABLE_NAME);
if($showDeclined == 1){
$newRow = $rows->where(array('status' => 'storno'));
}
return $newRow;
}
public function filter($showActiveOnly, $showNotAdded, $showHalfAdded, $showDeclined)
{
$newRow = [];
$statuses = [
'dodano' => $showActiveOnly,
'nedodano' => $showNotAdded,
'casdodano' => $showHalfAdded,
'storno' => $showDeclined,
];
foreach ($statuses as $status => $addFilter) {
if ($addFilter) {
$newRow[$status] = $this->db->table(self::TABLE_NAME)->where(array('status' => $status));
}
}
return $newRow ?: $this->db->table(self::TABLE_NAME);
}
public function filter($showActiveOnly, $showNotAdded, $showHalfAdded, $showDeclined)
{
$table = $this->db->table(self::TABLE_NAME);
$inArray = $this->getFilterInArray($showActiveOnly, $showNotAdded, $showHalfAdded, $showDeclined);
return empty($inArray) ? $table : $table->where('status', $inArray);
}
private function getFilterInArray($showActiveOnly, $showNotAdded, $showHalfAdded, $showDeclined): array
{
$statuses = [
'dodano' => $showActiveOnly,
'nedodano' => $showNotAdded,
'casdodano' => $showHalfAdded,
'storno' => $showDeclined,
];
return array_filter($statuses, static fn (bool $value): bool => $value);
//return array_filter($statuses, static function(bool $value) {return $value});
}