The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List available pages for a user
#1
This is a pretty ugly piece of hackery, so I'm hoping there's some sort of award.

I had a request from a user for a page to list other pages he was authorized to use. So I came up with this:

Code:
if ($user->data()->id) {
    $pageQuery = "SELECT DISTINCT `pages`.`page`, `pages`.`title` FROM `user_permission_matches` RIGHT JOIN `users` on `user_permission_matches`.`user_id`=`users`.`id` RIGHT JOIN `permission_page_matches` ON `user_permission_matches`.`permission_id`=`permission_page_matches`.`permission_id` RIGHT JOIN `pages` ON `pages`.`id`=`permission_page_matches`.`page_id` WHERE `users`.`id`= ? AND `title` LIKE 'PROJECT-PREFIX %'";
    $db->query($pageQuery, [$user->data()->id]);
    foreach ($db->results() as $page) {
        // Build a piece of HTML out of $page->page and $page->title
        // For bonus nastiness I check for <pagename>.png to use as an icon. Fugly but consistent ftw.
    }
}

Each page title already has a project prefix, so basically I'm just asking for a list of pages with that title, and matching uid->permission. There's no sorting, which may or may not be a problem at some stage.

I'm sure there's a much more elegant way, so suggestions are welcome!
  Reply


Messages In This Thread
List available pages for a user - by jtullett - 10-09-2018, 09:13 PM
RE: List available pages for a user - by mudmin - 10-09-2018, 09:27 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)