Json::categories PHP Method

categories() public method

Categories
public categories ( array | null $params = NULL ) : string
$params array | null
return string
  public function categories($params = NULL)
  {
    $this->initialize();

    if (is_null($params))
    {
      $params = ee()->TMPL->tagparams;
    }

    ee()->load->helper('array');

    $channel = element('channel', $params);
    $group_id = element('group_id', $params, element('category_group', $params));
    $cat_id = element('cat_id', $params, element('category_id', $params, element('show', $params)));
    $status = element('status', $params);
    $parent_only = element('parent_only', $params);
    $show_empty = element('show_empty', $params, TRUE);
    $joins = array();

    if ($channel)
    {
      ee()->db->join('channel_titles', 'channel_titles.entry_id = category_posts.entry_id');
      ee()->db->join('channels', 'channels.channel_id = channel_titles.channel_id');
      ee()->db->where_in('channels.channel_name', explode('|', $channel));
      $joins[] = 'channels';
      $joins[] = 'channel_titles';
    }

    if ($group_id)
    {
      ee()->db->where_in('categories.group_id', explode('|', $group_id));
    }

    if ($cat_id)
    {
      ee()->db->where_in('categories.cat_id', explode('|', $cat_id));
    }

    if ($status)
    {
      if ( ! in_array('channel_titles', $joins))
      {
        ee()->db->join('channel_titles', 'channel_titles.entry_id = category_posts.entry_id');
      }

      ee()->db->where_in('channel_titles.status', explode('|', $status));
    }

    if ($parent_only)
    {
      ee()->db->where('categories.parent_id', 0);
    }

    if ($show_empty)
    {
      ee()->db->where('count >', 0);
    }
  }