From b35b2efc52d053c2bf9d6efca69249421392f75c Mon Sep 17 00:00:00 2001 From: Adam Daley Date: Mon, 6 Nov 2023 04:10:09 +0000 Subject: [PATCH] Merge Kb and Support modules (#1180) * Merge Kb and Support modules Merge the Kb and Support modules as they contain related functionality. * General improvements to Support module UI Update Support module copy and navigation to be more consistent, and other general improvements. * This was missed.. and now it's not :wink: --------- Co-authored-by: Belle Aerni --- src/install/sql/content.sql | 31 +- src/install/sql/content_test.sql | 31 +- src/install/sql/structure.sql | 8 +- src/library/FOSSBilling/UpdatePatcher.php | 28 + .../{KbArticle.php => SupportKbArticle.php} | 2 +- ...egory.php => SupportKbArticleCategory.php} | 3 +- src/modules/Kb/Api/Admin.php | 256 ------- src/modules/Kb/Api/Guest.php | 134 ---- src/modules/Kb/Controller/Admin.php | 79 --- src/modules/Kb/Controller/Client.php | 56 -- src/modules/Kb/Service.php | 340 ---------- src/modules/Kb/icon.svg | 1 - src/modules/Kb/manifest.json | 12 - .../Page/html_client/mod_page_sitemap.xml | 8 +- src/modules/Support/Api/Admin.php | 243 +++++++ src/modules/Support/Api/Client.php | 2 +- src/modules/Support/Api/Guest.php | 131 ++++ src/modules/Support/Controller/Admin.php | 61 +- src/modules/Support/Controller/Client.php | 32 + src/modules/Support/Service.php | 333 +++++++++ .../mod_support_canned_category.html.twig | 6 +- .../mod_support_canned_response.html.twig | 8 +- .../mod_support_canned_responses.html.twig | 15 +- .../mod_support_canned_selector.html.twig | 2 +- .../html_admin/mod_support_helpdesk.html.twig | 17 +- .../mod_support_kb_article.html.twig} | 22 +- .../mod_support_kb_category.html.twig} | 19 +- .../mod_support_kb_index.html.twig} | 58 +- .../mod_support_public_ticket.html.twig | 11 +- .../mod_support_public_tickets.html.twig | 20 +- .../html_admin/mod_support_settings.html.twig | 54 +- .../html_admin/mod_support_ticket.html.twig | 23 +- .../html_admin/mod_support_tickets.html.twig | 46 +- .../modal/mod_support_new_helpdesk.html.twig | 9 +- .../mod_support_kb_article.html.twig} | 20 +- .../mod_support_kb_category.html.twig} | 6 +- .../mod_support_kb_index.html.twig} | 14 +- src/themes/huraga/config/settings.html | 2 +- .../huraga/html/layout_default.html.twig | 8 +- src/themes/huraga/html/partial_menu.html.twig | 16 +- tests/fixtures/extensions.xml | 3 +- .../bb-modules/mod_kb/Api_AdminTest.php | 122 ---- .../bb-modules/mod_kb/Api_GuestTest.php | 101 --- .../bb-modules/mod_redirect/Api_AdminTest.php | 18 +- .../bb-modules/mod_support/Api_AdminTest.php | 138 +++- .../bb-modules/mod_support/Api_GuestTest.php | 93 ++- tests/modules/Extension/ServiceTest.php | 16 +- tests/modules/Kb/Api/Api_AdminTest.php | 601 ---------------- tests/modules/Kb/Api/Api_GuestTest.php | 375 ---------- tests/modules/Kb/ServiceTest.php | 640 ------------------ tests/modules/Support/Api/Api_AdminTest.php | 589 ++++++++++++++++ tests/modules/Support/Api/Api_ClientTest.php | 5 +- tests/modules/Support/Api/Api_GuestTest.php | 370 +++++++++- tests/modules/Support/ServiceTest.php | 607 ++++++++++++++++- 54 files changed, 2889 insertions(+), 2956 deletions(-) rename src/library/Model/{KbArticle.php => SupportKbArticle.php} (84%) rename src/library/Model/{KbArticleCategory.php => SupportKbArticleCategory.php} (78%) delete mode 100644 src/modules/Kb/Api/Admin.php delete mode 100644 src/modules/Kb/Api/Guest.php delete mode 100644 src/modules/Kb/Controller/Admin.php delete mode 100644 src/modules/Kb/Controller/Client.php delete mode 100644 src/modules/Kb/Service.php delete mode 100644 src/modules/Kb/icon.svg delete mode 100644 src/modules/Kb/manifest.json rename src/modules/{Kb/html_admin/mod_kb_article.html.twig => Support/html_admin/mod_support_kb_article.html.twig} (84%) rename src/modules/{Kb/html_admin/mod_kb_category.html.twig => Support/html_admin/mod_support_kb_category.html.twig} (78%) rename src/modules/{Kb/html_admin/mod_kb_index.html.twig => Support/html_admin/mod_support_kb_index.html.twig} (76%) rename src/modules/{Kb/html_client/mod_kb_article.html.twig => Support/html_client/mod_support_kb_article.html.twig} (58%) rename src/modules/{Kb/html_client/mod_kb_category.html.twig => Support/html_client/mod_support_kb_category.html.twig} (72%) rename src/modules/{Kb/html_client/mod_kb_index.html.twig => Support/html_client/mod_support_kb_index.html.twig} (81%) delete mode 100644 tests/integration/bb-modules/mod_kb/Api_AdminTest.php delete mode 100644 tests/integration/bb-modules/mod_kb/Api_GuestTest.php delete mode 100644 tests/modules/Kb/Api/Api_AdminTest.php delete mode 100644 tests/modules/Kb/Api/Api_GuestTest.php delete mode 100644 tests/modules/Kb/ServiceTest.php diff --git a/src/install/sql/content.sql b/src/install/sql/content.sql index 0ea6817fa..26e07a185 100644 --- a/src/install/sql/content.sql +++ b/src/install/sql/content.sql @@ -133,11 +133,10 @@ LOCK TABLES `extension` WRITE; INSERT INTO `extension` (`id`, `type`, `name`, `status`, `version`, `manifest`) VALUES - (1,'mod','kb','installed','1.0.0','{\"id\":\"kb\",\"type\":\"mod\",\"name\":\"Knowledge Base\",\"description\":\"Knowledge base module for FOSSBilling\",\"homepage_url\":\"https:\\/\\/github.com\\/FOSSBilling\",\"author\":\"FOSSBilling\",\"author_url\":\"http:\\/\\/extensions.fossbilling.org\\/\",\"license\":\"https:\\/\\/github.com\\/FOSSBilling\\/FOSSBilling\\/blob\\/main\\/LICENSE\",\"version\":\"1.0.0\",\"icon_url\":\"\\/modules\\/Kb\\/icon.svg\",\"download_url\":null,\"project_url\":\"https:\\/\\/extensions.fossbilling.org\\/\",\"minimum_boxbilling_version\":null,\"maximum_boxbilling_version\":null}'), - (2,'mod','news','installed','1.0.0','{\"id\":\"news\",\"type\":\"mod\",\"name\":\"News\",\"description\":\"News module for FOSSBilling\",\"homepage_url\":\"https:\\/\\/github.com\\/FOSSBilling\",\"author\":\"FOSSBilling\",\"author_url\":\"http:\\/\\/extensions.fossbilling.org\\/\",\"license\":\"https:\\/\\/github.com\\/FOSSBilling\\/FOSSBilling\\/blob\\/main\\/LICENSE\",\"version\":\"1.0.0\",\"icon_url\":\"\\/modules\\/News\\/icon.svg\",\"download_url\":null,\"project_url\":\"https:\\/\\/extensions.fossbilling.org\\/\",\"minimum_boxbilling_version\":null,\"maximum_boxbilling_version\":null}'), - (3,'mod','branding','installed','0.0.1','{\"id\":\"branding\",\"type\":\"mod\",\"name\":\"Branding\",\"description\":\"Show your support by voluntarily displaying references to FOSSBilling.\",\"homepage_url\":\"https:\\/\\/fossbilling.org\",\"author\":\"FOSSBilling\",\"author_url\":\"https:\\/\\/fossbilling.org\",\"license\":\"https:\\/\\/github.com\\/FOSSBilling\\/FOSSBilling\\/blob\\/main\\/LICENSE\",\"version\":\"0.0.1\",\"icon_url\":\"\\/modules\\/Branding\\/icon.svg\",\"download_url\":null,\"project_url\":\"https:\\/\\/extensions.fossbilling.org\\/\",\"minimum_boxbilling_version\":null,\"maximum_boxbilling_version\":null}'), - (4,'mod','redirect','installed','1.0.0','{\"id\":\"redirect\",\"type\":\"mod\",\"name\":\"Redirect\",\"description\":\"Manage redirects\",\"homepage_url\":\"https:\\/\\/fossbilling.org\\/\",\"author\":\"FOSSBilling\",\"author_url\":\"https:\\/\\/www.fossbilling.org\",\"license\":\"N\\/A\",\"version\":\"1.0.0\",\"icon_url\":\"\\/modules\\/Redirect\\/icon.svg\",\"download_url\":null,\"project_url\":\"https:\\/\\/extensions.fossbilling.org\\/\",\"minimum_boxbilling_version\":null,\"maximum_boxbilling_version\":null}'), - (5,'mod','wysiwyg','installed','1.0.0','{\"id\":\"wysiwyg\",\"type\":\"mod\",\"name\":\"Wysiwyg\",\"description\":\"Integrates a What You See Is What You Get (WYSIWYG) editor to your admin panel.\",\"homepage_url\":\"https:\\/\\/fossbilling.org\\/\",\"author\":\"FOSSBilling\",\"author_url\":\"https:\\/\\/extensions.fossbilling.org\\/\",\"license\":\"N\\/A\",\"version\":\"1.0.0\",\"icon_url\":\"\\/modules\\/Wysiwyg\\/icon.svg\",\"download_url\":null,\"project_url\":\"https:\\/\\/extensions.fossbilling.org\\/\",\"minimum_boxbilling_version\":null,\"maximum_boxbilling_version\":null}'); + (1,'mod','news','installed','1.0.0','{\"id\":\"news\",\"type\":\"mod\",\"name\":\"News\",\"description\":\"News module for FOSSBilling\",\"homepage_url\":\"https:\\/\\/github.com\\/FOSSBilling\",\"author\":\"FOSSBilling\",\"author_url\":\"http:\\/\\/extensions.fossbilling.org\\/\",\"license\":\"https:\\/\\/github.com\\/FOSSBilling\\/FOSSBilling\\/blob\\/main\\/LICENSE\",\"version\":\"1.0.0\",\"icon_url\":\"\\/modules\\/News\\/icon.svg\",\"download_url\":null,\"project_url\":\"https:\\/\\/extensions.fossbilling.org\\/\",\"minimum_boxbilling_version\":null,\"maximum_boxbilling_version\":null}'), + (2,'mod','branding','installed','0.0.1','{\"id\":\"branding\",\"type\":\"mod\",\"name\":\"Branding\",\"description\":\"Show your support by voluntarily displaying references to FOSSBilling.\",\"homepage_url\":\"https:\\/\\/fossbilling.org\",\"author\":\"FOSSBilling\",\"author_url\":\"https:\\/\\/fossbilling.org\",\"license\":\"https:\\/\\/github.com\\/FOSSBilling\\/FOSSBilling\\/blob\\/main\\/LICENSE\",\"version\":\"0.0.1\",\"icon_url\":\"\\/modules\\/Branding\\/icon.svg\",\"download_url\":null,\"project_url\":\"https:\\/\\/extensions.fossbilling.org\\/\",\"minimum_boxbilling_version\":null,\"maximum_boxbilling_version\":null}'), + (3,'mod','redirect','installed','1.0.0','{\"id\":\"redirect\",\"type\":\"mod\",\"name\":\"Redirect\",\"description\":\"Manage redirects\",\"homepage_url\":\"https:\\/\\/fossbilling.org\\/\",\"author\":\"FOSSBilling\",\"author_url\":\"https:\\/\\/www.fossbilling.org\",\"license\":\"N\\/A\",\"version\":\"1.0.0\",\"icon_url\":\"\\/modules\\/Redirect\\/icon.svg\",\"download_url\":null,\"project_url\":\"https:\\/\\/extensions.fossbilling.org\\/\",\"minimum_boxbilling_version\":null,\"maximum_boxbilling_version\":null}'), + (4,'mod','wysiwyg','installed','1.0.0','{\"id\":\"wysiwyg\",\"type\":\"mod\",\"name\":\"Wysiwyg\",\"description\":\"Integrates a What You See Is What You Get (WYSIWYG) editor to your admin panel.\",\"homepage_url\":\"https:\\/\\/fossbilling.org\\/\",\"author\":\"FOSSBilling\",\"author_url\":\"https:\\/\\/extensions.fossbilling.org\\/\",\"license\":\"N\\/A\",\"version\":\"1.0.0\",\"icon_url\":\"\\/modules\\/Wysiwyg\\/icon.svg\",\"download_url\":null,\"project_url\":\"https:\\/\\/extensions.fossbilling.org\\/\",\"minimum_boxbilling_version\":null,\"maximum_boxbilling_version\":null}'); /*!40000 ALTER TABLE `extension` ENABLE KEYS */; UNLOCK TABLES; @@ -168,34 +167,34 @@ UNLOCK TABLES; -# Dump of table kb_article +# Dump of table support_kb_article # ------------------------------------------------------------ -LOCK TABLES `kb_article` WRITE; -/*!40000 ALTER TABLE `kb_article` DISABLE KEYS */; +LOCK TABLES `support_kb_article` WRITE; +/*!40000 ALTER TABLE `support_kb_article` DISABLE KEYS */; -INSERT INTO `kb_article` (`id`, `kb_article_category_id`, `views`, `title`, `content`, `slug`, `status`, `created_at`, `updated_at`) +INSERT INTO `support_kb_article` (`id`, `kb_article_category_id`, `views`, `title`, `content`, `slug`, `status`, `created_at`, `updated_at`) VALUES (1,2,0,'How to contact support','Registered clients can contact our support team:\n------------------------------------------------------------\n\n* Login to clients area\n* Select **Support** menu item\n* Click **Submit new ticket**\n* Fill the form and press *Submit*\n\nGuests can contact our support team:\n------------------------------------------------------------\n\n* Use our contact form.\n* Fill the form and click *Submit*\n','how-to-contact-support','active','2022-12-01 12:00:00','2022-12-01 12:00:00'), (2,2,0,'How to place new order','To place new order, follow these steps:\n------------------------------------------------------------\n\n* Select our services at *Order* page.\n* Depending on selected product, you might need to provide additional information to complete order request.\n* Click \"Continue\" and your product/service is now in shopping cart.\n* If you have promo code, you can apply it and get discount.\n* Click on \"Checkout\" button to proceed with checkout process\n * If you are already logged in, uou will be automaticaly redirected to new invoice\n * If you are registerd client, you can provide your login details\n * If you have never purchased any service from us, fill up client sign up form, and continue checkout\n* Choose payment method to pay for invoice. List of all avalable payment methods will be listed below invoice details.\n* Choose payment method\n* You will be redirected to payment gateway page\n* After successful payment, You will be redirected back to invoice page.\n* Depending on selected services your order will be reviewed and activated by our staff members.\n* After you receive confirmation email about order activation you are able to manage your services.\n','how-to-place-new-order','active','2022-12-01 12:00:00','2022-12-01 12:00:00'), (3,2,0,'Example article','Example article heading\n------------------------------------------------------------\n\nCursus, parturient porta dis sit? Habitasse non, sociis porttitor, sagittis dapibus scelerisque? Pid, porttitor integer, montes. Hac, in? Arcu nunc integer nascetur dis nisi. In, sed a amet? Adipiscing odio mauris mauris, porta, integer, adipiscing habitasse, elementum phasellus, turpis in? Quis magna placerat eu, cursus urna mattis egestas, a ac massa turpis mus et odio pid in, urna dapibus ridiculus in turpis cursus ac a urna magna purus etiam ac nisi porttitor! Auctor est? In adipiscing, hac platea augue vut, hac est cum sagittis! Montes nascetur pulvinar tristique porta platea? Magnis vel etiam nisi augue auctor sit pulvinar! Aliquet rhoncus, elit porta? Magnis pulvinar eu turpis purus sociis a augue? Sit, nascetur! Mattis nisi, penatibus ac ac natoque auctor turpis.\n\nExample article heading\n------------------------------------------------------------\n\nUt diam cursus, elit pulvinar, habitasse purus? Enim. Urna? Velit arcu, rhoncus sociis sed, et, ultrices nascetur lacus vut purus tempor a. Vel? Sagittis integer scelerisque, dapibus lectus mid, magnis, augue duis velit etiam tortor! Eros, a et phasellus est ultricies integer elementum in, tempor sed parturient. Dictumst rhoncus, ut sed sagittis facilisis? In, proin? Urna augue in sociis enim dignissim! Velit magna tincidunt ac. Nunc, vel auctor porta enim integer. Phasellus amet eu. Tristique lundium arcu! In? Massa penatibus arcu, rhoncus augue ut pid pulvinar, porttitor, porta, et! A sit odio, proin natoque ultrices cras cras magna porttitor! Ultrices sed magna in! Porttitor nunc, tincidunt nec, amet integer aenean. Tincidunt, placerat nec dolor parturient et ac pulvinar a.\n','example-article-slug','active','2022-12-01 12:00:00','2022-12-01 12:00:00'); -/*!40000 ALTER TABLE `kb_article` ENABLE KEYS */; +/*!40000 ALTER TABLE `support_kb_article` ENABLE KEYS */; UNLOCK TABLES; -# Dump of table kb_article_category +# Dump of table support_kb_article_category # ------------------------------------------------------------ -LOCK TABLES `kb_article_category` WRITE; -/*!40000 ALTER TABLE `kb_article_category` DISABLE KEYS */; +LOCK TABLES `support_kb_article_category` WRITE; +/*!40000 ALTER TABLE `support_kb_article_category` DISABLE KEYS */; -INSERT INTO `kb_article_category` (`id`, `title`, `description`, `slug`, `created_at`, `updated_at`) +INSERT INTO `support_kb_article_category` (`id`, `title`, `description`, `slug`, `created_at`, `updated_at`) VALUES (1,'Frequently asked questions','Section for common issues','faq','2022-12-01 12:00:00','2022-12-01 12:00:00'), (2,'How to''s','Section dedicated for tutorials','how-to','2022-12-01 12:00:00','2022-12-01 12:00:00'); -/*!40000 ALTER TABLE `kb_article_category` ENABLE KEYS */; +/*!40000 ALTER TABLE `support_kb_article_category` ENABLE KEYS */; UNLOCK TABLES; @@ -316,7 +315,7 @@ LOCK TABLES `setting` WRITE; INSERT INTO `setting` (`id`, `param`, `value`, `public`, `category`, `hash`, `created_at`, `updated_at`) VALUES - (1,'last_patch','34',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), + (1,'last_patch','36',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), (2,'company_name','Company Name',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), (3,'company_email','company@email.com',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), (4,'company_signature','FOSSBilling.org - Client Management, Invoice and Support Software',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), diff --git a/src/install/sql/content_test.sql b/src/install/sql/content_test.sql index 1a8ae832c..462bdfdc9 100644 --- a/src/install/sql/content_test.sql +++ b/src/install/sql/content_test.sql @@ -162,11 +162,10 @@ LOCK TABLES `extension` WRITE; INSERT INTO `extension` (`id`, `type`, `name`, `status`, `version`, `manifest`) VALUES - (1,'mod','kb','installed','1.0.0','{\"id\":\"kb\",\"type\":\"mod\",\"name\":\"Knowledge Base\",\"description\":\"Knowledge base module for FOSSBilling\",\"homepage_url\":\"https:\\/\\/github.com\\/FOSSBilling\",\"author\":\"FOSSBilling\",\"author_url\":\"http:\\/\\/extensions.fossbilling.org\\/\",\"license\":\"https:\\/\\/github.com\\/FOSSBilling\\/FOSSBilling\\/blob\\/main\\/LICENSE\",\"version\":\"1.0.0\",\"icon_url\":\"\\/modules\\/Kb\\/icon.svg\",\"download_url\":null,\"project_url\":\"https:\\/\\/extensions.fossbilling.org\\/\",\"minimum_boxbilling_version\":null,\"maximum_boxbilling_version\":null}'), - (2,'mod','news','installed','1.0.0','{\"id\":\"news\",\"type\":\"mod\",\"name\":\"News\",\"description\":\"News module for FOSSBilling\",\"homepage_url\":\"https:\\/\\/github.com\\/FOSSBilling\",\"author\":\"FOSSBilling\",\"author_url\":\"http:\\/\\/extensions.fossbilling.org\\/\",\"license\":\"https:\\/\\/github.com\\/FOSSBilling\\/FOSSBilling\\/blob\\/main\\/LICENSE\",\"version\":\"1.0.0\",\"icon_url\":\"\\/modules\\/News\\/icon.svg\",\"download_url\":null,\"project_url\":\"https:\\/\\/extensions.fossbilling.org\\/\",\"minimum_boxbilling_version\":null,\"maximum_boxbilling_version\":null}'), - (3,'mod','branding','installed','0.0.1','{\"id\":\"branding\",\"type\":\"mod\",\"name\":\"Branding\",\"description\":\"Show your support by voluntarily displaying references to FOSSBilling.\",\"homepage_url\":\"https:\\/\\/fossbilling.org\",\"author\":\"FOSSBilling\",\"author_url\":\"https:\\/\\/fossbilling.org\",\"license\":\"https:\\/\\/github.com\\/FOSSBilling\\/FOSSBilling\\/blob\\/main\\/LICENSE\",\"version\":\"0.0.1\",\"icon_url\":\"\\/modules\\/Branding\\/icon.svg\",\"download_url\":null,\"project_url\":\"https:\\/\\/extensions.fossbilling.org\\/\",\"minimum_boxbilling_version\":null,\"maximum_boxbilling_version\":null}'), - (4,'mod','redirect','installed','1.0.0','{\"id\":\"redirect\",\"type\":\"mod\",\"name\":\"Redirect\",\"description\":\"Manage redirects\",\"homepage_url\":\"https:\\/\\/fossbilling.org\\/\",\"author\":\"FOSSBilling\",\"author_url\":\"https:\\/\\/www.fossbilling.org\",\"license\":\"N\\/A\",\"version\":\"1.0.0\",\"icon_url\":\"\\/modules\\/Redirect\\/icon.svg\",\"download_url\":null,\"project_url\":\"https:\\/\\/extensions.fossbilling.org\\/\",\"minimum_boxbilling_version\":null,\"maximum_boxbilling_version\":null}'), - (5,'mod','wysiwyg','installed','1.0.0','{\"id\":\"wysiwyg\",\"type\":\"mod\",\"name\":\"Wysiwyg\",\"description\":\"Integrates a What You See Is What You Get (WYSIWYG) editor to your admin panel.\",\"homepage_url\":\"https:\\/\\/fossbilling.org\\/\",\"author\":\"FOSSBilling\",\"author_url\":\"https:\\/\\/extensions.fossbilling.org\\/\",\"license\":\"N\\/A\",\"version\":\"1.0.0\",\"icon_url\":\"\\/modules\\/Wysiwyg\\/icon.svg\",\"download_url\":null,\"project_url\":\"https:\\/\\/extensions.fossbilling.org\\/\",\"minimum_boxbilling_version\":null,\"maximum_boxbilling_version\":null}'); + (1,'mod','news','installed','1.0.0','{\"id\":\"news\",\"type\":\"mod\",\"name\":\"News\",\"description\":\"News module for FOSSBilling\",\"homepage_url\":\"https:\\/\\/github.com\\/FOSSBilling\",\"author\":\"FOSSBilling\",\"author_url\":\"http:\\/\\/extensions.fossbilling.org\\/\",\"license\":\"https:\\/\\/github.com\\/FOSSBilling\\/FOSSBilling\\/blob\\/main\\/LICENSE\",\"version\":\"1.0.0\",\"icon_url\":\"\\/modules\\/News\\/icon.svg\",\"download_url\":null,\"project_url\":\"https:\\/\\/extensions.fossbilling.org\\/\",\"minimum_boxbilling_version\":null,\"maximum_boxbilling_version\":null}'), + (1,'mod','branding','installed','0.0.1','{\"id\":\"branding\",\"type\":\"mod\",\"name\":\"Branding\",\"description\":\"Show your support by voluntarily displaying references to FOSSBilling.\",\"homepage_url\":\"https:\\/\\/fossbilling.org\",\"author\":\"FOSSBilling\",\"author_url\":\"https:\\/\\/fossbilling.org\",\"license\":\"https:\\/\\/github.com\\/FOSSBilling\\/FOSSBilling\\/blob\\/main\\/LICENSE\",\"version\":\"0.0.1\",\"icon_url\":\"\\/modules\\/Branding\\/icon.svg\",\"download_url\":null,\"project_url\":\"https:\\/\\/extensions.fossbilling.org\\/\",\"minimum_boxbilling_version\":null,\"maximum_boxbilling_version\":null}'), + (3,'mod','redirect','installed','1.0.0','{\"id\":\"redirect\",\"type\":\"mod\",\"name\":\"Redirect\",\"description\":\"Manage redirects\",\"homepage_url\":\"https:\\/\\/fossbilling.org\\/\",\"author\":\"FOSSBilling\",\"author_url\":\"https:\\/\\/www.fossbilling.org\",\"license\":\"N\\/A\",\"version\":\"1.0.0\",\"icon_url\":\"\\/modules\\/Redirect\\/icon.svg\",\"download_url\":null,\"project_url\":\"https:\\/\\/extensions.fossbilling.org\\/\",\"minimum_boxbilling_version\":null,\"maximum_boxbilling_version\":null}'), + (4,'mod','wysiwyg','installed','1.0.0','{\"id\":\"wysiwyg\",\"type\":\"mod\",\"name\":\"Wysiwyg\",\"description\":\"Integrates a What You See Is What You Get (WYSIWYG) editor to your admin panel.\",\"homepage_url\":\"https:\\/\\/fossbilling.org\\/\",\"author\":\"FOSSBilling\",\"author_url\":\"https:\\/\\/extensions.fossbilling.org\\/\",\"license\":\"N\\/A\",\"version\":\"1.0.0\",\"icon_url\":\"\\/modules\\/Wysiwyg\\/icon.svg\",\"download_url\":null,\"project_url\":\"https:\\/\\/extensions.fossbilling.org\\/\",\"minimum_boxbilling_version\":null,\"maximum_boxbilling_version\":null}'); /*!40000 ALTER TABLE `extension` ENABLE KEYS */; UNLOCK TABLES; @@ -266,31 +265,31 @@ UNLOCK TABLES; -# Dump of table kb_article +# Dump of table support_kb_article # ------------------------------------------------------------ -LOCK TABLES `kb_article` WRITE; -/*!40000 ALTER TABLE `kb_article` DISABLE KEYS */; +LOCK TABLES `support_kb_article` WRITE; +/*!40000 ALTER TABLE `support_kb_article` DISABLE KEYS */; -INSERT INTO `kb_article` (`id`, `kb_article_category_id`, `views`, `title`, `content`, `slug`, `status`, `created_at`, `updated_at`) +INSERT INTO `support_kb_article` (`id`, `kb_article_category_id`, `views`, `title`, `content`, `slug`, `status`, `created_at`, `updated_at`) VALUES (1,1,0,'Live demo instructions','Please note that there may be other users logged into the demo at the\nsame time as you, who may be editing and changing settings at the same\ntime as your testing.\n\nSome features have been intentionally disabled in this demo instance.\n\nAdmin area can be accesed at:\n\n> [https://demo.fossbilling.org/admin](https://demo.fossbilling.org/admin/staff/login?email=admin@fossbilling.org&password=demo)\n>\n> Username: admin@fossbilling.org\n>\n> Password: demo\n\nClient area can be accesed at:\n> [https://demo.fossbilling.org/login](https://demo.fossbilling.org/login?email=client@fossbilling.org&password=demo)\n>\n> Username: client@fossbilling.org\n>\n> Password: demo\n','live-demo','active','2022-12-01 12:00:00','2022-12-01 12:00:00'); -/*!40000 ALTER TABLE `kb_article` ENABLE KEYS */; +/*!40000 ALTER TABLE `support_kb_article` ENABLE KEYS */; UNLOCK TABLES; -# Dump of table kb_article_category +# Dump of table support_kb_article_category # ------------------------------------------------------------ -LOCK TABLES `kb_article_category` WRITE; -/*!40000 ALTER TABLE `kb_article_category` DISABLE KEYS */; +LOCK TABLES `support_kb_article_category` WRITE; +/*!40000 ALTER TABLE `support_kb_article_category` DISABLE KEYS */; -INSERT INTO `kb_article_category` (`id`, `title`, `description`, `slug`, `created_at`, `updated_at`) +INSERT INTO `support_kb_article_category` (`id`, `title`, `description`, `slug`, `created_at`, `updated_at`) VALUES (1,'Instructions','Section for common issues','instructions','2022-12-01 12:00:00','2022-12-01 12:00:00'), -/*!40000 ALTER TABLE `kb_article_category` ENABLE KEYS */; +/*!40000 ALTER TABLE `support_kb_article_category` ENABLE KEYS */; UNLOCK TABLES; @@ -481,7 +480,7 @@ LOCK TABLES `setting` WRITE; INSERT INTO `setting` (`id`, `param`, `value`, `public`, `category`, `hash`, `created_at`, `updated_at`) VALUES - (1,'last_patch','25',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), + (1,'last_patch','36',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), (2,'company_name','FOSSBilling demo',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), (3,'company_email','demo@fossbilling.org',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), (4,'company_signature','FOSSBilling.org - Client Management, Invoice and Support Software',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), diff --git a/src/install/sql/structure.sql b/src/install/sql/structure.sql index f1f736b69..7551cead8 100644 --- a/src/install/sql/structure.sql +++ b/src/install/sql/structure.sql @@ -613,12 +613,12 @@ CREATE TABLE `invoice_item` ( /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `kb_article` +-- Table structure for table `support_kb_article` -- /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `kb_article` ( +CREATE TABLE `support_kb_article` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `kb_article_category_id` bigint(20) DEFAULT NULL, `views` int(11) DEFAULT '0', @@ -635,12 +635,12 @@ CREATE TABLE `kb_article` ( /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `kb_article_category` +-- Table structure for table `support_kb_article_category` -- /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `kb_article_category` ( +CREATE TABLE `support_kb_article_category` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `title` varchar(100) DEFAULT NULL, `description` text, diff --git a/src/library/FOSSBilling/UpdatePatcher.php b/src/library/FOSSBilling/UpdatePatcher.php index 6746a1cd6..158046cc5 100644 --- a/src/library/FOSSBilling/UpdatePatcher.php +++ b/src/library/FOSSBilling/UpdatePatcher.php @@ -306,6 +306,34 @@ class UpdatePatcher implements InjectionAwareInterface $q = "ALTER TABLE session ADD created_at int(11);"; $this->executeSql($q); }, + 36 => function () { + // Patch to complete merging the Kb and Support modules. + // @see https://github.com/FOSSBilling/FOSSBilling/pull/1180 + + // Renames the "kb_article" and "kb_article_category" tables to "support_kb_article" and "support_kb_article_category", respectively. + $q = "RENAME TABLE kb_article TO support_kb_article, kb_article_category TO support_kb_article_category;"; + $this->executeSql($q); + + // If the Kb extension is currently active, set enabled in Support settings. + $ext_service = $this->di['mod_service']('extension'); + if ($ext_service->isExtensionActive('mod', 'kb')) { + $support_ext_config = $ext_service->getConfig('mod_support'); + $support_ext_config['kb_enable'] ?: 'on'; + $ext_service->setConfig($support_ext_config); + } + + // If the Kb extension exists, uninstall it. + $kb_ext = $ext_service->findExtension('mod', 'kb'); + if ($kb_ext instanceof \Model_Extension) { + $ext_service->uninstall($kb_ext); + } + + // Finally, remove old Kb extension files/folders. + $fileActions = [ + PATH_MODS . DIRECTORY_SEPARATOR . 'Kb' => 'unlink', + ]; + $this->executeFileActions($fileActions); + }, ]; ksort($patches, SORT_NATURAL); diff --git a/src/library/Model/KbArticle.php b/src/library/Model/SupportKbArticle.php similarity index 84% rename from src/library/Model/KbArticle.php rename to src/library/Model/SupportKbArticle.php index ae0e00ec3..8d1058f33 100644 --- a/src/library/Model/KbArticle.php +++ b/src/library/Model/SupportKbArticle.php @@ -8,7 +8,7 @@ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 */ -class Model_KbArticle extends \RedBeanPHP\SimpleModel +class Model_SupportKbArticle extends \RedBeanPHP\SimpleModel { public const ACTIVE = 'active'; public const DRAFT = 'draft'; diff --git a/src/library/Model/KbArticleCategory.php b/src/library/Model/SupportKbArticleCategory.php similarity index 78% rename from src/library/Model/KbArticleCategory.php rename to src/library/Model/SupportKbArticleCategory.php index 7f8c210e7..be6b5802d 100644 --- a/src/library/Model/KbArticleCategory.php +++ b/src/library/Model/SupportKbArticleCategory.php @@ -8,7 +8,6 @@ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 */ -class Model_KbArticleCategory extends \RedBeanPHP\SimpleModel +class Model_SupportKbArticleCategory extends \RedBeanPHP\SimpleModel { - } diff --git a/src/modules/Kb/Api/Admin.php b/src/modules/Kb/Api/Admin.php deleted file mode 100644 index ad72f0e86..000000000 --- a/src/modules/Kb/Api/Admin.php +++ /dev/null @@ -1,256 +0,0 @@ -getService()->searchArticles($status, $search, $cat); - - foreach ($pager['list'] as $key => $item) { - $article = $this->di['db']->getExistingModelById('KbArticle', $item['id'], 'KB Article not found'); - $pager['list'][$key] = $this->getService()->toApiArray($article); - } - - return $pager; - } - - /** - * Get knowledge base article. - * - * @return array - */ - public function article_get($data) - { - $required = [ - 'id' => 'Article id not passed', - ]; - $this->di['validator']->checkRequiredParamsForArray($required, $data); - - $model = $this->di['db']->findOne('KbArticle', 'id = ?', [$data['id']]); - - if (!$model instanceof \Model_KbArticle) { - throw new \FOSSBilling\Exception('Article not found'); - } - - return $this->getService()->toApiArray($model, true, $this->getIdentity()); - } - - /** - * Create new knowledge base article. - * - * @optional string $status - knowledge base article status - * @optional string $content - knowledge base article content - * - * @return array - */ - public function article_create($data) - { - $required = [ - 'kb_article_category_id' => 'Article category id not passed', - 'title' => 'Article title not passed', - ]; - $this->di['validator']->checkRequiredParamsForArray($required, $data); - - $articleCategoryId = $data['kb_article_category_id']; - $title = $data['title']; - $status = $data['status'] ?? \Model_KbArticle::DRAFT; - $content = $data['content'] ?? null; - - return $this->getService()->createArticle($articleCategoryId, $title, $status, $content); - } - - /** - * Update knowledge base article. - * - * @optional string $title - knowledge base article title - * @optional int $kb_article_category_id - knowledge base category ID - * @optional string $slug - knowledge base article slug - * @optional string $status - knowledge base article status - * @optional string $content - knowledge base article content - * @optional int $views - knowledge base article views counter - * - * @return bool - */ - public function article_update($data) - { - $required = [ - 'id' => 'Article ID not passed', - ]; - $this->di['validator']->checkRequiredParamsForArray($required, $data); - - $articleCategoryId = $data['kb_article_category_id'] ?? null; - $title = $data['title'] ?? null; - $slug = $data['slug'] ?? null; - $status = $data['status'] ?? null; - $content = $data['content'] ?? null; - $views = $data['views'] ?? null; - - return $this->getService()->updateArticle($data['id'], $articleCategoryId, $title, $slug, $status, $content, $views); - } - - /** - * Delete knowledge base article. - * - * @return bool - */ - public function article_delete($data) - { - $required = [ - 'id' => 'Article ID not passed', - ]; - $this->di['validator']->checkRequiredParamsForArray($required, $data); - - $model = $this->di['db']->findOne('KbArticle', 'id = ?', [$data['id']]); - - if (!$model instanceof \Model_KbArticle) { - throw new \FOSSBilling\Exception('Article not found'); - } - - $this->getService()->rm($model); - - return true; - } - - /** - * Get paginated list of knowledge base categories. - * - * @return array - */ - public function category_get_list($data) - { - [$sql, $bindings] = $this->getService()->categoryGetSearchQuery($data); - $per_page = $data['per_page'] ?? $this->di['pager']->getPer_page(); - $pager = $this->di['pager']->getAdvancedResultSet($sql, $bindings, $per_page); - - foreach ($pager['list'] as $key => $item) { - $category = $this->di['db']->getExistingModelById('KbArticleCategory', $item['id'], 'KB Article not found'); - $pager['list'][$key] = $this->getService()->categoryToApiArray($category, $this->getIdentity()); - } - - return $pager; - } - - /** - * Get knowledge base category. - * - * @return array - */ - public function category_get($data) - { - $required = [ - 'id' => 'Category ID not passed', - ]; - $this->di['validator']->checkRequiredParamsForArray($required, $data); - - $model = $this->di['db']->findOne('KbArticleCategory', 'id = ?', [$data['id']]); - - if (!$model instanceof \Model_KbArticleCategory) { - throw new \FOSSBilling\Exception('Article Category not found'); - } - - return $this->getService()->categoryToApiArray($model); - } - - /** - * Create new knowledge base category. - * - * @optional string $description - knowledge base category description - * - * @return array - */ - public function category_create($data) - { - $required = [ - 'title' => 'Category title not passed', - ]; - $this->di['validator']->checkRequiredParamsForArray($required, $data); - - $title = $data['title']; - $description = $data['description'] ?? null; - - return $this->getService()->createCategory($title, $description); - } - - /** - * Update knowledge base category. - * - * @optional string $title - knowledge base category title - * @optional string $slug - knowledge base category slug - * @optional string $description - knowledge base category description - * - * @return array - */ - public function category_update($data) - { - $required = [ - 'id' => 'Category ID not passed', - ]; - $this->di['validator']->checkRequiredParamsForArray($required, $data); - - $model = $this->di['db']->findOne('KbArticleCategory', 'id = ?', [$data['id']]); - - if (!$model instanceof \Model_KbArticleCategory) { - throw new \FOSSBilling\Exception('Article Category not found'); - } - - $title = $data['title'] ?? null; - $slug = $data['slug'] ?? null; - $description = $data['description'] ?? null; - - return $this->getService()->updateCategory($model, $title, $slug, $description); - } - - /** - * Delete knowledge base category. - * - * @return bool - */ - public function category_delete($data) - { - $required = [ - 'id' => 'Category ID not passed', - ]; - $this->di['validator']->checkRequiredParamsForArray($required, $data); - - $model = $this->di['db']->findOne('KbArticleCategory', 'id = ?', [$data['id']]); - - if (!$model instanceof \Model_KbArticleCategory) { - throw new \FOSSBilling\Exception('Category not found'); - } - - return $this->getService()->categoryRm($model); - } - - /** - * Get knowledge base categories id, title pairs. - * - * @return array - */ - public function category_get_pairs($data) - { - return $this->getService()->categoryGetPairs(); - } -} diff --git a/src/modules/Kb/Api/Guest.php b/src/modules/Kb/Api/Guest.php deleted file mode 100644 index 4ea1eb152..000000000 --- a/src/modules/Kb/Api/Guest.php +++ /dev/null @@ -1,134 +0,0 @@ -di['pager']->getPer_page(); - $page = $data['page'] ?? null; - - $pager = $this->getService()->searchArticles($status, $search, $cat, $per_page, $page); - - foreach ($pager['list'] as $key => $item) { - $article = $this->di['db']->getExistingModelById('KbArticle', $item['id'], 'KB Article not found'); - $pager['list'][$key] = $this->getService()->toApiArray($article); - } - - return $pager; - } - - /** - * Get active knowledge base article. - * - * @return array - */ - public function article_get($data) - { - if (!isset($data['id']) && !isset($data['slug'])) { - throw new \FOSSBilling\Exception('ID or slug is missing'); - } - - $id = $data['id'] ?? null; - $slug = $data['slug'] ?? null; - - $model = false; - if ($id) { - $model = $this->getService()->findActiveArticleById($id); - } else { - $model = $this->getService()->findActiveArticleBySlug($slug); - } - - if (!$model instanceof \Model_KbArticle) { - throw new \FOSSBilling\Exception('Article item not found'); - } - $this->getService()->hitView($model); - - return $this->getService()->toApiArray($model, true, $this->getIdentity()); - } - - /** - * Get paginated list of knowledge base categories. - * - * @return array - */ - public function category_get_list($data) - { - $data['article_status'] = \Model_KbArticle::ACTIVE; - [$query, $bindings] = $this->getService()->categoryGetSearchQuery($data); - - $per_page = $data['per_page'] ?? $this->di['pager']->getPer_page(); - $pager = $this->di['pager']->getAdvancedResultSet($query, $bindings, $per_page); - - $q = $data['q'] ?? null; - - foreach ($pager['list'] as $key => $item) { - $category = $this->di['db']->getExistingModelById('KbArticleCategory', $item['id'], 'KB Article not found'); - $pager['list'][$key] = $this->getService()->categoryToApiArray($category, $this->getIdentity(), $q); - } - - return $pager; - } - - /** - * Get knowledge base categories id, title pairs. - * - * @return array - */ - public function category_get_pairs($data) - { - return $this->getService()->categoryGetPairs(); - } - - /** - * Get knowledge base category by ID or SLUG. - * - * @return array - */ - public function category_get($data) - { - if (!isset($data['id']) && !isset($data['slug'])) { - throw new \FOSSBilling\Exception('Category ID or slug is missing'); - } - - $id = $data['id'] ?? null; - $slug = $data['slug'] ?? null; - - $model = false; - if ($id) { - $model = $this->getService()->findCategoryById($id); - } else { - $model = $this->getService()->findCategoryBySlug($slug); - } - - if (!$model instanceof \Model_KbArticleCategory) { - throw new \FOSSBilling\Exception('Knowledge base category not found'); - } - - return $this->getService()->categoryToApiArray($model, $this->getIdentity()); - } -} diff --git a/src/modules/Kb/Controller/Admin.php b/src/modules/Kb/Controller/Admin.php deleted file mode 100644 index d577711af..000000000 --- a/src/modules/Kb/Controller/Admin.php +++ /dev/null @@ -1,79 +0,0 @@ -di = $di; - } - - public function getDi(): ?\Pimple\Container - { - return $this->di; - } - - public function fetchNavigation() - { - return [ - 'group' => [ - 'index' => 501, - 'location' => 'kb', - 'label' => __trans('Knowledge base'), - 'uri' => $this->di['url']->adminLink('kb'), - 'class' => 'info', - 'sprite_class' => 'dark-sprite-icon sprite-docs', - ], - 'subpages' => [ - [ - 'location' => 'kb', - 'index' => 800, - 'label' => __trans('Knowledge base'), - 'uri' => $this->di['url']->adminLink('kb'), - 'class' => '', - ], - ], - ]; - } - - public function register(\Box_App &$app) - { - $app->get('/kb', 'get_index', [], static::class); - $app->get('/kb/article/:id', 'get_post', ['id' => '[0-9]+'], static::class); - $app->get('/kb/category/:id', 'get_cat', ['id' => '[0-9]+'], static::class); - } - - public function get_index(\Box_App $app) - { - $this->di['is_admin_logged']; - - return $app->render('mod_kb_index'); - } - - public function get_post(\Box_App $app, $id) - { - $api = $this->di['api_admin']; - $post = $api->kb_article_get(['id' => $id]); - - return $app->render('mod_kb_article', ['post' => $post]); - } - - public function get_cat(\Box_App $app, $id) - { - $api = $this->di['api_admin']; - $cat = $api->kb_category_get(['id' => $id]); - - return $app->render('mod_kb_category', ['category' => $cat]); - } -} diff --git a/src/modules/Kb/Controller/Client.php b/src/modules/Kb/Controller/Client.php deleted file mode 100644 index ade394238..000000000 --- a/src/modules/Kb/Controller/Client.php +++ /dev/null @@ -1,56 +0,0 @@ -di = $di; - } - - public function getDi(): ?\Pimple\Container - { - return $this->di; - } - - public function register(\Box_App &$app) - { - $app->get('/kb', 'get_kb', [], static::class); - $app->get('/kb/:category', 'get_kb_category', ['category' => '[a-z0-9-]+'], static::class); - $app->get('/kb/:category/:slug', 'get_kb_article', ['category' => '[a-z0-9-]+', 'slug' => '[a-z0-9-]+'], static::class); - } - - public function get_kb(\Box_App $app) - { - return $app->render('mod_kb_index'); - } - - public function get_kb_category(\Box_App $app, $category) - { - $api = $this->di['api_guest']; - $data = ['slug' => $category]; - $model = $api->kb_category_get($data); - - return $app->render('mod_kb_category', ['category' => $model]); - } - - public function get_kb_article(\Box_App $app, $category, $slug) - { - $api = $this->di['api_guest']; - $data = ['slug' => $slug]; - $article = $api->kb_article_get($data); - - return $app->render('mod_kb_article', ['article' => $article]); - } -} diff --git a/src/modules/Kb/Service.php b/src/modules/Kb/Service.php deleted file mode 100644 index 4c627e754..000000000 --- a/src/modules/Kb/Service.php +++ /dev/null @@ -1,340 +0,0 @@ -di = $di; - } - - public function searchArticles($status = null, $search = null, $cat = null, $per_page = 100, $page = null) - { - $filter = []; - - $sql = ' - SELECT * - FROM kb_article - WHERE 1 - '; - - if ($cat) { - $sql .= ' AND kb_article_category_id = :cid'; - $filter[':cid'] = $cat; - } - - if ($status) { - $sql .= ' AND status = :status'; - $filter[':status'] = $status; - } - - if ($search) { - $sql .= ' AND title LIKE :q OR content LIKE :q'; - $filter[':q'] = "%$search%"; - } - - $sql .= ' ORDER BY kb_article_category_id DESC, views DESC'; - - return $this->di['pager']->getSimpleResultSet($sql, $filter, $per_page, $page); - } - - public function findActiveArticleById($id) - { - $bindings = [ - ':id' => $id, - ':status' => \Model_KbArticle::ACTIVE, - ]; - - return $this->di['db']->findOne('KbArticle', 'id = :id AND status=:status', $bindings); - } - - public function findActiveArticleBySlug($slug) - { - $bindings = [ - ':slug' => $slug, - ':status' => \Model_KbArticle::ACTIVE, - ]; - - return $this->di['db']->findOne('KbArticle', 'slug = :slug AND status=:status', $bindings); - } - - public function findActive() - { - return $this->di['db']->find('KbArticle', 'status=:status', [':status' => \Model_KbArticle::ACTIVE]); - } - - public function hitView(\Model_KbArticle $model) - { - ++$model->views; - $this->di['db']->store($model); - } - - public function rm(\Model_KbArticle $model) - { - $id = $model->id; - $this->di['db']->trash($model); - $this->di['logger']->info('Deleted knowledge base article #%s', $id); - } - - public function toApiArray(\Model_KbArticle $model, $deep = false, $identity = null) - { - $data = [ - 'id' => $model->id, - 'slug' => $model->slug, - 'title' => $model->title, - 'views' => $model->views, - 'created_at' => $model->created_at, - 'status' => $model->status, - 'updated_at' => $model->updated_at, - ]; - - $cat = $this->di['db']->getExistingModelById('KbArticleCategory', $model->kb_article_category_id, 'Knowledge base category not found'); - $data['category'] = [ - 'id' => $cat->id, - 'slug' => $cat->slug, - 'title' => $cat->title, - ]; - - if ($deep) { - $data['content'] = $model->content; - } - - if ($identity instanceof \Model_Admin) { - $data['status'] = $model->status; - $data['kb_article_category_id'] = $model->kb_article_category_id; - } - - return $data; - } - - public function createArticle($articleCategoryId, $title, $status = null, $content = null) - { - if (!isset($status)) { - $status = \Model_KbArticle::DRAFT; - } - - $model = $this->di['db']->dispense('KbArticle'); - $model->kb_article_category_id = $articleCategoryId; - $model->title = $title; - $model->slug = $this->di['tools']->slug($title); - $model->status = $status; - $model->content = $content; - $model->updated_at = date('Y-m-d H:i:s'); - $model->created_at = date('Y-m-d H:i:s'); - $id = $this->di['db']->store($model); - - $this->di['logger']->info('Created new knowledge base article #%s', $id); - - return $id; - } - - public function updateArticle($id, $articleCategoryId = null, $title = null, $slug = null, $status = null, $content = null, $views = null) - { - $model = $this->di['db']->findOne('KbArticle', 'id = ?', [$id]); - - if (!$model instanceof \Model_KbArticle) { - throw new \FOSSBilling\Exception('Article not found'); - } - - if (isset($articleCategoryId)) { - $model->kb_article_category_id = $articleCategoryId; - } - - if (isset($title)) { - $model->title = $title; - } - - if (isset($slug)) { - $model->slug = $slug; - } - - if (isset($status)) { - $model->status = $status; - } - - if (isset($content)) { - $model->content = $content; - } - - if (isset($views)) { - $model->views = $views; - } - $model->updated_at = date('Y-m-d H:i:s'); - - $this->di['db']->store($model); - - $this->di['logger']->info('Updated knowledge base article #%s', $id); - - return true; - } - - public function categoryGetSearchQuery($data) - { - $sql = ' - SELECT kac.* - FROM kb_article_category kac - LEFT JOIN kb_article ka ON kac.id = ka.kb_article_category_id'; - - $article_status = $data['article_status'] ?? null; - $query = $data['q'] ?? null; - - $where = []; - $bindings = []; - if ($article_status) { - $where[] = 'ka.status = :status'; - - $bindings[':status'] = $article_status; - } - - if ($query) { - $where[] = '(ka.title LIKE :title OR ka.content LIKE :content)'; - - $bindings[':title'] = "%$query%"; - $bindings[':content'] = "%$query%"; - } - - if (!empty($where)) { - $sql = $sql . ' WHERE ' . implode(' AND ', $where); - } - - $sql .= ' GROUP BY kac.id ORDER BY kac.id DESC'; - - return [$sql, $bindings]; - } - - public function categoryFindAll() - { - $sql = 'SELECT kac.*, a.* - FROM kb_article_category kac - LEFT JOIN kb_article ka - ON kac.id = ka.kb_article_category_id - '; - - return $this->di['db']->getAll($sql); - } - - public function categoryGetPairs() - { - $sql = 'SELECT id, title FROM kb_article_category'; - $pairs = $this->di['db']->getAssoc($sql); - - return $pairs; - } - - public function categoryRm(\Model_KbArticleCategory $model) - { - $bindings = [ - ':kb_article_category_id' => $model->id, - ]; - - $articlesCount = $this->di['db']->getCell('SELECT count(*) as cnt FROM kb_article WHERE kb_article_category_id = :kb_article_category_id', $bindings); - - if ($articlesCount > 0) { - throw new \FOSSBilling\InformationException('Can not remove category which has articles'); - } - - $id = $model->id; - - $this->di['db']->trash($model); - - $this->di['logger']->info('Deleted knowledge base category #%s', $id); - - return true; - } - - public function categoryToApiArray(\Model_KbArticleCategory $model, $identity = null, $query = null) - { - $data = $this->di['db']->toArray($model); - - $sql = 'kb_article_category_id = :category_id'; - $bindings = [ - ':category_id' => $model->id, - ]; - - if (!$identity instanceof \Model_Admin) { - $sql .= " AND status = 'active'"; - } - - if ($query) { - $sql .= 'AND (title LIKE :title OR content LIKE :content)'; - $query = "%$query%"; - $bindings[':content'] = $query; - $bindings[':title'] = $query; - } - - $articles = $this->di['db']->find('KbArticle', $sql, $bindings); - - foreach ($articles as $article) { - $data['articles'][] = $this->toApiArray($article, false, $identity); - } - - return $data; - } - - public function createCategory($title, $description = null) - { - $systemService = $this->di['mod_service']('system'); - $systemService->checkLimits('Model_KbArticleCategory', 2); - - $model = $this->di['db']->dispense('KbArticleCategory'); - $model->title = $title; - $model->description = $description; - $model->slug = $this->di['tools']->slug($title); - $model->updated_at = date('Y-m-d H:i:s'); - $model->created_at = date('Y-m-d H:i:s'); - - $id = $this->di['db']->store($model); - - $this->di['logger']->info('Created new knowledge base category #%s', $id); - - return $id; - } - - public function updateCategory(\Model_KbArticleCategory $model, $title = null, $slug = null, $description = null) - { - if (isset($title)) { - $model->title = $title; - } - - if (isset($slug)) { - $model->slug = $slug; - } - - if (isset($description)) { - $model->description = $description; - } - - $model->updated_at = date('Y-m-d H:i:s'); - - $this->di['db']->store($model); - - $this->di['logger']->info('Updated knowledge base category #%s', $model->id); - - return true; - } - - public function findCategoryById($id) - { - return $this->di['db']->getExistingModelById('KbArticleCategory', $id, 'Knowledge base category not found'); - } - - public function findCategoryBySlug($slug) - { - $bindings = [ - ':slug' => $slug, - ]; - - return $this->di['db']->findOne('KbArticleCategory', 'slug = :slug', $bindings); - } -} diff --git a/src/modules/Kb/icon.svg b/src/modules/Kb/icon.svg deleted file mode 100644 index c3ffbd28d..000000000 --- a/src/modules/Kb/icon.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/modules/Kb/manifest.json b/src/modules/Kb/manifest.json deleted file mode 100644 index 7b83e8ad3..000000000 --- a/src/modules/Kb/manifest.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "id": "kb", - "type": "mod", - "name": "Knowledge Base", - "description": "Knowledge base module for FOSSBilling", - "homepage_url": "https://github.com/FOSSBilling", - "icon_url": "icon.svg", - "author": "FOSSBilling", - "author_url": "http://extensions.fossbilling.org/", - "license": "https://github.com/FOSSBilling/FOSSBilling/blob/main/LICENSE", - "version": "1.0.0" -} diff --git a/src/modules/Page/html_client/mod_page_sitemap.xml b/src/modules/Page/html_client/mod_page_sitemap.xml index 66f1f215f..3914e1e7f 100644 --- a/src/modules/Page/html_client/mod_page_sitemap.xml +++ b/src/modules/Page/html_client/mod_page_sitemap.xml @@ -23,14 +23,14 @@ {% endif %} {# knowledge base items #} -{% if guest.extension_is_on({"mod":'kb'}) %} -{% for i, article in guest.kb_article_get_list({"per_page":50}).list %} +{% if if guest.support_kb_enabled() %} +{% for i, article in guest.support_kb_article_get_list({"per_page":50}).list %} - {{ 'kb'|link }}/{{article.category.slug}}/{{article.slug}} + {{ 'support/kb'|link }}/{{article.category.slug}}/{{article.slug}} {{article.updated_at|date('Y-m-d')}} 0.9 weekly {% endfor %} {% endif %} - \ No newline at end of file + diff --git a/src/modules/Support/Api/Admin.php b/src/modules/Support/Api/Admin.php index ab4d63e09..5af251206 100644 --- a/src/modules/Support/Api/Admin.php +++ b/src/modules/Support/Api/Admin.php @@ -794,4 +794,247 @@ class Admin extends \Api_Abstract return true; } + + + /* + * Support Knowledge Base. + */ + + /** + * Get paginated list of knowledge base articles. + * + * @return array + */ + public function kb_article_get_list($data) + { + $status = $data['status'] ?? null; + $search = $data['search'] ?? null; + $cat = $data['cat'] ?? null; + + $pager = $this->getService()->kbSearchArticles($status, $search, $cat); + + foreach ($pager['list'] as $key => $item) { + $article = $this->di['db']->getExistingModelById('SupportKbArticle', $item['id'], 'KB Article not found'); + $pager['list'][$key] = $this->getService()->kbToApiArray($article); + } + + return $pager; + } + + /** + * Get knowledge base article. + * + * @return array + */ + public function kb_article_get($data) + { + $required = [ + 'id' => 'Article id not passed', + ]; + $this->di['validator']->checkRequiredParamsForArray($required, $data); + + $model = $this->di['db']->findOne('SupportKbArticle', 'id = ?', [$data['id']]); + + if (!$model instanceof \Model_SupportKbArticle) { + throw new \FOSSBilling\InformationException('Article not found'); + } + + return $this->getService()->kbToApiArray($model, true, $this->getIdentity()); + } + + /** + * Create new knowledge base article. + * + * @optional string $status - knowledge base article status + * @optional string $content - knowledge base article content + * + * @return array + */ + public function kb_article_create($data) + { + $required = [ + 'kb_article_category_id' => 'Article category id not passed', + 'title' => 'Article title not passed', + ]; + $this->di['validator']->checkRequiredParamsForArray($required, $data); + + $articleCategoryId = $data['kb_article_category_id']; + $title = $data['title']; + $status = $data['status'] ?? \Model_SupportKbArticle::DRAFT; + $content = $data['content'] ?? null; + + return $this->getService()->kbCreateArticle($articleCategoryId, $title, $status, $content); + } + + /** + * Update knowledge base article. + * + * @optional string $title - knowledge base article title + * @optional int $kb_article_category_id - knowledge base category ID + * @optional string $slug - knowledge base article slug + * @optional string $status - knowledge base article status + * @optional string $content - knowledge base article content + * @optional int $views - knowledge base article views counter + * + * @return bool + */ + public function kb_article_update($data) + { + $required = [ + 'id' => 'Article ID not passed', + ]; + $this->di['validator']->checkRequiredParamsForArray($required, $data); + + $articleCategoryId = $data['kb_article_category_id'] ?? null; + $title = $data['title'] ?? null; + $slug = $data['slug'] ?? null; + $status = $data['status'] ?? null; + $content = $data['content'] ?? null; + $views = $data['views'] ?? null; + + return $this->getService()->kbUpdateArticle($data['id'], $articleCategoryId, $title, $slug, $status, $content, $views); + } + + /** + * Delete knowledge base article. + * + * @return bool + */ + public function kb_article_delete($data) + { + $required = [ + 'id' => 'Article ID not passed', + ]; + $this->di['validator']->checkRequiredParamsForArray($required, $data); + + $model = $this->di['db']->findOne('SupportKbArticle', 'id = ?', [$data['id']]); + + if (!$model instanceof \Model_SupportKbArticle) { + throw new \FOSSBilling\InformationException('Article not found'); + } + + $this->getService()->kbRm($model); + + return true; + } + + /** + * Get paginated list of knowledge base categories. + * + * @return array + */ + public function kb_category_get_list($data) + { + [$sql, $bindings] = $this->getService()->kbCategoryGetSearchQuery($data); + $per_page = $data['per_page'] ?? $this->di['pager']->getPer_page(); + $pager = $this->di['pager']->getAdvancedResultSet($sql, $bindings, $per_page); + + foreach ($pager['list'] as $key => $item) { + $category = $this->di['db']->getExistingModelById('SupportKbArticleCategory', $item['id'], 'KB Article not found'); + $pager['list'][$key] = $this->getService()->kbCategoryToApiArray($category, $this->getIdentity()); + } + + return $pager; + } + + /** + * Get knowledge base category. + * + * @return array + */ + public function kb_category_get($data) + { + $required = [ + 'id' => 'Category ID not passed', + ]; + $this->di['validator']->checkRequiredParamsForArray($required, $data); + + $model = $this->di['db']->findOne('SupportKbArticleCategory', 'id = ?', [$data['id']]); + + if (!$model instanceof \Model_SupportKbArticleCategory) { + throw new \FOSSBilling\InformationException('Article Category not found'); + } + + return $this->getService()->kbCategoryToApiArray($model); + } + + /** + * Create new knowledge base category. + * + * @optional string $description - knowledge base category description + * + * @return array + */ + public function kb_category_create($data) + { + $required = [ + 'title' => 'Category title not passed', + ]; + $this->di['validator']->checkRequiredParamsForArray($required, $data); + + $title = $data['title']; + $description = $data['description'] ?? null; + + return $this->getService()->kbCreateCategory($title, $description); + } + + /** + * Update knowledge base category. + * + * @optional string $title - knowledge base category title + * @optional string $slug - knowledge base category slug + * @optional string $description - knowledge base category description + * + * @return array + */ + public function kb_category_update($data) + { + $required = [ + 'id' => 'Category ID not passed', + ]; + $this->di['validator']->checkRequiredParamsForArray($required, $data); + + $model = $this->di['db']->findOne('SupportKbArticleCategory', 'id = ?', [$data['id']]); + + if (!$model instanceof \Model_SupportKbArticleCategory) { + throw new \FOSSBilling\InformationException('Article Category not found'); + } + + $title = $data['title'] ?? null; + $slug = $data['slug'] ?? null; + $description = $data['description'] ?? null; + + return $this->getService()->kbUpdateCategory($model, $title, $slug, $description); + } + + /** + * Delete knowledge base category. + * + * @return bool + */ + public function kb_category_delete($data) + { + $required = [ + 'id' => 'Category ID not passed', + ]; + $this->di['validator']->checkRequiredParamsForArray($required, $data); + + $model = $this->di['db']->findOne('SupportKbArticleCategory', 'id = ?', [$data['id']]); + + if (!$model instanceof \Model_SupportKbArticleCategory) { + throw new \FOSSBilling\InformationException('Category not found'); + } + + return $this->getService()->kbCategoryRm($model); + } + + /** + * Get knowledge base categories id, title pairs. + * + * @return array + */ + public function kb_category_get_pairs($data) + { + return $this->getService()->kbCategoryGetPairs(); + } } diff --git a/src/modules/Support/Api/Client.php b/src/modules/Support/Api/Client.php index f2575ac08..2a39e66ef 100644 --- a/src/modules/Support/Api/Client.php +++ b/src/modules/Support/Api/Client.php @@ -121,7 +121,7 @@ class Client extends \Api_Abstract $ticket = $this->di['db']->findOne('SupportTicket', 'id = :id AND client_id = :client_id', $bindings); if (!$ticket instanceof \Model_SupportTicket) { - throw new \FOSSBilling\Exception('Ticket not found'); + throw new \FOSSBilling\InformationException('Ticket not found'); } if (!$this->getService()->canBeReopened($ticket)) { diff --git a/src/modules/Support/Api/Guest.php b/src/modules/Support/Api/Guest.php index e49c830f0..fa9863b24 100644 --- a/src/modules/Support/Api/Guest.php +++ b/src/modules/Support/Api/Guest.php @@ -89,4 +89,135 @@ class Guest extends \Api_Abstract return $this->getService()->publicTicketReplyForGuest($publicTicket, $data['message']); } + + + /* + * Support Knowledge Base Functions. + */ + + /** + * Get whether the knowledge base is enabled, or not. + * + * @return boolean + */ + public function kb_enabled() + { + return $this->getService()->kbEnabled(); + } + + /** + * Get paginated list of knowledge base articles. + * Returns only active articles. + * + * @return array + */ + public function kb_article_get_list($data) + { + $data['status'] = 'active'; + + $status = $data['status'] ?? null; + $search = $data['search'] ?? null; + $cat = $data['kb_article_category_id'] ?? null; + $per_page = $data['per_page'] ?? $this->di['pager']->getPer_page(); + $page = $data['page'] ?? null; + + $pager = $this->getService()->kbSearchArticles($status, $search, $cat, $per_page, $page); + + foreach ($pager['list'] as $key => $item) { + $article = $this->di['db']->getExistingModelById('SupportKbArticle', $item['id'], 'KB Article not found'); + $pager['list'][$key] = $this->getService()->kbToApiArray($article); + } + + return $pager; + } + + /** + * Get active knowledge base article. + * + * @return array + */ + public function kb_article_get($data) + { + if (!isset($data['id']) && !isset($data['slug'])) { + throw new \FOSSBilling\InformationException('ID or slug is missing'); + } + + $id = $data['id'] ?? null; + $slug = $data['slug'] ?? null; + + $model = false; + if ($id) { + $model = $this->getService()->kbFindActiveArticleById($id); + } else { + $model = $this->getService()->kbFindActiveArticleBySlug($slug); + } + + if (!$model instanceof \Model_SupportKbArticle) { + throw new \FOSSBilling\InformationException('Article item not found'); + } + $this->getService()->kbHitView($model); + + return $this->getService()->kbToApiArray($model, true, $this->getIdentity()); + } + + /** + * Get paginated list of knowledge base categories. + * + * @return array + */ + public function kb_category_get_list($data) + { + $data['article_status'] = \Model_SupportKbArticle::ACTIVE; + [$query, $bindings] = $this->getService()->kbCategoryGetSearchQuery($data); + + $per_page = $data['per_page'] ?? $this->di['pager']->getPer_page(); + $pager = $this->di['pager']->getAdvancedResultSet($query, $bindings, $per_page); + + $q = $data['q'] ?? null; + + foreach ($pager['list'] as $key => $item) { + $category = $this->di['db']->getExistingModelById('SupportKbArticleCategory', $item['id'], 'KB Article not found'); + $pager['list'][$key] = $this->getService()->kbCategoryToApiArray($category, $this->getIdentity(), $q); + } + + return $pager; + } + + /** + * Get knowledge base categories id, title pairs. + * + * @return array + */ + public function kb_category_get_pairs($data) + { + return $this->getService()->kbCategoryGetPairs(); + } + + /** + * Get knowledge base category by ID or SLUG. + * + * @return array + */ + public function kb_category_get($data) + { + if (!isset($data['id']) && !isset($data['slug'])) { + throw new \FOSSBilling\InformationException('Category ID or slug is missing'); + } + + $id = $data['id'] ?? null; + $slug = $data['slug'] ?? null; + + $model = false; + if ($id) { + $model = $this->getService()->kbFindCategoryById($id); + } else { + $model = $this->getService()->kbFindCategoryBySlug($slug); + } + + if (!$model instanceof \Model_SupportKbArticleCategory) { + throw new \FOSSBilling\InformationException('Knowledge base category not found'); + } + + return $this->getService()->kbCategoryToApiArray($model, $this->getIdentity()); + } } diff --git a/src/modules/Support/Controller/Admin.php b/src/modules/Support/Controller/Admin.php index fb76cb44d..507ee979f 100644 --- a/src/modules/Support/Controller/Admin.php +++ b/src/modules/Support/Controller/Admin.php @@ -26,7 +26,7 @@ class Admin implements \FOSSBilling\InjectionAwareInterface public function fetchNavigation() { - return [ + $nav = [ 'group' => [ 'location' => 'support', 'index' => 500, @@ -37,34 +37,47 @@ class Admin implements \FOSSBilling\InjectionAwareInterface 'subpages' => [ [ 'location' => 'support', - 'label' => __trans('Client tickets'), + 'label' => __trans('Client Tickets'), 'uri' => $this->di['url']->adminLink('support', ['status' => 'open']), 'index' => 100, 'class' => '', ], [ 'location' => 'support', - 'label' => __trans('Advanced ticket search'), - 'uri' => $this->di['url']->adminLink('support', ['show_filter' => 1]), + 'label' => __trans('Public Tickets'), + 'uri' => $this->di['url']->adminLink('support/public-tickets', ['status' => 'open']), 'index' => 200, 'class' => '', ], [ 'location' => 'support', - 'label' => __trans('Public tickets'), - 'uri' => $this->di['url']->adminLink('support/public-tickets', ['status' => 'open']), + 'label' => __trans('Advanced Ticket Search'), + 'uri' => $this->di['url']->adminLink('support', ['show_filter' => 1]), 'index' => 300, 'class' => '', ], [ 'location' => 'support', - 'label' => __trans('Canned responses'), + 'label' => __trans('Canned Responses'), 'uri' => $this->di['url']->adminLink('support/canned-responses'), 'index' => 400, 'class' => '', - ], - ], + ] + ] ]; + + if ($this->di['mod']('support')->getService()->kbEnabled()) { + array_push($nav['subpages'], + [ + 'location' => 'support', + 'index' => 500, + 'label' => __trans('Knowledge Base'), + 'uri' => $this->di['url']->adminLink('support/kb'), + 'class' => '', + ]); + } + + return $nav; } public function register(\Box_App &$app) @@ -81,6 +94,12 @@ class Admin implements \FOSSBilling\InjectionAwareInterface $app->get('/support/canned-responses', 'get_canned_list', [], static::class); $app->get('/support/canned/:id', 'get_canned', ['id' => '[0-9]+'], static::class); $app->get('/support/canned-category/:id', 'get_canned_cat', ['id' => '[0-9]+'], static::class); + + if ($this->di['mod']('support')->getService()->kbEnabled()) { + $app->get('/support/kb', 'get_kb_index', [], static::class); + $app->get('/support/kb/article/:id', 'get_kb_article', ['id' => '[0-9]+'], static::class); + $app->get('/support/kb/category/:id', 'get_kb_category', ['id' => '[0-9]+'], static::class); + } } public function get_index(\Box_App $app) @@ -169,4 +188,28 @@ class Admin implements \FOSSBilling\InjectionAwareInterface return $app->render('mod_support_canned_category', ['category' => $c]); } + + + /* + * Support Knowledge Base. + */ + public function get_kb_index(\Box_App $app) + { + $this->di['is_admin_logged']; + return $app->render('mod_support_kb_index'); + } + + public function get_kb_article(\Box_App $app, $id) + { + $api = $this->di['api_admin']; + $post = $api->support_kb_article_get(['id' => $id]); + return $app->render('mod_support_kb_article', ['post' => $post]); + } + + public function get_kb_category(\Box_App $app, $id) + { + $api = $this->di['api_admin']; + $cat = $api->support_kb_category_get(['id' => $id]); + return $app->render('mod_support_kb_category', ['category' => $cat]); + } } diff --git a/src/modules/Support/Controller/Client.php b/src/modules/Support/Controller/Client.php index 97b36b4c0..d951dd861 100644 --- a/src/modules/Support/Controller/Client.php +++ b/src/modules/Support/Controller/Client.php @@ -30,6 +30,12 @@ class Client implements \FOSSBilling\InjectionAwareInterface $app->get('/support/ticket/:id', 'get_ticket', [], static::class); $app->get('/support/contact-us', 'get_contact_us', [], static::class); $app->get('/support/contact-us/conversation/:hash', 'get_contact_us_conversation', ['hash' => '[a-z0-9]+'], static::class); + + if ($this->di['mod']('support')->getService()->kbEnabled()) { + $app->get('/support/kb', 'get_kb_index', [], static::class); + $app->get('/support/kb/:category', 'get_kb_category', ['category' => '[a-z0-9-]+'], static::class); + $app->get('/support/kb/:category/:slug', 'get_kb_article', ['category' => '[a-z0-9-]+', 'slug' => '[a-z0-9-]+'], static::class); + } } public function get_tickets(\Box_App $app) @@ -62,4 +68,30 @@ class Client implements \FOSSBilling\InjectionAwareInterface return $app->render('mod_support_contact_us_conversation', ['ticket' => $array]); } + + /* + * Support Knowledge Base. + */ + public function get_kb_index(\Box_App $app) + { + return $app->render('mod_support_kb_index'); + } + + public function get_kb_category(\Box_App $app, $category) + { + $api = $this->di['api_guest']; + $data = ['slug' => $category]; + $model = $api->support_kb_category_get($data); + + return $app->render('mod_support_kb_category', ['category' => $model]); + } + + public function get_kb_article(\Box_App $app, $category, $slug) + { + $api = $this->di['api_guest']; + $data = ['slug' => $slug]; + $article = $api->support_kb_article_get($data); + + return $app->render('mod_support_kb_article', ['article' => $article]); + } } diff --git a/src/modules/Support/Service.php b/src/modules/Support/Service.php index 166c08537..9f75a706f 100644 --- a/src/modules/Support/Service.php +++ b/src/modules/Support/Service.php @@ -1500,4 +1500,337 @@ class Service implements \FOSSBilling\InjectionAwareInterface return true; } + + + /* + * Knowledge Base Functions. + */ + + public function kbEnabled() + { + $extensionService = $this->di['mod_service']('extension'); + $config = $extensionService->getConfig('mod_support'); + + return isset($config['kb_enable']) && $config['kb_enable'] == 'on'; + } + + public function kbSearchArticles($status = null, $search = null, $cat = null, $per_page = 100, $page = null) + { + $filter = []; + + $sql = ' + SELECT * + FROM support_kb_article + WHERE 1 + '; + + if ($cat) { + $sql .= ' AND kb_article_category_id = :cid'; + $filter[':cid'] = $cat; + } + + if ($status) { + $sql .= ' AND status = :status'; + $filter[':status'] = $status; + } + + if ($search) { + $sql .= ' AND title LIKE :q OR content LIKE :q'; + $filter[':q'] = "%$search%"; + } + + $sql .= ' ORDER BY kb_article_category_id DESC, views DESC'; + + return $this->di['pager']->getSimpleResultSet($sql, $filter, $per_page, $page); + } + + public function kbFindActiveArticleById($id) + { + $bindings = [ + ':id' => $id, + ':status' => \Model_SupportKbArticle::ACTIVE, + ]; + + return $this->di['db']->findOne('SupportKbArticle', 'id = :id AND status=:status', $bindings); + } + + public function kbFindActiveArticleBySlug($slug) + { + $bindings = [ + ':slug' => $slug, + ':status' => \Model_SupportKbArticle::ACTIVE, + ]; + + return $this->di['db']->findOne('SupportKbArticle', 'slug = :slug AND status=:status', $bindings); + } + + public function kbFindActive() + { + return $this->di['db']->find('SupportKbArticle', 'status=:status', [':status' => \Model_SupportKbArticle::ACTIVE]); + } + + public function kbHitView(\Model_SupportKbArticle $model) + { + ++$model->views; + $this->di['db']->store($model); + } + + public function kbRm(\Model_SupportKbArticle $model) + { + $id = $model->id; + $this->di['db']->trash($model); + $this->di['logger']->info('Deleted knowledge base article #%s', $id); + } + + public function kbToApiArray(\Model_SupportKbArticle $model, $deep = false, $identity = null) + { + $data = [ + 'id' => $model->id, + 'slug' => $model->slug, + 'title' => $model->title, + 'views' => $model->views, + 'created_at' => $model->created_at, + 'status' => $model->status, + 'updated_at' => $model->updated_at, + ]; + + $cat = $this->di['db']->getExistingModelById('SupportKbArticleCategory', $model->kb_article_category_id, 'Knowledge base category not found'); + $data['category'] = [ + 'id' => $cat->id, + 'slug' => $cat->slug, + 'title' => $cat->title, + ]; + + if ($deep) { + $data['content'] = $model->content; + } + + if ($identity instanceof \Model_Admin) { + $data['status'] = $model->status; + $data['kb_article_category_id'] = $model->kb_article_category_id; + } + + return $data; + } + + public function kbCreateArticle($articleCategoryId, $title, $status = null, $content = null) + { + if (!isset($status)) { + $status = \Model_SupportKbArticle::DRAFT; + } + + $model = $this->di['db']->dispense('SupportKbArticle'); + $model->kb_article_category_id = $articleCategoryId; + $model->title = $title; + $model->slug = $this->di['tools']->slug($title); + $model->status = $status; + $model->content = $content; + $model->updated_at = date('Y-m-d H:i:s'); + $model->created_at = date('Y-m-d H:i:s'); + $id = $this->di['db']->store($model); + + $this->di['logger']->info('Created new knowledge base article #%s', $id); + + return $id; + } + + public function kbUpdateArticle($id, $articleCategoryId = null, $title = null, $slug = null, $status = null, $content = null, $views = null) + { + $model = $this->di['db']->findOne('SupportKbArticle', 'id = ?', [$id]); + + if (!$model instanceof \Model_SupportKbArticle) { + throw new \FOSSBilling\Exception('Article not found'); + } + + if (isset($articleCategoryId)) { + $model->kb_article_category_id = $articleCategoryId; + } + + if (isset($title)) { + $model->title = $title; + } + + if (isset($slug)) { + $model->slug = $slug; + } + + if (isset($status)) { + $model->status = $status; + } + + if (isset($content)) { + $model->content = $content; + } + + if (isset($views)) { + $model->views = $views; + } + $model->updated_at = date('Y-m-d H:i:s'); + + $this->di['db']->store($model); + + $this->di['logger']->info('Updated knowledge base article #%s', $id); + + return true; + } + + public function kbCategoryGetSearchQuery($data) + { + $sql = ' + SELECT kac.* + FROM support_kb_article_category kac + LEFT JOIN support_kb_article ka ON kac.id = ka.kb_article_category_id'; + + $article_status = $data['article_status'] ?? null; + $query = $data['q'] ?? null; + + $where = []; + $bindings = []; + if ($article_status) { + $where[] = 'ka.status = :status'; + + $bindings[':status'] = $article_status; + } + + if ($query) { + $where[] = '(ka.title LIKE :title OR ka.content LIKE :content)'; + + $bindings[':title'] = "%$query%"; + $bindings[':content'] = "%$query%"; + } + + if (!empty($where)) { + $sql = $sql . ' WHERE ' . implode(' AND ', $where); + } + + $sql .= ' GROUP BY kac.id ORDER BY kac.id DESC'; + + return [$sql, $bindings]; + } + + public function kbCategoryFindAll() + { + $sql = 'SELECT kac.*, a.* + FROM support_kb_article_category kac + LEFT JOIN support_kb_article ka + ON kac.id = ka.kb_article_category_id + '; + + return $this->di['db']->getAll($sql); + } + + public function kbCategoryGetPairs() + { + $sql = 'SELECT id, title FROM support_kb_article_category'; + $pairs = $this->di['db']->getAssoc($sql); + + return $pairs; + } + + public function kbCategoryRm(\Model_SupportKbArticleCategory $model) + { + $bindings = [ + ':kb_article_category_id' => $model->id, + ]; + + $articlesCount = $this->di['db']->getCell('SELECT count(*) as cnt FROM support_kb_article WHERE kb_article_category_id = :kb_article_category_id', $bindings); + + if ($articlesCount > 0) { + throw new \FOSSBilling\InformationException('Can not remove category which has articles'); + } + + $id = $model->id; + + $this->di['db']->trash($model); + + $this->di['logger']->info('Deleted knowledge base category #%s', $id); + + return true; + } + + public function kbCategoryToApiArray(\Model_SupportKbArticleCategory $model, $identity = null, $query = null) + { + $data = $this->di['db']->toArray($model); + + $sql = 'kb_article_category_id = :category_id'; + $bindings = [ + ':category_id' => $model->id, + ]; + + if (!$identity instanceof \Model_Admin) { + $sql .= " AND status = 'active'"; + } + + if ($query) { + $sql .= 'AND (title LIKE :title OR content LIKE :content)'; + $query = "%$query%"; + $bindings[':content'] = $query; + $bindings[':title'] = $query; + } + + $articles = $this->di['db']->find('SupportKbArticle', $sql, $bindings); + + foreach ($articles as $article) { + $data['articles'][] = $this->kbToApiArray($article, false, $identity); + } + + return $data; + } + + public function kbCreateCategory($title, $description = null) + { + $systemService = $this->di['mod_service']('system'); + $systemService->checkLimits('Model_SupportKbArticleCategory', 2); + + $model = $this->di['db']->dispense('SupportKbArticleCategory'); + $model->title = $title; + $model->description = $description; + $model->slug = $this->di['tools']->slug($title); + $model->updated_at = date('Y-m-d H:i:s'); + $model->created_at = date('Y-m-d H:i:s'); + + $id = $this->di['db']->store($model); + + $this->di['logger']->info('Created new knowledge base category #%s', $id); + + return $id; + } + + public function kbUpdateCategory(\Model_SupportKbArticleCategory $model, $title = null, $slug = null, $description = null) + { + if (isset($title)) { + $model->title = $title; + } + + if (isset($slug)) { + $model->slug = $slug; + } + + if (isset($description)) { + $model->description = $description; + } + + $model->updated_at = date('Y-m-d H:i:s'); + + $this->di['db']->store($model); + + $this->di['logger']->info('Updated knowledge base category #%s', $model->id); + + return true; + } + + public function kbFindCategoryById($id) + { + return $this->di['db']->getExistingModelById('SupportKbArticleCategory', $id, 'Knowledge base category not found'); + } + + public function kbFindCategoryBySlug($slug) + { + $bindings = [ + ':slug' => $slug, + ]; + + return $this->di['db']->findOne('SupportKbArticleCategory', 'slug = :slug', $bindings); + } + } diff --git a/src/modules/Support/html_admin/mod_support_canned_category.html.twig b/src/modules/Support/html_admin/mod_support_canned_category.html.twig index f40f38692..a730a57b2 100644 --- a/src/modules/Support/html_admin/mod_support_canned_category.html.twig +++ b/src/modules/Support/html_admin/mod_support_canned_category.html.twig @@ -2,9 +2,9 @@ {% import 'macro_functions.html.twig' as mf %} -{% set active_menu = 'support' %} +{% block meta_title %}Canned Category{% endblock %} -{% block meta_title %}Canned category{% endblock %} +{% set active_menu = 'support' %} {% block breadcrumbs %} @@ -24,7 +30,7 @@ {% block content %}
-
+

{{ post.title }}

@@ -32,7 +38,7 @@
- {{ mf.selectbox('kb_article_category_id', admin.kb_category_get_pairs, post.kb_article_category_id, 1) }} + {{ mf.selectbox('kb_article_category_id', admin.support_kb_category_get_pairs, post.kb_article_category_id, 1) }}
@@ -77,11 +83,11 @@ @@ -89,4 +95,4 @@
{% endblock %} -{% block head %}{{ mf.bb_editor('.bb-textarea') }}{% endblock %} \ No newline at end of file +{% block head %}{{ mf.bb_editor('.bb-textarea') }}{% endblock %} diff --git a/src/modules/Kb/html_admin/mod_kb_category.html.twig b/src/modules/Support/html_admin/mod_support_kb_category.html.twig similarity index 78% rename from src/modules/Kb/html_admin/mod_kb_category.html.twig rename to src/modules/Support/html_admin/mod_support_kb_category.html.twig index 74cfb01f5..cc28fb20c 100644 --- a/src/modules/Kb/html_admin/mod_kb_category.html.twig +++ b/src/modules/Support/html_admin/mod_support_kb_category.html.twig @@ -1,9 +1,9 @@ {% extends 'layout_default.html.twig' %} -{% set active_menu = 'support' %} - {% block meta_title %}{{ category.title }}{% endblock %} +{% set active_menu = 'support' %} + {% block breadcrumbs %} {% endblock %} {% block content %}
- +

{{ category.title}}

@@ -53,11 +56,11 @@ diff --git a/src/modules/Kb/html_admin/mod_kb_index.html.twig b/src/modules/Support/html_admin/mod_support_kb_index.html.twig similarity index 76% rename from src/modules/Kb/html_admin/mod_kb_index.html.twig rename to src/modules/Support/html_admin/mod_support_kb_index.html.twig index 98d03f209..e03685acf 100644 --- a/src/modules/Kb/html_admin/mod_kb_index.html.twig +++ b/src/modules/Support/html_admin/mod_support_kb_index.html.twig @@ -2,9 +2,25 @@ {% import 'macro_functions.html.twig' as mf %} -{% block meta_title %}{{ 'Knowledge base'|trans }}{% endblock %} +{% set active_menu = 'support' %} -{% set active_menu = 'kb' %} +{% block breadcrumbs %} + +{% endblock %} + +{% block meta_title %}{{ 'Knowledge Base'|trans }}{% endblock %} {% block content %} @@ -47,14 +63,14 @@ - {% set posts = admin.kb_article_get_list({ 'per_page': 30, 'page': request.page }|merge(request)) %} + {% set posts = admin.support_kb_article_get_list({ 'per_page': 30, 'page': request.page }|merge(request)) %} {% for i, post in posts.list %} - {{ post.title }} + {{ post.title }} - {{ post.category.title }} + {{ post.category.title }} {% if post.status == 'active' %} @@ -66,12 +82,12 @@ {{ mf.status_name(post.status) }} {{ post.views }} - + - + @@ -86,23 +102,23 @@ - {% include 'partial_pagination.html.twig' with { 'list': posts, 'url': 'kb' } %} + {% include 'partial_pagination.html.twig' with { 'list': posts, 'url': 'support/kb' } %}
- +
- {{ mf.selectbox('kb_article_category_id', admin.kb_category_get_pairs, request.kb_article_category_id, 1) }} + {{ mf.selectbox('kb_article_category_id', admin.support_kb_category_get_pairs, request.kb_article_category_id, 1) }}
- +
@@ -133,21 +149,21 @@
- {% for cat_id, cat_title in admin.kb_category_get_pairs %} + {% for cat_id, cat_title in admin.support_kb_category_get_pairs %} - + {% if ticket.created_at != ticket.updated_at %} - + {% endif %} @@ -107,7 +110,7 @@ - {{ 'View as client'|trans }} + {{ 'View as Client'|trans }} diff --git a/src/modules/Support/html_admin/mod_support_public_tickets.html.twig b/src/modules/Support/html_admin/mod_support_public_tickets.html.twig index 28aca0264..38edaae68 100644 --- a/src/modules/Support/html_admin/mod_support_public_tickets.html.twig +++ b/src/modules/Support/html_admin/mod_support_public_tickets.html.twig @@ -2,7 +2,23 @@ {% import 'macro_functions.html.twig' as mf %} -{% block meta_title %}Public tickets{% endblock %} +{% block meta_title %}Public Tickets{% endblock %} + +{% block breadcrumbs %} + +{% endblock %} {% set active_menu = 'support' %} @@ -69,7 +85,7 @@
-

{{ 'Public tickets'|trans }}

+

{{ 'Public Tickets'|trans }}

{% include 'partial_search.html.twig' %} diff --git a/src/modules/Support/html_admin/mod_support_settings.html.twig b/src/modules/Support/html_admin/mod_support_settings.html.twig index e256a8388..80d379cd5 100644 --- a/src/modules/Support/html_admin/mod_support_settings.html.twig +++ b/src/modules/Support/html_admin/mod_support_settings.html.twig @@ -2,7 +2,7 @@ {% import 'macro_functions.html.twig' as mf %} -{% block meta_title %}{{ 'Support settings'|trans }}{% endblock %} +{% block meta_title %}{{ 'Support Settings'|trans }}{% endblock %} {% set active_menu = 'system' %} @@ -18,33 +18,31 @@ - + {% endblock %} {% block content %}
-
- + + {% set params = admin.extension_config_get({ 'ext': 'mod_support' }) %}
-

{{ 'Auto responder settings'|trans }}

- - {% set params = admin.extension_config_get({ 'ext': 'mod_support' }) %} +

{{ 'Auto Responder'|trans }}

- +
{% include 'partial_search.html.twig' %} @@ -126,7 +135,7 @@
- + @@ -177,7 +186,6 @@ {% block js %}
- {{ cat_title }} + {{ cat_title }} - + + data-api-redirect="{{ 'support/kb'|alink }}"> @@ -165,7 +181,7 @@
- +
@@ -186,4 +202,4 @@
-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/src/modules/Support/html_admin/mod_support_public_ticket.html.twig b/src/modules/Support/html_admin/mod_support_public_ticket.html.twig index c64b761b0..71b3c5d9b 100644 --- a/src/modules/Support/html_admin/mod_support_public_ticket.html.twig +++ b/src/modules/Support/html_admin/mod_support_public_ticket.html.twig @@ -16,7 +16,10 @@
+ @@ -69,12 +72,12 @@
{{ 'Time opened'|trans }}:{{ 'Time Opened'|trans }}: {{ ticket.created_at|format_date }}
{{ 'Last updated'|trans }}:{{ 'Last Updated'|trans }}: {{ ticket.updated_at|timeago }} {{ 'ago'|trans }}
# {{ 'Title'|trans }} {{ 'Email'|trans }}{{ 'Close tickets after'|trans }}{{ 'Close Tickets After'|trans }}