diff --git a/classes/class-supportflow-admin.php b/classes/class-supportflow-admin.php index 38303f2..3d29780 100644 --- a/classes/class-supportflow-admin.php +++ b/classes/class-supportflow-admin.php @@ -233,62 +233,28 @@ public function filter_heartbeat_received( $response, $data ) { /** - * + * Filters links shown over dropdowns in all tickets page */ public function filter_views( $views ) { - $post_type = SupportFlow()->post_type; - $statuses = SupportFlow()->post_statuses; - $status_slugs = array(); - - foreach ( $statuses as $status => $status_data ) { - if ( true == $status_data['show_tickets'] ) { - $status_slugs[] = $status; - } - } - - $wp_query = new WP_Query( array( - 'post_type' => $post_type, - 'post_parent' => 0, - 'posts_per_page' => 1, - 'post_status' => $status_slugs, - ) ); - $total_posts = $wp_query->found_posts; - - $class = empty( $class ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['show_sticky'] ) ? ' class="current"' : ''; - $view_all = "" . sprintf( _nx( 'All (%s)', 'All (%s)', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ) . ''; - - $post_statuses = SupportFlow()->post_statuses; - array_pop( $post_statuses ); - $post_statuses = "'" . implode( "','", array_map( 'sanitize_key', array_keys( $post_statuses ) ) ) . "'"; - - // @todo Only show "Mine" if the user is an agent - $mine_args = array( - 'post_type' => SupportFlow()->post_type, - 'author' => get_current_user_id(), - ); - $wp_query = new WP_Query( array( - 'post_type' => SupportFlow()->post_type, - 'author' => get_current_user_id(), - 'post_status' => $post_statuses, - 'posts_per_page' => 1, - ) ); + $post_type = SupportFlow()->post_type; - $my_posts = $wp_query->found_posts; - $view_mine = '' . sprintf( _nx( 'Mine (%s)', 'Mine (%s)', $my_posts, 'posts' ), number_format_i18n( $my_posts ) ) . ''; + $total_posts = SupportFlow()->get_tickets_count(); + $class = empty( $class ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['author'] ) ? ' class="current"' : ''; + $view_all_link = add_query_arg( array( 'post_type' => SupportFlow()->post_type), admin_url( 'edit.php' ) ); + $view_all_title = sprintf( _nx( 'All (%s)', 'All (%s)', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ); + $view_all = "$view_all_title"; - $unassigned_args = array( - 'post_type' => SupportFlow()->post_type, - 'author' => 0, - ); - $wp_query = new WP_Query( array( - 'post_type' => SupportFlow()->post_type, - 'author' => 0, - 'post_status' => $post_statuses, - 'posts_per_page' => 1, - ) ); + $my_posts = SupportFlow()->get_tickets_count( array( 'author' => get_current_user_id() ) ); + $class = empty( $class ) && empty( $_REQUEST['post_status'] ) && ! empty( $_REQUEST['author'] ) && get_current_user_id() == $_REQUEST['author'] ? ' class="current"' : ''; + $view_mine_link = add_query_arg( array( 'post_type' => SupportFlow()->post_type, 'author' => get_current_user_id() ), admin_url( 'edit.php' ) ); + $view_mine_title = sprintf( _nx( 'Mine (%s)', 'Mine (%s)', $my_posts, 'posts' ), number_format_i18n( $my_posts ) ); + $view_mine = "$view_mine_title"; - $unassigned_posts = $wp_query->found_posts; - $view_unassigned = '' . sprintf( _nx( 'Unassigned (%s)', 'Unassigned (%s)', $unassigned_posts, 'posts' ), number_format_i18n( $unassigned_posts ) ) . ''; + $unassigned_posts = SupportFlow()->get_tickets_count( array( 'author' => 0 ) ); + $class = empty( $class ) && empty( $_REQUEST['post_status'] ) && isset( $_REQUEST['author'] ) && 0 == $_REQUEST['author'] ? ' class="current"' : ''; + $view_mine_link = add_query_arg( array( 'post_type' => SupportFlow()->post_type, 'author' => 0 ), admin_url( 'edit.php' ) ); + $view_unassigned_title = sprintf( _nx( 'Unassigned (%s)', 'Unassigned (%s)', $unassigned_posts, 'posts' ), number_format_i18n( $unassigned_posts ) ); + $view_unassigned = "$view_unassigned_title"; // Put 'All' and 'Mine' at the beginning of the array array_shift( $views ); @@ -297,7 +263,6 @@ public function filter_views( $views ) { $views['mine'] = $view_mine; $views['all'] = $view_all; $views = array_reverse( $views ); - // Remove private option from filter links as they are just private replies to ticket unset( $views['private'] ); @@ -346,6 +311,7 @@ public function action_restrict_manage_posts() { /** * Filter the actions available to the agent on the post type + * They are shown in All tickets page in subject column */ function filter_post_row_actions( $row_actions, $post ) { @@ -929,28 +895,6 @@ public function meta_box_cc_bcc() { public function meta_box_replies() { global $pagenow; - $predefined_replies = get_posts( array( 'post_type' => SupportFlow()->predefinded_replies_type, 'posts_per_page' => -1 ) ); - $pre_defs = array( array( 'title' => __( 'Pre-defined Replies', 'supportflow' ), 'content' => '' ) ); - - foreach ( $predefined_replies as $predefined_reply ) { - $content = $predefined_reply->post_content; - - if ( ! empty( $predefined_reply->post_title ) ) { - $title = $predefined_reply->post_title; - } else { - $title = $predefined_reply->post_content; - } - - // Limit size to 75 characters - if ( strlen( $title ) > 75 ) { - $title = substr( $title, 0, 75 - 3 ) . '...'; - } - - if ( 0 != strlen( $content ) ) { - $pre_defs[] = array( 'title' => $title, 'content' => $content ); - } - } - $email_account_id = get_post_meta( get_the_ID(), 'email_account', true ); $email_account = SupportFlow()->extend->email_accounts->get_email_account( $email_account_id ); @@ -971,11 +915,8 @@ public function meta_box_replies() { echo '

' . __( 'Conversation', 'supportflow' ) . '

'; echo '
'; - echo '
'; + SupportFlow()->extend->predefined_replies->get_dropdown_input(); + echo ''; echo '
'; echo "