Skip to content

Instantly share code, notes, and snippets.

@jaspertandy
Created July 16, 2013 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaspertandy/8e7940a171424e31e13c to your computer and use it in GitHub Desktop.
Save jaspertandy/8e7940a171424e31e13c to your computer and use it in GitHub Desktop.
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