protected function setupSubjects()
    {
        $subjects = $this->makeSubjectsArrayForPPN($this->rootPPN);

        // Figure out selected subjects from the request’s arguments. Subject argument names
        // are "pz2subject-x0-x1-x2-..." where xi is the index of the subject group
        // at level i.
        if ($this->requestArguments['button']) {
            $selectedCheckboxes = [];
            // Our form was submitted: use form values only.
            foreach ($this->requestArguments as $argumentName => $argument) {
                $fieldNameStart = 'pz2subject-';
                if (($argument != '') && (strpos($argumentName, $fieldNameStart) === 0)) {
                    $nameParts = explode('-', substr($argumentName, strlen($fieldNameStart)));
                    if (count($nameParts) > 0) {
                        $mySubjects =& $subjects;
                        while (count($nameParts) > 1) {
                            $subjectIndex = intval(array_shift($nameParts));
                            $mySubjects =& $mySubjects[$subjectIndex]['subjects'];
                        }

                        $subjectIndex = intval(array_shift($nameParts));
                        $subject =& $mySubjects[$subjectIndex];
                        $subject['selected'] = true;
                        $selectedCheckboxes[] = implode(',', $subject['queries']);
                    }
                }
            }

            // Also write the selected values to our cookie.
            $cookieString = implode(':', $selectedCheckboxes);
            setcookie('pz2neuerwerbungen-previousQuery', $cookieString);
        } else {
            // Our form was not submitted: use cookie to set the selected checkboxes.
            $previousQuery = $_COOKIE['pz2neuerwerbungen-previousQuery'];
            $queryItems = explode(':', $previousQuery);

            // Turn on the selection for each group if its queries have been
            // passed in the cookie xor for each included subject if its queries
            // have been passed in the cookie.
            foreach ($subjects as &$group) {
                $queriesString = implode(',', $group['queries']);
                if (in_array($queriesString, $queryItems)) {
                    $group['selected'] = true;
                } else {
                    foreach ($group['subjects'] as &$subject) {
                        $queriesString = implode(',', $subject['queries']);
                        if (in_array($queriesString, $queryItems)) {
                            $subject['selected'] = true;
                        }
                    }
                }
            }
        }

        // Turn on the checkbox if there only is a single one.
        if (count($subjects) === 1 && count($subjects[0]['subjects'] === 1)) {
            $subjects[0]['subjects'][0]['selected'] = true;
        }

        // Turn on the selection for the group if all containing subjects are selected.
        foreach ($subjects as &$group) {
            $this->turnOnGroupSelectionIfNeeded($group);
        }

        // Turn on the selection for all included subjects if the containing group is selected.
        foreach ($subjects as &$group) {
            $this->turnOnChildSelectionIfNeeded($group);
        }

        $this->subjects = $subjects;
    }