<?php

if ( $show === 'a' ) {
    $and = '';
} elseif ( $show === 's' ) {
    $and = ' AND selected = 1';
} else {
    $and = ' AND selected = 0';
}

switch ( $view ) {
    case 'c' :
        $projectSelections = $db->run("SELECT * FROM selection WHERE projectId = ? AND na != 1 ORDER BY category, selected, title", $userProject['id']);
        $categories = array_values(array_unique(array_column($projectSelections, 'category')));
        foreach ( $projectSelections as $projectSelection ) {
            $selections[$projectSelection['category']][] = $projectSelection;
        }
        break;
    case 'r' :
        $projectSelections = $db->run("SELECT * FROM selection WHERE projectId = ? AND na != 1 ORDER BY room, selected, title", $userProject['id']);
        foreach ( $projectSelections as $projectSelection ) {
            $selections[$projectSelection['room']][] = $projectSelection;
        }

        $rooms = array_values(array_unique(array_column($projectSelections, 'room')));
        foreach ( $rooms as $room ) {
            // $counts[$room]['total'] = $db->cell("SELECT COUNT(id) FROM selection WHERE projectId = ? AND room = ? AND na != 1", $userProject['id'], $room);
            $counts[$room]['selected'] = $db->cell("SELECT COUNT(id) FROM selection WHERE projectId = ? AND room = ? AND na != 1 AND selected = 1", $userProject['id'], $room);
            $counts[$room]['unselected'] = $db->cell("SELECT COUNT(id) FROM selection WHERE projectId = ? AND room = ? AND na != 1 AND selected = 0", $userProject['id'], $room);
            $counts[$room]['priority'] = $db->cell("SELECT COUNT(id) FROM selection WHERE projectId = ? AND room = ? AND na != 1 AND selected = 0 AND priority = 1", $userProject['id'], $room);
        }

        break;
}
