From 41edfa2f7c85d657ff41ba146bd45de84373281c Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sat, 21 Jul 2018 23:03:15 -0400 Subject: Add PAGE_OBJECT global mechanism This addresses a problem with most views. They need an object context to display in. IE what pad, group, etc. are we viewing? This variable is intended to be set by index.php and referenced by page models. --- app/class/globals.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/app/class/globals.php b/app/class/globals.php index 776fc35..8d27ae4 100644 --- a/app/class/globals.php +++ b/app/class/globals.php @@ -12,6 +12,8 @@ * For more information, please refer to UNLICENSE */ +require_once "class/obj.class.php"; + /* * This file defines various functions which exist in the global namespace. * These are utility functions and constants for the Scrott application. @@ -32,6 +34,14 @@ $_SCROTT[ERROR] = array(); $_SCROTT[WARNING] = array(); $_SCROTT[NOTICE] = array(); +/* + * The page object is the object our current request is primarily + * interested in. For example, when navigating to a pad web page by + * its guid, that pad is the page object. When viewing the dashboard, + * the current logged-in user is the page object. + */ +$_SCROTT['PAGE_OBJECT'] = NULL; + /* * Get the application root path. This is an absolute path on the server. */ @@ -125,6 +135,29 @@ function getErrors(string $level) : array return $_SCROTT[$level]; } +/* + * Set the page object for the current request. This can only + * be called once per runtime. + */ +function setPageObj(obj $obj) : void +{ + global $_SCROTT; + + if ($_SCROTT['PAGE_OBJECT'] !== NULL) + throw new Exception("Tried to establish page object context twice"); + + $_SCROTT['PAGE_OBJECT'] = $obj; +} + +/* + * Get the page object for the current request. + */ +function getPageObj() : ?obj +{ + global $_SCROTT; + return $_SCROTT['PAGE_OBJECT']; +} + /* * Save an uploaded file and impose some constraints on supplied * data. Caller can optionally pass some strings by reference to -- cgit v1.2.3