Skip to Content Skip to Menu

🌟Discover the Joomla AI Plugin that wrote its own story! - CB Editor Assistant 1.1now for Joomla 3, 4 & 5!
✍️ 5-Day Free Trial, then 🎯 save up to 30% with our 🛍️ Intro Offer (First 50 users, ends Dec. 31)
🌲 Merry Christmas! Great savings on Professional and Developer Memberships! Get 25% off now with code XMAS-2024!

How to programmatically insert a new field in comprofiler and comprofiler_fields

  • llau
  • llau
  • OFFLINE
  • Posts: 38
  • Thanks: 1
  • Karma: 0
7 years 6 months ago #295194 by llau
Hello,

I'm trying to use the Joomla API to add a new column to the comprofiler table, and I believe I also need to add a new row for this column in the comprofiler_fields table, please correct me if I'm wrong. I'm just trying to add a new field to be displayed on the user's profile and do all this programmatically. I think doing this through the CB backend, creates a new column in the comprofiler table as well as a new row in the "fields" table.

I'm wondering what is the "recommended" way to do this using the Joomla API, or is it easier to do through the CB API?

Cheers,
V

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48630
  • Thanks: 8307
  • Karma: 1446
7 years 6 months ago #295215 by krileon
Simply put, you don't. Use CB API to do so. Once CB API has been included you can make an instance of FieldTable class (note this is a namespaced class) where you'll be able to do a ->store to create a field. See the below on how to include CB API.

www.joomlapolis.com/documentation/279-community-builder/tutorials/18357-including-cb-api-for-usage-outside-of-cb

Below is where the FieldTable class is located.

libraries/CBLib/CB/Database/Table/FieldTable.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.
The following user(s) said Thank You: llau

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

  • llau
  • llau
  • OFFLINE
  • Posts: 38
  • Thanks: 1
  • Karma: 0
7 years 6 months ago - 7 years 6 months ago #295222 by llau
Ok, thanks for the link, Krilieon.

Would I create an instance of the FieldTable class and then use the store function to create the new field, and will it also add the associated columns in the comprofiler table? I'm planning on adding the new fields onUserLogin....

Thanks again,
V
Last edit: 7 years 6 months ago by llau.

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

  • llau
  • llau
  • OFFLINE
  • Posts: 38
  • Thanks: 1
  • Karma: 0
7 years 6 months ago #295223 by llau
Is there code I should be usinig to close database connection as well or does CB already do that after the store?

Thank you kindly,
V

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48630
  • Thanks: 8307
  • Karma: 1446
7 years 5 months ago #295236 by krileon

Would I create an instance of the FieldTable class and then use the store function to create the new field, and will it also add the associated columns in the comprofiler table?

Yes.

Is there code I should be usinig to close database connection as well or does CB already do that after the store?

With Joomla/CB APIs you don't manually open or close the connection. That's all handled further up the chain in the database APIs. Basically doing a ->store opens and closes the connection automatically.


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.

  • llau
  • llau
  • OFFLINE
  • Posts: 38
  • Thanks: 1
  • Karma: 0
7 years 5 months ago - 7 years 5 months ago #295404 by llau
Thanks for you quick response Krileon.

Sorry I have one more question, I had included the code below
Code:
if ( ( ! file_exists( JPATH_SITE . '/libraries/CBLib/CBLib/Core/CBLib.php' ) ) || ( ! file_exists( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ) ) ) { echo 'CB not installed'; return; } include_once( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' );

and it was working when I called it through a CB auto action.

When I called my function through another page, I now get this error when it tries to add new columns:
Code:
PHP Fatal error: Call to a member function loadPluginGroup() on a non-object in C:\WebRoot\website\joomla\libraries\CBLib\CB\Database\Table\FieldTable.php on line 234

I'm creating the new object using this code here:
Code:
$field_Table = new \CB\Database\Table\FieldTable(); $field_Table->set( 'name', 'cb_newfield'); $field_Table->set( 'title', 'New field'); $field_Table->set( 'profile', '0'); $field_Table->set( 'readonly', '1'); $field_Table->set( 'published', '1'); $field_Table->set( 'type', 'date'); $field_Table->set( 'tabid', '11'); $field_Table->set( 'table', '#__comprofiler');
It seems like it is happening inside the field table's store function on this line here: $_PLUGINS->loadPluginGroup( 'user' );

Any insights would be greatly appreciated.

Thanks again.
V
Last edit: 7 years 5 months ago by llau. Reason: additional information

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

Moderators: beatnantkrileon
Powered by Kunena Forum