Back to FinderIndexCommand class

Method getFilters

private void
getFilters
()
Save static filters.
Returns
  • void
Since
  • 4.0.0

Method getFilters - Source code

/**
 * Save static filters.
 *
 * Since a purge/index cycle will cause all the taxonomy ids to change,
 * the static filters need to be updated with the new taxonomy ids.
 * The static filter information is saved prior to the purge/index
 * so that it can later be used to update the filters with new ids.
 *
 * @return  void
 *
 * @since   4.0.0
 */
private function getFilters() : void
{
    $this->ioStyle->text(Text::_('FINDER_CLI_SAVE_FILTERS'));
    // Get the taxonomy ids used by the filters.
    $db = $this->db;
    $query = $db->getQuery(true);
    $query->select('filter_id, title, data')->from($db->quoteName('#__finder_filters'));
    $filters = $db->setQuery($query)->loadObjectList();
    // Get the name of each taxonomy and the name of its parent.
    foreach ($filters as $filter) {
        // Skip empty filters.
        if ($filter->data === '') {
            continue;
        }
        // Get taxonomy records.
        $query = $db->getQuery(true);
        $query->select('t.title, p.title AS parent')->from($db->quoteName('#__finder_taxonomy') . ' AS t')->leftJoin($db->quoteName('#__finder_taxonomy') . ' AS p ON p.id = t.parent_id')->where($db->quoteName('t.id') . ' IN (' . $filter->data . ')');
        $taxonomies = $db->setQuery($query)->loadObjectList();
        // Construct a temporary data structure to hold the filter information.
        foreach ($taxonomies as $taxonomy) {
            $this->filters[$filter->filter_id][] = array('filter' => $filter->title, 'title' => $taxonomy->title, 'parent' => $taxonomy->parent);
        }
    }
    $this->ioStyle->text(Text::sprintf('FINDER_CLI_SAVE_FILTER_COMPLETED', count($filters)));
}