| | |
| | | <?php |
| | | |
| | | use JVBase\managers\Cache; |
| | | use JVBase\meta\Meta; |
| | | use JVBase\utility\Image; |
| | | |
| | | if (!defined('ABSPATH')) { |
| | |
| | | { |
| | | $count = count($arr); |
| | | $and = ($and) ? ' and ' : ' or '; |
| | | if (empty($arr)){ |
| | | return ''; |
| | | } |
| | | switch ($count) { |
| | | case '1': |
| | | return implode(',', $arr); |
| | |
| | | |
| | | /** |
| | | * @param int $ID |
| | | * @param JVBase\meta\MetaManager|null $meta |
| | | * |
| | | * @param string $type 'post', 'user', or 'term' |
| | | * @return string |
| | | */ |
| | | function jvbFormatRating(int $ID, JVBase\meta\MetaManager|null $meta = null):string |
| | | function jvbFormatRating(int $ID, string $type = 'post'):string |
| | | { |
| | | $cache = Cache::for('rating', WEEK_IN_SECONDS)->connect('post')->connect('taxonomy')->connect('user'); |
| | | |
| | |
| | | return $cached; |
| | | } |
| | | |
| | | if (!$meta) { |
| | | if (term_exists((int)$ID)) { |
| | | $type = 'term'; |
| | | } elseif (get_post_status((int)$ID)) { |
| | | $type = 'post'; |
| | | } else { |
| | | $type = 'user'; |
| | | } |
| | | $meta = new JVBase\meta\MetaManager($ID, $type); |
| | | } |
| | | $meta = match ($type) { |
| | | 'term' => Meta::forTerm($ID), |
| | | 'post' => Meta::forPost($ID), |
| | | 'user' => Meta::forUser($ID), |
| | | default => false |
| | | }; |
| | | if (!$type) { |
| | | return ''; |
| | | } |
| | | |
| | | |
| | | $out = ''; |
| | | $avg = $meta->getValue('average_rating'); |
| | | $avg = $meta->get('average_rating'); |
| | | |
| | | $total = $meta->getValue('total_ratings'); |
| | | $total = $meta->get('total_ratings'); |
| | | if ($avg !== 'none') { |
| | | $out .= jvbFormatStarRating($avg, (int)$total); |
| | | } |