Skip to content

Instantly share code, notes, and snippets.

@jaspertandy

jaspertandy/pi.playlist.php Secret

Created Jul 16, 2013
Embed
What would you like to do?
public function projects(){
$this->fields = $this->EE->api_channel_fields->fetch_custom_channel_fields();
// get all the fields that start 'project_'
$fields = array();
foreach ( $this->fields['custom_channel_fields'][1] as $field => $id ) {
if ( substr( $field , 0 , strlen( 'project_' ) ) === 'project_' ) {
$fields[$field] = $id;
}
}
$select_fields = array(
'channel_titles.entry_id',
'channel_titles.title',
'channel_titles.url_title',
);
foreach ( $fields as $field => $id ) {
$select_fields[] = '`field_id_' . $id . '` AS `' . $field . '`';
}
$channel = $this->channel( 'projects' );
if ( !$_SESSION['PLAYLIST'] ) {
return '<section>No results</section>';
}
$projects = $this->EE->db->select( $select_fields )
->join('channel_titles' , 'channel_titles.entry_id = channel_data.entry_id')
->where( 'channel_titles.channel_id' , $channel['channel_id'] )
->where_in( 'channel_titles.entry_id' , $_SESSION['PLAYLIST'] )
->where( 'channel_titles.status' , 'open' )
->get('channel_data')
->result_array();
/**
* this is a horrible way of doing this, but I cannot
* for the life of me figure out how to hook into the
* file types stuff to do it nicely, so poke it
*/
foreach ( $projects as &$project ) {
$project['project_grid_image'] = str_replace('{filedir_1}' , '/uploads/projects/_small/' , $project['project_grid_image']);
}
return $this->EE->TMPL->parse_variables($this->EE->TMPL->tagdata, $projects);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment