Skip to content

Commit c4d15b6

Browse files
committed
More query chaining + PHPCS
1 parent 809feec commit c4d15b6

File tree

2 files changed

+91
-91
lines changed

2 files changed

+91
-91
lines changed

mod_shoutbox/helper.php

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,12 @@ public function getShouts($offset, $number, $message)
205205
private function getShoutData($offset, $number)
206206
{
207207
$db = JFactory::getDbo();
208-
$query = $db->getQuery(true);
209-
$query->select('*')
210-
->from($db->qn('#__shoutbox'))
211-
->order($db->qn('id') . ' DESC')
212-
->setLimit($number, $offset);
208+
209+
$query = $db->getQuery(true)
210+
->select('*')
211+
->from($db->qn('#__shoutbox'))
212+
->order($db->qn('id') . ' DESC')
213+
->setLimit($number, $offset);
213214

214215
$db->setQuery($query);
215216

@@ -244,10 +245,11 @@ private function getShoutData($offset, $number)
244245
public function getAShout($id)
245246
{
246247
$db = JFactory::getDbo();
247-
$query = $db->getQuery(true);
248-
$query->select('*')
249-
->from($db->qn('#__shoutbox'))
250-
->where($db->qn('id') . ' = ' . (int)$id);
248+
249+
$query = $db->getQuery(true)
250+
->select('*')
251+
->from($db->qn('#__shoutbox'))
252+
->where($db->qn('id') . ' = ' . (int)$id);
251253

252254
$db->setQuery($query);
253255

@@ -298,9 +300,9 @@ public function countShouts()
298300
{
299301
$db = JFactory::getDbo();
300302

301-
$query = $db->getQuery(true);
302-
$query->select('COUNT(id)')
303-
->from($db->qn('#__shoutbox'));
303+
$query = $db->getQuery(true)
304+
->select('COUNT(id)')
305+
->from($db->qn('#__shoutbox'));
304306

305307
$db->setQuery($query);
306308

@@ -687,7 +689,6 @@ public function addShout($type, $id, $name, $message, $ip)
687689
if ($type == 'insert')
688690
{
689691
// Insert a new shout into the database
690-
$query = $db->getQuery(true);
691692
$columns = array('name', 'when', 'ip', 'msg', 'user_id');
692693

693694
$values = array(
@@ -698,12 +699,12 @@ public function addShout($type, $id, $name, $message, $ip)
698699
$db->q(JFactory::getUser()->id)
699700
);
700701

701-
$query->insert($db->qn('#__shoutbox'))
702-
->columns($db->qn($columns))
703-
->values(implode(',', $values));
702+
$query = $db->getQuery(true)
703+
->insert($db->qn('#__shoutbox'))
704+
->columns($db->qn($columns))
705+
->values(implode(',', $values));
704706

705707
$db->setQuery($query);
706-
707708
$db->execute();
708709

709710
return $db->insertid();
@@ -736,13 +737,12 @@ public function addShout($type, $id, $name, $message, $ip)
736737
public function deletepost($id)
737738
{
738739
$db = JFactory::getDbo();
739-
$query = $db->getQuery(true);
740-
$query->delete()
741-
->from($db->qn('#__shoutbox'))
742-
->where($db->qn('id') . ' = ' . (int) $id);
740+
$query = $db->getQuery(true)
741+
->delete()
742+
->from($db->qn('#__shoutbox'))
743+
->where($db->qn('id') . ' = ' . (int) $id);
743744

744745
$db->setQuery($query);
745-
746746
$db->execute();
747747
}
748748

@@ -767,11 +767,11 @@ public function deleteall($delete, $dir = 'DESC')
767767
}
768768

769769
$db = JFactory::getDbo();
770-
$query = $db->getQuery(true);
771-
$query->select('*')
772-
->from($db->qn('#__shoutbox'))
773-
->order($db->qn('id') . ' ' . $dir)
774-
->setLimit($delete);
770+
$query = $db->getQuery(true)
771+
->select('*')
772+
->from($db->qn('#__shoutbox'))
773+
->order($db->qn('id') . ' ' . $dir)
774+
->setLimit($delete);
775775

776776
$db->setQuery($query);
777777

@@ -1270,12 +1270,10 @@ public function getAvatar($type, $id)
12701270
{
12711271
// Use a database query as the CB framework is horrible
12721272
$db = JFactory::getDbo();
1273-
1274-
$query = $db->getQuery(true);
1275-
1276-
$query->select($db->qn('avatar'))
1277-
->from($db->qn('#__comprofiler'))
1278-
->where($db->qn('user_id') . ' = ' . $db->q($user->id));
1273+
$query = $db->getQuery(true)
1274+
->select($db->qn('avatar'))
1275+
->from($db->qn('#__comprofiler'))
1276+
->where($db->qn('user_id') . ' = ' . $db->q($user->id));
12791277

12801278
$db->setQuery($query);
12811279

@@ -1397,10 +1395,11 @@ public static function checkTimestampAjax()
13971395
private function getTimestampData($id)
13981396
{
13991397
$db = JFactory::getDbo();
1400-
$query = $db->getQuery(true);
1401-
$query->select('*')
1402-
->from($db->qn('#__shoutbox'))
1403-
->where($db->qn('id') . ' = ' . (int) $id);
1398+
1399+
$query = $db->getQuery(true)
1400+
->select('*')
1401+
->from($db->qn('#__shoutbox'))
1402+
->where($db->qn('id') . ' = ' . (int) $id);
14041403

14051404
$db->setQuery($query);
14061405

0 commit comments

Comments
 (0)