PHP to show detail view of form in Community Builder tab

boyjah

Member
I am using Community Builder for subscription management and initial registration but using Fabrik to collect and display user profile information. I am looking for a way to display Fabrik collected user profile information under a tab in the Community Builder user profile page.

Community Builder has a field type called "Code" that allows the insertion of any php and it will render it. I tested it with several different sets of standard php code (such as difference between 2 dates) and it worked. But when I tried to display the detail information for a single Fabrik record, based on the Fabrik Wiki documentation for Load a single ROW of data as an object, the result is blank.

My Fabrik database table is #__fab_host_profile

As a test I tried the following code to try and pull detail view data for user id 540:

$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery
->select(array('hostregion', 'hostshichousonjpn','hostactivities'))
->from('#__fab_host_profile')
->where('user_id = ' . $myDb->quote('540'));
$myDb->setQuery($myQuery);
$row = $myDb->LoadObject();

Result was blank.

Then, as another test, I tried (just to display a single field's value):

$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery
->select('hostshichousonjpn')
->from('#__fab_host_profile')
->where('user_id = ' . $myDb->quote('540'));
$myDb->setQuery($myQuery);
$hostshichousonjpn = $myDb->loadResult();

Result is still blank.

Can someone tell me what I am missing or direct me to a good example to accomplish my goal?
 
It's looking ok.

For debugging you can add
echo $myQuery;
var_dump($hostshichousonjpn);
exit;
 
As another test I used the following code (with debug):

$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery
->select(array('hostregion', 'hostshichousonjpn','hostactivities'))
->from('#__fab_host_profile')
->where('user_id = ' . $myDb->quote('540'));
$myDb->setQuery($myQuery);
$row = $myDb->LoadObject();
echo $myQuery;
var_dump($row);
exit;

And the result is:

SELECT hostregion,hostshichousonjpn,hostactivities FROM #__fab_host_profile WHERE user_id = '540'object(stdClass)#1567 (3) { ["hostregion"]=> string(10) "_F_TOHOKU_" ["hostshichousonjpn"]=> string(9) "???" ["hostactivities"]=> string(27) "["_F_GENFARMINGKNOWLEDGE_"]" }

Which to me shows that the php code is correct. Right? All values showing for each field are exactly as in the database. So, with this debug result, does it make sense that, without the debug code, the field data should be displayed when this code is run? Or am I missing some line of code that would render the results properly when the debug code is removed? Because it still shows up as blank under Community Builder, whereas other php tests did not.
 
Last edited:
Your code doesn't show any rendering (echo a string, return something and CB is rendering?)
How did you render this ?
I tested it with several different sets of standard php code (such as difference between 2 dates) and it worked
 
For example, this is one of the sample codes I tried that works:

$datetime1 = new DateTime();
if ($user->cb_birthdate == "0000-00-00") return 'No birthday specified';
$datetime2 = new DateTime($user->cb_birthdate);
$difference = $datetime1->diff($datetime2);
return 'Exact age is: ' . $difference->y . ' years, ' . $difference->m . ' months, ' . $difference->d . ' days';

But I don't know how to format the "return" line for my debugged sample code in my previous post. Is that the difference?
 
OK, I played with it and use this:

return 'Region: ' . $row-> hostregion . ' ???: ' . $row-> hostshichousonjpn . ' Activities: ' . $row-> hostactivities;

Which gives a result as:
Screen Shot 2016-11-11 at 01.38.31.png

So, I guess it's "working". But it is a HUGE form. I used just 3 sample fields for my test. Is there no way to have all fields for the row render in the nice layout like the standard Fabrik detail view?
 
It's working on my test site with CB 2.0.15
Create a tab, in "parameters"/plugin text put something like
{fabrik view=details id=17 fabrik_user_reg___joomla_user_id_raw=[$my->id] resetfilters=1}
 
Sorry, I am going crazy trying to figure out how to download something from Github. Isn't there someplace where I can just download the plugin?
 
I is in http://fabrikar.com/download
but the Download button is missing...

So if you are running a Fabrik GitHub version I think (I can't remember how I did it) you can
go to components\com_comprofiler\plugin\user,
zip the folder "plug_fabrik"
install it from inside CB Plugin Management

or download the complete GitHub
unzip locally
then see ^^

The Fabrik plugin is showing "...not compatible with your current CB version..." but it seems to be running.
 
Installed plugin, inserted
{fabrik view=details id=6 fabrik_user_reg___joomla_user_id_raw=[$my->id] resetfilters=1}

and I get the same error that many others seem to get:

0 Serialization of 'Closure' is not allowed
 
id=6 fabrik_user_reg___joomla_user_id_raw
These are my form id and element name, you have to insert yours.

But CB plugin seems to be work in progress at the moment.
There's some other thread about it.

0 Serialization of 'Closure' is not allowed
How/where do you display the tab?
Which Joomla template?
 
Last edited:
Modifying form id and element name. My list id is 6, table name is y2vfp_fab_host_profile and element name is user_id

{fabrik view=details id=6 y2vfp_fab_host_profile___user_id_raw=[$my->id] resetfilters=1}

I still get the same error...
 
If you leave the parameters box blank, the following shows up on the front end under the Fabrik tab:

fabrik_social_profile_hash=9a9ed26c283e1d2e2eb73019ca06f89e}

Could that be causing some problems?
 
I can see this, too.
But it's working with the content string on my site.

A correction: to display the details view you must use
{fabrik view=details id=6 usekey=user_id rowid=[$my->id] resetfilters=1}

(the other syntax is for list view filtered by the userId)

0 Serialization of 'Closure' is not allowed
How/where do you display the tab?
Which Joomla template?
Do you have a link (in your sites)?
 
A correction: to display the details view you must use
{fabrik view=details id=6 usekey=user_id rowid=[$my->id] resetfilters=1}

This still produces the error "0 Serialization of 'Closure' is not allowed"

How/where do you display the tab?
Which Joomla template?
Do you have a link (in your sites)?

  • The tab is displayed under the standard Community Builder profile page, in the same position as other tabs
Screen Shot 2016-11-11 at 15.06.44.png

  • I am using the standard Joomla template called Protostar
  • I'm not sure what you mean about a "link (in your sites)"
I can say that I am able to get some Fabrik instances to display correctly under the Community Builder tab. For example {fabrik view=list id=6} does in fact display the full list under the Fabrik tab in Community Builder. And {fabrik view=form id=6} does in fact display the form. It seems that any attempt to introduce any more parameters, such as user_id, leads to the Serialization of 'Closure' error.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top