Changeset 7549
- Timestamp:
- 11/09/2013 05:04:41 PM (11 years ago)
- Location:
- trunk/bp-notifications
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-notifications/bp-notifications-classes.php
r7536 r7549 255 255 256 256 $where_conditions = array(); 257 $where = ''; 257 258 258 259 // id … … 327 328 } 328 329 330 // Custom WHERE 329 331 if ( ! empty( $where_conditions ) ) { 330 332 $where = 'WHERE ' . implode( ' AND ', $where_conditions ); 331 } else {332 $where = '';333 333 } 334 334 335 335 return $where; 336 } 337 338 /** 339 * Assemble the ORDER BY clause of a get() SQL statement. 340 * 341 * Used by BP_Notifications_Notification::get() to create its ORDER BY 342 * clause. 343 * 344 * @since BuddyPress (1.9.0) 345 * 346 * @param array $args See {@link BP_Notifications_Notification::get()} 347 * for more details. 348 * @return string ORDER BY clause. 349 */ 350 protected static function get_order_by_sql( $args = array() ) { 351 352 // Setup local variable 353 $conditions = array(); 354 $retval = ''; 355 356 // Order by 357 if ( ! empty( $args['order_by'] ) ) { 358 $order_by = implode( ', ', (array) $args['order_by'] ); 359 $conditions['order_by'] = "{$order_by}"; 360 } 361 362 // Sort order direction 363 if ( ! empty( $args['sort_order'] ) && in_array( $args['sort_order'], array( 'ASC', 'DESC' ) ) ) { 364 $sort_order = $args['sort_order']; 365 $conditions['sort_order'] = "{$sort_order}"; 366 } 367 368 // Custom ORDER BY 369 if ( ! empty( $conditions ) ) { 370 $retval = 'ORDER BY ' . implode( ' ', $conditions ); 371 } 372 373 return $retval; 374 } 375 376 /** 377 * Assemble the LIMIT clause of a get() SQL statement. 378 * 379 * Used by BP_Notifications_Notification::get() to create its LIMIT clause. 380 * 381 * @since BuddyPress (1.9.0) 382 * 383 * @param array $args See {@link BP_Notifications_Notification::get()} 384 * for more details. 385 * @return string LIMIT clause. 386 */ 387 protected static function get_paged_sql( $args = array() ) { 388 global $wpdb; 389 390 // Setup local variable 391 $retval = ''; 392 393 // Custom LIMIT 394 if ( ! empty( $args['page'] ) && ! empty( $args['per_page'] ) ) { 395 $page = absint( $args['page'] ); 396 $per_page = absint( $args['per_page'] ); 397 $offset = $per_page * ( $page - 1 ); 398 $retval = $wpdb->prepare( "LIMIT %d, %d", $offset, $per_page ); 399 } 400 401 return $retval; 336 402 } 337 403 … … 482 548 global $wpdb; 483 549 484 $r = wp_parse_args( $args, array( 550 // Parse the arguments 551 $r = wp_parse_args( $args, array( 485 552 'id' => false, 486 553 'user_id' => false, … … 491 558 'is_new' => true, 492 559 'search_terms' => '', 560 'order_by' => false, 561 'sort_order' => false, 493 562 'page' => false, 494 563 'per_page' => false, 495 564 ) ); 496 565 497 $bp = buddypress(); 498 $pag_sql = ''; 566 // SELECT 499 567 $select_sql = "SELECT *"; 500 $from_sql = "FROM {$bp->notifications->table_name}"; 568 569 // FROM 570 $from_sql = "FROM " . buddypress()->notifications->table_name; 571 572 // WHERE 501 573 $where_sql = self::get_where_sql( array( 502 574 'id' => $r['id'], … … 510 582 ) ); 511 583 512 if ( ! empty( $r['page'] ) && ! empty( $r['per_page'] ) ) { 513 $page = absint( $r['page'] ); 514 $per_page = absint( $r['per_page'] ); 515 $offset = $per_page * ( $page - 1 ); 516 $pag_sql = $wpdb->prepare( "LIMIT %d, %d", $offset, $per_page ); 517 } 518 519 $sql = "{$select_sql} {$from_sql} {$where_sql} {$pag_sql}"; 584 // ORDER BY 585 $order_sql = self::get_order_by_sql( array( 586 'order_by' => $r['order_by'], 587 'sort_order' => $r['sort_order'] 588 ) ); 589 590 // LIMIT %d, %d 591 $pag_sql = self::get_paged_sql( array( 592 'page' => $r['page'], 593 'per_page' => $r['per_page'], 594 ) ); 595 596 $sql = "{$select_sql} {$from_sql} {$where_sql} {$order_sql} {$pag_sql}"; 520 597 521 598 return $wpdb->get_results( $sql ); -
trunk/bp-notifications/bp-notifications-template.php
r7547 r7549 227 227 'page' => 1, 228 228 'per_page' => 25, 229 'order_by' => 'date_notified', 230 'sort_order' => 'DESC', 229 231 'max' => null, 230 232 'search_terms' => '', … … 239 241 $this->search_terms = $r['search_terms']; 240 242 $this->page_arg = $r['page_arg']; 243 $this->order_by = $r['order_by']; 244 $this->sort_order = $r['sort_order']; 241 245 242 246 // Get the notifications … … 247 251 'per_page' => $this->pag_num, 248 252 'search_terms' => $this->search_terms, 253 'order_by' => $this->order_by, 254 'sort_order' => $this->sort_order, 249 255 ) ); 250 256
Note: See TracChangeset
for help on using the changeset viewer.