RTMediaModel::get_other_album_count PHP Метод

get_other_album_count() публичный Метод

public get_other_album_count ( integer $profile_id, string $context = 'profile' ) : integer
$profile_id integer
$context string
Результат integer
    function get_other_album_count($profile_id, $context = 'profile')
    {
        global $wpdb;
        $global = RTMediaAlbum::get_globals();
        $sql = $wpdb->prepare("select distinct album_id from {$this->table_name} where 2=2 AND context = %s ", $context);
        if (is_multisite()) {
            $sql .= $wpdb->prepare(" AND {$this->table_name}.blog_id = %d ", get_current_blog_id());
        }
        if (is_array($global) && count($global) > 0) {
            $sql .= ' and album_id in (';
            $sep = '';
            foreach ($global as $id) {
                $sql .= $sep . esc_sql($id);
                $sep = ',';
            }
            $sql .= ')';
        }
        if ('profile' === $context) {
            $sql .= $wpdb->prepare(' AND media_author=%d ', $profile_id);
        } else {
            if ('group' === $context) {
                $sql .= $wpdb->prepare(' AND context_id=%d ', $profile_id);
            }
        }
        $sql .= 'limit 100';
        $result = $wpdb->get_results($sql);
        if (isset($result)) {
            return count($result);
        } else {
            return 0;
        }
    }

Usage Example

Пример #1
0
 public function sub_nav()
 {
     global $rtmedia, $rtmedia_query;
     if (function_exists('bp_is_group') && bp_is_group()) {
         if (isset($rtmedia->options['buddypress_enableOnGroup']) && $rtmedia->options['buddypress_enableOnGroup'] == '0') {
             return;
         }
         global $bp;
         $counts = $this->actual_counts($bp->groups->current_group->id, "group");
     } else {
         if (class_exists('BuddyPress') && isset($rtmedia->options['buddypress_enableOnProfile']) && $rtmedia->options['buddypress_enableOnProfile'] == '0') {
             return;
         }
         $counts = $this->actual_counts();
     }
     $default = false;
     if (function_exists('bp_is_group') && bp_is_group()) {
         $link = get_rtmedia_group_link(bp_get_group_id());
         $model = new RTMediaModel();
         $other_count = $model->get_other_album_count(bp_get_group_id(), "group");
     } else {
         if (function_exists('bp_displayed_user_id') && bp_displayed_user_id()) {
             $link = get_rtmedia_user_link(bp_displayed_user_id());
         } elseif (get_query_var('author')) {
             $link = get_rtmedia_user_link(get_query_var('author'));
         }
         $model = new RTMediaModel();
         $other_count = $model->get_other_album_count(bp_displayed_user_id(), "profile");
     }
     $all = '';
     if (!isset($rtmedia_query->action_query->media_type)) {
         $all = 'class="current selected"';
     }
     echo apply_filters('rtmedia_sub_nav_all', '<li id="rtmedia-nav-item-all-li" ' . $all . '><a id="rtmedia-nav-item-all" href="' . trailingslashit($link) . RTMEDIA_MEDIA_SLUG . '/">' . __("All", "rtmedia") . '<span>' . (isset($counts['total']['all']) ? $counts['total']['all'] : 0) . '</span>' . '</a></li>');
     if (!isset($rtmedia_query->action_query->action) || empty($rtmedia_query->action_query->action)) {
         $default = true;
     }
     //print_r($rtmedia_query->action_query);
     $global_album = '';
     $albums = '';
     if (isset($rtmedia_query->action_query->media_type) && $rtmedia_query->action_query->media_type == 'album') {
         $albums = 'class="current selected"';
     }
     //$other_count = 0;
     if (is_rtmedia_album_enable()) {
         if (!isset($counts['total']["album"])) {
             $counts['total']["album"] = 0;
         }
         $counts['total']["album"] = $counts['total']["album"] + $other_count;
         $album_label = __(defined('RTMEDIA_ALBUM_PLURAL_LABEL') ? constant('RTMEDIA_ALBUM_PLURAL_LABEL') : 'Albums', 'rtmedia');
         echo apply_filters('rtmedia_sub_nav_albums', '<li id="rtmedia-nav-item-albums-li" ' . $albums . '><a id="rtmedia-nav-item-albums" href="' . trailingslashit($link) . RTMEDIA_MEDIA_SLUG . '/album/">' . $album_label . '<span>' . (isset($counts['total']["album"]) ? $counts['total']["album"] : 0) . '</span>' . '</a></li>');
     }
     foreach ($rtmedia->allowed_types as $type) {
         //print_r($type);
         if (!isset($rtmedia->options['allowedTypes_' . $type['name'] . '_enabled'])) {
             continue;
         }
         if (!$rtmedia->options['allowedTypes_' . $type['name'] . '_enabled']) {
             continue;
         }
         $selected = '';
         if (isset($rtmedia_query->action_query->media_type) && $type['name'] == $rtmedia_query->action_query->media_type) {
             $selected = ' class="current selected"';
         } else {
             $selected = '';
         }
         $context = isset($rtmedia_query->query['context']) ? $rtmedia_query->query['context'] : 'default';
         $context_id = isset($rtmedia_query->query['context_id']) ? $rtmedia_query->query['context_id'] : 0;
         $name = strtoupper($type['name']);
         $is_group = false;
         $profile = self::profile_id();
         if (!$profile) {
             $profile = self::group_id();
             $is_group = true;
         }
         if (!$is_group) {
             $profile_link = trailingslashit(get_rtmedia_user_link($profile));
         } else {
             $profile_link = trailingslashit(get_rtmedia_group_link($profile));
         }
         $type_label = __(defined('RTMEDIA_' . $name . '_PLURAL_LABEL') ? constant('RTMEDIA_' . $name . '_PLURAL_LABEL') : $type['plural_label'], 'rtmedia');
         echo apply_filters('rtmedia_sub_nav_' . $type['name'], '<li id="rtmedia-nav-item-' . $type['name'] . '-' . $context . '-' . $context_id . '-li" ' . $selected . '><a id="rtmedia-nav-item-' . $type['name'] . '" href="' . $profile_link . RTMEDIA_MEDIA_SLUG . '/' . constant('RTMEDIA_' . $name . '_SLUG') . '/' . '">' . $type_label . '<span>' . (isset($counts['total'][$type['name']]) ? $counts['total'][$type['name']] : 0) . '</span>' . '</a></li>', $type['name']);
     }
     do_action("add_extra_sub_nav");
 }
All Usage Examples Of RTMediaModel::get_other_album_count