array_key_exists( $period, Reports::periods() ) || preg_match( '/^\d{4}-\d{2}-\d{2}_\d{4}-\d{2}-\d{2}$/', $period ) ? $period : 'all', 'dimension' => array_key_exists( $dimension, Reports::dimensions() ) ? $dimension : 'channel', 'model' => 'last' === $model ? 'last' : 'first', 'group_value' => $value, ); $remember = array( // Days asked for once, e.g. by the assistant, are not kept as the usual period. 'period' => array_key_exists( $state['period'], Reports::periods() ) ? $state['period'] : ( $saved['period'] ?? 'all' ), 'dimension' => $state['dimension'], 'model' => $state['model'], ); if ( $remember !== $saved && self::remembers() ) { update_user_meta( get_current_user_id(), self::META_KEY, $remember ); } return $state; } /** * The periods to choose from, with days asked for once, e.g. by the assistant, as one more. * * @return array */ public static function periods() { $periods = Reports::periods(); $current = self::current()['period']; if ( ! isset( $periods[ $current ] ) ) { list( $from, $to ) = explode( '_', $current ); $format = get_option( 'date_format' ); $periods[ $current ] = wp_date( $format, (int) strtotime( $from . ' 12:00:00' ) ) . ' – ' . wp_date( $format, (int) strtotime( $to . ' 12:00:00' ) ); } return $periods; } /** * Query arguments for Leads::query() matching the selection. * * @return array */ public static function query_args() { $state = self::current(); list( $from, $to ) = Reports::range( $state['period'] ); $args = array( 'from' => $from, 'to' => $to, ); if ( null !== $state['group_value'] ) { $args['column'] = Reports::column( $state['dimension'], $state['model'] ); $args['value'] = $state['group_value']; } return $args; } /** * URL arguments that keep the selection when linking within the screen. * * @param bool $with_drilldown Include the drill-down value. * @return array */ public static function url_args( $with_drilldown = true ) { $state = self::current(); $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended $args = array( 'page' => Admin::LEADS_PAGE === $page ? Admin::LEADS_PAGE : Admin::PAGE, 'period' => $state['period'], 'dim' => $state['dimension'], 'model' => $state['model'], self::KEEP => wp_create_nonce( 'dealroot_keep_view' ), ); if ( $with_drilldown && null !== $state['group_value'] ) { $args['group_value'] = $state['group_value']; } return $args; } }