Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonatan Hanson committed Aug 28, 2017
2 parents 501d67e + b44f777 commit 5dfe475
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
49 changes: 33 additions & 16 deletions source/php/Parser/EventManagerApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,17 @@ public function saveEvent($event)
$latitude = is_array($location) && ! empty($location['latitude']) ? $location['latitude'] : null;
$longitude = is_array($location) && ! empty($location['longitude']) ? $location['longitude'] : null;

// Check if category, tag and group filter is set or not
$tax_filter = (empty(get_field('event_filter_cat', 'options')) && empty(get_field('event_filter_tag', 'options')) && empty(get_field('event_filter_group', 'options'))) ? true : false;

// Filter by categories
if (! empty(get_field('event_filter_cat', 'options'))) {
$tax_filter = ($this->filterTaxonomies($categories, 0)) ? true : false;
}

// Filter by tags
if (! $tax_filter && ! empty(get_field('event_filter_tag', 'options'))) {
$tax_filter = ($this->filterTaxonomies($tags, 1)) ? true : false;
}
$pass_tax_filter = $this->checkFilters($this->filterTaxonomies($categories, 0), $this->filterTaxonomies($tags, 1));
$passes = true;

// Filter by groups
if (! $tax_filter && ! empty(get_field('event_filter_group', 'options'))) {
$tax_filter = $this->filterGroups($groups);
// Check if event passes "group" filter and taxonomy filters
if (! empty(get_field('event_filter_group', 'options'))) {
$passes = $this->filterGroups($groups);
if ($passes) {
$passes = $pass_tax_filter;
}
} else {
$passes = $pass_tax_filter;
}

// Check if event already exist and get the post status
Expand All @@ -121,7 +116,7 @@ public function saveEvent($event)
}

// Save event if it passed taxonomy and group filters
if ($tax_filter) {
if ($passes) {
$event = new Event(
array(
'post_title' => $post_title,
Expand Down Expand Up @@ -176,6 +171,28 @@ public function saveEvent($event)
}
}

/**
* Check if the event passes one of the taxonomy filters
* @param bool $cat_filter Bool, equals true if event passed category filter
* @param bool $tag_filter Bool, equals true if event passed tag filter
* @return bool
*/
public function checkFilters($cat_filter, $tag_filter) : bool
{
$tax_filter = (empty(get_field('event_filter_cat', 'options')) && empty(get_field('event_filter_tag', 'options'))) ? true : false;

// Check category filters
if (!empty(get_field('event_filter_cat', 'options'))) {
$tax_filter = $cat_filter;
}
// Check tag filters
if (!$tax_filter && !empty(get_field('event_filter_tag', 'options'))) {
$tax_filter = $tag_filter;
}

return $tax_filter;
}

/**
* Sort out duplicate events.
* @param array $array array to be unique
Expand Down
4 changes: 2 additions & 2 deletions source/php/Parser/EventManagerGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public function start()
$parent_term = $this->saveTerms($group->name, $group->slug, $taxonomy);
if ($group->children) {
foreach ($group->children as $child) {
$child_term = $this->saveTerms($child->name, $child->name, $taxonomy, $parent_term);
$child_term = $this->saveTerms($child->name, $child->slug, $taxonomy, $parent_term);
if ($child->children) {
foreach ($child->children as $grand_child) {
$grand_child_term = $this->saveTerms($grand_child->name, $grand_child->name, $taxonomy, $child_term);
$grand_child_term = $this->saveTerms($grand_child->name, $grand_child->slug, $taxonomy, $child_term);
}
}
}
Expand Down

0 comments on commit 5dfe475

Please sign in to comment.