CB Activity Create an entry with a special asset ref

4 years 1 month ago #316811 by activha
Hello

Just to know if it's feasible : starting from the tab or the main menu for CB Activity / display activity, is it possible to create an entry and apply to this entry a special asset ref ?

I mean that we would like to keep all the standard behavior for CB Activity create feature, but that, when the user selects a special action (to be added) then the asset 'wanted' would be added, thus allowing us to retrieve this special entry, list it elsewhere and retrieve it.

Is it doable ?

Thanks

Please Log in to join the conversation.

4 years 1 month ago #316814 by krileon
The asset used for storage is the first asset in the Asset parameter list. It can not be modified outside of that. I assume by selecting an action you mean with the Action button in which case no it can not modify the asset at time of storage. Only way to do what you're wanting is probably an auto action to modify the activity entry. activity_onBeforeCreateStreamActivity and activity_onBeforeUpdateStreamActivity are fired just before an activity entry is created or updated. Their variables are as follows.

activity_onBeforeUpdateStreamActivity
$_PLUGINS->trigger( 'activity_onBeforeUpdateStreamActivity', array( $stream, $source, &$row, $old ) );

activity_onBeforeCreateStreamActivity
$_PLUGINS->trigger( 'activity_onBeforeCreateStreamActivity', array( $stream, $source, &$row ) );

Since $row (the activity row) is sent by reference it can be set as a reference variable in your auto action and be modified. Example below using a Code action.

Method: PHP
Code:
$variables['var3']->set( 'MY_ASSET_HERE' );
Reference Variables: Variable 3

The action selected is stored in the rows parameters so you should be able to get it with [var3_params_action_id]. It may not nest that far down, but I believe it should. So in theory you could have the below.

$variables['var3']->set( $variables['var3']->get( 'asset' ) . '.[var3_params_action_id]' );


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

4 years 1 month ago - 4 years 1 month ago #316816 by activha
Wonderful, that's really amazing what we can achieve with these APIs.
I'll let you know if I encounter some difficulties after some trials

PS : just a tiny thing, could you change the action icon from fa-smile-o to fa-smile only ? because the latter is perfectly compatible with fontawesome 5 but not the former :-)

Please Log in to join the conversation.

4 years 1 month ago #316819 by krileon

PS : just a tiny thing, could you change the action icon from fa-smile-o to fa-smile only ? because the latter is perfectly compatible with fontawesome 5 but not the former

We're not compatible with Fontawesome 5. We may not even be using Fontawesome anymore in the near future since Bootstrap icons is progressing more and more. Fontawesome has went far too commercial and their new CSS structure is frustrating with different base classes for no reason breaking backwards compatibility. Note fa-smile does not exist in Fontawesome 4, which is what we are currently using.

With that said you should be able to just change that using CSS. The below for example should work.

.cb_template .streamInputAction .fa-smile-o:before {
    content: "\f118";
}


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

4 years 1 month ago - 4 years 1 month ago #316829 by activha
Thanks for that !

It seems that I have some difficulties getting the auto action to work.

Using activity_onBeforeUpdateStreamActivity is fine but using and activity_onBeforeCreateStreamActivity does not give the expected results as there are not yet any id or params registered in the DB. I have also tried activity_onAfterCreateStreamActivity but this last one does not change the asset id

I used
$variables['var3']->set( 'asset', 'wanted.[var3_id].action.[var3_params_action_id].profile.[user_id]');
also tried
$variables['var3']->set( 'asset', 'wanted.' . $variables['var3']->get( 'id' ) . '.action.[var3_params_action_id].profile.' . $variables['var3']->get( 'user_id' ) );
and
$variables['var3']->set( 'asset', 'wanted.' . $variables['var3']->get( 'id' ) . '.action.' . $variables['var3']->get( 'params_action_id' ) . '.profile.' . $variables['var3']->get( 'user_id' ) );
without results outputs are
wanted..event.[var3_params_action_id].profile.57
wanted..action..profile.57


Only the trigger activity_onBeforeUpdateStreamActivity works fine with
$variables['var3']->set( 'asset', 'wanted.[var3_id].action.[var3_params_action_id].profile.[user_id]');
outputting : wanted.5008.action.12.profile.57

Any idea for another trigger or something else when creating entries ?

Another linked question : can I add a special like behavior ? or a special join/subscribe function ?
The idea would be to register users interests in the wanted asset either by a like button or a following action on #__comprofiler_plugin_activity_following

Please Log in to join the conversation.

4 years 1 month ago #316840 by krileon

Using activity_onBeforeUpdateStreamActivity is fine but using and activity_onBeforeCreateStreamActivity does not give the expected results as there are not yet any id or params registered in the DB.

activity_onBeforeUpdateStreamActivity only fires after an activity entry edit. The params should be available perfectly fine in activity_onBeforeCreateStreamActivity. It doesn't need to be stored in the database yet; the params exist in the $row object, but you'll likely need to use PHP to reach them.

I have also tried activity_onAfterCreateStreamActivity but this last one does not change the asset id

Did you be sure to set Reference Variables under Parameters in your auto action? Without that it won't pass $row by reference so your changes won't persist to the store function called after that trigger. See my reply earlier where you need to set Reference Variables to Variable 3 for those triggers.

without results outputs are

You can't insert the activity id into the asset. The id doesn't exist yet. You shouldn't be inserting an activity id into its own asset though. The asset is meant to depict the location. Example as follows.

Incorrect: wanted.5008.action.12.profile.57
Correct: wanted.profile.57.action.12 (profile is the primary source)
Correct: wanted.action.12.profile.57 (action is the primary source)

You could then wildcard this in the Asset param as follows.

All wanted actions: wanted.profile.%.action.%
All wanted actions for profile X: wanted.profile.X.action.%
All wanted actions of X: wanted.profile.%.action.X
All wanted actions of X for profile X: wanted.profile.X.action.X

With the above for example this would give you the following.

wanted.action.[var3_params_action_id].profile.[user_id]
or
wanted.profile.[user_id].action.[var3_params_action_id]

You may need to use PHP here though. Example as follows.

$variables['var3']->set( 'wanted.profile.[user_id].action.' . (int) $variables['var3']->params()->subTree( 'action' )->get( 'id' ) );

Another linked question : can I add a special like behavior ? or a special join/subscribe function ?
The idea would be to register users interests in the wanted asset either by a like button or a following action on #__comprofiler_plugin_activity_following

Likes should already be enabled so they can like that activity entry. Aside from that you'll need to be more specific about what you mean by special function.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.229 seconds

Facebook Twitter LinkedIn