summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2018-07-21 23:03:15 -0400
committerMalf Furious <m@lfurio.us>2018-07-21 23:03:15 -0400
commit41edfa2f7c85d657ff41ba146bd45de84373281c (patch)
tree21e766f89a5b6413cf52b853930a244147316c2e
parent398f4852874e33c32faa51ae332383f81ac7f82c (diff)
downloadscrott-41edfa2f7c85d657ff41ba146bd45de84373281c.tar.gz
scrott-41edfa2f7c85d657ff41ba146bd45de84373281c.zip
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.
-rw-r--r--app/class/globals.php33
1 files changed, 33 insertions, 0 deletions
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.
@@ -33,6 +35,14 @@ $_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.
*/
function ar() : string
@@ -126,6 +136,29 @@ function getErrors(string $level) : array
}
/*
+ * 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
* be given the supplied file's original name and mime-type.