From ca168423eda75903422a2ed2d35d3547e733098e Mon Sep 17 00:00:00 2001 From: Gaurav Kumar Date: Tue, 26 Jul 2022 18:05:53 +0530 Subject: [PATCH] List of all web as well as email notification setting of the user. Note: you have to pass JWT token to get the notification setting list of the user --- Events.php | 1 + .../notification/NotificationController.php | 44 +++++++++++++++++++ .../Smart Village API.postman_collection.json | 34 +++++++++++++- 3 files changed, 77 insertions(+), 2 deletions(-) diff --git a/Events.php b/Events.php index 9c9ad8e..ecd0812 100644 --- a/Events.php +++ b/Events.php @@ -71,6 +71,7 @@ public static function onRestApiAddRules() ['pattern' => 'space//membership/', 'route' => 'smartVillage/space/membership/create', 'verb' => 'POST'], //E-mail and Web Notification Setting + ['pattern' => 'setting/notification', 'route' => 'smartVillage/setting/notification/index', 'verb' => 'GET'], ['pattern' => 'settings', 'route' => 'smartVillage/setting/notification/save-settings', 'verb' => 'PUT'], ], 'smartVillage'); } diff --git a/controllers/notification/NotificationController.php b/controllers/notification/NotificationController.php index c3b18e7..1b58afb 100644 --- a/controllers/notification/NotificationController.php +++ b/controllers/notification/NotificationController.php @@ -13,6 +13,50 @@ class NotificationController extends BaseController { + /** + * @return array + * @throws \Throwable + * Show the list of web as well as email notification setting of the user + */ + public function actionIndex(){ + $form = new NotificationSettings(['user' => Yii::$app->user->getIdentity()]); + $result = []; + foreach($form->categories() as $category){ + //List down all category name like calendar, mail, conversation etc. + $categoriesData = $category->getTitle(); + $result[] = $categoriesData; + + foreach($form->targets() as $target) { + //Get the name of the setting, It will return the setting name like this(NotificationSettings[settings][notification.admin_web]) + $formName = $form->getSettingFormname($category, $target); + + //Get the status of setting i.e true(1) or false(0) + $categoryEnabled = $target->isCategoryEnabled($category, $form->user); + + //List down the all notification setting name + $settingNames = array("admin_web","admin_email","calendar_web","calendar_email","mail_web","mail_email","mail_conversation_web", + "mail_conversation_email","comments_web", + "comments_email","content_created_web","content_created_email","like_web","like_email", + "space_member_web","space_member_email","followed_web","followed_email","mentioned_web","mentioned_email"); + + foreach($settingNames as $name){ + //Check the setting name we are getting from $fromName is matching in $settingNames or not + if(strpos($formName,$name)!=FALSE){ + $result[] = self::getData($name,$categoryEnabled); + } + } + } + } + return $result; + + } + public static function getData($name,$status){ + return [ + $name => $status, + ]; + } + + /** * @return array|int[] * Save the setting of notification for space, email and web diff --git a/docs/postman/Smart Village API.postman_collection.json b/docs/postman/Smart Village API.postman_collection.json index e89f279..3a87f5f 100644 --- a/docs/postman/Smart Village API.postman_collection.json +++ b/docs/postman/Smart Village API.postman_collection.json @@ -1,6 +1,6 @@ { "info": { - "_postman_id": "60569f18-7f41-45ed-b2d3-958f5b0afa74", + "_postman_id": "35a430e5-bbeb-41b2-8286-2679f2c06458", "name": "Smart Village API", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, @@ -350,6 +350,36 @@ } }, "response": [] + }, + { + "name": "List of Notification Setting", + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "", + "type": "string" + } + ] + }, + "method": "GET", + "header": [], + "url": { + "raw": "{{API_URL}}/api/v2/setting/notification", + "host": [ + "{{API_URL}}" + ], + "path": [ + "api", + "v2", + "setting", + "notification" + ] + } + }, + "response": [] } ] }, @@ -546,4 +576,4 @@ "response": [] } ] -} +} \ No newline at end of file