Welcome, Guest
Username: Password: Remember me

TOPIC: Adding a WHERE... OR... to the database class

Adding a WHERE... OR... to the database class 28 Mar 2012 17:13 #1769

  • andypooz
  • andypooz's Avatar
  • Offline
  • New Member
  • Posts: 18
  • Thank you received: 2
  • Karma: 0
I am OK with PHP and MySQL but not got the MVC thing right yet. A few questions about editing the database class please.

1

My challenge is to add a '...WHERE ... OR ....' clause to a query (I have followed instructions on adding a WHERE by itself)

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 in advance for you guidance
Last Edit: 28 Mar 2012 17:13 by andypooz.
The administrator has disabled public write access.
Time to create page: 0.058 seconds

Get Started