'', 'pub_id' => '', 'output_type' => OBJECT ); $atts = wp_parse_args( $args, $defaults ); global $wpdb; $select = "SELECT * FROM " . TEACHPRESS_USER; $awhere = array(); $awhere[] = TP_DB_Helpers::generate_where_clause($atts['user'], "user", "OR", "="); $awhere[] = TP_DB_Helpers::generate_where_clause($atts['pub_id'], "pub_id", "OR", "="); $where = TP_DB_Helpers::compose_clause($awhere); $sql = $select . $where; return $wpdb->get_results($sql, $atts['output_type']); } /** * Adds a new bookmark for a user * @param int $pub_id The publication ID * @param int $user The user ID * @param bool $exist_check true = Checks if the bookmark already exists before inserting, default: false * @return int The id of the created element * @since 5.0.0 */ public static function add_bookmark($pub_id, $user, $exist_check = false) { global $wpdb; // Check if the bookmark already exists before inserting if ( $exist_check === true ) { $check = TP_Bookmarks::bookmark_exists($pub_id, $user); if ( $check === true ) { return; } } // Add the bookmark $wpdb->insert( TEACHPRESS_USER, array( 'pub_id' => $pub_id, 'user' => $user), array('%d', '%d') ); return $wpdb->insert_id; } /** * Delete a bookmark * @param int $bookmark_id * @since 5.0.0 */ public static function delete_bookmark($bookmark_id) { global $wpdb; $wpdb->query( "DELETE FROM " . TEACHPRESS_USER . " WHERE `bookmark_id` = '" . intval($bookmark_id) . "'" ); } /** * Deletes all bookmarks of a publication * @param int $pub_id * @since 8.1.0 */ public static function delete_bookmarks_by_publication($pub_id) { global $wpdb; $wpdb->query( "DELETE FROM " . TEACHPRESS_USER . " WHERE `pub_id` = '" . intval($pub_id) . "'" ); } /** * Checks if an user has bookmarked a publication. Returns true the bookmark exists. * @param int $pub_id The publication ID * @param int $user_id The user ID * @return boolean * @since 5.0.0 */ public static function bookmark_exists($pub_id, $user_id) { global $wpdb; $test = $wpdb->query("SELECT `pub_id` FROM " . TEACHPRESS_USER . " WHERE `pub_id`='" . intval($pub_id) . "' AND `user` = '" . intval($user_id) . "'"); if ($test != 0) { return true; } return false; } }