Skip to content

Commit

Permalink
Merge c108d48 into 7110849
Browse files Browse the repository at this point in the history
  • Loading branch information
esudalaimadan committed Dec 3, 2020
2 parents 7110849 + c108d48 commit 1f29f6b
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 3 deletions.
50 changes: 50 additions & 0 deletions assets/js/src/bulk-delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,46 @@ jQuery(document).ready(function () {
}
}

/**
* Toggle the date fields.
*/
function toggle_date_filter(el) {
if ( 2 === jQuery("#smbd" + el + "_op").prop('selectedIndex') ) {
// Enable and display published on date.
jQuery("#smbd" + el + "_pub_date").prop('disabled', false);
jQuery("#smbd" + el + "_pub_date").show();
// Disable and hide other fields.
jQuery("#smbd" + el + "_pub_date_start").prop('disabled', true);
jQuery("#smbd" + el + "_pub_date_start").hide();
jQuery("#smbd" + el + "_pub_date_end").prop('disabled', true);
jQuery("#smbd" + el + "_pub_date_end").hide();
jQuery("#smbd" + el + "_days").prop('disabled', true);
jQuery("#smbd" + el + "_days_box").hide();
} else if ( 3 === jQuery( "#smbd" + el + "_op" ).prop('selectedIndex') ){
// Enable and display between date boxes.
jQuery("#smbd" + el + "_pub_date_start").prop('disabled', false);
jQuery("#smbd" + el + "_pub_date_start").show();
jQuery("#smbd" + el + "_pub_date_end").prop('disabled', false);
jQuery("#smbd" + el + "_pub_date_end").show();
// Disable and hide other fields.
jQuery("#smbd" + el + "_days").prop('disabled', true);
jQuery("#smbd" + el + "_days_box").hide();
jQuery("#smbd" + el + "_pub_date").prop('disabled', true);
jQuery("#smbd" + el + "_pub_date").hide();
} else {
// Enable and display day box.
jQuery("#smbd" + el + "_days").prop('disabled', false);
jQuery("#smbd" + el + "_days_box").show();
// Disable and hide other fields.
jQuery("#smbd" + el + "_pub_date").prop('disabled', true);
jQuery("#smbd" + el + "_pub_date").hide();
jQuery("#smbd" + el + "_pub_date_start").prop('disabled', true);
jQuery("#smbd" + el + "_pub_date_start").hide();
jQuery("#smbd" + el + "_pub_date_end").prop('dsiabled', true);
jQuery("#smbd" + el + "_pub_date_end").hide();
}
}

/**
* Toggle limit restrict fields
*/
Expand Down Expand Up @@ -148,6 +188,16 @@ jQuery(document).ready(function () {
timeFormat: 'HH:mm:ss'
});

jQuery('#smbd' + value + '_pub_date').datepicker( { dateFormat: 'yy-mm-dd' } );

jQuery('#smbd' + value + '_pub_date_start').datepicker( { dateFormat: 'yy-mm-dd' } );

jQuery('#smbd' + value + '_pub_date_end').datepicker( { dateFormat: 'yy-mm-dd' } );

jQuery('#smbd' + value + '_op').change(function () {
toggle_date_filter(value);
});

jQuery('#smbd' + value + '_restrict').change(function () {
toggle_date_restrict(value);
});
Expand Down
20 changes: 19 additions & 1 deletion include/Core/Base/Mixin/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,25 @@ protected function render_filtering_table_header() {
* Render restrict settings.
*/
protected function render_restrict_settings() {
bd_render_restrict_settings( $this->field_slug, $this->item_type );
$slug = $this->field_slug;
$item = $this->item_type;
?>
<tr>
<td scope="row" colspan="3">
<input name="smbd_<?php echo $slug; ?>_restrict" id="smbd_<?php echo $slug; ?>_restrict" value="true" type="checkbox">
<label for="smbd_<?php echo $slug; ?>_restrict"><?php printf( __( 'Only restrict to %s which are ', 'bulk-delete' ), $item ); ?></label>
<select name="smbd_<?php echo $slug; ?>_op" id="smbd_<?php echo $slug; ?>_op" disabled>
<option value="before"><?php _e( 'older than', 'bulk-delete' ); ?></option>
<option value="after"><?php _e( 'posted within last', 'bulk-delete' ); ?></option>
<option value="="><?php _e( 'published on', 'bulk-delete' ); ?></option>
<option value="between"><?php _e( 'published between', 'bulk-delete' ); ?></option>
</select>
<div style="display:inline;" id="smbd_<?php echo $slug; ?>_days_box"><input type="number" name="smbd_<?php echo $slug; ?>_days" id="smbd_<?php echo $slug; ?>_days" class="screen-per-page" disabled value="0" min="0"><?php _e( 'days', 'bulk-delete' ); ?></div>
<input type="text" name="smbd_<?php echo $slug; ?>_pub_date" id="smbd_<?php echo $slug; ?>_pub_date" placeholder="Choose Date" style="display: none;">
<input type="text" name="smbd_<?php echo $slug; ?>_pub_date_start" id="smbd_<?php echo $slug; ?>_pub_date_start" placeholder="Choose Date" style="display: none;">
<input type="text" name="smbd_<?php echo $slug; ?>_pub_date_end" id="smbd_<?php echo $slug; ?>_pub_date_end" placeholder="Choose Date"style="display: none;">
</tr>
<?php
}

/**
Expand Down
7 changes: 5 additions & 2 deletions include/Core/Posts/PostsModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ protected function parse_common_filters( $request ) {
$options['exclude_sticky'] = bd_array_get_bool( $request, 'smbd_' . $this->field_slug . '_exclude_sticky', false );
$options['force_delete'] = bd_array_get_bool( $request, 'smbd_' . $this->field_slug . '_force_delete', false );

$options['date_op'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_op' );
$options['days'] = absint( bd_array_get( $request, 'smbd_' . $this->field_slug . '_days' ) );
$options['date_op'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_op' );
$options['days'] = absint( bd_array_get( $request, 'smbd_' . $this->field_slug . '_days' ) );
$options['pub_date'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_pub_date' );
$options['pub_date_start'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_pub_date_start' );
$options['pub_date_end'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_pub_date_end' );

return $options;
}
Expand Down
19 changes: 19 additions & 0 deletions include/util/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ function bd_build_query_options( $delete_options, $options = array() ) {
$delete_options['date_op'] => "{$delete_options['days']} day ago",
),
);
} elseif ( '=' === $delete_options['date_op'] ) {
$published_date = getdate( strtotime( $delete_options['pub_date'] ) );
$options['date_query'] = [
[
'year' => $published_date['year'],
'month' => $published_date['mon'],
'day' => $published_date['mday'],
],
];
} elseif ( 'between' === $delete_options['date_op'] ) {
$published_date_start = date( 'Y-m-d', strtotime( $delete_options['pub_date_start'] ) );
$published_date_end = date( 'Y-m-d', strtotime( $delete_options['pub_date_end'] ) );
$options['date_query'] = [
[
'after' => $published_date_start,
'before' => $published_date_end,
'inclusive' => true,
],
];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,72 @@ public function provide_data_to_test_posts_deletion_by_comments_count_with_less_
'available_posts' => 15,
),
),
// (+ve Case) Deletes few posts for the given comment count with less than operator and given published date and post type/status.
array(
array(
array(
'posts' => 15,
'comments' => 5,
'post_type' => 'post',
'post_status' => 'publish',
),
array(
'posts' => 10,
'comments' => 7,
'post_type' => 'order',
'post_status' => 'publish',
),
),
array(
'operator' => '<',
'comment_count' => 10,
'selected_post_type' => 'order|publish',
'limit_to' => 0,
'restrict' => true,
'date_op' => '=',
'pub_date' => date( 'Y-m-d' ),
'force_delete' => true,
),
array(
'deleted_posts' => 10,
'trashed_posts' => 0,
'available_posts' => 15,
),
),
// (+ve Case) Deletes few posts for the given comment count with less than operator and given published date and post type/status.
array(
array(
array(
'posts' => 15,
'comments' => 5,
'post_type' => 'post',
'post_status' => 'publish',
'published_date' => date( 'Y-m-d h:i:s', strtotime( '-4 day' ) ),
),
array(
'posts' => 10,
'comments' => 7,
'post_type' => 'post',
'post_status' => 'publish',
),
),
array(
'operator' => '<',
'comment_count' => 10,
'selected_post_type' => 'post|publish',
'limit_to' => 0,
'restrict' => true,
'date_op' => 'between',
'pub_date_start' => date( 'Y-m-d', strtotime( '-5 day') ),
'pub_date_end' => date( 'Y-m-d', strtotime( '-3 day' ) ),
'force_delete' => true,
),
array(
'deleted_posts' => 15,
'trashed_posts' => 0,
'available_posts' => 10,
),
),
);
}

Expand All @@ -303,11 +369,15 @@ public function test_posts_can_be_deleted_by_posts_count( $setup, $operations, $
if ( ! array_key_exists( 'post_status', $element ) ) {
$element['post_status'] = 'publish';
}
if ( ! array_key_exists( 'published_date', $element ) ) {
$element['published_date'] = date( 'Y-m-d' );
}
$post_ids = $this->factory->post->create_many(
$element['posts'],
array(
'post_type' => $element['post_type'],
'post_status' => $element['post_status'],
'post_date' => $element['published_date'],
)
);
foreach ( $post_ids as $post_id ) {
Expand Down

0 comments on commit 1f29f6b

Please sign in to comment.