]> git.mxchange.org Git - friendica.git/commitdiff
code lisibility & filter optimization
authorPhilipp Holzer <admin@philipp.info>
Fri, 1 Mar 2019 16:15:34 +0000 (17:15 +0100)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sat, 23 Mar 2019 02:55:48 +0000 (22:55 -0400)
src/Content/ForumManager.php
src/Core/NotificationsManager.php
src/Core/UserImport.php
src/Database/DBStructure.php

index b23a9e6924eb89e2c492c40953be7b444563b8dc..e9dab41ef9a26da1454993918b88f63a54d22a1a 100644 (file)
@@ -196,7 +196,7 @@ class ForumManager
         */
        public static function countUnseenItems()
        {
-               $r = DBA::p(
+               $stmtContacts = DBA::p(
                        "SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
                                INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
                                WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
@@ -208,6 +208,6 @@ class ForumManager
                        intval(local_user())
                );
 
-               return DBA::toArray($r);
+               return DBA::toArray($stmtContacts);
        }
 }
index d54492f3b0f0cccfcc5c254e7c2222baee3aa503..4c6b932deb7714516bfa69735e89936ccaf9dc0a 100644 (file)
@@ -36,7 +36,7 @@ class NotificationsManager extends BaseObject
         *  - msg_plain: message as plain text string
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       private function _set_extra($notes)
+       private function _set_extra(array $notes)
        {
                $rets = [];
                foreach ($notes as $n) {
@@ -73,10 +73,10 @@ class NotificationsManager extends BaseObject
 
                $dbFilter = array_merge($filter, ['uid' => local_user()]);
 
-               $r = DBA::select('notify', [], $dbFilter, $order, $params);
+               $stmtNotifies = DBA::select('notify', [], $dbFilter, $order, $params);
 
-               if (DBA::isResult($r)) {
-                       return $this->_set_extra($r);
+               if (DBA::isResult($stmtNotifies)) {
+                       return $this->_set_extra(DBA::toArray($stmtNotifies));
                }
 
                return false;
@@ -91,9 +91,9 @@ class NotificationsManager extends BaseObject
         */
        public function getByID($id)
        {
-               $r = DBA::selectFirst('notify', ['id' => $id, 'uid' => local_user()]);
-               if (DBA::isResult($r)) {
-                       return $this->_set_extra($r)[0];
+               $stmtNotify = DBA::selectFirst('notify', ['id' => $id, 'uid' => local_user()]);
+               if (DBA::isResult($stmtNotify)) {
+                       return $this->_set_extra([$stmtNotify])[0];
                }
                return null;
        }
@@ -423,22 +423,21 @@ class NotificationsManager extends BaseObject
                $notifs = [];
                $sql_seen = "";
 
+               $filter = ['uid' => local_user()];
                if ($seen === 0) {
-                       $filter = ['`uid` = ? AND NOT `seen`', local_user()];
-               } else {
-                       $filter = ['uid' => local_user()];
+                       $filter['seen'] = false;
                }
 
                $params = [];
                $params['limit'] = [$start, $limit];
 
-               $r = DBA::select('notify',
+               $stmtNotifies = DBA::select('notify',
                        ['id', 'url', 'photo', 'msg', 'date', 'seen', 'verb'],
                        $filter,
                        $params);
 
-               if (DBA::isResult($r)) {
-                       $notifs = $this->formatNotifs(DBA::toArray($r), $ident);
+               if (DBA::isResult($stmtNotifies)) {
+                       $notifs = $this->formatNotifs(DBA::toArray($stmtNotifies), $ident);
                }
 
                $arr = [
@@ -561,7 +560,7 @@ class NotificationsManager extends BaseObject
                }
 
                /// @todo Fetch contact details by "Contact::getDetailsByUrl" instead of queries to contact, fcontact and gcontact
-               $r = DBA::p(
+               $stmtNotifies = DBA::p(
                        "SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.*,
                                `fcontact`.`name` AS `fname`, `fcontact`.`url` AS `furl`, `fcontact`.`addr` AS `faddr`,
                                `fcontact`.`photo` AS `fphoto`, `fcontact`.`request` AS `frequest`,
@@ -578,8 +577,8 @@ class NotificationsManager extends BaseObject
                        intval($start),
                        intval($limit)
                );
-               if (DBA::isResult($r)) {
-                       $notifs = $this->formatIntros(DBA::toArray($r));
+               if (DBA::isResult($stmtNotifies)) {
+                       $notifs = $this->formatIntros(DBA::toArray($stmtNotifies));
                }
 
                $arr = [
index 07119873d97a371d14dec7d3d46d40d44a19d192..0a4223fecdf5f45241051631dcb23a0c5d10aab2 100644 (file)
@@ -36,11 +36,11 @@ class UserImport
         */
        private static function checkCols($table, &$arr)
        {
-               $r = DBStructure::getColumns($table);
+               $tableColumns = DBStructure::getColumns($table);
 
                $tcols = [];
                // get a plain array of column names
-               foreach ($r as $tcol) {
+               foreach ($tableColumns as $tcol) {
                        $tcols[] = $tcol['Field'];
                }
                // remove inexistent columns
index 4732f8d707f1a7d2ad9daee2246a1fe5cadd34d7..abbac4e781795a700b10c52c95cbecf0abc0aeb2 100644 (file)
@@ -855,7 +855,7 @@ class DBStructure
         */
        public static function getColumns($table)
        {
-               $r = DBA::p("SHOW COLUMNS FROM `" . $table . "`");
-               return DBA::toArray($r);
+               $stmtColumns = DBA::p("SHOW COLUMNS FROM `" . $table . "`");
+               return DBA::toArray($stmtColumns);
        }
 }