Changeset 716688
- Timestamp:
- 05/22/2013 02:47:05 PM (13 years ago)
- Location:
- live-stream-badger/trunk
- Files:
-
- 1 added
- 2 edited
-
domain/class-stream-sorter.php (added)
-
domain/class-stream.php (modified) (1 diff)
-
stream-status-widget.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
live-stream-badger/trunk/domain/class-stream.php
r714835 r716688 57 57 } 58 58 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 59 70 } 60 71 -
live-stream-badger/trunk/stream-status-widget.php
r715213 r716688 4 4 include_once LSB_PLUGIN_BASE . 'domain/class-stream.php'; 5 5 include_once LSB_PLUGIN_BASE . 'domain/class-stream-summary.php'; 6 include_once LSB_PLUGIN_BASE . 'domain/class-stream-sorter.php'; 6 7 include_once LSB_PLUGIN_BASE . 'store/class-stream-storage.php'; 7 8 … … 22 23 $hide_offline = isset ( $instance['hide_offline'] ) ? $instance['hide_offline'] : FALSE; 23 24 $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'; 24 26 25 27 // Get menu items for configured menu … … 59 61 $streams = $store->load(); 60 62 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 62 74 ?> 63 75 <div class="lsb-status-widget-holder"> … … 136 148 $instance['hide_offline_images'] = $new_instance['hide_offline_images']; 137 149 150 $instance['sorting_strategy'] = $new_instance['sorting_strategy']; 151 138 152 return $instance; 139 153 } … … 145 159 $hide_offline = isset ( $instance['hide_offline'] ) ? $instance['hide_offline'] : FALSE; 146 160 $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'; 147 162 148 163 $menus = get_terms( 'nav_menu', array( 'hide_empty' => FALSE ) ); … … 199 214 </label> 200 215 </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> 201 226 <?php 202 227 } // form()
Note: See TracChangeset
for help on using the changeset viewer.