I got this working for my project matching the user id to the added_by field (I had to call the JUser otherwise $user->id was returning NULL)
My next challenge is to add a WHERE ... OR .... clause to a query
What I have at the moment is
function _buildQueryWhere($where = array())
{
$app = JFactory::getApplication();
$db= JFactory::getDBO();
$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
$layout = JRequest::getCmd('layout', 'default');
$baseUserState = $option . '_' . $view . '.' . $layout . '.';
if (!isset($this->_active['publish']) || $this->_active['publish'] !== false) $where[] = "a.publish=1";
return parent::_buildQueryWhere($where);
}
This checks whether the category is published and then includes it. I'd like to override this with an OR. There is a field in the categories table called 'added_by' which includes the id of the user who added it. I'm used to normal SQL, but not Joomla database way of doing things. What I'd like is something that will have this effect:
...WHERE ('publish' = 1 OR 'added_by' = $userid)... or ...WHERE ('publish' = 1 || 'added_by' = $userid)...
So that it is included even if it's not published only if it is that user's own category
How can I do this? I'm fine getting the user id into a variable, but how to I add a WHERE..OR.. clause to the model above?
Many thanks
Andy