Skip to Content Skip to Menu

Using Soucerer plugin to do CB calculated field

  • superpcan
  • superpcan
  • OFFLINE
  • Posts: 1
  • Thanks: 0
  • Karma: 0
12 years 11 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 or Create an account to join the conversation.

12 years 10 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
Code:
{source} <?php $radius = $_GET["radius"]; echo $radius; ?> {/source}

Instead of
Code:
'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 or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum