Skip to content

Commit

Permalink
some "modern" queries...
Browse files Browse the repository at this point in the history
  • Loading branch information
infograf768 committed Dec 1, 2019
1 parent 6f49f62 commit 2c59072
Showing 1 changed file with 74 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ public static function getHomes()
$query = $db->getQuery(true)
->select('COUNT(*)')
->from($db->quoteName('#__menu'))
->where($db->quoteName('home') . ' = 1')
->where($db->quoteName('published') . ' = 1')
->where($db->quoteName('client_id') . ' = 0');
->where(
[
$db->quoteName('home') . ' = 1',
$db->quoteName('published') . ' = 1',
$db->quoteName('client_id') . ' = 0',
]
);

$db->setQuery($query);

return $db->loadResult();
Expand All @@ -56,9 +61,14 @@ public static function getLangswitchers()
$query = $db->getQuery(true)
->select('COUNT(*)')
->from($db->quoteName('#__modules'))
->where($db->quoteName('module') . ' = ' . $db->quote('mod_languages'))
->where($db->quoteName('published') . ' = 1')
->where($db->quoteName('client_id') . ' = 0');
->where(
[
$db->quoteName('module') . ' = ' . $db->quote('mod_languages'),
$db->quoteName('published') . ' = 1',
$db->quoteName('client_id') . ' = 0',
]
);

$db->setQuery($query);

return $db->loadResult();
Expand All @@ -74,9 +84,14 @@ public static function getContentlangs()
// Check for published Content Languages.
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('a.lang_code', 'lang_code'))
->select($db->quoteName('a.published', 'published'))
->select(
[
$db->quoteName('a.lang_code', 'lang_code'),
$db->quoteName('a.published', 'published'),
]
)
->from($db->quoteName('#__languages', 'a'));

$db->setQuery($query);

return $db->loadObjectList();
Expand Down Expand Up @@ -105,10 +120,14 @@ public static function getStatus()
->join('LEFT', $db->quoteName('#__menu', 'l') . ' ON ' . $db->quoteName('l.language') . ' = ' . $db->quoteName('a.lang_code') . ' AND ' . $db->quoteName('l.home') . ' = 1 AND ' . $db->quoteName('l.language') . ' <> \'*\'')
->select($db->quoteName('e.enabled', 'enabled'))
->select($db->quoteName('e.element', 'element'))
->join('LEFT', $db->quoteName('#__extensions', 'e') . ' ON ' . $db->quoteName('e.element') . ' = ' . $db->quoteName('a.lang_code'))
->where($db->quoteName('e.client_id') . ' = 0')
->where($db->quoteName('e.enabled') . ' = 1')
->where($db->quoteName('e.state') . ' = 0');
->join('LEFT', $db->quoteName('#__extensions', 'e'), $db->quoteName('e.element') . ' = ' . $db->quoteName('a.lang_code'))
->where(
[
$db->quoteName('e.client_id') . ' = 0',
$db->quoteName('e.enabled') . ' = 1',
$db->quoteName('e.state') . ' = 0',
]
);

$db->setQuery($query);

Expand All @@ -129,27 +148,39 @@ public static function getContacts()
$alang = $db->getQuery(true)
->select('count(*)')
->from($db->quoteName('#__contact_details', 'cd'))
->where($db->quoteName('cd.user_id') . ' = ' . $db->quoteName('u.id'))
->where($db->quoteName('cd.published') . ' = 1')
->where($db->quoteName('cd.language') . ' = ' . $db->quote('*'));
->where(
[
$db->quoteName('cd.user_id') . ' = ' . $db->quoteName('u.id'),
$db->quoteName('cd.published') . ' = 1',
$db->quoteName('cd.language') . ' = ' . $db->quote('*'),
]
);

// Get the number of languages for the contact
$slang = $db->getQuery(true)
->select('count(distinct(l.lang_code))')
->from($db->quoteName('#__languages', 'l'))
->join('LEFT', $db->quoteName('#__contact_details', 'cd') . ' ON ' . $db->quoteName('cd.language') . '= ' . $db->quoteName('l.lang_code'))
->where($db->quoteName('cd.user_id') . ' = ' . $db->quoteName('u.id'))
->where($db->quoteName('cd.published') . ' = 1')
->where($db->quoteName('l.published') . ' = 1');
->where(
[
$db->quoteName('cd.user_id') . ' = ' . $db->quoteName('u.id'),
$db->quoteName('cd.published') . ' = 1',
$db->quoteName('l.published') . ' = 1',
]
);

// Get the number of multiple contact/language
$mlang = $db->getQuery(true)
->select('count(*)')
->from($db->quoteName('#__languages', 'l'))
->join('LEFT', $db->quoteName('#__contact_details', 'cd') . ' ON ' . $db->quoteName('cd.language') . ' = ' . $db->quoteName('l.lang_code'))
->where($db->quoteName('cd.user_id') . ' = ' . $db->quoteName('u.id'))
->where($db->quoteName('cd.published') . ' = 1')
->where($db->quoteName('l.published') . ' = 1')
->where(
[
$db->quoteName('cd.user_id') . ' = ' . $db->quoteName('u.id'),
$db->quoteName('cd.published') . ' = 1',
$db->quoteName('l.published') . ' = 1',
]
)
->group($db->quoteName('l.lang_code'))
->having('count(*) > 1');

Expand Down Expand Up @@ -199,10 +230,14 @@ public static function getDefaultHomeModule()
$query = $db->getQuery(true)
->select($db->quoteName('menutype'))
->from($db->quoteName('#__menu'))
->where($db->quoteName('home') . ' = ' . $db->quote('1'))
->where($db->quoteName('published') . ' = ' . $db->quote('1'))
->where($db->quoteName('client_id') . ' = ' . $db->quote('0'))
->where($db->quoteName('language') . ' = ' . $db->quote('*'));
->where(
[
$db->quoteName('home') . ' = ' . $db->quote('1'),
$db->quoteName('published') . ' = ' . $db->quote('1'),
$db->quoteName('client_id') . ' = ' . $db->quote('0'),
$db->quoteName('language') . ' = ' . $db->quote('*'),
]
);

$db->setQuery($query);

Expand All @@ -212,9 +247,13 @@ public static function getDefaultHomeModule()
$query->clear()
->select($db->quoteName('title'))
->from($db->quoteName('#__modules'))
->where($db->quoteName('module') . ' = ' . $db->quote('mod_menu'))
->where($db->quoteName('published') . ' = ' . $db->quote('1'))
->where($db->quoteName('client_id') . ' = ' . $db->quote('0'));
->where(
[
$db->quoteName('module') . ' = ' . $db->quote('mod_menu'),
$db->quoteName('published') . ' = ' . $db->quote('1'),
$db->quoteName('client_id') . ' = ' . $db->quote('0'),
]
);

$db->setQuery($query);

Expand Down Expand Up @@ -253,9 +292,13 @@ public static function getModule($moduleName, $instanceTitle = null)
$query = $db->getQuery(true)
->select('id, title, module, position, content, showtitle, params')
->from($db->quoteName('#__modules'))
->where($db->quoteName('module') . ' = ' . $db->quote($moduleName))
->where($db->quoteName('published') . ' = ' . $db->quote('1'))
->where($db->quoteName('client_id') . ' = ' . $db->quote('0'));
->where(
[
$db->quoteName('module') . ' = ' . $db->quote($moduleName),
$db->quoteName('published') . ' = ' . $db->quote('1'),
$db->quoteName('client_id') . ' = ' . $db->quote('0'),
]
);

if ($instanceTitle)
{
Expand Down

0 comments on commit 2c59072

Please sign in to comment.