You are here

public function UcWishlistManager::searchUserWishlist in UC Wish List 8

This function displays the list of wish lists created by a user by providing specific matching keywords referring to a user name, wish list title and address.

Parameters

$keywords: refers to the keywords to make three queries and return a new DatabaseCondition.

Return value

string displays a list of user wish lists.

File

src/Database/UcWishlistManager.php, line 145

Class

UcWishlistManager
Defines an UcWishlistManager service.

Namespace

Drupal\uc_wishlist\Database

Code

public function searchUserWishlist($keywords) {
  if (!empty($keywords)) {

    // Check for user, wish list title, or address matches.
    $query = $this->connection
      ->select('uc_wishlists', 'w');
    $query
      ->join('users', 'u', 'w.uid = u.uid');
    $query
      ->fields('w', [
      'wid',
      'title',
    ]);
    $query
      ->distinct();
    $query
      ->condition(db_or()
      ->condition('u.name', '%' . $keywords . '%', 'LIKE')
      ->condition('w.title', '%' . $keywords . '%', 'LIKE')
      ->condition('w.address', '%' . $keywords . '%', 'LIKE'));
  }
  else {
    $query = $this->connection
      ->select('uc_wishlists', 'w');
    $query
      ->fields('w', [
      'wid',
      'title',
    ]);
  }
  $query
    ->condition('w.private', 0, '=');
  $result = $query
    ->orderBy('w.title')->execute;

  /**
   * @todo
   * extend default pager limit
   * $query->extend('PagerDefault')->limit(25)->execute();
   */
  return $result;
}