Pārlūkot izejas kodu

Ticket #5026 - Connections flow improvements. Relations.

AntonLV 1 gadu atpakaļ
vecāks
revīzija
24c9e14b17

+ 3 - 3
inc/classes/BxDolRelation.php → inc/classes/BxDolConnectionRelation.php

@@ -7,7 +7,7 @@
  * @{
  */
 
-class BxDolRelation extends BxTemplConnection
+class BxDolConnectionRelation extends BxTemplConnection
 {
     protected static $_sParamEnabled = 'sys_relations_enable';
     protected static $_sParamTypes = 'sys_relations';
@@ -19,7 +19,7 @@ class BxDolRelation extends BxTemplConnection
     {
         parent::__construct($aObject);
 
-        $this->_oQuery = new BxDolRelationQuery($aObject);
+        $this->_oQuery = new BxDolConnectionRelationQuery($aObject);
 
         $this->_sParamDivider = '_';
         $this->_sPreList = 'sys_relations';
@@ -132,7 +132,7 @@ class BxDolRelation extends BxTemplConnection
          *      - `initiator` - [int] profile id who created the connection
          *      - `content` - [int] profile id with whom the connection was created
          *      - `mutual` - [int] if the relation is mutual or not
-         *      - `object` - [object] an instance of relation, @see BxDolRelation
+         *      - `object` - [object] an instance of relation, @see BxDolConnectionRelation
          * @hook @ref hook-bx_dol_relation-connection_confirmed
          */
         bx_alert($this->_sObject, 'connection_confirmed', 0, bx_get_logged_profile_id(), [

+ 1 - 1
inc/classes/BxDolRelationQuery.php → inc/classes/BxDolConnectionRelationQuery.php

@@ -11,7 +11,7 @@
  * Database queries for Relation objects.
  * @see BxDolConnection
  */
-class BxDolRelationQuery extends BxDolConnectionQuery
+class BxDolConnectionRelationQuery extends BxDolConnectionQuery
 {
     public function __construct($aObject)
     {

+ 1 - 1
inc/classes/BxDolPrivacy.php

@@ -936,7 +936,7 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
 
     public function isAllowedRelations($iUserId)
     {
-        return BxDolRelation::isEnabled();
+        return BxDolConnectionRelation::isEnabled();
     }
 
     public function isAllowedMemberships($iUserId)

+ 1 - 1
install/sql/system.sql

@@ -5729,7 +5729,7 @@ CREATE TABLE IF NOT EXISTS `sys_objects_connection` (
 INSERT INTO `sys_objects_connection` (`object`, `table`, `profile_initiator`, `profile_content`, `type`, `override_class_name`, `override_class_file`) VALUES
 ('sys_profiles_friends', 'sys_profiles_conn_friends', 1, 1, 'mutual', 'BxTemplConnectionFriend', ''),
 ('sys_profiles_subscriptions', 'sys_profiles_conn_subscriptions', 1, 1, 'one-way', 'BxTemplConnectionSubscription', ''),
-('sys_profiles_relations', 'sys_profiles_conn_relations', 1, 1, 'mutual', 'BxDolRelation', ''),
+('sys_profiles_relations', 'sys_profiles_conn_relations', 1, 1, 'mutual', 'BxTemplConnectionRelation', ''),
 ('sys_profiles_bans', 'sys_profiles_conn_bans', 1, 1, 'one-way', 'BxDolConnectionBan', '');
 
 CREATE TABLE IF NOT EXISTS `sys_profiles_conn_bans` (

+ 7 - 0
modules/base/profile/classes/BxBaseModProfileMenuViewActionsAll.php

@@ -123,6 +123,13 @@ class BxBaseModProfileMenuViewActionsAll extends BxBaseModGeneralMenuViewActions
         ]));
     }
 
+    protected function _getMenuItemProfileRelations($aItem, $aParams = [])
+    {
+        return $this->_getMenuItemConnection($aItem, array_merge($aParams, [
+            'object' => 'sys_profiles_relations'
+        ]));
+    }
+
     protected function _getMenuItemProfileSubscriptions($aItem, $aParams = [])
     {
         return $this->_getMenuItemConnection($aItem, array_merge($aParams, [

+ 6 - 6
modules/base/profile/classes/BxBaseModProfileModule.php

@@ -1288,7 +1288,7 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
 
     public function serviceProfileRelations ($iContentId = 0, $aParams = array())
     {
-        if(!BxDolRelation::isEnabled())
+        if(!BxDolConnectionRelation::isEnabled())
             return false;
 
         $mixedContent = $this->_getContent($iContentId);
@@ -1307,7 +1307,7 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
 
     public function serviceProfileRelatedMe ($iContentId = 0)
     {
-        if(!BxDolRelation::isEnabled())
+        if(!BxDolConnectionRelation::isEnabled())
             return false;
 
         $mixedContent = $this->_getContent($iContentId);
@@ -1340,7 +1340,7 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
 
     public function serviceIsEnableRelations()
     {
-        if(!BxDolRelation::isEnabled())
+        if(!BxDolConnectionRelation::isEnabled())
             return false;
 
         $sModule = $this->_oConfig->getName();
@@ -1955,7 +1955,7 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
     public function checkAllowedRelationAdd (&$aDataEntry, $isPerformAction = false)
     {
         $sResult = _t('_sys_txt_access_denied');
-        if(!BxDolRelation::isEnabled())
+        if(!BxDolConnectionRelation::isEnabled())
             return $sResult;
 
         if(($sMsg = $this->checkAllowedView($aDataEntry)) !== CHECK_ACTION_RESULT_ALLOWED)
@@ -1970,7 +1970,7 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
     public function checkAllowedRelationRemove (&$aDataEntry, $isPerformAction = false)
     {
         $sResult = _t('_sys_txt_access_denied');
-        if(!BxDolRelation::isEnabled())
+        if(!BxDolConnectionRelation::isEnabled())
             return $sResult;
 
         return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_relations', false, true);
@@ -1979,7 +1979,7 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
     public function checkAllowedRelationsView (&$aDataEntry, $isPerformAction = false)
     {
         $sResult = _t('_sys_txt_access_denied');
-        if(!BxDolRelation::isEnabled())
+        if(!BxDolConnectionRelation::isEnabled())
             return $sResult;
 
         $sModule = $this->_oConfig->getName();

+ 3 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -2497,6 +2497,9 @@ If it is not enabled then please consider implement this optimization, since it
     <string name="_sys_conn_friends_do_content"><![CDATA[Respond]]></string>
     <string name="_sys_conn_subscriptions_do_initiator"><![CDATA[Following]]></string>
     <string name="_sys_conn_subscriptions_counter"><![CDATA[{0} followers]]></string>
+    <string name="_sys_conn_relations_do_initiator"><![CDATA[Add Relationship]]></string>
+    <string name="_sys_conn_relations_do_initiator_done"><![CDATA[Relations]]></string>
+    <string name="_sys_conn_relations_do_initiator_undo"><![CDATA[Remove Relationship]]></string>
     <string name=""><![CDATA[]]></string>
     <string name=""><![CDATA[]]></string>
     <string name="_sys_conn_err_connection_already_exists"><![CDATA[Connection already exists]]></string>

+ 3 - 2
modules/boonex/persons/install/sql/enable.sql

@@ -266,8 +266,9 @@ INSERT INTO `sys_menu_items`(`set_name`, `module`, `name`, `title_system`, `titl
 ('bx_persons_view_actions_all', 'bx_persons', 'profile-friends', '_bx_persons_menu_item_title_system_friends', '', '', '', '', '', '', '', 0, 2147483647, '', 1, 0, 10),
 ('bx_persons_view_actions_all', 'bx_persons', 'profile-friend-add', '_bx_persons_menu_item_title_system_befriend', '', '', '', '', '', '', '', 0, 2147483647, '', 0, 0, 12),
 ('bx_persons_view_actions_all', 'bx_persons', 'profile-friend-remove', '_bx_persons_menu_item_title_system_unfriend', '', '', '', '', '', '', '', 0, 2147483647, '', 0, 0, 14),
-('bx_persons_view_actions_all', 'bx_persons', 'profile-relation-add', '_bx_persons_menu_item_title_system_relation_add', '', '', '', '', '', '', '', 0, 2147483647, '', 1, 0, 23),
-('bx_persons_view_actions_all', 'bx_persons', 'profile-relation-remove', '_bx_persons_menu_item_title_system_relation_delete', '', '', '', '', '', '', '', 0, 2147483647, '', 1, 0, 27),
+('bx_persons_view_actions_all', 'bx_persons', 'profile-relations', '_bx_persons_menu_item_title_system_relations', '', '', '', '', '', '', '', 0, 2147483647, '', 1, 0, 20),
+('bx_persons_view_actions_all', 'bx_persons', 'profile-relation-add', '_bx_persons_menu_item_title_system_relation_add', '', '', '', '', '', '', '', 0, 2147483647, '', 0, 0, 22),
+('bx_persons_view_actions_all', 'bx_persons', 'profile-relation-remove', '_bx_persons_menu_item_title_system_relation_delete', '', '', '', '', '', '', '', 0, 2147483647, '', 0, 0, 24),
 ('bx_persons_view_actions_all', 'bx_persons', 'profile-subscriptions', '_bx_persons_menu_item_title_system_subscriptions', '', '', '', '', '', '', '', 0, 2147483647, '', 1, 0, 30),
 ('bx_persons_view_actions_all', 'bx_persons', 'profile-subscribe-add', '_bx_persons_menu_item_title_system_subscribe', '', '', '', '', '', '', '', 0, 2147483647, '', 0, 0, 32),
 ('bx_persons_view_actions_all', 'bx_persons', 'profile-subscribe-remove', '_bx_persons_menu_item_title_system_unsubscribe', '', '', '', '', '', '', '', 0, 2147483647, '', 0, 0, 34),

+ 3 - 0
modules/boonex/russian/data/langs/system/ru.xml

@@ -2472,6 +2472,9 @@
     <string name="_sys_conn_friends_do_content"><![CDATA[Ответить]]></string>
     <string name="_sys_conn_subscriptions_do_initiator"><![CDATA[Слежу]]></string>
     <string name="_sys_conn_subscriptions_counter"><![CDATA[Подписчики: {0}]]></string>
+    <string name="_sys_conn_relations_do_initiator"><![CDATA[Добавить связь]]></string>
+    <string name="_sys_conn_relations_do_initiator_done"><![CDATA[Отношения]]></string>
+    <string name="_sys_conn_relations_do_initiator_undo"><![CDATA[Удалить связь]]></string>
     <string name=""><![CDATA[]]></string>
     <string name=""><![CDATA[]]></string>
     <string name="_sys_conn_err_connection_already_exists"><![CDATA[Связь уже существует]]></string>

+ 6 - 0
template/css/connection.css

@@ -6,4 +6,10 @@
 
 .sys-action-counter-profile .bx-base-pofile-unit-online {
     display: none;
+}
+
+
+/*-- Relations: Do menu --*/
+.bx-menu-add-relation-hidden {
+    display: none;
 }

+ 0 - 3
template/css/menu.css

@@ -1045,9 +1045,6 @@ ul.bx-menu-btns-icon-hor li:last-child .bx-btn {
     text-transform: capitalize;
 }
 
-.bx-menu-add-relation-hidden {
-    display: none;
-}
 
 /* --------------- footer menu */
 #bx-menu-footer.bx-menu-hor li {

+ 17 - 12
template/scripts/BxBaseConnection.php

@@ -106,6 +106,8 @@ class BxBaseConnection extends BxDolConnection
 
         if(!$iInitiator)
             $iInitiator = bx_get_logged_profile_id();
+        if($iInitiator && $iInitiator == $iContent)
+            return '';
 
         $aActions = $this->_getActions($iInitiator, $iContent, $aParams);
 
@@ -139,18 +141,21 @@ class BxBaseConnection extends BxDolConnection
 
             $aMenuItems = [];
             foreach($aActions['items'] as $aItem)
-                if(!empty($aItem) && is_array($aItem))
-                    $aMenuItems[] = [
-                        'id' => $aItem['name'], 
-                        'name' => $aItem['name'], 
-                        'class' => '', 
-                        'icon' => $this->_getActionIcon($aItem, $aParams), 
-                        'link' => 'javascript:void(0)', 
-                        'onclick' => 'javascript:bx_conn_action(this, \'' . $this->_sObject . '\', \'' . $aItem['name'] . '\', ' . $iContent . ')', 
-                        'target' => '_self', 
-                        'title' => !empty($aItem['title']) ? _t($aItem['title']) : '', 
-                        'active' => 1
-                    ];
+                if(!empty($aItem) && is_array($aItem)) {
+                    if(!isset($aItem['link'], $aItem['onclick']))    
+                        $aMenuItems[] = [
+                            'id' => $aItem['name'], 
+                            'name' => $aItem['name'], 
+                            'icon' => $this->_getActionIcon($aItem, $aParams), 
+                            'link' => 'javascript:void(0)', 
+                            'onclick' => "javascript:bx_conn_action(this, '" . $this->_sObject . "', '" . $aItem['name'] . "', " . $iContent . ")", 
+                            'target' => '_self', 
+                            'title' => !empty($aItem['title']) ? _t($aItem['title']) : '', 
+                            'active' => 1
+                        ];
+                    else
+                        $aMenuItems[] = $aItem;
+                }
 
             $oMenu = new BxTemplMenu(['template' => 'menu_vertical.html', 'menu_id'=> $sHtmlIdDoMenu, 'menu_items' => $aMenuItems]);
 

+ 122 - 0
template/scripts/BxBaseConnectionRelation.php

@@ -0,0 +1,122 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaBaseView UNA Base Representation Classes
+ * @{
+ */
+
+/**
+ * @see BxBaseConnection
+ */
+class BxBaseConnectionRelation extends BxDolConnectionRelation
+{
+    protected function __construct($aObject)
+    {
+        parent::__construct($aObject);
+
+        $this->_aT = array_merge($this->_aT, [
+            'do_initiator' => '_sys_conn_relations_do_initiator',
+            'do_initiator_done' => '_sys_conn_relations_do_initiator_done',
+            'do_initiator_undo' => '_sys_conn_relations_do_initiator_undo',
+            'counter' => '_sys_conn_relations_counter'
+        ]);
+    }
+
+    //TODO: Continue from here. Copy actions (relation types: mom, dad, etc) from menu into actions list.
+    protected function _getActions($iInitiator, $iContent, $aParams = [])
+    {
+        $sName = $sTitle = '';
+        $aActions = [];
+
+        if($this->isConnected($iInitiator, $iContent)) {
+            $sName = 'remove';
+            $sTitle = $this->_aT['do_initiator_done'];
+            $aActions = [[
+                'name' => 'remove',
+                'title' => ($sKey = 'txt_unsubscribe') && !empty($aParams[$sKey]) ? $aParams[$sKey] : $this->_aT['do_initiator_undo']
+            ], [
+                /*
+                 * An empty array item to show all items in popup.
+                 * More actions will be added later.
+                 */
+            ]];
+        } 
+        else {
+            $sName = 'add';
+            $sTitle = $this->_aT['do_initiator'];
+            $aActions = [];
+
+            $aSuggestions = [];
+            $aRelations = $this->getRelations($iInitiator, $iContent, $aSuggestions);
+            $bSuggestions = !empty($aSuggestions) && is_array($aSuggestions);
+
+            $sClassHidden = 'bx-menu-add-relation-hidden';
+            foreach($aRelations as $iId => $aRelation) {
+                $aActions[] = [
+                    'id' => 'bx-conn-rl-' . $iId,
+                    'name' => 'bx-conn-rl-' . $iId,
+                    'class_add' => $bSuggestions && !in_array($iId, $aSuggestions) ? $sClassHidden : '',
+                    'title' => _t($aRelation[BX_DATA_VALUES_DEFAULT]),
+                    'icon' => '',
+                    'link' => 'javascript:void(0);',
+                    'onclick' => "bx_conn_action(this, '" . $this->_sObject . "', 'add', " . bx_js_string(json_encode(['content' => $iContent, 'relation' => $iId])) . ")"
+                ];
+            }
+
+            if($bSuggestions)
+                $aActions[] = [
+                    'id' => 'see_more',
+                    'name' => 'see_more',
+                    'title' => _t('_see_more'),
+                    'icon' => '',
+                    'link' => 'javascript:void(0);',
+                    'onclick' => bx_js_string("$(this).parents('li:first').hide().siblings('." . $sClassHidden . "').removeClass('" . $sClassHidden . "');")
+                ];
+        }
+
+        return [
+            'name' => $sName,
+            'title' => $sTitle,
+            'items' => $aActions
+        ];
+    }
+    
+    protected function _getActionIconAsIcon($sAction)
+    {
+        $sDefault = 'sync';
+
+        $aA2I = [
+            'add' => $sDefault,
+            'remove' => $sDefault
+        ];
+
+        return isset($aA2I[$sAction]) ? $aA2I[$sAction] : $sDefault;
+    }
+
+    //TODO: Get emoji similar to 
+    protected function _getActionIconAsEmoji($sAction)
+    {
+        $sDefault = '';
+
+        $aA2I = [
+            'add' => $sDefault,
+            'remove' => $sDefault
+        ];
+
+        return isset($aA2I[$sAction]) ? $aA2I[$sAction] : $sDefault;
+    }
+
+    protected function _getActionIconAsImage($sAction)
+    {
+        $sDefault = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-refresh-cw-icon lucide-refresh-cw"><path d="M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"/><path d="M21 3v5h-5"/><path d="M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16"/><path d="M8 16H3v5"/></svg>';
+
+        $aA2I = [
+            'add' => $sDefault,
+            'remove' => $sDefault
+        ];
+
+        return isset($aA2I[$sAction]) ? $aA2I[$sAction] : $sDefault;
+    }
+}

+ 4 - 1
template/scripts/BxBaseMenu.php

@@ -251,7 +251,10 @@ class BxBaseMenu extends BxDolMenu
 
         list ($sIcon, $sIconUrl, $sIconA, $sIconHtml) = $this->_getMenuIcon($a);
 
-        $a['class_add'] = $bIsSelected ? 'bx-menu-tab-active' : '';
+        if(!isset($a['class_add']))
+            $a['class_add'] = '';
+        if($bIsSelected)
+            $a['class_add'] .= ' bx-menu-tab-active';
         $a['class_add'] .= $this->_getVisibilityClass($a);
         $a['class_link'] = '';
 

+ 9 - 22
template/scripts/BxBaseMenuAddRelation.php

@@ -29,7 +29,7 @@ class BxBaseMenuAddRelation extends BxTemplMenu
 
     public function getCode ()
     {
-        if(!BxDolRelation::isEnabled())
+        if(!BxDolConnectionRelation::isEnabled())
             return '';
 
         return parent::getCode();
@@ -42,18 +42,6 @@ class BxBaseMenuAddRelation extends BxTemplMenu
         return parent::getMenuItems();
     }
 
-    protected function _getMenuItem ($a)
-    {
-        $aResult = parent::_getMenuItem($a);
-        if(empty($aResult) || !is_array($aResult))
-            return $aResult;
-
-        if(!empty($a['class']))
-            $aResult['class_add'] .= ' ' . $a['class'];
-
-        return $aResult;
-    }
-
     protected function loadData()
     {
         $sClassHidden = 'bx-menu-add-relation-hidden';
@@ -61,33 +49,32 @@ class BxBaseMenuAddRelation extends BxTemplMenu
         if(bx_get('profile_id') !== false)
             $this->_iContent = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
 
-        $aSuggestions = array();
+        $aSuggestions = [];
         $aRelations = BxDolConnection::getObjectInstance($this->_sConnection)->getRelations($this->_iInitiator, $this->_iContent, $aSuggestions);
         $bSuggestions = !empty($aSuggestions) && is_array($aSuggestions);
 
         $aItems = array();
         foreach($aRelations as $iId => $aRelation) {
-            $aItems[] = array(
-                'id' => $iId,
-                'name' => $iId,
-                'class' => $bSuggestions && !in_array($iId, $aSuggestions) ? $sClassHidden : '',
+            $aItems[] = [
+                'id' => 'bx-conn-rl-' . $iId,
+                'name' => 'bx-conn-rl-' . $iId,
+                'class_add' => $bSuggestions && !in_array($iId, $aSuggestions) ? $sClassHidden : '',
                 'title' => _t($aRelation[BX_DATA_VALUES_DEFAULT]),
                 'icon' => '',
                 'link' => 'javascript:void(0);',
                 'onclick' => "bx_conn_action(this, '" . $this->_sConnection . "', 'add', " . bx_js_string(json_encode(array('content' => $this->_iContent, 'relation' => $iId))) . ")"
-            );
+            ];
         }
 
         if($bSuggestions)
-            $aItems[] = array(
+            $aItems[] = [
                 'id' => 'see_more',
                 'name' => 'see_more',
-                'class' => '',
                 'title' => _t('_see_more'),
                 'icon' => '',
                 'link' => 'javascript:void(0);',
                 'onclick' => bx_js_string("$(this).parents('li:first').hide().siblings('." . $sClassHidden . "').removeClass('" . $sClassHidden . "');")
-            );
+            ];
 
         $this->_aObject['menu_items'] = $aItems;
     }

+ 2 - 2
template/scripts/BxBaseServiceConnections.php

@@ -352,7 +352,7 @@ class BxBaseServiceConnections extends BxDol
      */
     public function serviceRelationsTable ($iProfileId = 0)
     {
-        if(!BxDolRelation::isEnabled())
+        if(!BxDolConnectionRelation::isEnabled())
             return false;
 
         if(!$iProfileId && bx_get('profile_id') !== false)
@@ -389,7 +389,7 @@ class BxBaseServiceConnections extends BxDol
      */
     public function serviceRelatedMeTable ($iProfileId = 0)
     {
-        if(!BxDolRelation::isEnabled())
+        if(!BxDolConnectionRelation::isEnabled())
             return false;
 
         if(!$iProfileId && bx_get('profile_id') !== false)

+ 21 - 0
template/scripts_templ/BxTemplConnectionRelation.php

@@ -0,0 +1,21 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaTemplate UNA Template Classes
+ * @{
+ */
+
+/**
+ * @see BxDolConnection
+ */
+class BxTemplConnectionRelation extends BxBaseConnectionRelation
+{
+    protected function __construct($aObject)
+    {
+        parent::__construct($aObject);
+    }
+}
+
+/** @} */