Ejemplo n.º 1
0
function wpmt_run()
{
    $my_token = esc_attr(get_option('wpmt_veezi_token'));
    $veezi_access_token = 'VeeziAccessToken: ' . $my_token;
    $session_data = call_service('https://api.us.veezi.com/v1/websession', $veezi_access_token);
    $film_and_performance_data = call_service('https://api.us.veezi.com/v1/film', $veezi_access_token);
    //1. delete all sessions
    wpmt_delete_all_posts('wpmt_session');
    //1-B. for testing, delete all films. This should be commented-out
    //wpmt_delete_all_posts( 'wpmt_film' );
    //2. if all sessions have been deleted, add the new ones
    if (NULL == get_posts(array('post_type' => 'wpmt_session'))) {
        wpmt_add_sessions($session_data);
    }
    //3. update all films & performances
    wpmt_update_posts($film_and_performance_data);
}
Ejemplo n.º 2
0
function wpmt_do_option_updates()
{
    //need to add a verification of user priviledges in here
    if (isset($_POST['wpmt_manual_update'])) {
        //$wpmt_updates = get_option('wpmt_manual_updates_checkbox');
        $wpmt_updates = $_POST['wpmt_manual_updates_checkbox'];
    }
    for ($i = 0; $i < count($wpmt_updates); $i++) {
        if ($wpmt_updates[$i] == 'force delete all films') {
            wpmt_delete_all_posts('WPMT_Film');
        }
        if ($wpmt_updates[$i] == 'force delete all performances') {
            wpmt_delete_all_posts('WPMT_Performance');
        }
        if ($wpmt_updates[$i] == 'force delete all sessions') {
            wpmt_delete_all_posts('WPMT_Session');
        }
        if ($wpmt_updates[$i] == 'add new films and performances') {
            $my_token = esc_attr(get_option('wpmt_veezi_token'));
            $veezi_access_token = 'VeeziAccessToken: ' . $my_token;
            $film_and_performance_data = call_service('https://api.us.veezi.com/v1/film', $veezi_access_token);
            wpmt_update_posts($film_and_performance_data);
        }
        if ($wpmt_updates[$i] == 'add new sessions') {
            $my_token = esc_attr(get_option('wpmt_veezi_token'));
            $veezi_access_token = 'VeeziAccessToken: ' . $my_token;
            $session_data = call_service('https://api.us.veezi.com/v1/websession', $veezi_access_token);
            //1. delete all sessions
            wpmt_delete_all_posts('WPMT_Session');
            if (NULL == get_posts(array('post_type' => 'WPMT_Session'))) {
                wpmt_add_sessions($session_data);
            }
        }
        if ($wpmt_updates[$i] == 'update film formats' || $wpmt_updates[$i] == 'update performance formats') {
            $my_token = esc_attr(get_option('wpmt_veezi_token'));
            $veezi_access_token = 'VeeziAccessToken: ' . $my_token;
            $film_and_performance_data = call_service('https://api.us.veezi.com/v1/film', $veezi_access_token);
            $post_data_as_array = wpmt_object_to_array($film_and_performance_data);
            for ($c = 0; $c < count($post_data_as_array); $c++) {
                if ($post_data_as_array[$c]["Genre"] != "Festival") {
                    // if the format is 'not a film' and it's not a documentary, then make a performance
                    if ($post_data_as_array[$c]["Format"] == "Not a Film" && $post_data_as_array[$c]["Genre"] != "Documentary") {
                        if ($wpmt_updates[$i] == 'update performance formats') {
                            $performance = new WPMT_Performance();
                            $performance->assign_values($post_data_as_array, $c);
                            if (NULL != get_posts(array('posts_per_page' => -1, 'post_type' => 'WPMT_Performance', 'meta_key' => 'wpmt_performance_id', 'meta_value' => $performance->id))) {
                                $posts = get_posts(array('posts_per_page' => -1, 'post_type' => 'WPMT_Performance', 'meta_key' => 'wpmt_performance_id', 'meta_value' => $performance->id));
                                foreach ($posts as $post) {
                                    $performance->update_performance_format($post->ID);
                                }
                            }
                        }
                    } elseif ($wpmt_updates[$i] == 'update film formats') {
                        $film = new WPMT_Film();
                        $film->assign_values($post_data_as_array, $c);
                        if (NULL != get_posts(array('posts_per_page' => -1, 'post_type' => 'WPMT_Film', 'meta_key' => 'wpmt_film_id', 'meta_value' => $film->id))) {
                            $posts = get_posts(array('posts_per_page' => -1, 'post_type' => 'WPMT_Film', 'meta_key' => 'wpmt_film_id', 'meta_value' => $film->id));
                            foreach ($posts as $post) {
                                $film->update_film_format($post->ID);
                            }
                        }
                    }
                }
            }
            // end for loop
        }
    }
}