/** * Gets rating results * * @param unknown_type $params */ public static function get_rating_results($params = array()) { extract(wp_parse_args($params, array('taxonomy' => null, 'term_id' => 0, 'limit' => 10, 'result_type' => Multi_Rating::STAR_RATING_RESULT_TYPE, 'sort_by' => 'highest_rated', 'post_id' => null))); $order_by = array(); if ($sort_by == 'post_title_asc') { $order_by = array('post_title ASC'); } else { if ($sort_by == 'post_title_desc') { $order_by = array('post_title DESC'); } } $group_by = array('rie.post_id'); $rating_entries = Multi_Rating_API::get_rating_item_entries(array('taxonomy' => $taxonomy, 'term_id' => $term_id, 'post_id' => $post_id, 'order_by' => $order_by, 'group_by' => $group_by)); $rating_results = array(); foreach ($rating_entries as $rating_entry) { $temp_post_id = $rating_entry['post_id']; $rating_result = Multi_Rating_API::get_rating_result($temp_post_id); // WPML get adjusted post id for active language and override if (function_exists('icl_object_id')) { $rating_result['post_id'] = icl_object_id($temp_post_id, get_post_type($temp_post_id), true, ICL_LANGUAGE_CODE); } array_push($rating_results, $rating_result); } // TODO pagination $rating_results = array_slice(MR_Utils::sort_rating_results($rating_results, $sort_by, $result_type), 0, $limit); return $rating_results; }
/** * Clears all rating results from the database */ function mr_clear_database() { if (!current_user_can('manage_options')) { return; } $username = isset($_POST['username']) ? $_POST['username'] : null; $from_date = isset($_POST['from-date2']) ? $_POST['from-date2'] : null; $to_date = isset($_POST['to-date2']) ? $_POST['to-date2'] : null; $post_id = isset($_POST['post-id']) ? $_POST['post-id'] : null; $user_id = null; if ($username) { $user = get_user_by('login', $username); if ($user && $user->ID) { $user_id = $user->ID; } } $entries = Multi_Rating_API::get_rating_item_entries(array('user_id' => $user_id, 'from_date' => $from_date, 'to_date' => $to_date, 'post_id' => $post_id)); if (count($entries) > 0) { $entry_id_array = array(); foreach ($entries as $entry) { array_push($entry_id_array, $entry['rating_item_entry_id']); // rating results cache will be refreshed next time it's needed delete_post_meta($entry['post_id'], Multi_Rating::RATING_RESULTS_POST_META_KEY); } global $wpdb; $entry_id_list = implode(',', $entry_id_array); try { $rows = $wpdb->get_results('DELETE FROM ' . $wpdb->prefix . Multi_Rating::RATING_ITEM_ENTRY_TBL_NAME . ' WHERE rating_item_entry_id IN ( ' . $entry_id_list . ')'); $rows = $wpdb->get_results('DELETE FROM ' . $wpdb->prefix . Multi_Rating::RATING_ITEM_ENTRY_VALUE_TBL_NAME . ' WHERE rating_item_entry_id IN ( ' . $entry_id_list . ')'); echo '<div class="updated"><p>' . __('Database cleared successfully.', 'multi-rating') . '</p></div>'; } catch (Exception $e) { echo '<div class="error"><p>' . sprintf(__('An error has occured. %s', 'multi-rating'), $e->getMessage()) . '</p></div>'; } } else { echo '<div class="error"><p>' . __('No entries found', 'multi-rating') . '</p></div>'; } }
/** * Handles bulk actions */ function process_bulk_action() { if (!current_user_can('manage_options')) { return; // should not get here } if ($this->current_action() === 'delete') { global $wpdb; $checked = is_array($_REQUEST['delete']) ? $_REQUEST['delete'] : array($_REQUEST['delete']); foreach ($checked as $post_id) { /* * delete rating item entry values as well */ $entries = Multi_Rating_API::get_rating_item_entries(array('post_id' => $post_id)); foreach ($entries as $entry) { $rating_item_entry_id = $entry['rating_item_entry_id']; $entry_values_query = 'DELETE FROM ' . $wpdb->prefix . Multi_Rating::RATING_ITEM_ENTRY_VALUE_TBL_NAME . ' WHERE ' . MR_Rating_Entry_Table::RATING_ITEM_ENTRY_ID_COLUMN . ' = "' . $rating_item_entry_id . '"'; $results = $wpdb->query($entry_values_query); $entries_query = 'DELETE FROM ' . $wpdb->prefix . Multi_Rating::RATING_ITEM_ENTRY_TBL_NAME . ' WHERE ' . MR_Rating_Entry_Table::RATING_ITEM_ENTRY_ID_COLUMN . ' = "' . $rating_item_entry_id . '"'; $results = $wpdb->query($entries_query); } /* * delete rating results cache in WordPress postmeta table */ delete_post_meta($post_id, Multi_Rating::RATING_RESULTS_POST_META_KEY); } echo '<div class="updated"><p>' . __('Rating results deleted successfully.', 'multi-rating') . '</p></div>'; } }