Code: Select all
#__component_shows_exhibitors
Code: Select all
#__component_shows_categories
Code: Select all
#__component_shows_exhibitor_categories
Now, I've manage to save the categories assigned to each exhibitor, with the following code, inside my exhibitor model (suggestions accepted):
Code: Select all
public function save($data)
{
if (!parent::save($data)) {
return false;
}
if (isset($data['categories'])) {
$exhibitor_id = $data['id'];
foreach ($data['categories'] as $category) {
$exhibitorCategories = [
'exhibitor_id' => $exhibitor_id,
'category_id' => $category,
];
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName(array('exhibitor_id', 'category_id')));
$query->from($db->quoteName('#__component_shows_exhibitor_categories'));
$conditions = array(
$db->quoteName('exhibitor_id') . "= $exhibitor_id",
$db->quoteName('category_id') . "= $category",
);
$query->where($conditions);
$db->setQuery($query);
if (!$db->loadObjectList()) {
$table = $this->getTable('ExhibitorCategories');
if (!$table->bind($exhibitorCategories))
{
$this->setError($table->getError());
return false;
}
if ($table->check($exhibitorCategories))
{
if (!$table->store()) {
$this->setError($table->getError());
return false;
}
}
else
{
$this->setError($table->getError());
return false;
}
}
}
}
return true;
}
I also have the custom field called categories (options.png attachment), which works just fine, with the following code:
Code: Select all
protected function getOptions()
{
$options = array();
// Create a new query object.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
// Select the required fields from the table.
$query->select('id as value, name as text');
$query->from('#__component_shows_categories');
$db->setQuery($query);
$options = $db->loadObjectList();
// reset($options);
// Check for a database error.
if ($db->getErrorNum()) {
JError::raiseWarning(500, $db->getErrorMsg());
}
return $options;
}
The only issue is that, after saving the assigned categories to each exhibitor, I get a blank input, instead of the values assigned (input.png). Any suggestions how can I work out that highlight?