Skip to content

Instantly share code, notes, and snippets.

@airways
Created July 10, 2012 03:48
Show Gist options
  • Save airways/3080850 to your computer and use it in GitHub Desktop.
Save airways/3080850 to your computer and use it in GitHub Desktop.
VS Members Filtering for Playa
./system/expressionengine/third_party/playa/
diff /Volumes/HDD/Installers/CMS/EE/Playa4.3/Playa4/ee2/third_party/playa/ft.playa.php ./system/expressionengine/third_party/playa/ft.playa.php
1152a1153
> array_unshift($authors, array('id' => 'related', 'title' => '— '.lang('related').' —'));
1525a1527,1592
> // Related author?
> // -------------------------------------------
>
> $add_to_sql = array();
> if (($key = array_search('related', $this->settings['authors'])) !== FALSE)
> {
> // remove the 'related' value
> array_splice($this->settings['authors'], $key, 1);
>
> // if this is an existing entry, use the entry's author
> if ($entry_id)
> {
> $author_id = $this->EE->db->select('author_id')
> ->where('entry_id', $entry_id)
> ->limit(1)
> ->get('channel_titles')
> ->row('author_id');
> }
> // otherwise use the current member's ID
> else
> {
> $author_id = $this->EE->session->userdata('member_id');
> }
>
> // find VZ Member fields on the specified channels
> $query = $this->EE->db
> ->select('field_id')
> ->where('field_type', 'vz_members')
> ->join('exp_channel_fields', 'exp_channel_fields.group_id = exp_channels.field_group')
> ->where_in('exp_channels.channel_id', $this->settings['channels'])
> ->get('exp_channels');
> $where = array();
> foreach($query->result() as $field)
> {
> $where['field_id_'.$field->field_id] = $author_id;
> }
>
> // filter the results to those entries that have a VZ Member field with
> // the current author specified in it
> $this->EE->db->select('entry_id');
> foreach(array_keys($where) as $field)
> {
> $this->EE->db->select($field);
> }
>
> $query = $this->EE->db
> ->like($where)
> ->get('exp_channel_data');
>
> $entry_ids = array();
> // LIKE searches are not super precise, check each entry to make sure it really has the author
> foreach($query->result() as $entry)
> {
> foreach(array_keys($where) as $key)
> {
> if(in_array($author_id, explode('|', $entry->$key)))
> {
> $entry_ids[] = $entry->entry_id;
> }
> }
> }
>
> $add_to_sql['where'] = 'entry_id IN ('.implode($entry_ids).')';
> }
>
> // -------------------------------------------
1557c1624
< ));
---
> ), $add_to_sql);
1612c1679
< $vars['entries'] = $this->helper->entries_query($params);
---
> $vars['entries'] = $this->helper->entries_query($params, $add_to_sql);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment