/** * Retrieve referral data * * @since 1.1 */ public function get_data() { $dates = affwp_get_report_dates(); $start = $dates['year'] . '-' . $dates['m_start'] . '-' . $dates['day'] . ' 00:00:00'; $end = $dates['year_end'] . '-' . $dates['m_end'] . '-' . $dates['day_end'] . ' 23:59:59'; $date = array('start' => $start, 'end' => $end); $affiliates = affiliate_wp()->affiliates->get_affiliates(array('orderby' => 'date_registered', 'order' => 'ASC', 'number' => -1, 'date' => $date)); $affiliate_data = array(); $affiliate_data[] = array(strtotime($start) * 1000); $affiliate_data[] = array(strtotime($end) * 1000); if ($affiliates) { foreach ($affiliates as $affiliate) { if ('today' == $dates['range'] || 'yesterday' == $dates['range']) { $point = strtotime($affiliate->date_registered) * 1000; $affiliate_data[$point] = array($point, 1); } else { $time = date('Y-n-d', strtotime($affiliate->date_registered)); $timestamp = strtotime($time) * 1000; if (array_key_exists($time, $affiliate_data) && isset($affiliate_data[$time][1])) { $count = $affiliate_data[$time][1] += 1; $affiliate_data[$time] = array($timestamp, $count); } else { $affiliate_data[$time] = array($timestamp, 1); } } } } $data = array(__('Affiliate Registrations', 'affiliate-wp') => $affiliate_data); return $data; }
/** * Retrieve referral data * * @since 1.1 */ public function get_data() { $converted = array(); $unconverted = array(); $dates = affwp_get_report_dates(); $start = $dates['year'] . '-' . $dates['m_start'] . '-' . $dates['day'] . ' 00:00:00'; $end = $dates['year_end'] . '-' . $dates['m_end'] . '-' . $dates['day_end'] . ' 23:59:59'; $date = array('start' => $start, 'end' => $end); $visits = affiliate_wp()->visits->get_visits(array('orderby' => 'date', 'order' => 'ASC', 'date' => $date, 'number' => -1, 'affiliate_id' => $this->get('affiliate_id'))); $converted_data = array(); $unconverted_data = array(); if ($visits) { // Loop through each visit and find how many there are per day foreach ($visits as $visit) { $date = date('Y-m-d', strtotime($visit->date)); $this->total += 1; if (!empty($visit->referral_id)) { if (array_key_exists($date, $converted_data)) { $converted_data[$date] += 1; } else { $converted_data[$date] = 1; } $this->converted += 1; } else { if (array_key_exists($date, $unconverted_data)) { $unconverted_data[$date] += 1; } else { $unconverted_data[$date] = 1; } } } } $converted_visits = array(); foreach ($converted_data as $date => $count) { $converted_visits[] = array(strtotime($date) * 1000, $count); } $unconverted_visits = array(); $unconverted_visits[] = array(strtotime($start) * 1000); $unconverted_visits[] = array(strtotime($end) * 1000); foreach ($unconverted_data as $date => $count) { $unconverted_visits[] = array(strtotime($date) * 1000, $count); } $data = array(__('Converted Visits', 'affiliate-wp') => $converted_visits, __('Unconverted Visits', 'affiliate-wp') => $unconverted_visits); return $data; }
/** * Retrieve referral data * * @since 1.0 */ public function get_data() { $paid = array(); $unpaid = array(); $rejected = array(); $pending = array(); $dates = affwp_get_report_dates(); $start = $dates['year'] . '-' . $dates['m_start'] . '-' . $dates['day'] . ' 00:00:00'; $end = $dates['year_end'] . '-' . $dates['m_end'] . '-' . $dates['day_end'] . ' 23:59:59'; $date = array('start' => $start, 'end' => $end); //echo '<pre>'; print_r( $date ); echo '</pre>'; exit; $referrals = affiliate_wp()->referrals->get_referrals(array('orderby' => 'date', 'order' => 'ASC', 'date' => $date, 'number' => -1, 'affiliate_id' => $this->get('affiliate_id'))); $pending[] = array(strtotime($start) * 1000); $pending[] = array(strtotime($end) * 1000); if ($referrals) { foreach ($referrals as $referral) { switch ($referral->status) { case 'paid': $paid[] = array(strtotime($referral->date) * 1000, $referral->amount); break; case 'unpaid': $unpaid[] = array(strtotime($referral->date) * 1000, $referral->amount); break; case 'rejected': $rejected[] = array(strtotime($referral->date) * 1000, $referral->amount); break; case 'pending': $pending[] = array(strtotime($referral->date) * 1000, $referral->amount); break; default: break; } } } $data = array(__('Unpaid Referral Earnings', 'affiliate-wp') => $unpaid, __('Pending Referral Earnings', 'affiliate-wp') => $pending, __('Rejected Referral Earnings', 'affiliate-wp') => $rejected, __('Paid Referral Earnings', 'affiliate-wp') => $paid); return $data; }
/** * Show report graph date filters * * @since 1.0 * @return void */ function graph_controls() { $date_options = apply_filters('affwp_report_date_options', array('today' => __('Today', 'affiliate-wp'), 'yesterday' => __('Yesterday', 'affiliate-wp'), 'this_week' => __('This Week', 'affiliate-wp'), 'last_week' => __('Last Week', 'affiliate-wp'), 'this_month' => __('This Month', 'affiliate-wp'), 'last_month' => __('Last Month', 'affiliate-wp'), 'this_quarter' => __('This Quarter', 'affiliate-wp'), 'last_quarter' => __('Last Quarter', 'affiliate-wp'), 'this_year' => __('This Year', 'affiliate-wp'), 'last_year' => __('Last Year', 'affiliate-wp'), 'other' => __('Custom', 'affiliate-wp'))); $dates = affwp_get_report_dates(); $display = $dates['range'] == 'other' ? 'style="display:inline-block;"' : 'style="display:none;"'; $current_time = current_time('timestamp'); ?> <form id="affwp-graphs-filter" method="get"> <div class="tablenav top"> <?php if (is_admin()) { ?> <?php $tab = isset($_GET['tab']) ? $_GET['tab'] : 'referral'; ?> <?php $page = isset($_GET['page']) ? $_GET['page'] : 'affiliate-wp'; ?> <input type="hidden" name="page" value="<?php echo esc_attr($page); ?> "/> <?php } else { ?> <?php $tab = isset($_GET['tab']) ? $_GET['tab'] : 'graphs'; ?> <input type="hidden" name="page_id" value="<?php echo esc_attr(get_the_ID()); ?> "/> <?php } ?> <input type="hidden" name="tab" value="<?php echo esc_attr($tab); ?> "/> <?php if (isset($_GET['affiliate_id'])) { ?> <input type="hidden" name="affiliate_id" value="<?php echo absint($_GET['affiliate_id']); ?> "/> <input type="hidden" name="action" value="view_affiliate"/> <?php } ?> <select id="affwp-graphs-date-options" name="range"> <?php foreach ($date_options as $key => $option) { echo '<option value="' . esc_attr($key) . '" ' . selected($key, $dates['range']) . '>' . esc_html($option) . '</option>'; } ?> </select> <div id="affwp-date-range-options" <?php echo $display; ?> > <span><?php _e('From', 'affiliate-wp'); ?> </span> <select id="affwp-graphs-month-start" name="m_start"> <?php for ($i = 1; $i <= 12; $i++) { ?> <option value="<?php echo absint($i); ?> " <?php selected($i, $dates['m_start']); ?> ><?php echo affwp_month_num_to_name($i); ?> </option> <?php } ?> </select> <select id="affwp-graphs-year" name="year_start"> <?php for ($i = 2007; $i <= date('Y', $current_time); $i++) { ?> <option value="<?php echo absint($i); ?> " <?php selected($i, $dates['year']); ?> ><?php echo $i; ?> </option> <?php } ?> </select> <span><?php _e('To', 'affiliate-wp'); ?> </span> <select id="affwp-graphs-month-start" name="m_end"> <?php for ($i = 1; $i <= 12; $i++) { ?> <option value="<?php echo absint($i); ?> " <?php selected($i, $dates['m_end']); ?> ><?php echo affwp_month_num_to_name($i); ?> </option> <?php } ?> </select> <select id="affwp-graphs-year" name="year_end"> <?php for ($i = 2007; $i <= date('Y', $current_time); $i++) { ?> <option value="<?php echo absint($i); ?> " <?php selected($i, $dates['year_end']); ?> ><?php echo $i; ?> </option> <?php } ?> </select> </div> <input type="submit" class="button" value="<?php _e('Filter', 'affiliate-wp'); ?> "/> </div> </form> <?php }