Using Soucerer plugin to do CB calculated field

12 years 3 months ago #187515 by superpcan
This is my first project using CB (download version), I wanted to display a field based on existing field(s).

Without pro version or writing a custom CB plugin, it seems fairly hard to achieve the goal. All I need is an indicator on profile/userlist for membership expiration (our membership is yearly renewal).

After some try out, here I share what I did, all you need is Joomla Plugin 'Sourcerer':
extensions.joomla.org/extensions/5051

Steps:
1. Create a new [Fields delimeter] type field in CB Field Manager

2. In description, click the [insert code <>] button and put your PHP code in:
{source}
<?php
$smdt = "[cb_memberdate]";
$mdays = round(abs(strtotime($smdt)-strtotime(date('Y-m-d')))/86400);
if ($mdays>365) {
echo "Expired";
}
?>
{/source}

3. Place the field anywhere you want like other fields.

The trick is how to refer the existing field. Here [cb_memberdate] is the stored field for member's reg date, the double-quote is important (single-quote also OK).

In my case, the code just compare the reg date with today, if it is over 1 year, then show "Expired", simple?

You can do other stuff with same trick, and refer to more existing fields in your code.

Note: the source code will show up "as is" in backend->CB User Manager

Have fun!

Please Log in to join the conversation.

12 years 3 months ago #189182 by jnetsolution
Replied by jnetsolution on topic User list Advanced filter
Hi superpcan,
It work with Delimeter field but is it possible to use this plugin in User list Advanced filter? Can we insert script like this
{source}
<?php
$radius = $_GET["radius"];
echo $radius;
?>
{/source}

Instead of
'30'

I tried and it doesn't work out. Anybody know how can we use a php variable in User list Advanced filter?

Best regard!

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.131 seconds

Facebook Twitter LinkedIn