Sindbad~EG File Manager

Current Path : /home/xiedrke/entrepot/wp-content/plugins/realpress/app/Models/
Upload File :
Current File : /home/xiedrke/entrepot/wp-content/plugins/realpress/app/Models/CommentModel.php

<?php

namespace RealPress\Models;

class CommentModel {

	/**
	 * @param $object_id
	 * @param $comment_type
	 *
	 * @return float|int|mixed
	 */
	public static function get_comment_total( $object_id, $comment_type = 'property' ) {
		global $wpdb;
		$comment_tbl = $wpdb->comments;

		$total = $wpdb->get_var(
			$wpdb->prepare(
				"SELECT COUNT($comment_tbl.comment_id) FROM $comment_tbl WHERE $comment_tbl.comment_approved='1' 
					AND $comment_tbl.comment_type='%s' AND $comment_tbl.comment_post_id=%s",
				$comment_type,
				$object_id
			)
		);

		return empty( $total ) ? 0 : abs( $total );
	}

	/**
	 * @param $object_id
	 * @param $comment_type
	 *
	 * @return float|int
	 */
	public static function get_average_reviews( $object_id, $comment_type = 'property' ) {
		global $wpdb;
		$comment_tbl     = $wpdb->comments;
		$commentmeta_tbl = $wpdb->commentmeta;
		$average_reviews = $wpdb->get_var(
			$wpdb->prepare(
				"SELECT AVG ($commentmeta_tbl.meta_value) FROM $commentmeta_tbl INNER JOIN $comment_tbl ON ($comment_tbl.comment_id = $commentmeta_tbl.comment_id)
					WHERE $comment_tbl.comment_post_id = %d AND $comment_tbl.comment_type=%s AND $comment_tbl.comment_approved='1' AND $commentmeta_tbl.meta_key='realpress_fields\:review_stars'",
				$object_id,
				$comment_type
			)
		);

		return empty( $average_reviews ) ? 0 : round( $average_reviews, 2 );
	}

	/**
	 * @param $object_id
	 * @param $author_email
	 * @param $comment_type
	 *
	 * @return string|null
	 */
	public static function is_comment_exist( $object_id, $author_email, $comment_type = 'property' ) {
		global $wpdb;
		$comment_tbl = $wpdb->comments;

		return $wpdb->get_var(
			$wpdb->prepare(
				"SELECT EXISTS(SELECT $comment_tbl.comment_id FROM $comment_tbl WHERE $comment_tbl.comment_post_id = %d AND $comment_tbl.comment_type=%s 
					   AND $comment_tbl.comment_approved='1' AND $comment_tbl.comment_author_email =%s)",
				$object_id,
				$comment_type,
				$author_email
			)
		);
	}
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists