/** * get_latest_sql * Get the latest sql */ public static function get_latest_sql($type, $user_id = null) { if (is_null($user_id)) { $user_id = $GLOBALS['user']->id; } $user_id = intval($user_id); $type = Stats::validate_type($type); $sql = "SELECT `object_id` as `id` FROM user_flag" . " WHERE object_type = '" . $type . "' AND `user` = '" . $user_id . "'"; if (AmpConfig::get('catalog_disable')) { $sql .= " AND " . Catalog::get_enable_filter($type, '`object_id`'); } $sql .= " ORDER BY `date` DESC "; return $sql; }
/** * get_highest_sql * Get highest sql */ public static function get_highest_sql($type) { $type = Stats::validate_type($type); $sql = "SELECT `object_id` as `id`, AVG(`rating`) AS `rating` FROM rating" . " WHERE object_type = '" . $type . "'"; if (AmpConfig::get('catalog_disable')) { $sql .= " AND " . Catalog::get_enable_filter($type, '`object_id`'); } $sql .= " GROUP BY object_id ORDER BY `rating` DESC "; return $sql; }
/** * get_latest_sql * Get the latest sql */ public static function get_latest_sql($type, $user_id = null) { if (is_null($user_id)) { $user_id = $GLOBALS['user']->id; } $user_id = intval($user_id); $sql = "SELECT `user_flag`.`object_id` as `id`, `user_flag`.`object_type` as `type`, `user_flag`.`user` as `user` FROM `user_flag`"; if ($user_id <= 0) { // Get latest only from user rights >= content manager $sql .= " LEFT JOIN `user` ON `user`.`id` = `user_flag`.`user`" . " WHERE `user`.`access` >= 50"; } if (!is_null($type)) { if ($user_id <= 0) { $sql .= " AND"; } else { $sql .= " WHERE"; } $type = Stats::validate_type($type); $sql .= " `user_flag`.`object_type` = '" . $type . "'"; if ($user_id > 0) { $sql .= " AND `user_flag`.`user` = '" . $user_id . "'"; } if (AmpConfig::get('catalog_disable')) { $sql .= " AND " . Catalog::get_enable_filter($type, '`object_id`'); } } $sql .= " ORDER BY `user_flag`.`date` DESC "; return $sql; }