summaryrefslogtreecommitdiff
path: root/html/app/controllers/Resolve.php
diff options
context:
space:
mode:
authorGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-03-12 07:16:23 +0200
committerGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-03-12 07:16:23 +0200
commit7076343338ae3439f3c86f01144818abe8c31978 (patch)
tree794abb1e6b8f821091fd095341885496b6dad51d /html/app/controllers/Resolve.php
parent47cbb529f5723b246125ae083a193e11481b89ef (diff)
downloadclassroom-7076343338ae3439f3c86f01144818abe8c31978.tar.gz
classroom-7076343338ae3439f3c86f01144818abe8c31978.tar.bz2
classroom-7076343338ae3439f3c86f01144818abe8c31978.zip
add container helpers; constuct public directory-tree
Diffstat (limited to 'html/app/controllers/Resolve.php')
-rw-r--r--html/app/controllers/Resolve.php91
1 files changed, 91 insertions, 0 deletions
diff --git a/html/app/controllers/Resolve.php b/html/app/controllers/Resolve.php
new file mode 100644
index 0000000..7b9222c
--- /dev/null
+++ b/html/app/controllers/Resolve.php
@@ -0,0 +1,91 @@
+<?php
+
+namespace app\controllers;
+
+use \Benchmark;
+
+/** Resolve class
+ * will resolve ambiguous utl-request patterns
+ * ---
+ * Then it can route the request to some controller;
+ * Alternatively it can proccess the request via Models
+ * and initiate the View engine
+ */
+class Resolve {
+
+ public static function url($array)
+ {
+ $fullUrl = implode('/', $array);
+ $url = $array[count($array) - 1];
+
+
+ if (!PRODUCTION) Benchmark::add_spot('proxy-page');
+
+ // proxying check if page with this url
+ $page = proxy(
+ [\app\models\cms\Page_model::class, 'fromUrl'],
+ [ $fullUrl ], CACHE_ROOT_TTL,
+ PROXY_CACHE_ERRORS
+ );
+ // if page exist, construct page
+ if ($page !== false) {
+ // page exists, render page
+ load_template('base', [ 'page' => [
+ 'title' => $page['Title'],
+ 'seo' => [],
+ 'sections' => [
+ [
+ 'view' => 'content/static',
+ 'key' => 'page',
+ 'data' => $page
+ ]
+ ]
+ ]
+ ]);
+ return ;
+ }
+
+
+ if (!PRODUCTION) Benchmark::add_spot('proxy-category');
+
+ // proxying check if products category with this url
+ $category = proxy(
+ [\app\models\market\ProductCategories_model::class, 'categoryFromUrl'],
+ [ $fullUrl ], CACHE_CATEGORY_TTL
+ );
+ // if category exist, construct category
+ if ($category !== false) {
+ // render page
+ load_template('products', [ 'data' => [
+ 'title' => $category['Title'],
+ 'seo' => [],
+ 'tree' => proxy(
+ [\app\models\market\ProductCategories_model::class, 'tree'],
+ [], CACHE_ROOT_TTL
+ ),
+ 'hierarchyPath' => explode('.', substr($category['Hierarchy'], 1, -1)),
+ 'sections' => [
+ [
+ 'view' => 'content/product_list/Product_List_Filters',
+ 'key' => 'filters',
+ 'data' => $category
+ ],
+ [
+ 'view' => 'content/product_list/product_list',
+ 'key' => 'products',
+ 'data' => $category['products']
+ ]
+ ]
+ ]
+ ]);
+ return ;
+ }
+
+
+ // not page nor category?: reply 404
+ header("HTTP/1.0 404 Not Found");
+ render_view('error/404', ['message' => 'Say something I\'m givin\' up on you.']);
+
+ }
+
+} \ No newline at end of file