public static function get_sql_join($alias, $component, $ratingarea, $itemidjoin, $userid, $innerjoin = false) {
        static $count = 0;
        $count++;

        $userwhere = '';

        if ($innerjoin) {
            // Join the rating table with the specified alias and the relevant join params.
            $join = "JOIN {rating} {$alias} ON ";
            $join .= "{$alias}.itemid = {$itemidjoin}";

            $userwhere .= "{$alias}.userid = :ratinguserid{$count} AND ";
            $userwhere .= "{$alias}.component = :ratingcomponent{$count} AND ";
            $userwhere .= "{$alias}.ratingarea = :ratingarea{$count}";
        } else {
            // Join the rating table with the specified alias and the relevant join params.
            $join = "LEFT JOIN {rating} {$alias} ON ";
            $join .= "{$alias}.userid = :ratinguserid{$count} AND ";
            $join .= "{$alias}.component = :ratingcomponent{$count} AND ";
            $join .= "{$alias}.ratingarea = :ratingarea{$count} AND ";
            $join .= "{$alias}.itemid = {$itemidjoin}";

            // Match against the specified user.
            $userwhere = "{$alias}.id IS NOT NULL";
        }

        $params = [
            'ratingcomponent' . $count  => $component,
            'ratingarea' . $count       => $ratingarea,
            'ratinguserid' . $count     => $userid,
        ];

        $return = (object) [
            'join' => $join,
            'params' => $params,
            'userwhere' => $userwhere,
        ];
        return $return;
    }