Example #1
0
 public function at_ajax_add_tournament_round()
 {
     check_ajax_referer(ajax_nonce_string, 'security');
     if (!is_admin()) {
         exit('Get oouuuttaaa heeeere.');
     }
     global $at_functions, $at_tournament;
     $at_functions = new at_functions();
     $at_tournament = new at_tournament();
     // get tournament id for relevant tournament
     $tournament_id = $_REQUEST['postId'];
     if (!is_numeric($tournament_id) || $tournament_id <= 0) {
         exit('Get oouuuttaaa heeeere.');
     }
     // get post information to determine tournament_slug
     $tournament = get_post($tournament_id);
     //$tournament_categories = wp_get_object_terms( $tournament_id, 'category' ); // unused so far
     // get post slug to determine original post and newest post
     $tournament_slug = get_post_meta($tournament_id, at_tournament_slug, true);
     // get oldest post with tournament_slug
     $result = get_posts(array('post_type' => at_post_type_tournament, 'posts_per_page' => 1, 'meta_query' => array(array('key' => at_tournament_slug, 'value' => $tournament_slug, 'compare' => 'AND')), 'orderby' => 'date', 'order' => 'ASC'));
     if (!empty($result)) {
         $original_tournament = $result[0];
     } else {
         return false;
     }
     // get newest post with tournament_slug
     $result = get_posts(array('post_type' => at_post_type_tournament, 'posts_per_page' => 1, 'meta_query' => array(array('key' => at_tournament_slug, 'value' => $tournament_slug, 'compare' => 'AND')), 'orderby' => 'date', 'order' => 'DESC'));
     if (!empty($result)) {
         $newest_tournament = $result[0];
     } else {
         return false;
     }
     // get newest tournament round number
     $newest_tournament_round = get_post_meta($newest_tournament->ID, at_tournament_round, true);
     // increment round number for new post
     $new_tournament_round = $newest_tournament_round + 1;
     // get current (admin) user id for new post insertion
     $current_user_id = get_current_user_id();
     // get full category list to update categories for new post
     $at_categories = $at_functions->at_get_categories();
     // get category for current tournament
     $tournament_category = get_category_by_slug($tournament_slug);
     // build new tournament post array
     $new_round_post = array('post_type' => at_post_type_tournament, 'comment_status' => 'closed', 'post_title' => $original_tournament->post_title . ' ' . $new_tournament_round, 'post_author' => $current_user_id, 'post_parent' => 0, 'post_status' => 'draft');
     // insert new tournament post and return post ID on success
     $new_round_id = $at_functions->at_insert_post($new_round_post);
     // if insertion is successful, update tags & categories
     if (!empty($new_round_id)) {
         add_post_meta($new_round_id, at_tournament_slug, $tournament_slug);
         add_post_meta($new_round_id, at_tournament_round, $new_tournament_round);
         $result = wp_set_object_terms($new_round_id, array($at_categories[at_post_type_tournament], $tournament_category->term_id), 'category');
         // build round id & link for return to view
         $new_round_link = get_edit_post_link($new_round_id, '&');
         wp_send_json(array('round_id' => $new_round_id, 'round_link' => $new_round_link));
     }
     exit;
 }
Example #2
0
 public function at_insert_listen_list($listen_attrs)
 {
     $attrs = shortcode_atts(array(at_tournament_slug => ''), $listen_attrs, 'at_insert_listen_list');
     $slug = reset($attrs);
     if (!isset($at_functions)) {
         $at_functions = new at_functions();
     }
     if (!isset($at_entry)) {
         $at_entry = new at_entry();
     }
     $tournaments = get_posts(array('posts_per_page' => -1, 'meta_key' => at_post_type, 'meta_value' => at_post_type_results_page, 'post_type' => at_post_type_tournament, 'post_status' => 'publish'));
     $entries = array();
     $entry_posts = array();
     $author_ids = array();
     $authors = array();
     $players = array();
     foreach ($tournaments as $tournament) {
         $entry_ids = array();
         $tournament_id = $tournament->post_parent;
         $tournament_slug = get_post_meta($tournament_id, at_tournament_slug, true);
         if ($tournament_slug == $slug) {
             $tournament->ID = $tournament_id;
             $tournament->post_title = get_the_title($tournament_id);
             $tournament_round = get_post_meta($tournament_id, at_tournament_round, true);
             $entries[$tournament_id] = $at_entry->at_get_entry_data(NULL, NULL, $tournament_id, $tournament_round);
             foreach ($entries[$tournament_id] as $entry) {
                 $entry_url = $at_functions->get_entries_url($entry->user_id, $tournament_id, $tournament_round);
                 $audio = array('src' => $entry_url . "/" . rawurlencode($entry->mp3File));
                 $players[$entry->post_id] = wp_audio_shortcode($audio);
                 $entry_ids[] = $entry->post_id;
                 $author_ids[] = $entry->user_id;
             }
             $posts = $at_entry->at_get_entry_posts($entry_ids);
             $entry_posts[$tournament_id] = array();
             foreach ($posts as $post) {
                 $entry_posts[$tournament_id][$post->ID] = $post;
             }
         }
     }
     $users = get_users(array('include' => $author_ids, 'fields' => array('ID', 'user_nicename', 'display_name')));
     foreach ($users as $user) {
         $authors[$user->ID] = $user;
     }
     $viewData = array('tournaments' => $tournaments, 'players' => $players, 'authors' => $authors, 'entries' => $entries, 'entry_posts' => $entry_posts);
     return $at_functions->at_get_template('listen_list', $viewData);
 }