By Josh Lewis on Friday, 29 January 2016
Replies 19
Likes 0
Views 1.5K
Votes 0
I understand that creating customizations are not supported. I was wondering if I could get pointed in the right direction with a snippet of code.

I'm wanting to access an EasySocial boolean custom field for the current logged in user. For example I want to let the user decide if certain site menu's should float such as the header. The problem is that I don't know how to check the boolean field in the condition. See PHP code:

<?php
if(ES-Unique-Key-BOOLEAN == true) {
//JS code to append floating class
}

else {
// remove floating class from menus
}
?>


I see some info on it in the docs.

Would the PHP code block start out with:

require_once(JPATH_ADMINISTRATOR . '/components/com_easysocial/includes/easysocial.php');
$my = ES::user();
$state = $my->setFieldValue(string $key, 'some value here');


? Also where it says "some value here", is this where the unique key goes? Also I'm not quite sure where to apply:

public function setFieldValue($key, $value)


I would put the code in index.php of the current template. Any pointers would go greatly appreciated.
You should try to output the $state and see what is the output
·
Monday, 01 February 2016 14:03
·
0 Likes
·
0 Votes
·
0 Comments
·
Rather than calling "setFieldValue", you should actually call "getFieldValue"
·
Friday, 29 January 2016 23:14
·
0 Likes
·
0 Votes
·
0 Comments
·
Thanks for the correction. Seems like I'm not quite there:

<?php

require_once(JPATH_ADMINISTRATOR . '/components/com_easysocial/includes/easysocial.php');
$my = ES::user();
$state = $my->getFieldValue(string $BOOLEAN);

if($state == true) {
echo "Success";
}

else {
echo "Fail";
}
?>


I also tried another slight variation of the above code with no luck:

$state = $my->getFieldValue(string $key, 'BOOLEAN');


I'm aware that I'm not well versed with PHP. I'm hoping to learn a lot more of it within the next 3 months thanks to Randall giving me access to some lessons on it.
·
Saturday, 30 January 2016 18:28
·
0 Likes
·
0 Votes
·
0 Comments
·
·
Sunday, 31 January 2016 17:04
·
0 Likes
·
0 Votes
·
0 Comments
·
Yes, the key for now is literally called BOOLEAN due to that being the default generated field key name.

So the code works without producing any errors, however it doesn't seem to be actually retrieving the boolean value. When I change the boolean on my profile it doesn't shift to the else statement. Here's the code I am now using:

<?php

require_once(JPATH_ADMINISTRATOR . '/components/com_easysocial/includes/easysocial.php');
$my = ES::user();
$state = $my->getFieldValue('BOOLEAN');

if($state == True) {
echo "Show floating menu";
}

else {
echo "Hide floating menu";
}
?>


I think what is happening is that it is able to see the boolean field, but is not retrieving the value.
·
Monday, 01 February 2016 05:22
·
0 Likes
·
0 Votes
·
0 Comments
·
Thanks Mark for the hint. I did try 0 and 1 for my comparison earlier (I swapped back to true/false due to this not working), however my fatal flaw was that I did not treat the numerical value as a string. Last month I took a programming class which I used functions such as CInt(). I was told by my teacher than PHP does a lot of stuff for you such as declaring data types. As a result I assumed that 1 was the same as "1". Although to be honest I actually didn't give it a lot of thought on that aspect or else I would have figured it out. Figured I did something else wrong.

Anyways, the code is working as expected:

<?php

require_once(JPATH_ADMINISTRATOR . '/components/com_easysocial/includes/easysocial.php');
$my = ES::user();
$state = $my->getFieldValue('BOOLEAN');

if($state == "1") {
echo "Show floating menu";
}

else {
echo "Hide floating menu";
}
?>


Anyways, I tested this on other fields such as auto complete and listbox with total success! I am ecstatic about how many possibilities open up for giving site users content relevant to them. I really appreciate you helping me full through this. The echo hint really helped me with other custom fields (auto complete for example outputs [brackets] which would have been harder to figure out on my own). I know about using the escape character for quotes.
·
Monday, 01 February 2016 15:00
·
0 Likes
·
0 Votes
·
0 Comments
·
You are most welcome Josh Glad that your issues are resolved now.
·
Monday, 01 February 2016 16:00
·
0 Likes
·
0 Votes
·
0 Comments
·
can i use the upper script also if i want by boolean = false that other custom profile type fields are visible?
·
Friday, 24 June 2016 22:29
·
0 Likes
·
0 Votes
·
0 Comments
·
Hey Josef,

Assuming that you want to determine if the value is false, you can do something like this,

·
Saturday, 25 June 2016 03:08
·
0 Likes
·
0 Votes
·
0 Comments
·
Ok, i will explan better:
I have by profile type "privat person" the custom boolean field: "visible in dating" in a seperate tab "Dating Profile"
Below this boolean field i want have other custom fields: eyes color, hair color, size, etc.
But this fields schould only visible if the user set the boolean field to "yes".
·
Saturday, 25 June 2016 03:17
·
0 Likes
·
0 Votes
·
0 Comments
·
It's not possible right now unfortunately . The only way to achieve this from what I can see,

1. Create the other fields that you want.
2. Using css, hide these new fields
3. With javascript, hook onto the "yes/no" button event (change) to show these events.
·
Saturday, 25 June 2016 03:22
·
0 Likes
·
0 Votes
·
0 Comments
·
Ok, i have only expiriense about css, but no about php or javascript coding
·
Saturday, 25 June 2016 03:28
·
0 Likes
·
0 Votes
·
0 Comments
·
You can always contract a freelancer We are also available for hire for custom works.
·
Saturday, 25 June 2016 03:30
·
0 Likes
·
0 Votes
·
0 Comments
·
I had contacted your custom worker, the first time i get the answer if i pay 90 us dollar per hour then i can do,
Its expensive if i do not know how many hours i must pay.
And the second time he said i should ask the support.
Then i get sometimes custom info, a little bit, and then the answer for customize contact ......

Always if i have a question i search first in forum, there i see many custom solution, not the right for me, but little like me.
And always if ask, then i get half answers or no answers.

I think if you resell a community application then should be the customize aviable.
If not then we can also use the same community and need not a own on our pages.

But i want also say specialy say to you thanks for your friendly answers
·
Saturday, 25 June 2016 03:42
·
0 Likes
·
0 Votes
·
0 Comments
·
Hey Josef,

Firstly, I do apologize for the mix-ups. I believe the reason is most likely because of some miscommunication. Your question was probably not understood correctly since there are some language barrier here?

Anyway if you are interested, we can customize this at the rate of $90 / hour. Let me know how many fields are you looking at and I would then be able to give you a rough estimate of the cost. Perhaps it's ideal that you start a new thread on our forums and set it as "private".
·
Saturday, 25 June 2016 03:58
·
0 Likes
·
0 Votes
·
0 Comments
·
Do you have maybe a supsribe plan that i pay monthly for any small customation?
Because i have any small specially things.
·
Saturday, 25 June 2016 04:04
·
0 Likes
·
0 Votes
·
0 Comments
·
Unfortunately we don't have such plans. We work by the hour
·
Saturday, 25 June 2016 04:05
·
0 Likes
·
0 Votes
·
0 Comments
·
if i use your upper code to hide a menu item by boolean, where i should insert this code?
·
Monday, 27 June 2016 18:10
·
0 Likes
·
0 Votes
·
0 Comments
·
Hey Josef,

I have a little bit lost here, which menu item are you referring? Perhaps you can provide us some screenshot so that we can better take a look.
·
Tuesday, 28 June 2016 13:15
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post