[SOLVED] Display Joomla Menu item only if Fabrik table is not empty + solution

Status
Not open for further replies.

marcq

Member
Hi,

Is there a way to display (or not) a menu item in frontend if there's no record in the

gprh_fabrik_user_training


table with "statut_traitement" field value = 2 ?

Would appreciate some instructions for this.

Thanks in advance,

Marc
 
Not that I'm aware of, no. Unless you can find an extension that allows conditional menu display.

-- hugh
 
Not that I'm aware of, no. Unless you can find an extension that allows conditional menu display.

-- hugh

Hi Hugh,

Thanks for your feedback, I will try to find something and I'll keep you posted if I find something. Cheers, Marc
 
Tx.

You'd have to be able to run PHP code as part of the conditional, and do a database lookup.

-- hugh
 
How do you modify your table?

If you know what you are doing you can try to modify the "published" column in the #_menu table via Fabrik.
E.g. with a form php plugin which will publish (or unpublish) your menu entry if a record is modified.
 
Thanks troester,

Great idea : I will create a query which will check in the "gprh_fabrik_user_training" table if records with "statut_traitement" field value = 2 exists. If Yes I publish if not I unpublish the menu.

I will run every time a new training courses and session is created (PHP Form Plugin : Backend New), each time the status of a training course and session is modified (PHP Form Plugin : Backend Edit | 1 = in process, 2 = published and 3 = unpublished).

I have already created queries which are altering the content of joomla tables, so it should be doable.

I'll keep you both posted when it is done and works. Cheers, Marc
 
Solution to whom it might interest :
I have created a list/form ("gprh_fabrik_user_training") which enable Training Manager to create training courses and to publish them in front end.

I have replicated this list/form 3 times to enable Training Managers to list / edit their contents :

1. Preparation of Training courses
2. Training courses which are added to the training catalog
3. Training courses which are removed from the training catalog

These forms contain among other a radio button field element called "Status" containing 3 Sub options ("gprh_fabrik_user_training___statut_traitement");

Values
1 | Training course is in preparation / modified -> form shouldn't be published in front end
2 | Training is added to the training catalog -> form can be published in front end
3 | Training is removed from the training catalog -> form shouldn't be published in front end

Training managers can change the status as they wish by editing one of the appropriate form.

I have created a Training enrollment form (gprh_fabrik_user_training) which is accessible in front end via a menu link and enable candidates to enroll to specific training courses. The training related information are displayed in a databasejoin | checkbox | Concat | element.

If there's no Training courses available to enroll for, I need to hide the menu link in front.

So every time a Training course is created or edited by a Training Manager, I need to check if I have got in my "gprh_fabrik_user_training" table at minimum one string which have a Status = 2, if this is the case I will display the menu link, if not I will hide it, since there's no need to publish the enrollment form with no Training courses to enroll for.

So in the following 4 of my 5 forms :

1. Training Creation Form
2. Preparation of Training courses
3. Training courses which are added to the training catalog
4. Training courses which are removed from the training catalog

I have added the PHP Plugin and parameter has followed :

Form 1. Plugin is published in front end, new, after data stored, before calculation (onBeforeCalculations)
Form 2. Plugin is published in front end, edit, after data stored, before calculation (onBeforeCalculations)
Form 3. Plugin is published in front end, edit, after data stored, before calculation (onBeforeCalculations)
Form 4. Plugin is published in front end, edit, after data stored, before calculation (onBeforeCalculations)

PHP code is for these 4 forms :

Code:
$statut = 2;
$menuid = 327;
$unpublished = 0;
$published = 1;
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
    ->select('COUNT(*)')
    ->from($db->quoteName('gprh_fabrik_user_training'))
    ->where($db->quoteName('statut_traitement')." = ".$db->quote($statut));

$db->setQuery($query);

$count = $db->loadResult();

if ($count == 0) {
$query = $db->getQuery(true);
$query = "UPDATE gprh_menu SET published = '$unpublished' WHERE id = '$menuid'";
$db->setQuery($query);
$db->execute();
} else if ($count > 0) {
$query = $db->getQuery(true);
$query = "UPDATE gprh_menu SET published = '$published' WHERE id = '$menuid'";
$db->setQuery($query);
$db->execute();
}

Special thanks to troester and Hugh
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top