You are here

public function UCWishlistController::AdminWishlist in UC Wish List 8

This function returns a list of user wish lists by displaying the user, title and expiration status.

Return value

array a paged list of wish lists.

1 string reference to 'UCWishlistController::AdminWishlist'
uc_wishlist.routing.yml in ./uc_wishlist.routing.yml
uc_wishlist.routing.yml

File

src/Controller/UCWishlistController.php, line 47

Class

UCWishlistController

Namespace

Drupal\uc_wishlist\Controller

Code

public function AdminWishlist() {
  $rows = [];
  $header = [
    [
      'data' => t('User'),
      'field' => 'u.name',
      'sort' => 'asc',
    ],
    [
      'data' => t('Title'),
      'field' => 'w.title',
    ],
    [
      'data' => t('Expiration date'),
      'field' => 'w.expiration',
    ],
    [
      'data' => t('Status'),
    ],
  ];

  // Database returns a paged list of wish lists.
  $result = $this->db
    ->getAllWishlist();
  foreach ($result as $wishlist) {
    $deleteUrl = Url::fromRoute('uc_wishlist.admin_delete', [
      'uc_wishlist' => $wishlist->wid,
    ]);
    $link_options = [
      'attributes' => [],
    ];
    $deleteUrl
      ->setOptions($link_options);

    // Wishlist expiration status.
    $expired = '';
    if ($wishlist->expiration < REQUEST_TIME) {
      $expired = t('Expired');
    }
    elseif ($wishlist->expiration > 0) {
      $expired = t('Active');
    }
    $deleteUrl = Link::fromTextAndUrl($expired . ' | Delete', $deleteUrl)
      ->toString();
    $account = User::load($wishlist->uid);
    $name = $account
      ->getAccountName();
    $rows[] = [
      $name ? Link::fromTextAndUrl($name, Url::fromRoute('entity.user.canonical', [
        'user' => $wishlist->uid,
      ]))
        ->toString() : t('Anonymous'),
      Link::fromTextAndUrl($wishlist->title, Url::fromRoute('uc_wishlist.wishlist_view', [
        'wid' => $wishlist->wid,
      ]))
        ->toString(),
      \Drupal::service('date.formatter')
        ->format($wishlist->expiration),
      $deleteUrl,
    ];
  }
  if (empty($rows)) {
    $rows[] = [
      [
        'data' => t('No wish lists found'),
        'colspan' => 4,
      ],
    ];
  }
  return [
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
  ];
}