/** * Method to get a list of options for a list input. * * @return array An array of JHtml options. */ protected function _getOptions() { $db =& JFactory::getDbo(); $query = new JQuery(); $query->select('a.id AS value, a.title AS text, a.level'); $query->from('#__categories AS a'); $query->join('LEFT', '`#__categories` AS b ON a.lft > b.lft AND a.rgt < b.rgt'); // Filter by the type if ($extension = $this->_form->getValue('extension')) { $query->where('(a.extension = ' . $db->quote($extension) . ' OR a.parent_id = 0)'); } // Prevent parenting to children of this item. if ($id = $this->_form->getValue('id')) { $query->join('LEFT', '`#__categories` AS p ON p.id = ' . (int) $id); $query->where('NOT(a.lft >= p.lft AND a.rgt <= p.rgt)'); } $query->group('a.id'); $query->order('a.lft ASC'); // Get the options. $db->setQuery($query); $options = $db->loadObjectList(); // Check for a database error. if ($db->getErrorNum()) { JError::raiseWarning(500, $db->getErrorMsg()); } // Pad the option text with spaces using depth level as a multiplier. for ($i = 0, $n = count($options); $i < $n; $i++) { $options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->text; } $options = array_merge(parent::_getOptions(), $options); return $options; }
/** * Build an SQL query to load the list data. * * @return JQuery */ protected function _getListQuery() { // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.*')); $query->from('`#__usergroups` AS a'); // Add the level in the tree. $query->select('COUNT(DISTINCT c2.id) AS level'); $query->join('LEFT OUTER', '`#__usergroups` AS c2 ON a.lft > c2.lft AND a.rgt < c2.rgt'); $query->group('a.id'); // Count the objects in the user group. $query->select('COUNT(DISTINCT map.user_id) AS user_count'); $query->join('LEFT', '`#__user_usergroup_map` AS map ON map.group_id = a.id'); $query->group('a.id'); // Filter the comments over the search string if set. $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { $search = $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%'); $query->where('a.title LIKE ' . $search); } } // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.lft')) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; }
/** * Gets a list of banners * @return array An array of banner objects */ function _getListQuery() { static $query; if (!isset($query)) { $query = new JQuery(); $ordering = $this->getState('filter.ordering'); $tagSearch = $this->getState('filter.tag_search'); $cid = $this->getState('filter.client_id'); $catid = $this->getState('filter.category_id'); $keywords = $this->getState('filter.keywords'); $randomise = $ordering == 'random'; $query->select('a.id as id,' . 'a.type as type,' . 'a.name as name,' . 'a.clickurl as clickurl,' . 'a.cid as cid,' . 'a.params as params,' . 'a.track_impressions as track_impressions'); $query->from('#__banners as a'); $query->where('a.state=1'); $query->where("(NOW() >= a.publish_up OR a.publish_up='0000-00-00 00:00:00')"); $query->where("(NOW() <= a.publish_down OR a.publish_down='0000-00-00 00:00:00')"); $query->where('(a.imptotal = 0 OR a.impmade = a.imptotal)'); if ($cid) { $query->where('a.cid = ' . (int) $cid); $query->join('LEFT', '#__banner_clients AS cl ON cl.id = a.cid'); $query->select('cl.track_impressions as client_track_impressions'); $query->where('cl.state = 1'); } if ($catid) { $query->where('a.catid = ' . (int) $catid); $query->join('LEFT', '#__categories AS cat ON cat.id = a.catid'); $query->where('cat.published = 1'); } if ($tagSearch) { if (count($keywords) == 0) { $query->where('0'); } else { $temp = array(); $config =& JComponentHelper::getParams('com_banners'); $prefix = $config->get('metakey_prefix'); foreach ($keywords as $keyword) { $keyword = trim($keyword); $condition1 = "a.own_prefix=1 AND a.metakey_prefix=SUBSTRING('" . $keyword . "',1,LENGTH( a.metakey_prefix)) OR a.own_prefix=0 AND cl.own_prefix=1 AND cl.metakey_prefix=SUBSTRING('" . $keyword . "',1,LENGTH(cl.metakey_prefix)) OR a.own_prefix=0 AND cl.own_prefix=0 AND " . ($prefix == substr($keyword, 0, strlen($prefix)) ? '1' : '0'); $condition2 = "a.metakey REGEXP '[[:<:]]" . $this->_db->getEscaped($keyword) . "[[:>:]]'"; if ($cid) { $condition2 .= " OR cl.metakey REGEXP '[[:<:]]" . $this->_db->getEscaped($keyword) . "[[:>:]]'"; } if ($catid) { $condition2 .= " OR cat.metakey REGEXP '[[:<:]]" . $this->_db->getEscaped($keyword) . "[[:>:]]'"; } $temp[] = "({$condition1}) AND ({$condition2})"; } $query->where('(' . implode(' OR ', $temp) . ')'); } } $query->order('a.sticky DESC,' . ($randomise ? 'RAND()' : 'a.ordering')); } return $query; }
/** * @param boolean True to join selected foreign information * * @return string */ function _getListQuery($resolveFKs = true) { // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.id, a.name, a.alias, a.checked_out, a.checked_out_time, a.published, a.access, a.ordering, a.catid')); $query->from('#__contact_details AS a'); // Join over the users for the checked out user. $query->select('uc.name AS editor'); $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out'); // Join over the asset groups. $query->select('ag.title AS access_level'); $query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); // Join over the categories. $query->select('c.title AS category_title'); $query->join('LEFT', '#__categories AS c ON c.id = a.catid'); // Filter by access level. if ($access = $this->getState('filter.access')) { $query->where('a.access = ' . (int) $access); } // Filter by published state $published = $this->getState('filter.published'); if (is_numeric($published)) { $query->where('a.published = ' . (int) $published); } else { if ($published === '') { $query->where('(a.published = 0 OR a.published = 1)'); } } // Filter by category. $categoryId = $this->getState('filter.category_id'); if (is_numeric($categoryId)) { $query->where('a.catid = ' . (int) $categoryId); } // Filter by search in name $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { if (stripos($search, 'author:') === 0) { $search = $this->_db->Quote('%' . $this->_db->getEscaped(substr($search, 7), true) . '%'); $query->where('ua.name LIKE ' . $search . ' OR ua.username LIKE ' . $search); } else { $search = $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%'); $query->where('a.name LIKE ' . $search . ' OR a.alias LIKE ' . $search); } } } // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.name')) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; }
/** * Build an SQL query to load the list data. * * @return JQuery */ protected function _getListQuery() { // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.*')); $query->from('`#__users` AS a'); // Join over the group mapping table. $query->select('COUNT(map.group_id) AS group_count'); $query->join('LEFT', '#__user_usergroup_map AS map ON map.user_id = a.id'); $query->group('a.id'); // Join over the user groups table. $query->select('GROUP_CONCAT(g2.title SEPARATOR ' . $this->_db->Quote("\n") . ') AS group_names'); $query->join('LEFT', '#__usergroups AS g2 ON g2.id = map.group_id'); // If the model is set to check item state, add to the query. $state = $this->getState('filter.state'); if (is_numeric($state)) { $query->where('a.block = ' . (int) $state); } // If the model is set to check the activated state, add to the query. $active = $this->getState('filter.active'); if (is_numeric($active)) { if ($active == '0') { $query->where('a.activation = ""'); } else { if ($active == '1') { $query->where('LENGTH(a.activation) = 32'); } } } // Filter the items over the group id if set. if ($groupId = $this->getState('filter.group_id')) { $query->join('LEFT', '#__user_usergroup_map AS map2 ON map2.user_id = a.id'); $query->where('map2.group_id = ' . (int) $groupId); } // Filter the items over the search string if set. if ($this->getState('filter.search') !== '') { // Escape the search token. $token = $this->_db->Quote('%' . $this->_db->getEscaped($this->getState('filter.search')) . '%'); // Compile the different search clauses. $searches = array(); $searches[] = 'a.name LIKE ' . $token; $searches[] = 'a.username LIKE ' . $token; $searches[] = 'a.email LIKE ' . $token; // Add the clauses to the query. $query->where('(' . implode(' OR ', $searches) . ')'); } // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.name')) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; }
/** * Build an SQL query to load the list data. * * @return JQuery */ protected function _getListQuery() { // Get the application object $app =& JFactory::getApplication(); require_once JPATH_COMPONENT . '/helpers/banners.php'; // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select('a.track_date as track_date,' . 'a.track_type as track_type,' . 'a.`count` as `count`'); $query->from('`#__banner_tracks` AS a'); // Join with the banners $query->join('LEFT', '`#__banners` as b ON b.id=a.banner_id'); $query->select('b.name as name'); // Join with the client $query->join('LEFT', '`#__banner_clients` as cl ON cl.id=b.cid'); $query->select('cl.name as client_name'); // Join with the category $query->join('LEFT', '`#__categories` as cat ON cat.id=b.catid'); $query->select('cat.title as category_title'); // Filter by type $type = $this->getState('filter.type'); if (!empty($type)) { $query->where('a.track_type = ' . (int) $type); } // Filter by client $clientId = $this->getState('filter.client_id'); if (is_numeric($clientId)) { $query->where('b.cid = ' . (int) $clientId); } // Filter by category $catedoryId = $this->getState('filter.category_id'); if (is_numeric($catedoryId)) { $query->where('b.catid = ' . (int) $catedoryId); } // Filter by begin date $begin = $this->getState('filter.begin'); if (!empty($begin)) { $query->where('a.track_date >= ' . $this->_db->Quote($begin)); } // Filter by end date $end = $this->getState('filter.end'); if (!empty($end)) { $query->where('a.track_date <= ' . $this->_db->Quote($end)); } // Add the list ordering clause. $orderCol = $this->getState('list.ordering', 'name'); $query->order($this->_db->getEscaped($orderCol) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); return $query; }
function fetchElement($name, $value, &$node, $control_name) { $access = JFactory::getACL(); // Include user in groups that have access to edit their articles, other articles, or manage content. $action = array('com_content.article.edit_own', 'com_content.article.edit_article', 'com_content.manage'); $groups = $access->getAuthorisedUsergroups($action, true); // Check the results of the access check. if (!$groups) { return false; } // Clean up and serialize. JArrayHelper::toInteger($groups); $groups = implode(',', $groups); // Build the query to get the users. $query = new JQuery(); $query->select('u.id AS value'); $query->select('u.name AS text'); $query->from('#__users AS u'); $query->join('INNER', '#__user_usergroup_map AS m ON m.user_id = u.id'); $query->where('u.block = 0'); $query->where('m.group_id IN (' . $groups . ')'); // Get the users. $db = JFactory::getDbo(); $db->setQuery((string) $query); $users = $db->loadObjectList(); // Check for a database error. if ($db->getErrorNum()) { JError::raiseNotice(500, $db->getErrorMsg()); return false; } return JHtml::_('select.genericlist', $users, $name, 'class="inputbox" size="1"', 'value', 'text', $value); }
/** * Method to build an SQL query to load the list data. * * @return string An SQL query * @since 1.6 */ protected function _getListQuery() { $user =& JFactory::getUser(); $groups = implode(',', $user->authorisedLevels()); // Create a new query object. $query = new JQuery(); // Select required fields from the categories. $query->select($this->getState('list.select', 'a.*')); $query->from('`#__weblinks` AS a'); $query->where('a.access IN (' . $groups . ')'); // Filter by category. if ($categoryId = $this->getState('category.id')) { $query->where('a.catid = ' . (int) $categoryId); $query->join('LEFT', '#__categories AS c ON c.id = a.catid'); $query->where('c.access IN (' . $groups . ')'); } // Filter by state $state = $this->getState('filter.state'); if (is_numeric($state)) { $query->where('a.state = ' . (int) $state); } // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.ordering')) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); return $query; }
/** * Build an SQL query to load the list data. * * @return JQuery */ protected function _getListQuery() { // Create a new query object. $query = new JQuery(); $user = JFactory::getUser(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.*, ' . 'u.name AS user_from')); $query->from('#__messages AS a'); // Join over the users for message owner. $query->join('INNER', '#__users AS u ON u.id = a.user_id_from'); $query->where('a.user_id_to = ' . (int) $user->get('id')); // Filter by published state. $state = $this->getState('filter.state'); if (is_numeric($state)) { $query->where('a.state = ' . (int) $state); } else { if ($state === '') { $query->where('(a.state IN (0, 1))'); } } // Filter by search in subject or message. $search = $this->getState('filter.search'); if (!empty($search)) { $search = $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%', false); $query->where('a.subject LIKE ' . $search . ' OR a.message LIKE ' . $search . ')'); } // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.date_time')) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'DESC'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; }
/** * Method to build an SQL query to load the list data. * * @return string An SQL query */ protected function _getListQuery() { // Create a new query object. $query = new JQuery(); // Select all fields from the table. $query->select($this->getState('list.select', 'a.*')); $query->from('`#__menu_types` AS a'); // Self join to find the number of published menu items in the menu. $query->select('COUNT(DISTINCT m1.id) AS count_published'); $query->join('LEFT', '`#__menu` AS m1 ON m1.menutype = a.menutype AND m1.published = 1'); // Self join to find the number of unpublished menu items in the menu. $query->select('COUNT(DISTINCT m2.id) AS count_unpublished'); $query->join('LEFT', '`#__menu` AS m2 ON m2.menutype = a.menutype AND m2.published = 0'); // Self join to find the number of trashed menu items in the menu. $query->select('COUNT(DISTINCT m3.id) AS count_trashed'); $query->join('LEFT', '`#__menu` AS m3 ON m3.menutype = a.menutype AND m3.published = -2'); $query->group('a.id'); // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.id')) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query->toString())).'<hr/>'; return $query; }
/** * Build an SQL query to load the list data. * * @return JQuery */ protected function _getListQuery() { // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.id AS id,' . 'a.name AS name,' . 'a.contact AS contact,' . 'a.checked_out AS checked_out,' . 'a.checked_out_time AS checked_out_time, ' . 'a.state AS state,' . 'a.metakey AS metakey,' . 'a.purchase_type as purchase_type')); $query->from('`#__banner_clients` AS a'); // Join over the banners for counting $query->select('COUNT(b.id) as nbanners'); $query->join('LEFT', '#__banners AS b ON a.id = b.cid'); // Join over the users for the checked out user. $query->select('uc.name AS editor'); $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out'); // Filter by published state $published = $this->getState('filter.state'); if (is_numeric($published)) { $query->where('a.state = ' . (int) $published); } else { if ($published === '') { $query->where('(a.state IN (0, 1))'); } } $query->group('a.id'); // Filter by search in title $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { $search = $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%'); $query->where('a.name LIKE ' . $search); } } // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'ordering')) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; }
/** * Build an SQL query to load the list data. * * @return JQuery */ protected function _getListQuery() { // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.extension_id, a.name, a.element, a.folder, a.checked_out, a.checked_out_time,' . ' a.enabled, a.access, a.ordering')); $query->from('`#__extensions` AS a'); $query->where('`type` = ' . $this->_db->quote('plugin')); // Join over the users for the checked out user. $query->select('uc.name AS editor'); $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out'); // Join over the asset groups. $query->select('ag.title AS access_level'); $query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); // Filter by access level. if ($access = $this->getState('filter.access')) { $query->where('a.access = ' . (int) $access); } // Filter by published state $published = $this->getState('filter.state'); if (is_numeric($published)) { $query->where('a.enabled = ' . (int) $published); } else { if ($published === '') { $query->where('(a.enabled IN (0, 1))'); } } // Filter by folder. if ($folder = $this->getState('filter.folder')) { $query->where('a.folder = ' . $this->_db->quote($folder)); } // Filter by search in title $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { $search = $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%'); $query->where('a.name LIKE ' . $search); } } // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.name')) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; }
/** * Build an SQL query to load the list data. * * @return JQuery */ protected function _getListQuery() { // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.*')); $query->from('`#__social_comments` AS a'); // Resolve foriegn keys. $query->select('b.page_route, b.page_url, b.page_title'); $query->join('LEFT', '`#__social_threads` AS b ON b.id=a.thread_id'); // Filter by published state. $published = $this->getState('filter.state'); if (is_numeric($published)) { $query->where('a.published = ' . (int) $published); } else { if ($published === '') { $query->where('(a.published IN (0, 1))'); } } // Filter the items over the thread id if set. $thread_id = $this->getState('filter.thread_id'); if ($thread_id !== null && $thread_id > 0) { $query->where('a.thread_id = ' . (int) $thread_id); } // Filter the items over the context if set. $context = $this->getState('filter.context'); if (!empty($context)) { $query->where('b.context = ' . $this->_db->Quote($context)); } // Filter over the search string if set. $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { $search = $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%'); $query->where('a.name LIKE ' . $search); } } // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering') . ' ' . $this->getState('list.direction'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; }
/** * Builds the query to select contact items * @param array * @return string * @access protected */ function _getContactQuery($pk = null) { // TODO: Cache on the fingerprint of the arguments $db =& JFactory::getDbo(); $user =& JFactory::getUser(); $pk = !empty($pk) ? $pk : (int) $this->getState('contact.id'); $query = new JQuery(); if ($pk) { $query->select('a.*, cc.access as category_access, cc.title as category_name, ' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug, ' . ' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(\':\', cc.id, cc.alias) ELSE cc.id END AS catslug '); $query->from('#__contact_details AS a'); $query->join('INNER', '#__categories AS cc on cc.id = a.catid'); $query->where('a.id = ' . (int) $pk); $query->where('a.published = 1'); $query->where('cc.published = 1'); $groups = implode(',', $user->authorisedLevels()); $query->where('a.access IN (' . implode(',', $user->authorisedLevels()) . ')'); } return $query; }
/** * Get a list of the most popular articles * * @param JObject The module parameters. * * @return array */ public static function getList($params) { jimport('joomla.database.query'); $db = JFactory::getDbo(); $limit = $params->get('limit', 10); $result = null; $query = new JQuery(); $query->select('a.hits, a.id, a.sectionid, a.title, a.created, u.name'); $query->from('#__content AS a'); $query->join('LEFT', '#__users AS u ON u.id=a.created_by'); $query->where('a.state <> -2'); $query->order('hits'); $db->setQuery($query, 0, $limit); $rows = $db->loadObjectList(); if ($error = $db->getErrorMsg()) { JError::raiseWarning(500, $error); return false; } return $rows; }
/** * Get a list of the menu items. */ static function getList(&$params) { // Initialise variables. $list = array(); $db = JFactory::getDbo(); $user = JFactory::getUser(); $menu = JSite::getMenu(); // If no active menu, use default $active = $menu->getActive() ? $menu->getActive() : $menu->getDefault(); $rlu = array(); $start = (int) $params->get('startLevel'); $end = (int) $params->get('endLevel'); $showAll = $params->get('showAllChildren'); // Deal with start level. if ($start) { // Need a second query to backtrace. $query = new JQuery(); $query->select('m.id'); $query->from('#__menu AS m'); $query->join('LEFT', '#__menu AS p ON p.id = ' . (int) $active->id); $query->where('m.level = ' . $start); $query->where('m.lft <= p.lft'); $query->where('m.rgt >= p.rgt'); $db->setQuery($query); $startId = $db->loadResult(); // Check for a database error. if ($db->getErrorNum()) { JError::raiseWarning($db->getErrorMsg()); return $list; } if (empty($startId)) { return $list; } } // Get the menu items as a tree. $query = new JQuery(); $query->select('n.id, n.parent_id, n.title, n.alias, n.path, n.level, n.link, n.type, n.browserNav, n.params, n.home'); $query->from('#__menu AS n'); // Deal with start level. if ($start) { $query->join('INNER', '#__menu AS p ON p.id = ' . (int) $startId); } else { $query->join('INNER', '#__menu AS p ON p.lft = 0'); } // Deal with end level. if ($end) { $query->where('n.level <= ' . $end); } $query->where('n.lft > p.lft'); $query->where('n.lft < p.rgt'); $query->order('n.lft'); // Filter over the appropriate menu. $query->where('n.menutype = ' . $db->quote($params->get('menutype', 'mainmenu'))); // Filter over authorized access levels and publishing state. $query->where('n.published = 1'); $query->where('n.access IN (' . implode(',', (array) $user->authorisedLevels()) . ')'); // Get the list of menu items. $db->setQuery($query); $list = $db->loadObjectList(); // Check for a database error. if ($db->getErrorNum()) { JError::raiseWarning($db->getErrorMsg()); return array(); } // Set some values to make nested HTML rendering easier. foreach ($list as $i => &$item) { $rlu[$item->id] = $i; // Compute tree step information. $item->deeper = isset($list[$i + 1]) && $item->level < $list[$i + 1]->level; $item->shallower = isset($list[$i + 1]) && $item->level > $list[$i + 1]->level; $item->level_diff = isset($list[$i + 1]) ? $item->level - $list[$i + 1]->level : 0; $item->active = false; $item->params = new JObject(json_decode($item->params)); switch ($item->type) { case 'separator': // No further action needed. continue; case 'url': if (strpos($item->link, 'index.php?') === 0 && strpos($item->link, 'Itemid=') === false) { // If this is an internal Joomla link, ensure the Itemid is set. $item->link = $tmp->link . '&Itemid=' . $item->id; } break; case 'alias': // If this is an alias use the item id stored in the parameters to make the link. $item->link = 'index.php?Itemid=' . $item->params->aliasoptions; break; default: $router = JSite::getRouter(); if ($router->getMode() == JROUTER_MODE_SEF) { $item->link = 'index.php?Itemid=' . $item->id; } else { $item->link .= '&Itemid=' . $item->id; } break; } if ($item->home == 1) { // Correct the URL for the home page. $item->link = JURI::base(); } elseif (strcasecmp(substr($item->link, 0, 4), 'http') && strpos($item->link, 'index.php?') !== false) { // This is an internal Joomla web site link. $item->link = JRoute::_($item->link, true, $item->params->get('secure')); } else { // Correct the & in the link. $item->link = str_replace('&', '&', $item->link); } } // Set the active state of items from active to the tree root. $itemId = $active->id; $runaway = count($list); while ($itemId && $runaway--) { if (@$list[$rlu[$itemId]]) { $list[$rlu[$itemId]]->active = true; $itemId = $list[$rlu[$itemId]]->parent_id; } else { $itemId = 0; } } return $list; }
/** * Build an SQL query to load the list data. * * @return JQuery */ protected function _getListQuery() { // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.id, a.title, a.position, a.module, ' . 'a.checked_out, a.checked_out_time, a.published, a.access, a.ordering, a.language')); $query->from('`#__modules` AS a'); // Join over the users for the checked out user. $query->select('uc.name AS editor'); $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out'); // Join over the asset groups. $query->select('ag.title AS access_level'); $query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); // Join over the module menus $query->select('MIN(mm.menuid) AS pages'); $query->join('LEFT', '#__modules_menu AS mm ON mm.moduleid = a.id'); $query->group('a.id'); // Filter by access level. if ($access = $this->getState('filter.access')) { $query->where('a.access = ' . (int) $access); } // Filter by published state $state = $this->getState('filter.state'); if (is_numeric($state)) { $query->where('a.published = ' . (int) $state); } else { if ($state === '') { $query->where('(a.published IN (0, 1))'); } } // Filter by position $position = $this->getState('filter.position'); if ($position) { $query->where('a.position = ' . $this->_db->Quote($position)); } // Filter by module $module = $this->getState('filter.module'); if ($module) { $query->where('a.module = ' . $this->_db->Quote($module)); } // Filter by client. $clientId = $this->getState('filter.client_id'); if (is_numeric($clientId)) { $query->where('a.client_id = ' . (int) $clientId); } // Filter by search in title $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { $search = $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%'); $query->where('a.title LIKE ' . $search); } } // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.ordering')) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; }
/** * @param boolean True to join selected foreign information * * @return string */ function _getListQuery() { // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.id, a.title, a.alias, a.title_alias, a.introtext, a.state, a.catid, a.created, a.created_by, a.created_by_alias,' . ' a.modified, a.modified_by,a.publish_up, a.publish_down, a.attribs, a.metadata, a.metakey, a.metadesc, a.access,' . ' a.hits,' . ' LENGTH(a.fulltext) AS readmore')); $query->from('#__content AS a'); // Join over the categories. $query->select('c.title AS category_title, c.path AS category_route, c.access AS category_access, c.alias AS category_alias'); $query->join('LEFT', '#__categories AS c ON c.id = a.catid'); // Join over the users for the author. $query->select("CASE WHEN a.created_by_alias > ' ' THEN a.created_by_alias ELSE ua.name END AS author_name"); $query->join('LEFT', '#__users AS ua ON ua.id = a.created_by'); // Filter by access level. if ($access = $this->getState('filter.access')) { $user =& JFactory::getUser(); $groups = implode(',', $user->authorisedLevels()); $query->where('a.access IN (' . $groups . ')'); } // Filter by published state $published = $this->getState('filter.published'); if (is_numeric($published)) { $query->where('a.state = ' . (int) $published); } else { if (is_array($published)) { JArrayHelper::toInteger($published); $published = implode(',', $published); $query->where('a.state IN (' . $published . ')'); } } // Filter by a single or group of categories. $categoryId = $this->getState('filter.category_id'); if (is_numeric($categoryId)) { $type = $this->getState('filter.category_id.include', true) ? '= ' : '<>'; $query->where('a.catid ' . $type . (int) $categoryId); } else { if (is_array($categoryId)) { JArrayHelper::toInteger($categoryId); $categoryId = implode(',', $categoryId); $type = $this->getState('filter.category_id.include', true) ? 'IN' : 'NOT IN'; $query->where('a.catid ' . $type . ' (' . $categoryId . ')'); } } $authorId = $this->getState('filter.author_id'); if (is_numeric($authorId)) { $type = $this->getState('filter.author_id.include', true) ? '= ' : '<>'; $query->where('a.created_by ' . $type . (int) $authorId); } else { if (is_array($authorId)) { JArrayHelper::toInteger($authorId); $authorId = implode(',', $authorId); $type = $this->getState('filter.author_id.include', true) ? 'IN' : 'NOT IN'; $query->where('a.created ' . $type . ' (' . $authorId . ')'); } } // Filter by start and end dates. $nullDate = $this->_db->Quote($this->_db->getNullDate()); $nowDate = $this->_db->Quote(JFactory::getDate()->toMySQL()); $query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')'); $query->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')'); // process the filter for list views with user-entered filters $params = $this->getState('params'); if (is_object($params) && $params->get('filter_field') != 'hide' && ($filter = $this->getState('list.filter'))) { // clean filter variable $filter = JString::strtolower($filter); $hitsFilter = intval($filter); $filter = $this->_db->Quote('%' . $this->_db->getEscaped($filter, true) . '%', false); switch ($params->get('filter_field')) { case 'author': $query->where('LOWER( CASE WHEN a.created_by_alias > " " THEN a.created_by_alias ELSE ua.name END ) LIKE ' . $filter . ' '); break; case 'hits': $query->where('a.hits >= ' . $hitsFilter . ' '); break; case 'title': default: // default to 'title' if parameter is not valid $query->where('LOWER( a.title ) LIKE ' . $filter); break; } } // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.ordering'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; }
/** * Build an SQL query to load the list data. * * @return JQuery */ protected function _getListQuery() { // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid,' . ' a.state, a.access, a.created, a.hits, a.ordering, a.featured')); $query->from('#__content AS a'); // Join over the users for the checked out user. $query->select('uc.name AS editor'); $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out'); // Join over the asset groups. $query->select('ag.title AS access_level'); $query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); // Join over the categories. $query->select('c.title AS category_title'); $query->join('LEFT', '#__categories AS c ON c.id = a.catid'); // Join over the users for the author. $query->select('ua.name AS author_name'); $query->join('LEFT', '#__users AS ua ON ua.id = a.created_by'); // Filter by access level. if ($access = $this->getState('filter.access')) { $query->where('a.access = ' . (int) $access); } // Filter by published state $published = $this->getState('filter.published'); if (is_numeric($published)) { $query->where('a.state = ' . (int) $published); } else { if ($published === '') { $query->where('(a.state = 0 OR a.state = 1)'); } } // Filter by a single or group of categories. $categoryId = $this->getState('filter.category_id'); if (is_numeric($categoryId)) { $query->where('a.catid = ' . (int) $categoryId); } else { if (is_array($categoryId)) { JArrayHelper::toInteger($categoryId); $categoryId = implode(',', $categoryId); $query->where('a.catid IN (' . $categoryId . ')'); } } // Filter by author $authorId = $this->getState('filter.author_id'); if (is_numeric($authorId)) { $type = $this->getState('filter.author_id.include', true) ? '= ' : '<>'; $query->where('a.created_by ' . $type . (int) $authorId); } // Filter by search in title $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { if (stripos($search, 'author:') === 0) { $search = $this->_db->Quote('%' . $this->_db->getEscaped(substr($search, 7), true) . '%'); $query->where('ua.name LIKE ' . $search . ' OR ua.username LIKE ' . $search); } else { $search = $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%'); $query->where('a.title LIKE ' . $search . ' OR a.alias LIKE ' . $search); } } } // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.title')) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; }
/** * Get the data for a banner */ function &getItem() { if (!isset($this->_item)) { $id = $this->getState('banner.id'); // redirect to banner url $query = new JQuery(); $query->select('a.clickurl as clickurl,' . 'a.cid as cid,' . 'a.track_clicks as track_clicks'); $query->from('#__banners as a'); $query->where('a.id = ' . (int) $id); $query->join('LEFT', '#__banner_clients AS cl ON cl.id = a.cid'); $query->select('cl.track_clicks as client_track_clicks'); $this->_db->setQuery((string) $query); if (!$this->_db->query()) { JError::raiseError(500, $this->_db->getErrorMsg()); } $this->_item = $this->_db->loadObject(); } return $this->_item; }
/** * Get a list of menu links for one or all menus. * * @param string An option menu to filter the list on, otherwise all menu links are returned as a grouped array. * @param int An optional parent ID to pivot results around. * @param int An optional mode. If parent ID is set and mode=2, the parent and children are excluded from the list. * @param array An optional array of states */ public static function getMenuLinks($menuType = null, $parentId = 0, $mode = 0, $published = array()) { $db = JFactory::getDbo(); $query = new JQuery(); $query->select('a.id AS value, a.title AS text, a.level, a.menutype, a.type'); $query->from('#__menu AS a'); $query->join('LEFT', '`#__menu` AS b ON a.lft > b.lft AND a.rgt < b.rgt'); // Filter by the type if ($menuType) { $query->where('(a.menutype = ' . $db->quote($menuType) . ' OR a.parent_id = 0)'); } if ($parentId) { if ($mode == 2) { // Prevent the parent and children from showing. $query->join('LEFT', '`#__menu` AS p ON p.id = ' . (int) $parentId); $query->where('(a.lft <= p.lft OR a.rgt >= p.rgt)'); } } if (!empty($published)) { if (is_array($published)) { $published = '(' . implode(',', $published) . ')'; } $query->where('a.published IN ' . $published); } $query->group('a.id'); $query->order('a.lft ASC'); // Get the options. $db->setQuery($query); $links = $db->loadObjectList(); // Check for a database error. if ($error = $db->getErrorMsg()) { JError::raiseWarning(500, $error); return false; } // Pad the option text with spaces using depth level as a multiplier. foreach ($links as &$link) { $link->text = str_repeat('- ', $link->level) . $link->text; } if (empty($menuType)) { // If the menutype is empty, group the items by menutype. $query = new JQuery(); $query->select('*'); $query->from('#__menu_types'); $query->where('menutype <> ' . $db->quote('')); $query->order('title, menutype'); $db->setQuery($query); $menuTypes = $db->loadObjectList(); // Check for a database error. if ($error = $db->getErrorMsg()) { JError::raiseWarning(500, $error); return false; } // Create a reverse lookup and aggregate the links. $rlu = array(); foreach ($menuTypes as &$type) { $rlu[$type->menutype] =& $type; $type->links = array(); } // Loop through the list of menu links. foreach ($links as &$link) { if (isset($rlu[$link->menutype])) { $rlu[$link->menutype]->links[] =& $link; // Cleanup garbage. unset($link->menutype); } } return $menuTypes; } else { return $links; } }
/** * Method to get article data. * * @param integer The id of the article. * * @return mixed Menu item data object on success, false on failure. */ public function &getItem($pk = null) { // Initialise variables. $pk = !empty($pk) ? $pk : (int) $this->getState('article.id'); if ($this->_item === null) { $this->_item = array(); } if (!isset($this->_item[$pk])) { try { $query = new JQuery(); $query->select($this->getState('item.select', 'a.*')); $query->from('#__content AS a'); // Join on category table. $query->select('c.title AS category_title, c.alias AS category_alias, c.access AS category_access'); $query->join('LEFT', '#__categories AS c on c.id = a.catid'); // Join on user table. $query->select('u.name AS author'); $query->join('LEFT', '#__users AS u on u.id = a.created_by'); $query->where('a.id = ' . (int) $pk); // Filter by published state. $published = $this->getState('filter.published'); $archived = $this->getState('filter.archived'); if (is_numeric($published)) { $query->where('(a.state = ' . (int) $published . ' OR a.state =' . (int) $archived . ')'); } // Filter by access level. if ($access = $this->getState('filter.access')) { $user =& JFactory::getUser(); $groups = implode(',', $user->authorisedLevels()); $query->where('a.access IN (' . $groups . ')'); $query->where('(c.access IS NULL OR c.access IN (' . $groups . '))'); } $this->_db->setQuery($query); $data = $this->_db->loadObject(); if ($error = $this->_db->getErrorMsg()) { throw new Exception($error); } if (empty($data)) { throw new Exception(JText::_('Content_Error_Article_not_found'), 404); } // Check for published state if filter set. if ((is_numeric($published) || is_numeric($archived)) && ($data->state != $published && $data->state != $archived)) { throw new Exception(JText::_('Content_Error_Article_not_found'), 404); } // Convert parameter fields to objects. $registry = new JRegistry(); $registry->loadJSON($data->attribs); $data->params = clone $this->getState('params'); $data->params->merge($registry); $registry = new JRegistry(); $registry->loadJSON($data->metadata); $data->metadata = $registry; // Compute access permissions. if ($access) { // If the access filter has been set, we already know this user can view. $data->params->set('access-view', true); } else { // If no access filter is set, the layout takes some responsibility for display of limited information. $user =& JFactory::getUser(); $groups = $user->authorisedLevels(); if ($data->catid == 0 || $data->category_access === null) { $data->params->set('access-view', in_array($data->access, $groups)); } else { $data->params->set('access-view', in_array($data->access, $groups) && in_array($data->category_access, $groups)); } } // TODO: Type 2 permission checks? $this->_item[$pk] = $data; } catch (Exception $e) { $this->setError($e); $this->_item[$pk] = false; } } return $this->_item[$pk]; }
/** * Method to return a list of user Ids contained in a Group * * @param int The group Id * @param boolean Recursively include all child groups (optional) * * @return array * @todo This method should move somewhere else. */ public function getUsersByGroup($groupId, $recursive = false) { // Get a database object. $db =& JFactory::getDbo(); $test = $recursive ? '>=' : '='; // First find the users contained in the group $query = new JQuery(); $query->select('DISTINCT(user_id)'); $query->from('#__usergroups as ug1'); $query->join('INNER', '#__usergroups AS ug2 ON ug2.lft' . $test . 'ug1.lft AND ug1.rgt' . $test . 'ug2.rgt'); $query->join('INNER', '#__user_usergroup_map AS m ON ug2.id=m.group_id'); $query->where('ug1.id=' . $db->Quote($groupId)); $db->setQuery($query); $result = $db->loadResultArray(); // Clean up any NULL values, just in case JArrayHelper::toInteger($result); return $result; }
/** * Builds an SQL query to load the list data. * * @return JQuery A query object. */ protected function _getListQuery() { // Create a new query object. $query = new JQuery(); // Select all fields from the table. $query->select($this->getState('list.select', 'a.*')); $query->from('`#__menu` AS a'); // Join over the users. $query->select('u.name AS editor'); $query->join('LEFT', '`#__users` AS u ON u.id = a.checked_out'); //Join over components $query->select('c.name AS componentname'); $query->join('LEFT', '`#__extensions` AS c ON c.extension_id = a.component_id'); // Join over the asset groups. $query->select('ag.title AS access_level'); $query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); // Exclude the root category. $query->where('a.id > 1'); // Filter on the published state. $published = $this->getState('filter.published'); if (is_numeric($published)) { $query->where('a.published = ' . (int) $published); } else { if ($published === '') { $query->where('(a.published IN (0, 1))'); } } // Filter by search in title, alias or id if ($search = trim($this->getState('filter.search'))) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { if (stripos($search, 'link:') === 0) { if ($search = substr($search, 5)) { $search = $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%'); $query->where('a.link LIKE ' . $search); } } else { $search = $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%'); $query->where('a.title LIKE ' . $search . ' OR a.alias LIKE ' . $search); } } } // Filter the items over the parent id if set. $parentId = $this->getState('filter.parent_id'); if (!empty($parentId)) { $query->where('p.id = ' . (int) $parentId); } // Filter the items over the menu id if set. $menuId = $this->getState('filter.menu_id'); if (!empty($menuId)) { $query->where('a.menu_id = ' . (int) $menuId); } // Filter the items over the menu id if set. $menuType = $this->getState('filter.menutype'); if (!empty($menuType)) { $query->where('a.menutype = ' . $this->_db->quote($menuType)); } // Filter on the access level. if ($access = $this->getState('filter.access')) { $query->where('a.access = ' . (int) $access); } // Filter on the level. if ($level = $this->getState('filter.level')) { $query->where('a.level <= ' . (int) $level); } // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.lft')) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query->toString())).'<hr/>'; return $query; }
/** * Get the list of modules not in trash. * * @return mixed An array of module records (id, title, position), or false on error. */ public function getModules() { $query = new JQuery(); $query->select('a.id, a.title, a.position, a.published'); $query->from('#__modules AS a'); // Join on the module-to-menu mapping table. // We are only interested if the module is displayed on ALL or THIS menu item (or the inverse ID number). $query->select('map.menuid'); $query->join('LEFT', '#__modules_menu AS map ON map.moduleid = a.id AND (map.menuid = 0 OR ABS(map.menuid) = ' . (int) $this->getState('item.id') . ')'); // Join on the asset groups table. $query->select('ag.title AS access_title'); $query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); $query->where('a.published >= 0'); $query->where('a.client_id = 0'); $query->order('a.position, a.ordering'); $this->_db->setQuery($query); $result = $this->_db->loadObjectList(); if ($error = $this->_db->getError()) { $this->setError($error); return false; } return $result; }
/** * Build an SQL query to load the list data. * * @return JQuery */ protected function _getListQuery() { // Get the application object $app =& JFactory::getApplication(); // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.id AS id, a.name AS name, a.alias AS alias,' . 'a.checked_out AS checked_out,' . 'a.checked_out_time AS checked_out_time, a.catid AS catid,' . 'a.clicks AS clicks, a.metakey AS metakey, a.sticky AS sticky,' . 'a.impmade AS impmade, a.imptotal AS imptotal,' . 'a.state AS state, a.ordering AS ordering,' . 'a.purchase_type as purchase_type')); $query->from('`#__banners` AS a'); // Join over the users for the checked out user. $query->select('uc.name AS editor'); $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out'); // Join over the categories. $query->select('c.title AS category_title'); $query->join('LEFT', '#__categories AS c ON c.id = a.catid'); // Join over the clients. $query->select('cl.name AS client_name,cl.purchase_type as client_purchase_type'); $query->join('LEFT', '#__banner_clients AS cl ON cl.id = a.cid'); // Filter by published state $published = $this->getState('filter.state'); if (is_numeric($published)) { $query->where('a.state = ' . (int) $published); } else { if ($published === '') { $query->where('(a.state IN (0, 1))'); } } // Filter by category. $categoryId = $this->getState('filter.category_id'); if (is_numeric($categoryId)) { $query->where('a.catid = ' . (int) $categoryId); } // Filter by client. $clientId = $this->getState('filter.client_id'); if (is_numeric($clientId)) { $query->where('a.cid = ' . (int) $clientId); } // Filter by search in title $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { $search = $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%'); $query->where('(a.name LIKE ' . $search . ' OR a.alias LIKE ' . $search . ')'); } } // Add the list ordering clause. $orderCol = $this->getState('list.ordering', 'ordering'); $app->setUserState($this->_context . '.' . $orderCol . '.orderdirn', $this->getState('list.direction', 'ASC')); if ($orderCol == 'ordering') { $query->order($this->_db->getEscaped('category_title') . ' ' . $this->_db->getEscaped($app->getUserState($this->_context . '.category_title.orderdirn', 'ASC'))); } $query->order($this->_db->getEscaped($orderCol) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); if ($orderCol == 'category_title') { $query->order($this->_db->getEscaped('ordering') . ' ' . $this->_db->getEscaped($app->getUserState($this->_context . '.ordering.orderdirn', 'ASC'))); } $query->order($this->_db->getEscaped('state') . ' ' . $this->_db->getEscaped($app->getUserState($this->_context . '.state.orderdirn', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; }
/** * Generic check for whether dependancies exist for this object in the database schema * * Can be overloaded/supplemented by the child class * * @deprecated * @param mixed An optional primary key value check the row for. If not * set the instance property value is used. * @param array An optional array to compiles standard joins formatted like: * [label => 'Label', name => 'table name' , idfield => 'field', joinfield => 'field'] * @return boolean True on success. * @since 1.0 * @link http://docs.joomla.org/JTable/canDelete */ public function canDelete($pk = null, $joins = null) { // Initialise variables. $k = $this->_tbl_key; $pk = is_null($pk) ? $this->{$k} : $pk; // If no primary key is given, return false. if ($pk === null) { return false; } if (is_array($joins)) { // Get a query object. jimport('joomla.database.query'); $query = new JQuery(); // Setup the basic query. $query->select('`' . $this->_tbl_key . '`'); $query->from('`' . $this->_tbl . '`'); $query->where('`' . $this->_tbl_key . '` = ' . $this->_db->quote($this->{$k})); $query->group('`' . $this->_tbl_key . '`'); // For each join add the select and join clauses to the query object. foreach ($joins as $table) { $query->select('COUNT(DISTINCT ' . $table['idfield'] . ') AS ' . $table['idfield']); $query->join('LEFT', $table['name'] . ' ON ' . $table['joinfield'] . ' = ' . $k); } // Get the row object from the query. $this->_db->setQuery((string) $query, 0, 1); $row = $this->_db->loadObject(); // Check for a database error. if ($this->_db->getErrorNum()) { $this->setError($this->_db->getErrorMsg()); return false; } $msg = array(); $i = 0; foreach ($joins as $table) { $k = $table['idfield'] . $i; if ($obj->{$k}) { $msg[] = JText::_($table['label']); } $i++; } if (count($msg)) { $this->setError("noDeleteRecord" . ": " . implode(', ', $msg)); return false; } else { return true; } } return true; }