Use Validation or PHP code, to manage registers, which would be better?

javier94

Member
in the website, we have a suscriptions..

we have 3 types of suscriptions.

basic = you can publish 3 menu restaurants
gold = you can publish 6 menu restaurants
platinum = you can publish 15 menu restaurants.

=========
the suscription is made by the user, before to access to the registered part
========
i have bought a component to manage the payment of suscriptions etc.. but a part of that, i use
fabrik to create the menu restaurants forms

So to manage, how many items every user can publish i have to create a validation in fabrik, for each suscription.

I have try a PHP using the fabrik form plugin... (redirect option)

in the code i try to manage how many registers the user can activate depending of suscription..

if the user try to activate more than the suscription allows --> re-direct to suscription page, to upgrade the suscription.

the trouble is...

the code seems is ok, but there is something i don´t understand..

if i try to activate more registers than suscription allows - redirect to the suscription page -- this would be ok

But if i came back to the activation page "without upgrade the suscription"

this register is ACTIVATE and saved,
when this register should be as default and NOT ACTIVATE.

Not sure if is a mistake in my code, or i should use a "validation element" to check the registers.

the code i have done is.. i use a redirect.. with the following condition:

$uid = '{cartas_registro___user_id}';

$db = JFactory::getDbo();

/// Contamos registros a Sí
$query1 = $db
->getQuery(true)
->select('COUNT(*)')
->from($db->quoteName('cartas_registro'))
->where($db->quoteName('check_1') . " = 1")
->where($db->quoteName('user_id') . " = " . $uid);
// Reset the query using our newly populated query object.
$db->setQuery($query1);
$count = $db->loadResult();

/// Cogemos plan_id de la fecha del último plan suscrito
$query = $db->getQuery(true);
$query->select($db->quoteName(array('plan_subscription_status','plan_subscription_to_date','plan_id','user_id', 'first_name', 'published'))); //published - 1 activo - 0 no es activo
$query->from($db->quoteName('w47fa_osmembership_subscribers'));
$query->where($db->quoteName('user_id') . ' = ' . $uid);
$query->order($db->quoteName('plan_subscription_to_date') . ' DESC');
$db->setQuery($query);
//$row = $db->loadResult();
$row = $db->loadAssoc();
//var_dump("A Sí tenemos: " . $count . " - " . $row['plan_subscription_to_date'] . " - " . $row['plan_id']);
//exit();
$plan = $row['plan_id'];
if($row['published'] == 0){
return true;
} else {
switch ($plan) {
case 1:
if ($count <= 3){
return false;
} else {
return true;
}
break;
case 2:
if ($count <= 6){
return false;
} else {
return true;
}
break;
case 3:
if ($count <= 15){
return false;
} else {
return true;
}
break;
default:
return true;
}
}


=======


Any suggestion???

Thanks in advance!

Javier
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top