Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 101
0.00% covered (danger)
0.00%
0 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
SupportAdminPageController
0.00% covered (danger)
0.00%
0 / 101
0.00% covered (danger)
0.00%
0 / 8
506
0.00% covered (danger)
0.00%
0 / 1
 checkAdminPermission
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
12
 pageDashboard
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 pageArticles
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 pageArticleEditor
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 1
42
 pageCategories
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 pageSuggestions
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 pageAnalytics
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 pageArticlePreview
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2/**
3 * SupportAdminPageController
4 *
5 * Handles rendering of the Support Admin Portal pages.
6 * These are global admin pages for managing articles, categories,
7 * edit suggestions, and viewing analytics.
8 *
9 * All methods require uri_support_admin permission.
10 */
11
12namespace BuyerKiosk\Support\Controllers;
13
14use BuyerKiosk\Core\Controllers\BaseController;
15use BuyerKiosk\Support\ArticleManager;
16
17class SupportAdminPageController extends BaseController
18{
19    /**
20     * Check admin permission and redirect if not authorized
21     *
22     * @return bool True if authorized
23     */
24    private function checkAdminPermission()
25    {
26        $app = $this->_app;
27
28        // Check user is logged in
29        if (!$app->user) {
30            $app->redirect($app->urlFor('login'));
31            return false;
32        }
33
34        // Check admin permission
35        if (!$app->user->checkAccess('uri_support_admin')) {
36            $app->notAuthorized();
37            return false;
38        }
39
40        return true;
41    }
42
43    /**
44     * Render the admin dashboard
45     *
46     * GET /admin/support/dashboard
47     */
48    public function pageDashboard()
49    {
50        if (!$this->checkAdminPermission()) {
51            return;
52        }
53
54        $app = $this->_app;
55
56        $app->render('support/admin/admin.html', [
57            'page' => [
58                'title' => 'Support Admin - Dashboard',
59                'description' => 'Support Portal Administration Dashboard'
60            ],
61            'user' => $app->user,
62            'activePage' => 'dashboard'
63        ]);
64    }
65
66    /**
67     * Render the articles list page
68     *
69     * GET /admin/support/articles
70     */
71    public function pageArticles()
72    {
73        if (!$this->checkAdminPermission()) {
74            return;
75        }
76
77        $app = $this->_app;
78
79        $app->render('support/admin/articles.html', [
80            'page' => [
81                'title' => 'Support Admin - Articles',
82                'description' => 'Manage Support Portal Articles'
83            ],
84            'user' => $app->user,
85            'activePage' => 'articles'
86        ]);
87    }
88
89    /**
90     * Render the article editor page
91     *
92     * GET /admin/support/articles/new
93     * GET /admin/support/articles/:id/edit
94     *
95     * @param int|null $id Article ID (null for new article)
96     */
97    public function pageArticleEditor($id = null)
98    {
99        if (!$this->checkAdminPermission()) {
100            return;
101        }
102
103        $app = $this->_app;
104        $article = null;
105
106        // If editing, load the article
107        if ($id) {
108            $db = \dbConnectByName('kiosk_buykiosk');
109            $manager = new ArticleManager($db);
110            $article = $manager->getById($id);
111
112            if (!$article) {
113                $app->notFound();
114                return;
115            }
116        }
117
118        $app->render('support/admin/article-editor.html', [
119            'page' => [
120                'title' => $article ? 'Edit Article - ' . $article->title : 'New Article',
121                'description' => $article ? 'Edit Support Article' : 'Create New Support Article'
122            ],
123            'user' => $app->user,
124            'article' => $article,
125            'activePage' => 'articles'
126        ]);
127    }
128
129    /**
130     * Render the categories management page
131     *
132     * GET /admin/support/categories
133     */
134    public function pageCategories()
135    {
136        if (!$this->checkAdminPermission()) {
137            return;
138        }
139
140        $app = $this->_app;
141
142        $app->render('support/admin/categories.html', [
143            'page' => [
144                'title' => 'Support Admin - Categories',
145                'description' => 'Manage Support Portal Categories'
146            ],
147            'user' => $app->user,
148            'activePage' => 'categories'
149        ]);
150    }
151
152    /**
153     * Render the edit suggestions review page
154     *
155     * GET /admin/support/suggestions
156     */
157    public function pageSuggestions()
158    {
159        if (!$this->checkAdminPermission()) {
160            return;
161        }
162
163        $app = $this->_app;
164
165        $app->render('support/admin/suggestions.html', [
166            'page' => [
167                'title' => 'Support Admin - Edit Suggestions',
168                'description' => 'Review Edit Suggestions from Users'
169            ],
170            'user' => $app->user,
171            'activePage' => 'suggestions'
172        ]);
173    }
174
175    /**
176     * Render the analytics page
177     *
178     * GET /admin/support/analytics
179     */
180    public function pageAnalytics()
181    {
182        if (!$this->checkAdminPermission()) {
183            return;
184        }
185
186        $app = $this->_app;
187
188        $app->render('support/admin/analytics.html', [
189            'page' => [
190                'title' => 'Support Admin - Analytics',
191                'description' => 'Support Portal Analytics and Insights'
192            ],
193            'user' => $app->user,
194            'activePage' => 'analytics'
195        ]);
196    }
197
198    /**
199     * Render article preview page (admin-only, no store context)
200     *
201     * GET /admin/support/preview/:slug
202     *
203     * @param string $slug Article slug
204     */
205    public function pageArticlePreview($slug)
206    {
207        if (!$this->checkAdminPermission()) {
208            return;
209        }
210
211        $app = $this->_app;
212
213        // Load the article by slug (include unpublished for admin preview)
214        $db = \dbConnectByName('kiosk_buykiosk');
215        $manager = new ArticleManager($db);
216        $article = $manager->getArticleBySlug($slug, false);
217
218        if (!$article) {
219            $app->notFound();
220            return;
221        }
222
223        $app->render('support/admin/article-preview.html', [
224            'page' => [
225                'title' => 'Preview: ' . $article->title,
226                'description' => 'Article Preview'
227            ],
228            'user' => $app->user,
229            'article' => $article,
230            'activePage' => 'articles'
231        ]);
232    }
233}