Skip to content

Commit

Permalink
List of all web as well as email notification setting of the user.
Browse files Browse the repository at this point in the history
Note: you have to pass JWT token to get the notification setting list of the user

# Conflicts:
#	docs/postman/Smart Village API.postman_collection.json
  • Loading branch information
gaurav-handysolver authored and donni106 committed Jul 26, 2022
1 parent 833161d commit 23c8703
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
1 change: 1 addition & 0 deletions Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public static function onRestApiAddRules()
['pattern' => 'link/category/<categoryId:\d+>', 'route' => 'smartVillage/linklist/link/link-category', 'verb' => 'GET'],

//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');
}
Expand Down
44 changes: 44 additions & 0 deletions controllers/notification/NotificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 31 additions & 1 deletion docs/postman/Smart Village API.postman_collection.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down Expand Up @@ -801,6 +801,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": []
}
]
},
Expand Down

0 comments on commit 23c8703

Please sign in to comment.