Skip to content
This repository has been archived by the owner on Nov 28, 2019. It is now read-only.

Commit

Permalink
Update Filter\ImportMetaFilter
Browse files Browse the repository at this point in the history
Apply the filter to each record if it is a multi-record meta #56
  • Loading branch information
dnaber-de committed Feb 14, 2016
1 parent 8bc01b3 commit 37fc7de
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
23 changes: 22 additions & 1 deletion inc/Import/Filter/ImportMetaFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,34 @@ public function __construct(
*/
public function filter_value( Type\ImportMetaInterface $meta, $object_id ) {

if ( $meta->is_single() )
return $this->apply_filters( $meta, $meta->value(), $object_id );

$value = [];
foreach ( $meta->value() as $v ) {
$value[] = $this->apply_filters( $meta, $v, $object_id );
}

return $value;
}

/**
* @param Type\ImportMetaInterface $meta
* @param string $value
* @param int $object_id
*
* @return mixed
*/
public function apply_filters( Type\ImportMetaInterface $meta, $value, $object_id ) {

$filters = $this->filter_list->get_filters( $this->type, $meta->key() );
$value = $meta->value();
foreach ( $filters as $filter ) {
if ( ! $filter->is_filterable( $meta->value(), $object_id ) ) {
/**
* Fires when a filter is invalid (due to missing data)
*
* Todo: Check if these parameter are sufficient for multiple meta records!
*
* @param string $type ('post', 'comment', 'user' or 'term')
* @param int $object_id
* @param Type\ImportMetaInterface $meta
Expand Down
2 changes: 1 addition & 1 deletion inc/Import/Filter/ImportMetaFilterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface ImportMetaFilterInterface {
* @param Type\ImportMetaInterface $meta
* @param int $object_id
*
* @return mixed (The filtered value)
* @return mixed (The filtered value. This MUST be an array if $meta->is_single() is false!)
*/
public function filter_value( Type\ImportMetaInterface $meta, $object_id );
}
6 changes: 6 additions & 0 deletions tests/phpunit/Unit/Import/Filter/ImportMetaFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ public function test_filter_value() {
// Todo: Write tests for
$this->markTestIncomplete( 'Under construction' );
}

public function test_apply_filters() {

// Todo: Write tests for
$this->markTestIncomplete( 'Under construction' );
}
}

0 comments on commit 37fc7de

Please sign in to comment.