Skip to Content Skip to Menu

Autoaction Query and chained statements

  • activha
  • activha
  • OFFLINE
  • Posts: 2326
  • Thanks: 117
  • Karma: 13
2 years 10 months ago - 2 years 10 months ago #327451 by activha
Hello

Could you tell me how to chain two INSERT in an autoaction query ?

I tried with
Code:
INSERT INTO `#__groupjive_plugin_events` (`published`, `params`, `user_id`, `group`, `title`, `event`, `location`, `end`, `start`) VALUES (1, '{\"drophscat\":\"50\",\"gallery\":"[var3_asset]"}', [user_id], 56, '[var3_params_campaign]', '[var3_message]', 'internet', NOW()+INTERVAL 10 YEAR, NOW()); INSERT INTO `#__groupjive_plugin_events_attendance` (`user_id`, `event`, `date`) VALUES ([user_id], SELECT LAST_INSERT_ID(), NOW());
and also
Code:
INSERT INTO `#__groupjive_plugin_events` (`published`, `params`, `user_id`, `group`, `title`, `event`, `location`, `end`, `start`) VALUES (1, '{\"drophscat\":\"50\",\"gallery\":"[var3_asset]"}', [user_id], 56, '[var3_params_campaign]', '[var3_message]', 'internet', NOW()+INTERVAL 10 YEAR, NOW()); SELECT LAST_INSERT_ID() AS l.id; INSERT INTO `#__groupjive_plugin_events_attendance` (`user_id`, `event`, `date`) VALUES ([user_id], l.id, NOW());
but only the first query is executed.
I also tried to separate rows but no result neither, still the first one only is executed.

Thanks
Last edit: 2 years 10 months ago by activha.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48423
  • Thanks: 8274
  • Karma: 1443
2 years 10 months ago #327455 by krileon
Replied by krileon on topic Autoaction Query and chained statements
Try removing the SELECT before calling LAST_INSERT_ID. Alternative is don't use SQL. Use the API. All of our tables have PHP classes for their table objects. Review the saveEventEdit function in the below file for the full process of creating an event and its initial attendance.

components/com_comprofiler/plugin/user/plug_cbgroupjive/plugins/cbgroupjiveevents/component.cbgroupjiveevents.php


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 or Create an account to join the conversation.

  • activha
  • activha
  • OFFLINE
  • Posts: 2326
  • Thanks: 117
  • Karma: 13
2 years 10 months ago #327457 by activha
Replied by activha on topic Autoaction Query and chained statements
I guess that will be much simpler.
How do I call the API to use the function in an auto action ? and in a standalone file ?

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48423
  • Thanks: 8274
  • Karma: 1443
2 years 10 months ago #327459 by krileon
Replied by krileon on topic Autoaction Query and chained statements
You include its PHP namespace and call it or just call it with the namespace included. See the file above for the entire store process for events. Have added a feature ticket to extend the CB GroupJive auto action type to support GJ integrations in a future release so it'll be easier to create events programmatically.


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 or Create an account to join the conversation.

  • activha
  • activha
  • OFFLINE
  • Posts: 2326
  • Thanks: 117
  • Karma: 13
2 years 10 months ago #327460 by activha
Replied by activha on topic Autoaction Query and chained statements
Yes I know how to include it but I am not sure how to pass the information ?
It is supposed to get strings so should I do something like :
Code:
use CB\Plugin\GroupJiveEvents\CBGroupJiveEvents; [post_title]= [var3_params_campaign]; [post_group] = 56; [post_user_id] = [user_id]; etc... CBGroupJiveEvents::saveEventEdit(0,[user_id]);

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48423
  • Thanks: 8274
  • Karma: 1443
2 years 10 months ago #327461 by krileon
Replied by krileon on topic Autoaction Query and chained statements
You don't pass information to that function. Review the function to see how it's handling the storage of an event. The code is meant to be a reference. Example as follows.

Code:
// Create the event object $row = new \CB\Plugin\GroupJiveEvents\Table\EventTable(); // Set the events data $row->set( 'user_id', EVENT_OWNER_USER_ID_HERE ); $row->set( 'group', GROUP_ID_HERE ); $row->set( 'title', EVENT_TITLE_HERE ); $row->set( 'published', 1 ); etc... // Validate and store the event if ( $row->getError() || ( ! $row->check() ) ) { return; } if ( $row->getError() || ( ! $row->store() ) ) { return; } // Create the initial attendence (event owner default attending) $attend = new \CB\Plugin\GroupJiveEvents\Table\AttendanceTable(); $attend->set( 'user_id', $row->getInt( 'user_id', 0 ) ); $attend->set( 'event', $row->getInt( 'id', 0 ) ); $attend->store();


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 or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum