Plugin Directory

Changeset 716688


Ignore:
Timestamp:
05/22/2013 02:47:05 PM (13 years ago)
Author:
tkrivickas
Message:

NF: Added sort feature

Location:
live-stream-badger/trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • live-stream-badger/trunk/domain/class-stream.php

    r714835 r716688  
    5757    }
    5858
     59    static function sort_by_status( $la, $lb ) {
     60        $count_a = $la->watching_now;
     61        $count_b = $lb->watching_now;
     62
     63        if ( ( -1 == $count_a && -1 == $count_b ) || ( -1 != $count_a && -1 != $count_b ) )
     64            return 0;
     65
     66        $natural = ( $count_a > $count_b ) ? 1 : -1;
     67        return ( -1 ) * $natural;
     68    }
     69
    5970}
    6071
  • live-stream-badger/trunk/stream-status-widget.php

    r715213 r716688  
    44include_once LSB_PLUGIN_BASE . 'domain/class-stream.php';
    55include_once LSB_PLUGIN_BASE . 'domain/class-stream-summary.php';
     6include_once LSB_PLUGIN_BASE . 'domain/class-stream-sorter.php';
    67include_once LSB_PLUGIN_BASE . 'store/class-stream-storage.php';
    78
     
    2223        $hide_offline        = isset ( $instance['hide_offline'] ) ? $instance['hide_offline'] : FALSE;
    2324        $hide_offline_images = isset ( $instance['hide_offline_images'] ) ? $instance['hide_offline_images'] : FALSE;
     25        $sorting_strategy    = isset ( $instance['sorting_strategy'] ) ? $instance['sorting_strategy'] : 'by_watching_now';
    2426
    2527        // Get menu items for configured menu
     
    5961        $streams = $store->load();
    6062
    61         usort( $streams, array( 'LSB_Stream', 'sort_by_watching_now' ) );
     63        $stream_sorter = new LSB_Stream_Sorter( $links );
     64        if ( $sorting_strategy == 'by_status' ) {
     65            usort( $streams, array( $stream_sorter, 'sort_by_status' ) );
     66        }
     67        else if ( $sorting_strategy == 'by_watching_now' ) {
     68            usort( $streams, array( $stream_sorter, 'sort_by_watching_now' ) );
     69        }
     70        else {
     71            usort( $streams, array( $stream_sorter, 'sort_by_menu_order' ) );
     72        }
     73
    6274        ?>
    6375        <div class="lsb-status-widget-holder">
     
    136148        $instance['hide_offline_images'] = $new_instance['hide_offline_images'];
    137149
     150        $instance['sorting_strategy'] = $new_instance['sorting_strategy'];
     151
    138152        return $instance;
    139153    }
     
    145159        $hide_offline        = isset ( $instance['hide_offline'] ) ? $instance['hide_offline'] : FALSE;
    146160        $hide_offline_images = isset ( $instance['hide_offline_images'] ) ? $instance['hide_offline_images'] : FALSE;
     161        $sorting_strategy    = isset( $instance['sorting_strategy'] ) ? $instance['sorting_strategy'] : 'by_watching_now';
    147162
    148163        $menus = get_terms( 'nav_menu', array( 'hide_empty' => FALSE ) );
     
    199214            </label>
    200215        </p>
     216        <p>
     217            <label>
     218                <?php _e( 'Sort streams by:' ); ?>
     219                <select name="<?php echo $this->get_field_name( 'sorting_strategy' ); ?>" id="<?php echo $this->get_field_id( 'sorting_strategy' ); ?>">
     220                    <option value="by_watching_now" <?php selected( $sorting_strategy, 'by_watching_now' ) ?>>Watching Now</option>
     221                    <option value="by_status" <?php selected( $sorting_strategy, 'by_status' ) ?>>Status</option>
     222                    <option value="no_sort" <?php selected( $sorting_strategy, 'no_sort' ) ?>>No sort</option>
     223                </select>
     224            </label>
     225        </p>
    201226    <?php
    202227    } // form()
Note: See TracChangeset for help on using the changeset viewer.