Trying to solve 2 issues.

58 views
Skip to first unread message

Neo314

unread,
Dec 26, 2023, 12:21:04 AM12/26/23
to Joomla! General Development
I'm just getting back into writing for Joomla and I was not that far into it way back when, but I've worked through a lot of documentation and I am trying to get my feet wet.

My project involves users making reservations per event. My events are defined by categories, so all the 2016 event reservations are in the 2016 category, the 2017 vent reservations in the 2017 category, etc. Each reservation is tied to the user through a foreign key (user_id).

If I can get referred to some examples, that would help.

  1. In the list view, I want to pull user information for the user attached to the reservation and display it, but not edit it. I am reading some references here, but can't quite get how to how I include the data from multiple tables into one view either by including two models or by putting all the data from multiple tables into one object in one model.
  2. I have learned how to make a custom field for a component's site menu item and display that custom field in the front end. There is however, no custom firld for category. I'm trying to figure out how to make it so that, when I create a menu item for the reservation form, the menu item will have to be configured for a category of the component, and that category information will follow into the form as a hidden field. The goal is that when the reservation form is entered into the database, it is already assigned a category based on the configuration of the menu item.
Any help or referrals to existing examples would be greatly appreciated.
 

Neo314

unread,
Dec 26, 2023, 1:54:19 PM12/26/23
to Joomla! General Development
I resolved #1 by putting the values in the user state object after loading the form. I am still unclear how I can put data from two tables into the component's container.

//Get USer Information Associated with reservation
$resUserID = $this->getState('gwrequest.id');
$db = Factory::getContainer()->get('DatabaseDriver');
// Create a new query object.
$query = $db->getQuery(true);
// Select User Info based on freign key
$query->select(
$db->quoteName(['u.name', 'u.email'])
);
$query->from($db->quoteName('#__users','u'));
$query->join('LEFT', $db->quoteName('#__gwrequests','gwr'),$db->quoteName('gwr.user_id').' = '.$db->quoteName('u.id'));
$query->where($db->quoteName('gwr.id')." = ".$resUserID);
$db->setQuery($query);
$db->execute();
$result=$db->loadRow();
//Put results in user state
$app = Factory::getApplication();
$app->setUserState('resUserName',$result[0]);
$app->setUserState('resUserEmail',$result[1]);
Reply all
Reply to author
Forward
0 new messages