Просмотр исходного кода

Ticket #4885 - New friend requests alerts counter: Core.

AntonLV 1 год назад
Родитель
Сommit
b4cefc55ae

+ 24 - 0
inc/classes/BxDolConnection.php

@@ -589,6 +589,18 @@ class BxDolConnection extends BxDolFactory implements iBxDolFactoryObject
         return $this->_oQuery->getConnectedContentByType($iInitiator, $mixedType, $isMutual, $iStart, $iLimit, $iOrder);
     }
 
+    /**
+     * Get connected content IDs for specified type
+     * @param $iInitiator initiator of the connection
+     * @param $iDate get connections appeared since this date 
+     * @param $isMutual get mutual connections only
+     * @return array of available connections
+     */
+    public function getConnectedContentSince ($iInitiator, $iDate, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
+    {
+        return $this->_oQuery->getConnectedContentSince($iInitiator, $iDate, $isMutual, $iStart, $iLimit, $iOrder);
+    }
+
     /**
      * Get connected initiators IDs
      * @param $iContent content of the connection
@@ -612,6 +624,18 @@ class BxDolConnection extends BxDolFactory implements iBxDolFactoryObject
         return $this->_oQuery->getConnectedInitiatorsByType($iContent, $mixedType, $isMutual, $iStart, $iLimit, $iOrder);
     }
 
+    /**
+     * Get connected initiators IDs
+     * @param $iContent content of the connection
+     * @param $iDate get connections appeared since this date 
+     * @param $isMutual get mutual connections only
+     * @return array of available connections
+     */
+    public function getConnectedInitiatorsSince ($iContent, $iDate, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
+    {
+        return $this->_oQuery->getConnectedInitiatorsSince($iContent, $iDate, $isMutual, $iStart, $iLimit, $iOrder);
+    }
+
     /**
      * Similar to getConnectionsAsArray, but for getCommonContentAsSQLParts, getConnectedContentAsSQLParts or getConnectedInitiatorsAsSQLParts methods
      * @see getConnectionsAsArray

+ 28 - 0
inc/classes/BxDolConnectionQuery.php

@@ -193,6 +193,20 @@ class BxDolConnectionQuery extends BxDolDb
             'initiator' => $iInitiator,
         ));
     }
+    
+    public function getConnectedContentSince ($iInitiator, $iDate, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
+    {
+        $sWhere = " AND `c`.`initiator` = :initiator AND `c`.`added` >= :date";
+
+        $sJoin = $this->_aObject['profile_content'] ? 'INNER JOIN `sys_profiles` `p` ON `p`.`id` = `c`.`content` AND `p`.`status` = \'active\'' : '';
+
+        $sQuery = $this->_getConnectionsQuery($sWhere, $sJoin, '`c`.`content`', $isMutual, $iStart, $iLimit, $iOrder);
+
+        return $this->getColumn($sQuery, [
+            'initiator' => $iInitiator,
+            'date' => $iDate
+        ]);
+    }
 
     public function getConnectedInitiators ($iContent, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
     {
@@ -222,6 +236,20 @@ class BxDolConnectionQuery extends BxDolDb
         ));
     }
 
+    public function getConnectedInitiatorsSince ($iContent, $iDate, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
+    {
+        $sWhere = " AND `c`.`content` = :content AND `c`.`added` >= :date";
+
+        $sJoin = $this->_aObject['profile_initiator'] ? 'INNER JOIN `sys_profiles` `p` ON `p`.`id` = `c`.`initiator` AND `p`.`status` = \'active\'' : ''; 
+
+        $sQuery = $this->_getConnectionsQuery($sWhere, $sJoin, '`c`.`initiator`', $isMutual, $iStart, $iLimit, $iOrder);
+
+        return $this->getColumn($sQuery, [
+            'content' => $iContent,
+            'date' => $iDate
+        ]);
+    }
+
     protected function _getConnectionsQuery ($sWhere, $sJoin = '', $sFields = '*', $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
     {
         $sOrder = $this->_getOrderClause($iOrder, '`c`');

+ 3 - 0
inc/classes/BxDolGridConnections.php

@@ -15,6 +15,7 @@ class BxDolGridConnections extends BxTemplGrid
     protected $_bOwner = false;
     protected $_sObjectConnections = 'sys_profiles_friends';
     protected $_oProfile;
+    protected $_sProfileTrackAction = 'view_friend_requests';
     protected $_oConnection;
 
     public function __construct ($aOptions, $oTemplate = false)
@@ -65,6 +66,8 @@ class BxDolGridConnections extends BxTemplGrid
         if(!$this->_bInit)
             return '';
 
+        BxDolProfileQuery::getInstance()->updateProfileTrack($this->_oProfile->id(), $this->_sProfileTrackAction);
+
         return parent::getCode($isDisplayHeader);        
     }
 

+ 17 - 0
inc/classes/BxDolProfileQuery.php

@@ -505,6 +505,23 @@ class BxDolProfileQuery extends BxDolDb implements iBxDolSingleton
 
         return $bResult;
     }
+    
+    public function updateProfileTrack($iProfileId, $sAction)
+    {
+        return $this->query("INSERT INTO `sys_profiles_track` SET `profile_id`=:profile_id, `action`=:action, `date`=:now ON DUPLICATE KEY UPDATE `date`=:now", [
+            'profile_id' => $iProfileId,
+            'action' => $sAction,
+            'now' => time()
+        ]);
+    }
+
+    public function getProfileTrack($iProfileId, $sAction)
+    {
+        return (int)$this->getOne("SELECT `date` FROM `sys_profiles_track` WHERE `profile_id`=:profile_id AND `action`=:action LIMIT 1", [
+            'profile_id' => $iProfileId,
+            'action' => $sAction
+        ]);
+    }
 }
 
 /** @} */

Разница между файлами не показана из-за своего большого размера
+ 0 - 0
install/sql/system.sql


+ 43 - 11
template/scripts/BxBaseServiceConnections.php

@@ -143,9 +143,10 @@ class BxBaseServiceConnections extends BxDol
      * get number of received unconfirmed connections (friend requests)
      * @param $sConnectionsObject connections object to get unconfirmed connections from
      * @param $mixedId id to get connections for, if omitted then logged-in profile id is used
+     * @param $bNew return all or only new (appeared since last check) unconfirmed connections
      * @return number
      */
-    public function serviceGetUnconfirmedConnectionsNum ($sConnectionsObject, $mixedId = 0)
+    public function serviceGetUnconfirmedConnectionsNum ($sConnectionsObject, $mixedId = 0, $bNew = false)
     {
         $oConnection = BxDolConnection::getObjectInstance($sConnectionsObject);
         if (!$oConnection)
@@ -154,10 +155,17 @@ class BxBaseServiceConnections extends BxDol
         if (!$mixedId)
             $mixedId = bx_get_logged_profile_id();
 
+        $sMethodName = 'getConnectedInitiators';
+        $aMethodParams = [$mixedId, 0];
+        if($bNew) {
+            $sMethodName .= 'Since';
+            $aMethodParams = [$mixedId, BxDolProfileQuery::getInstance()->getProfileTrack($mixedId, 'view_friend_requests'), 0];
+        }
+
         $i = 0;
-        $a = $oConnection->getConnectedInitiators($mixedId, 0); // get received friend requests
-        foreach ($a as $iId)
-            if (BxDolProfile::getInstance($iId))
+        $a = call_user_func_array([$oConnection, $sMethodName], $aMethodParams); // get received friend requests
+        foreach($a as $iId)
+            if(BxDolProfile::getInstance($iId))
                 ++$i;
 
         return $i;
@@ -172,20 +180,44 @@ class BxBaseServiceConnections extends BxDol
 
         $iCountNew = (int)$this->serviceGetUnconfirmedConnectionsNum($sConnectionsObject, $iProfile);
         if($iCountNew == (int)$iCount)
-			return false;
+            return false;
 
         return array(
-    		'count' => $iCountNew, // required
-    		'method' => 'bx_menu_show_live_update(oData)', // required
-    		'data' => array(
-    			'code' => BxDolTemplate::getInstance()->parseHtmlByTemplateName('menu_item_addon', array(
-    				'content' => '{count}'
+            'count' => $iCountNew, // required
+            'method' => 'bx_menu_show_live_update(oData)', // required
+            'data' => array(
+                'code' => BxDolTemplate::getInstance()->parseHtmlByTemplateName('menu_item_addon', array(
+                    'content' => '{count}'
                 )),
                 'mi_parent' => $aMenuItemParent,
                 'mi_child' => $aMenuItemChild
-    		),  // optional, may have some additional data to be passed in JS method provided using 'method' param above.
+            ),  // optional, may have some additional data to be passed in JS method provided using 'method' param above.
     	);
     }
+    
+    public function serviceGetLiveUpdatesUnconfirmedConnectionsNew($sModule, $sConnectionsObject, $aMenuItemParent, $aMenuItemChild, $iCount = 0)
+    {
+        $iProfile = bx_get_logged_profile_id();
+        $oProfile = BxDolProfile::getInstance($iProfile);
+        if(!$oProfile || $oProfile->getModule() != $sModule)
+            return false;
+
+        $iCountNew = (int)$this->serviceGetUnconfirmedConnectionsNum($sConnectionsObject, $iProfile, true);
+        if($iCountNew == (int)$iCount)
+            return false;
+
+        return [
+            'count' => $iCountNew, // required
+            'method' => 'bx_menu_show_live_update(oData)', // required
+            'data' => [
+                'code' => BxDolTemplate::getInstance()->parseHtmlByTemplateName('menu_item_addon', [
+                    'content' => '{count}'
+                ]),
+                'mi_parent' => $aMenuItemParent,
+                'mi_child' => $aMenuItemChild
+            ],  // optional, may have some additional data to be passed in JS method provided using 'method' param above.
+    	];
+    }
 
     /**
      * get number of initiated connections (like "my subscriptions")

+ 2 - 0
template/scripts/BxBaseServiceProfiles.php

@@ -744,6 +744,8 @@ class BxBaseServiceProfiles extends BxDol
         if(!empty($aParams['params']) && is_array($aParams['params']))
             $aParamsBrowse = array_merge($aParamsBrowse, $aParams['params']);
 
+        BxDolProfileQuery::getInstance()->updateProfileTrack($iProfileId, 'view_friend_requests');
+
         return $this->_serviceBrowseConnections('friend_requests', $aParamsBrowse, $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
     }
 

Некоторые файлы не были показаны из-за большого количества измененных файлов