Im writing a component that will use some core functionality of one of the stock OSSN components. Im wondering if there is something built into the OSSN framework that allows me to import a component into mine essentially so that I can call its functions and have the class accessible to me. I hate copying code that performs simple tasks and creating a new code fork vs. tapping into the core functionality in its pure form. I know I can include those files too, just wondering if there is a better way that is less sensitive for me to do this.
So lets say I am wanting to create a notification for example. Well a lot goes into thos notifications from what I can tell in the OSSN Notifications component so my thought process is why recreate the wheel when I can hopefully "import" OSSNNotifications and call a OSSNNotifications.CreateNotification() method (pseudo code obviously).
Thanks
[Topic is Close]
LOL, Im a putz. I was trying to access the values of the params wrong. My bad, thank you for pointing that out.
I'm sure you enabled error_reporting from your Ossn admin panel.
So ... add a line like
error_log('POSTER GUID: ' . $params->poster_guid);
to your loop and verify the result in your error_log
file.
Thank you thank you Z Man, very sorry for overlooking that. I will definitely take a second look. Hey so any thoughts on how to create that dynamic subject? Also, I stubbed in the object_guid in its place for now just to perform some tests and I dont get any errors with the following code but no notifications send out. I have verified that I am getting the list of guids of users to loop through and it is entering the loop for each user that isnt the posting user. Any thoughts on why notifications are not actually getting added?
function notificationHandler($callback, $type, $params) {
$notifications = new OssnNotifications;
$user = new OssnUser;
$users = $user->getSiteUsers(['page_limit' => false]);
foreach ($users as $key => $value) {
// send the notification to all users except the posting user
if ($value->guid != $params->poster_guid) {
$notifications->add($type, $params->poster_guid, $params->object_guid, $params->object_guid, $value->guid);
}
}
}
Bryce,
14 days ago I told you to add a handler like
function myNotificationHandler($callback, $type, $params) {
but your handler looks like
function notificationHandler() {
No wonder you won't get the post guid this way. ;)
Having a look at the ossn_trigger_callback
at the end of the Post method again you'll see that it is using 3 args and that several vars are put into the $params
array. Thus of course your handler has to be coded accordingly to retrieve the passed stuff.
Hey guys, so I want to use the wall post guid that triggers the callback for this method call in the notification handler but I dont know how to get it. So the scenario is user Bob posts on the wall saying Hello. This gets hooked and calls the notificationHandler which will loop through and send a notification to users Bill, Fred, and Dan with a dynamic message of
'$post_user has a new post'
Here is my code and Im confused on how to add this message since it seems to be looking for a guid. It also seems that would fill the place holder for subjectguid and the wall post guid would fill the place holder for itemguid. Do I have that right
function post_notifications() {
ossn_register_callback("wall", "post:created", "notificationHandler");
}
function notificationHandler() {
$notifications = new OssnNotifications;
$user = new OssnUser;
$users = $user->getSiteUsers(['page_limit' => false]);
$post_user = ossn_loggedin_user();
foreach ($users as $key => $value) {
// send the notification to all users except the posting user
if ($value->guid != $post_user->guid) {
$notifications->add('post:created', $post_user->guid, <<subject_guid>>, <<item_guid>>, $value->guid);
}
}
}
Hey hopefully Arsalan, Z Man, or Bansh33 sees this. Im curious to know what the reason is for these hooks Arsalan mentions in this link to Bansh33 thread (loc: https://www.opensource-socialnetwork.org/discussion/view/2967/how-to-send-notifications-to-users-using-ossnnotifications-class?offset=2). The only thing Im trying to do is loop through users and do a $OssnNotifications->add() so Im trying to understand the context. do I have call the notificationaddconfig for each user or can I just populate the variables from within the loop and call the add method for each user
<?php
function init_function(){
ossn_add_hook("notification:view", "notification:type", "notification_view");
ossn_add_hook("notification:add", "notification:type", "notification_add_config");
}
function notification_view($hook, $type, $return, $params){
see the notifcation:view of other components
return //
}
function notification_add_config($hook, $type, $return, $params){
$params["owner_guid"] = $params["notification_owner"]
..
..
..
return $params
}
Thank you for the info Bansh33!
just so you know, sending a notification is a bit more involved than just calling OssnNotifications->add(). Arsalan explained this to me in a post a while back, it may be useful to you too: https://www.opensource-socialnetwork.org/discussion/view/2967/how-to-send-notifications-to-users-using-ossnnotifications-class
At the end of the Post method (see OssnWall/classes) there's a
ossn_trigger_callback('wall', 'post:created', $params);
You can make use of it by registering a callback inside of your component's init function like:
ossn_register_callback('wall', 'post:created', 'myNotificationHandler');
and adding that handler to your com file like
function myNotificationHandler($callback, $type, $params) {
.....
}
Be aware that the current design of OssnNotifications is in that way limited that only the owner of the object which has been liked, commented ... whatever ... will receive a notification by default. Thus, in your case (since you want to notify everyone) you need to create fake notification records for each member in a loop. No problem with your small family community, but no really good idea with larger ones.
Sorry, one more related question. I have a few sites running ossn and on one its a small user base for a family. What I am doing is creating a component that will trigger a new user notification when any other user does something that posts to the wall. So my question is, is there a way for me to hook into the Post method call so that whenever it is called, I can add my function to it? Think of it as an eventhandler in js, thats what Im looking for? So essentially Post turns into Post + MyNotifiyComponentFunction
Due to the many requests in the past for additonal features and components we have decided to develope a premium version. Features like Hashtags, Videos, Polls, Events, Stories, Link Preview, etc included in it.
$199 (Life Time)