Skip to content

Commit

Permalink
Merge pull request Softcatala#99 from Softcatala/programes_filtre_so
Browse files Browse the repository at this point in the history
Softcatala#10 Add operating system filter to 'programas'
  • Loading branch information
xavivars committed Jan 28, 2016
2 parents 27e5924 + 61da128 commit 7123da7
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 18 deletions.
34 changes: 31 additions & 3 deletions archive-programa.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,48 @@
$categoria_programa = get_query_var( 'categoria_programa' );
$arxivat = get_query_var( 'arxivat' );

if( ! empty( $search ) || ! empty( $sistema_operatiu ) || ! empty( $categoria_programa ) || ! empty( $arxivat ) ) {
if( ! empty( $search ) || ! empty( $categoria_programa ) || ! empty( $arxivat ) ) {
$query['s'] = $search;
$query['sistema-operatiu-programa'] = $sistema_operatiu;
$query['categoria-programa'] = $categoria_programa;
$query['arxivat'] = $arxivat;
$args = get_post_query_args( 'programa', SearchQueryType::Programa, $query );
$context['cerca'] = $search;
$context['selected_filter_so'] = ( isset ( $args['filter_so'] ) ? $args['filter_so'] : '' );
$context['selected_filter_categoria'] = ( isset ( $args['filter_categoria'] ) ? $args['filter_categoria'] : '' );
$context['selected_arxivat'] = ( isset ( $args['arxivat'] ) ? $args['arxivat'] : '' );
} else {
$args = get_post_query_args( 'programa', SearchQueryType::Programa );
}

if( ! empty( $sistema_operatiu ) ) {
$query['sistema-operatiu-programa'] = $sistema_operatiu;

$args_so_baixades = array (
'post_type' => 'baixada',
'tax_query' => array (
array(
'taxonomy' => 'sistema-operatiu-programa',
'field' => 'slug',
'terms' => $sistema_operatiu,
'post_status' => 'publish'
)
)
);
$baixades_posts = get_posts( $args_so_baixades );
$programes_baixades_ids = array_map( "extract_post_ids_program", $baixades_posts );

if( isset( $args ) ) {
$all_programs = get_posts( $args );
$all_programs_ids = array_map("extract_post_ids", $all_programs);
$programes_ids = array_intersect( $all_programs_ids, $programes_baixades_ids);
} else {
$programes_ids = $programes_baixades_ids;
}
$query['post__in'] = $programes_ids;

$args = get_post_query_args( 'programa', SearchQueryType::Programa, $query );
$context['selected_filter_so'] = $sistema_operatiu;
}

$context['content_title'] = 'Programes i aplicacions';
$post = retrieve_page_data(get_query_var( 'post_type' ));
$context['categories']['sistemes_operatius'] = Timber::get_terms( 'sistema-operatiu-programa' );
Expand Down
13 changes: 12 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ function get_post_query_args( $post_type, $queryType, $filter = array() )
$filter_args['s'] = $filter['s'];
}

if ( ! empty ( $filter['post__in'] ) ) {
$filter_args['post__in'] = $filter['post__in'];
}

if (!empty ($filter['categoria-programa'])) {
$filter_args['tax_query'][] = array(
'taxonomy' => 'categoria-programa',
Expand Down Expand Up @@ -539,4 +543,11 @@ function sendEmailForm( $to_email, $nom_from, $assumpte, $fields ) {
$output = json_encode(array('type'=>'message', 'text' => 'S\'ha enviat la informació.'));
}
return $output;
}
}

/* Add responsive container to embeds
/* ------------------------------------ */
function sc_embed_html( $html ) {
return '<div class="embed-responsive embed-responsive-16by9">' . $html . '</div>';
}
add_filter( 'embed_oembed_html', 'sc_embed_html', 10, 3 );
14 changes: 14 additions & 0 deletions inc/post_types_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,18 @@ function get_parent_page_hierarchy($parent_id, $sort_column = 'menu_order', $sor
$pages_tree = str_replace( 'children', 'nav children', $pages_tree);

return $pages_tree;
}

/*
* Function that extracts the post id from a specific post (for use on array_map)
*/
function extract_post_ids( $post ) {
return $post->ID;
}

/*
* Function that extracts the post id from a specific post relationship (for use on array_map)
*/
function extract_post_ids_program( $post ) {
return wpcf_pr_post_get_belongs( $post->ID, 'programa' );
}
1 change: 0 additions & 1 deletion single-programa.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
$context['links'] = $post->get_field( 'link' );
$context['baixades'] = $post->get_field( 'baixada' );
$context['credits'] = $post->get_field( 'credit' );
$context['url_video'] = wp_oembed_get( $post->video_url, array('width'=>560, 'height'=>315, 'class'=>'embed-responsive-item', 'allowfullscreen'=>1) );

if ( post_password_required( $post->ID ) ) {
Timber::render( 'single-password.twig', $context );
Expand Down
2 changes: 1 addition & 1 deletion templates/archive-programa.twig
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<div class="caption">
<h3>{{ post.title }}</h3>
<div class="cont-rating">
<input id="input-id" value="{{ post.valoracio }}" class="rating" min=0 max=5 step=1 data-glyphicon="false" data-symbol="&#xf006;" data-rating-class="rating-fa" data-show-caption="false" data-show-clear="false" data-readonly/>
<input id="input-id" value="{{ post.valoracio }}" class="rating" data-glyphicon="false" data-symbol="&#xf006;" data-rating-class="rating-fa" data-show-caption="false" data-show-clear="false" disabled="disabled" data-readonly/>
{% if post.total_baixades_programa %}<em>({{ post.total_baixades_programa }})</em>{% endif %}
</div>
</div>
Expand Down
12 changes: 0 additions & 12 deletions templates/single-programa.twig
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,6 @@
{{ post.content }}
</section><!--/.contingut-section -->

<!-- .contingut-section -->
{% if url_video %}
<section class="contingut-section">
<h2>{{ post.video_title }}</h2>
<!-- 16:9 aspect ratio -->
<div class="embed-responsive embed-responsive-16by9">
{{ url_video }}
</div>
<p>{{ post.video_description }}</p>
</section><!--/.contingut-section -->
{% endif %}

<!-- .comentaris -->
{% include "comentaris.twig" %}
<!--/.comentaris -->
Expand Down

0 comments on commit 7123da7

Please sign in to comment.