{"id":15089269,"url":"https://github.com/cb-techservices/yii2-notification-system","last_synced_at":"2025-04-11T15:32:04.296Z","repository":{"id":62500242,"uuid":"157494699","full_name":"cb-techservices/yii2-notification-system","owner":"cb-techservices","description":"Yii2 extension which provides a fully functional notification system backed with ActiveRecord and a customizable UI.","archived":false,"fork":false,"pushed_at":"2019-04-20T00:48:31.000Z","size":247,"stargazers_count":4,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T15:35:02.159Z","etag":null,"topics":["activerecord","javacsript","jquery","notification","notification-system","php","yii2","yii2-extension","yii2-notification","yii2-widgets"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cb-techservices.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-14T05:15:36.000Z","updated_at":"2022-01-04T11:10:07.000Z","dependencies_parsed_at":"2022-11-02T11:47:34.375Z","dependency_job_id":null,"html_url":"https://github.com/cb-techservices/yii2-notification-system","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cb-techservices%2Fyii2-notification-system","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cb-techservices%2Fyii2-notification-system/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cb-techservices%2Fyii2-notification-system/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cb-techservices%2Fyii2-notification-system/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cb-techservices","download_url":"https://codeload.github.com/cb-techservices/yii2-notification-system/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248431620,"owners_count":21102231,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activerecord","javacsript","jquery","notification","notification-system","php","yii2","yii2-extension","yii2-notification","yii2-widgets"],"created_at":"2024-09-25T08:41:55.965Z","updated_at":"2025-04-11T15:32:04.003Z","avatar_url":"https://github.com/cb-techservices.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Yii2 Notification System\nThis Yii2 extension provides a fully functional notification system backed with ActiveRecord and a customizable UI.\n\nInstallation\n------------\n##### Composer\n```shell\nphp composer.phar require cb-techservices/yii2-notification-system \"*\"\n```\nor add\n```json\n\"cb-techservices/yii2-notification-system\": \"*\"\n```\nto the require section of your `composer.json` file.\n\nConfiguration\n------------\nBefore using this module, you have to run its migrations scripts. This will add the notification table to your database.\n\nRun this command from the root of your Yii project:\n```bash\n./yii migrate/up --migrationPath=vendor/cb-techservices/yii2-notification-system/migrations/\n```\n\nAdd the following to the `modules` section of your Yii project config.\n```php\n'modules'=\u003e[\n    'notifications' =\u003e [\n        'class' =\u003e 'cbtech\\notification_system\\NotificationSystemModule',\n        //The controller's namespace for where to find the Controller actions.\n        //You may use the default NotificationsController provided or create your own custom controller.\n        'controllerNamespace' =\u003e 'cbtech\\notification_system\\controllers',\n        // Point this to your own Notification class\n        // See the \"Declaring your notifications\" section below\n        'notificationClass' =\u003e 'common\\models\\Notification',\n        // Allow to have notification with same (user_id, key, key_id)\n        // Default to FALSE\n        'allowDuplicate' =\u003e true,\n        // Allow custom date formatting in database\n        'dbDateFormat' =\u003e 'Y-m-d H:i:s',\n\t\t// This callable should return your logged in user Id\n        'userId' =\u003e function() {\n            return \\Yii::$app-\u003euser-\u003eid;\n        },\n        'expirationTime'=\u003e0\n    ],\n],\n```\n### Module Parameters\n| Parameter             |  Type   | Description                                                                                     | Default     |\n| :-------------------- | ------- | :---------------------------------------------------------------------------------------------- |:----------- |\n| class | String | The required class path to the NotificationSystemModule | 'cbtech\\notification_system\\NotificationSystemModule' | \n| controllerNamespace | String | The controller's namespace for where to find the Controller actions.  You may use the default NotificationsController provided or create your own custom controller. | 'cbtech\\notification_system\\controllers' |\n| notificationClass | String | Point this to your own Notification class. See the \"Declaring your notifications\" section below. | 'common\\models\\Notification' |\n| allowDuplicate | Boolean | Allow to have notifications with the same user_id, key, key_id | false |\n| dbDateFormat | String | Allows custom date formatting in databse | 'Y-m-d H:i:s' |\n| userId | callable/integer | This callable should return your logged in user Id | ``` function() { return \\Yii::$app-\u003euser-\u003eid; } ``` |\n\n### Declaring your notifications\nYour custom Notification class must **extend** `cbtech\\notification_system\\models\\NotificationBase`\n\nAn example is provided in [examples/Notification.php](examples/Notification.php)\n\n\nUsage\n------------\n\n### Triggering a notification\n\n\n```php\n\n// A connection request made by a user to the $recipient_id\nNotification::notify(Notification::KEY_NEW_CONNECTION_REQUEST, $recipient_id, $connectionRequest-\u003eid);\n\n// You may also use the following static methods to set the notification type:\nNotification::warning(Notification::KEY_NEW_MESSAGE, $recipient_id, $message-\u003eid);\nNotification::success(Notification::ORDER_PLACED, $admin_id, $order-\u003eid);\nNotification::error(Notification::KEY_NO_DISK_SPACE, $admin_id);\n\n```\n          \n### Listening and showing notifications in the UI\nThis extension comes with a `NotificationsWidget` that is used to regularly poll the server for new notifications.\n\n### Widget Parameters\n\n| Parameter             |  Type   | Description                                                                                     | Default     |\n| :-------------------- | ------- | :---------------------------------------------------------------------------------------------- |:----------- |\n| pollUrl               | String  | The URL for the poll() for new notifications controller action                                  | '/notifications/notifications/poll'       |\n| markAsReadUrl         | String  | The URL for the controller action that marks an individual notification as read                 | '/notifications/notifications/read'       |\n| markAsUnreadUrl       | String  | The URL for the controller action that marks an individual notification as unread               | '/notifications/notifications/unread'     |\n| flashUrl              | String  | The URL for the controller action that marks an individual notification as having been flashed  | '/notifications/notifications/flash'      |\n| readAllUrl            | String  | The URL for the controller action that marks all notifications as read                          | '/notifications/notifications/read-all'   |\n| unreadAllUrl          | String  | The URL for the controller action that marks all notifications as unread                        | '/notifications/notifications/unread-all' |\n| delay                 | Integer | The time to leave the notification shown on screen                                              | 5000        |\n| pollInterval          | Integer | The delay in milliseconds between polls                                                         | 5000        |\n| xhrTimeout            | Integer | The XHR request timeout in milliseconds                                                         | 2000        |\n| counters              | Array   | An array of jQuery selectors to update with the current notifications count                     | []          |\n| markAllReadSelector   | String  | The jQuery selector for the Mark All as Read button                                             | null        |\n| markAllUnreadSelector | String  | The jQuery selector for the Mark All as Unread button                                           | null        |\n| viewAllSelector       | String  | The jQuery selector for your UI element that will holds the notification list                   | null        |\n| viewUnreadSelector    | String  | The jQuery selector for the View Unread button                                                  | null        |\n| headerSelector        | String  | The jQuery selector for the Notifications header view                                           | null        |\n| headerTemplate        | String  | The header HTML template. You can provide your own HTML structure and use the following variables: `{title}`,`{readAllId}`,`{unreadAllId}` | See default example below. |\n| headerTitle           | String  | The header title string                                                                         | \"Notifications\" |\n| listSelector          | String  | The jQuery selector for the View All button                                                     | null        |\n| listItemTemplate      | String  | The list item HTML template. You can provide your own HTML structure and use the following variables: `{id}`,`{title}`,`{body}`,`{read}`,`{unread}`,`{timeago}`,`{footer}` | See default example below. |\n\n### Widget Usage\nBelow is an example of the widget with all possible parameters.  Optional values are indicated. This should be added at the top of your main layout template.\n```php\nNotificationsWidget::widget([\n    'pollUrl' =\u003e '/notifications/notifications/poll', //Optional, default value\n    'markAsReadUrl' =\u003e '/notifications/notifications/read', //Optional, default value\n    'markAsUnreadUrl' =\u003e '/notifications/notifications/unread', //Optional, default value\n    'flashUrl' =\u003e '/notifications/notifications/flash', //Optional, default value\n    'readAllUrl' =\u003e '/notifications/notifications/read-all', //Optional, default value\n    'unreadAllUrl' =\u003e '/notifications/notifications/unread-all', //Optional, default value\n    'clientOptions' =\u003e [\n        'location' =\u003e 'tr',\n    ],\n    'delay' =\u003e 5000,\n\t'xhrTimeout' =\u003e 2000,\n    'pollInterval' =\u003e 5000,\n    'counters' =\u003e [\n        '.notifications-header-count',\n        '.notifications-icon-count'\n    ],\n    'markAllReadSelector' =\u003e '#notification-read-all',\n    'markAllUnreadSelector' =\u003e '#notification-unread-all',\n    'listSelector' =\u003e '#notifications',\n    'viewAllSelector' =\u003e '#viewAll',\n    'viewUnreadSelector' =\u003e '#viewUnread',\n    'headerSelector' =\u003e '#notifications-header',\n    'headerTitle' =\u003e 'Notifications',\n    'headerTemplate' =\u003e \n        '\u003cdiv class=\"col-xs-12\"\u003e' . \n            '\u003cdiv class=\"pull-left\" style=\"font-size:14px;font-weight:bold;margin-left:10px;\"\u003e{title}\u003c/div\u003e' . \n            '\u003cbutton id=\"{readAllId}\" class=\"btn btn-xs btn-link pull-right\" style=\"color:#3399ff;\" data-keepOpenOnClick\u003eRead\u003c/button\u003e' . \n            '\u003cbutton id=\"{unreadAllId}\" class=\"btn btn-xs btn-link pull-right\" style=\"color:#3399ff;\" data-keepOpenOnClick\u003eUnread\u003c/button\u003e' . \n            '\u003clabel style=\"font-size:12px;padding-top:1px;\" class=\"pull-right\"\u003eMark All as \u003c/label\u003e' .\n        '\u003c/div\u003e', //Optional, default value\n    'listItemTemplate' =\u003e \n        '\u003cdiv class=\"notificationRow\" id=\"notification_{id}\" data-keepOpenOnClick\u003e' .\n            '\u003cdiv class=\"col-xs-11\" onclick=\"goToRoute(\\'{id}\\');\"\u003e' .\n                '\u003cdiv class=\"notification-title\"\u003e{title}\u003c/div\u003e' .\n                '\u003cdiv class=\"notification-body\"\u003e{body}\u003c/div\u003e' .\n            '\u003c/div\u003e' .\n            '\u003cdiv class=\"col-xs-1\"\u003e' .\n                '\u003cdiv class=\"notification-actions pull-right\"\u003e{read}{unread}\u003c/div\u003e' .\n            '\u003c/div\u003e' .\n            '\u003cdiv class=\"clearfix\"\u003e\u003c/div\u003e' . \n            '\u003cdiv class=\"col-xs-1\"\u003e' .\n                '\u003cdiv class=\"notification-timeago\"\u003e{timeago}\u003c/div\u003e' .\n            '\u003c/div\u003e' .\n            '\u003cdiv class=\"col-xs-10\"\u003e' .\n                '\u003cdiv class=\"notification-footer\"\u003e{footer}\u003c/div\u003e' .\n            '\u003c/div\u003e' .\n            '\u003cdiv class=\"clearfix\"\u003e\u003c/div\u003e' . \n        '\u003c/div\u003e', //Optional, default value\n]);\n```\n\nIf you have provided a value for the `headerSelector` and/or the `listItemTemplate` you can include the notifications list view by adding the following to your navbar:\n```php\n$menuItems[] = '\u003cli class=\"dropdown\"\u003e\n                    \u003ca href=\"#\" class=\"dropdown-toggle\" data-toggle=\"dropdown\" role=\"button\" aria-haspopup=\"true\" aria-expanded=\"false\"\u003e\n                        \u003cspan style=\"font-size:18px;top: 5px;margin-right:3px;\" class=\"glyphicon glyphicon-bell\"\u003e\u003c/span\u003e\n                        \u003cspan class=\"badge notifications-icon-count\"\u003e0\u003c/span\u003e\n                    \u003c/a\u003e\n                    \u003cul class=\"dropdown-menu\"\u003e\n                        \u003cli id=\"notifications-header\" style=\"text-align:center;\"\u003e\u003c/li\u003e\n                        \u003cli id=\"notifications\"\u003e\u003c/li\u003e\n                        \u003cli style=\"text-align:center;border-bottom:1px #cccccc solid;padding:10px;\"\u003e\n                            \u003cbutton class=\"btn btn-xs btn-primary\" id=\"viewAll\" data-keepOpenOnClick\u003eView All\u003c/button\u003e /\n                            \u003cbutton class=\"btn btn-xs btn-primary\" id=\"viewUnread\" data-keepOpenOnClick\u003eView Unread\u003c/button\u003e\n                        \u003c/li\u003e\n                    \u003c/ul\u003e\n                \u003c/li\u003e';\n```\n\n#### Notifications List View\n![Notifications list view](https://raw.githubusercontent.com/cb-techservices/yii2-notification-system/master/images/NotificationsListView.png)\n\n#### Tostr Notification\n![Toastr notification](https://raw.githubusercontent.com/cb-techservices/yii2-notification-system/master/images/ToastrNotification.png)\n\nContributors\n------------\nCarl Burnstein https://github.com/carlb0329\n\nCredits\n------------\nInspired by [machour/yii2-notifications](https://github.com/machour/yii2-notifications) \u003cbr/\u003e\nUses [CodeSeven/toastr](https://github.com/CodeSeven/toastr)\n\nLicense\n------------\nYii2 Notification System is licensed under MIT license - https://github.com/cb-techservices/yii2-notification-system/blob/master/LICENSE \u003cbr/\u003e\nCopyright (c) 2018 CB Tech Services","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcb-techservices%2Fyii2-notification-system","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcb-techservices%2Fyii2-notification-system","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcb-techservices%2Fyii2-notification-system/lists"}