SubsectionManager::__filterEntries PHP Method

__filterEntries() private method

private __filterEntries ( $subsection_id, $fields, $filter = '', $items = NULL, $full = false )
    private function __filterEntries($subsection_id, $fields, $filter = '', $items = NULL, $full = false)
    {
        // Fetch entry data
        $entries = EntryManager::fetch($full ? NULL : (isset($items['relation_id']) ? $items['relation_id'] : $items), $subsection_id);
        // Return early if there were no $entries found
        if (empty($entries) || !is_array($entries)) {
            return array();
        }
        // Setup filter
        $tag_fields = array();
        $gogoes = array();
        $nonos = array();
        $filters = empty($filter) ? array() : explode(', ', $filter);
        if (!empty($filters)) {
            // Fetch taglist, select and upload fields
            if (is_array($fields)) {
                foreach ($fields as $field) {
                    if (in_array($field->get('type'), array('taglist', 'select'))) {
                        $tag_fields[] = $field->get('id');
                    }
                }
            }
            foreach ($filters as $filter) {
                $operator = substr($filter, 0, 1);
                if ($operator == '-') {
                    $nonos[] = substr($filter, 1);
                } else {
                    $gogoes[] = $filter;
                }
            }
        }
        // Filter entries and add select options
        $entry_data = array();
        foreach ($entries as $entry) {
            $data = $entry->getData();
            if (!empty($filters)) {
                // Collect taglist and select field values
                $tags = array();
                foreach ($tag_fields as $field_id) {
                    $tag_values = $data[$field_id]['value'];
                    if (!is_array($tag_values)) {
                        $tag_values = array($tag_values);
                    }
                    $tags = array_merge($tags, $tag_values);
                }
                // Investigate entry exclusion
                $filter_nonos = array_intersect($tags, $nonos);
                // Investigate entry inclusion
                $filter_gogoes = array_intersect($tags, $gogoes);
                // Filter entries
                if (!empty($filter_nonos) || empty($filter_gogoes) && !empty($gogoes)) {
                    continue;
                }
            }
            // Entry data
            $entry_data[$entry->get('id')] = array('data' => $data, 'id' => $entry->get('id'));
        }
        // Keep custom sort order if items given
        if (is_array($items)) {
            if (!is_array($items['relation_id'])) {
                $items['relation_id'] = array($items['relation_id']);
            }
            $ordered = array();
            foreach ($items['relation_id'] as $id) {
                $ordered[] = $entry_data[$id];
            }
            $entry_data = $ordered;
        }
        // Return filtered entry data
        return $entry_data;
    }