Skip to content

Commit

Permalink
Merge pull request #1238 from OpenDevelopmentMekong/master
Browse files Browse the repository at this point in the history
Merging to prod for releasing v2.4.20
  • Loading branch information
Alex Corbi authored Dec 14, 2017
2 parents 111dc06 + 056e02e commit cfac464
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 56 deletions.
75 changes: 33 additions & 42 deletions archive-topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
<div class="panel more-filters-content row">
<?php
$filter_arg = array(
'search_box' => true,
'cat_selector' => true,
'con_selector' => false,
'date_rang' => true,
'post_type' => get_post_type()
);
'search_box' => true,
'cat_selector' => true,
'con_selector' => false,
'date_rang' => true,
'post_type' => get_post_type()
);
odm_adv_nav_filters($filter_arg);
?>
</div>
Expand All @@ -36,70 +36,61 @@

<div class="row">
<div class="sixteen columns">
<h3 class="clearfix"><?php _e('Environment and land','odm'); ?></h3>

<?php

<?php
$taxonomy_categories_1 = array("Agriculture and fishing", "Disaster and emergency response", "Environment and natural resources", "Extractive Industries", "Land");

$taxonomy_categories_2 = array("Economy and commerce", "Energy", "Industry", "Infrastructure", "Labor", "Science and technology");
$taxonomy_categories_3 = array("Aid and development", "Government", "Law and judiciary", "Population and cencuses", "Social development", "Urban administration and development"); ?>

$taxonomy_categories_3 = array("Aid and development", "Government", "Law and judiciary", "Population and cencuses", "Social development", "Urban administration and development");
<h3 class="clearfix"><?php _e('Environment and land','odm'); ?></h3>
<?php

while (have_posts()) : the_post();
$post = get_post();
$category = get_the_category($post->ID);
if(isset($category[0]->cat_ID)):
$top_level_cat = get_top_level_category_english_name($category[0]->cat_ID);
if (in_array($top_level_cat,$taxonomy_categories_1)):
odm_get_template('post-grid-single-4-cols',array(
"post" => $post,
"show_meta" => true,
"meta_fields" => array("date"),
"order" => $date_to_show
),true);
endif;
$top_level_cat_names = get_top_level_category_english_names(get_the_category($post->ID));
if (arrays_have_common_items($top_level_cat_names,$taxonomy_categories_1)):
odm_get_template('post-grid-single-4-cols',array(
"post" => $post,
"show_meta" => true,
"meta_fields" => array("date"),
"order" => $date_to_show
),true);
endif;
endwhile; ?>
endwhile;

<?php rewind_posts(); ?>
rewind_posts(); ?>

<h3 class="clearfix"><?php _e('Economy','odm'); ?></h3>
<?php
while (have_posts()) : the_post();
$post = get_post();
$category = get_the_category($post->ID);
if(isset($category[0]->cat_ID)):
$top_level_cat = get_top_level_category_english_name($category[0]->cat_ID);
if (in_array($top_level_cat,$taxonomy_categories_2)):
$post = get_post();
$top_level_cat_names = get_top_level_category_english_names(get_the_category($post->ID));
if (arrays_have_common_items($top_level_cat_names,$taxonomy_categories_2)):
odm_get_template('post-grid-single-4-cols',array(
"post" => $post,
"show_meta" => true,
"order" => $date_to_show
),true);
endif;
endif;
endwhile; ?>
endwhile;

<?php rewind_posts(); ?>
rewind_posts(); ?>

<h3 class="clearfix"><?php _e('People','odm'); ?></h3>

<?php
while (have_posts()) : the_post();
$post = get_post();
$category = get_the_category($post->ID);
if(isset($category[0]->cat_ID)):
$top_level_cat = get_top_level_category_english_name($category[0]->cat_ID);
if (in_array($top_level_cat,$taxonomy_categories_3)):
odm_get_template('post-grid-single-4-cols',array(
"post" => $post,
"show_meta" => true,
"order" => $date_to_show
),true);
endif;
$top_level_cat_names = get_top_level_category_english_names(get_the_category($post->ID));
if (arrays_have_common_items($top_level_cat_names,$taxonomy_categories_3)):
odm_get_template('post-grid-single-4-cols',array(
"post" => $post,
"show_meta" => true,
"order" => $date_to_show
),true);
endif;
endwhile; ?>

</div>
</div>
</section>
Expand Down
1 change: 1 addition & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
require_once get_stylesheet_directory().'/inc/utils/breadcrumbs.php';
require_once get_stylesheet_directory().'/inc/utils/layout.php';
require_once get_stylesheet_directory().'/inc/utils/urls.php';
require_once get_stylesheet_directory().'/inc/utils/arrays.php';
require_once get_stylesheet_directory().'/inc/utils/config.php';

/*
Expand Down
16 changes: 16 additions & 0 deletions inc/utils/arrays.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

function arrays_have_common_items($array1, $array2) {

foreach ($array1 as $value1):
foreach ($array2 as $value2):
if (strtolower($value1) == strtolower($value2)):
return true;
endif;
endforeach;
endforeach;

return false;
}

?>
22 changes: 9 additions & 13 deletions inc/utils/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -776,19 +776,15 @@ function is_page_dataset_detail_template(){
return (strpos(get_page_template(), 'page-dataset-detail') !== false);
}

function get_top_level_category_english_name($cat_id) {
global $wpdb;
while ($cat_id) {
$cat = get_category($cat_id); // get the object for the catid
$cat_id = $cat->category_parent; // assign parent ID (if exists) to $catid
$cat_parent_id = $cat->cat_ID;
}

$cat_parent_name = $wpdb->get_var($wpdb->prepare(
"SELECT `name` FROM $wpdb->terms WHERE `term_id` = %d", $cat_parent_id));
$cat_parent_name = apply_filters('translate_text', $cat_parent_name, 'en');
return $cat_parent_name;
}

function get_top_level_category_english_names($cats) {
$top_cat_names = array();
foreach($cats as $cat) {
$all_parent_cats = get_category_parents($cat);
$top_cat_names = array_merge($top_cat_names,split('/', $all_parent_cats));
}
return $top_cat_names;
}

function odm_echo_extras($postID = "") {
$postID = $postID ? $postID : get_the_ID();
Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Author: Open Development Mekong
Author URI: http://github.com/OpenDevelopmentMekong
Description: Open Development Mekong's wordpress theme. Based on JEO child theme
Template: jeo
Version: 2.4.19
Version: 2.4.20
License: GNU General Public License v3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
Expand Down
44 changes: 44 additions & 0 deletions tests/ArraysTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

require_once dirname(dirname(__FILE__)) . '/inc/utils/arrays.php';

class ArraysTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
// init vars here
}

public function tearDown()
{
// undo stuff here
}

public function testDummy(){
$this->assertTrue(true);
}

public function testArrayHaveCommonItems()
{
$array1 = array("Economy and Commerce", "Disaster and emergency response", "Extractive Industries");
$array2 = array("Land", "Extractive Industries");
$result = arrays_have_common_items($array1,$array2);
$this->assertEquals($result,true);
}

public function testArrayHaveCommonItemsIgnoreCase()
{
$array1 = array("Economy and Commerce", "Disaster and emergency response", "Extractive Industries");
$array2 = array("Land", "Extractive industries");
$result = arrays_have_common_items($array1,$array2);
$this->assertEquals($result,true);
}

public function testArrayHaveCommonItemsNegativeCase()
{
$array1 = array("Labor", "Illegal labor");
$array2 = array("Agriculture and fishing", "Disaster and emergency response", "Environment and natural resources", "Extractive Industries", "Land");
$result = arrays_have_common_items($array1,$array2);
$this->assertEquals($result,false);
}
}

0 comments on commit cfac464

Please sign in to comment.