소스 검색

#43 - friend requests in profile popup

Alex Trofimov 12 년 전
부모
커밋
2f50beb3eb

+ 19 - 18
inc/classes/BxDolConnection.php

@@ -157,8 +157,11 @@ class BxDolConnection extends BxDol implements iBxDolFactoryObject {
      * @param $iContent content to make connection to, in most cases some content id, or other profile id in case of friends
      * @return array
      */ 
-    public function actionAdd () {
-        return $this->_action ('addConnection', '_sys_conn_err_connection_already_exists', false, true);
+    public function actionAdd ($iContent = 0) {
+        if (!$iContent)
+            $iContent = bx_process_input($_POST['id'], BX_DATA_INT);
+
+        return $this->_action (bx_get_logged_profile_id(), $iContent, 'addConnection', '_sys_conn_err_connection_already_exists', true);
     }
 
     /**
@@ -166,11 +169,15 @@ class BxDolConnection extends BxDol implements iBxDolFactoryObject {
      * @param $iContent content to make connection to, in most cases some content id, or other profile id in case of friends
      * @return array
      */ 
-    public function actionRemove () {
-        $a = $this->actionReject();
+    public function actionRemove ($iContent = 0) {
+        if (!$iContent)
+            $iContent = bx_process_input($_POST['id'], BX_DATA_INT);
+
+        $a = $this->actionReject($iContent);
         if (false == $a['err'])
-            return $a;
-        return $this->_action ('removeConnection', '_sys_conn_err_connection_does_not_exists', false);
+            return $a;     
+
+        return $this->_action (bx_get_logged_profile_id(), $iContent, 'removeConnection', '_sys_conn_err_connection_does_not_exists');
     }
 
     /**
@@ -178,21 +185,15 @@ class BxDolConnection extends BxDol implements iBxDolFactoryObject {
      * @param $iContent content to make connection to, in most cases some content id, or other profile id in case of friends
      * @return array
      */ 
-    public function actionReject () {
-        return $this->_action ('removeConnection', '_sys_conn_err_connection_does_not_exists', true);
+    public function actionReject ($iContent = 0) {
+        if (!$iContent)
+            $iContent = bx_process_input($_POST['id'], BX_DATA_INT);
+
+        return $this->_action ($iContent, bx_get_logged_profile_id(), 'removeConnection', '_sys_conn_err_connection_does_not_exists');
     }
 
-    protected function _action ($sMethod, $sErrorKey, $bSwapInitiatorAndContent, $isMutual = false) {
+    protected function _action ($iInitiator, $iContent, $sMethod, $sErrorKey, $isMutual = false) {
         bx_import('BxDolLanguages');
-        $iContent = 0;
-        $iInitiator = 0;
-        if ($bSwapInitiatorAndContent) {
-            $iInitiator = bx_process_input($_POST['id'], BX_DATA_INT);
-            $iContent = bx_get_logged_profile_id();
-        } else {
-            $iContent = bx_process_input($_POST['id'], BX_DATA_INT);
-            $iInitiator = bx_get_logged_profile_id();
-        }
 
         if (!$iContent || !$iInitiator)
             return array ('err' => true, 'msg' => _t('_sys_conn_err_input_data_is_not_defined'));

+ 120 - 0
inc/classes/BxDolGridConnections.php

@@ -0,0 +1,120 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    Messages Messages
+ * @ingroup     DolphinModules
+ *
+ * @{
+ */
+
+require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
+
+bx_import('BxTemplGrid');
+
+class BxDolGridConnections extends BxTemplGrid 
+{
+    protected $_bOwner = false;
+    protected $_sContentModule = 'bx_persons';
+    protected $_sObjectConnections = 'sys_profiles_friends';
+
+    public function __construct ($aOptions, $oTemplate = false) 
+    {
+        parent::__construct ($aOptions, $oTemplate);
+        $this->_sDefaultSortingOrder = 'DESC';
+
+        $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
+        if (!$iContentId) 
+            return;
+
+        bx_import('BxDolProfile');
+        $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->_sContentModule);
+        if (!$oProfile)
+            return;
+
+        bx_import('BxDolConnection');
+        $oConnection = BxDolConnection::getObjectInstance($this->_sObjectConnections);
+        if (!$oConnection)
+            return;
+
+        if ($oProfile->id() == bx_get_logged_profile_id())
+            $this->_bOwner = true;
+
+        $aSQLParts = $oConnection->getConnectedInitiatorsAsSQLParts('p', 'id', $oProfile->id(), $this->_bOwner ? false : true);
+
+        $this->addMarkers(array(
+            'id' => $iContentId,
+            'join_connections' => $aSQLParts['join'],
+            'content_module' => $this->_sContentModule,
+        ));
+    }
+
+    /**
+     * 'accept' action handler
+     */
+    public function performActionAccept() 
+    {
+        $iId = 0;
+        $aIds = bx_get('ids');
+        if ($aIds && is_array($aIds))
+            $iId = (int)array_pop($aIds);
+/*
+        if (!$iId)
+            $iId = (int)bx_get('ID');
+*/
+
+        if (!$iId) {
+            $this->_echoResultJson(array('msg' => _t('_sys_txt_error_occured')), true);
+            exit;
+        }
+
+        bx_import('BxDolConnection');
+        $oConn = BxDolConnection::getObjectInstance($this->_sObjectConnections);
+
+        $a = $oConn->actionAdd($iId);
+        if (isset($a['err']) && $a['err'])
+            $this->_echoResultJson(array('msg' => $a['msg']), true);
+        else
+            $this->_echoResultJson(array('grid' => $this->getCode(false), 'blink' => $iId), true);
+    }
+
+    protected function _delete ($mixedId) {
+        bx_import('BxDolConnection');
+        $oConn = BxDolConnection::getObjectInstance($this->_sObjectConnections);
+
+        if ($oConn->isConnected(bx_get_logged_profile_id(), (int)$mixedId, true))
+            $a = $oConn->actionRemove($mixedId);
+        else
+            $a = $oConn->actionReject($mixedId);
+
+        return isset($a['err']) && $a['err'] ? false : true;
+    }
+
+    protected function _getCellName ($mixedValue, $sKey, $aField, $aRow)
+    {
+        bx_import('BxDolProfile');
+        $oProfile = BxDolProfile::getInstance($aRow['id']);
+        if (!$oProfile)
+            return _t('_sys_txt_error_occured');
+        
+        return parent::_getCellDefault ($oProfile->getUnit(), $sKey, $aField, $aRow);
+    }
+
+    protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
+    {
+        if (!$this->_bOwner)
+            return '';
+        return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
+    }
+
+    protected function _getActionAccept ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
+    {
+        if (!$this->_bOwner || $aRow['mutual'])
+            return '';
+
+        return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
+    }
+}
+
+/** @} */

+ 15 - 0
install/sql/system.sql

@@ -2911,6 +2911,8 @@ CREATE TABLE IF NOT EXISTS `sys_objects_grid` (
   UNIQUE KEY `object` (`object`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
 
+-- GRIDS: studio
+
 INSERT INTO `sys_objects_grid` (`object`, `source_type`, `source`, `table`, `field_id`, `field_order`, `field_active`, `paginate_url`, `paginate_per_page`, `paginate_simple`, `paginate_get_start`, `paginate_get_per_page`, `filter_fields`, `filter_fields_translatable`, `filter_mode`, `sorting_fields`, `sorting_fields_translatable`, `override_class_name`, `override_class_file`) VALUES
 ('sys_studio_lang_keys', 'Sql', 'SELECT `tlk`.`ID` AS `id`, `tlk`.`Key` AS `key`, `tlc`.`Name` AS `module`, `tls`.`String` AS `string` FROM `sys_localization_keys` AS `tlk` LEFT JOIN `sys_localization_categories` AS `tlc` ON `tlk`.`IDCategory`=`tlc`.`ID` LEFT JOIN `sys_localization_strings` AS `tls` ON `tlk`.`ID`=`tls`.`IDKey` WHERE `tls`.`IDLanguage`=\'%d\'', 'sys_localization_keys', 'id', '', '', '', 20, NULL, 'start', '', 'key,string', '', 'like', 'key,module,string', '', 'BxTemplStudioPolyglotKeys', ''),
 ('sys_studio_lang_etemplates', 'Sql', 'SELECT * FROM `sys_email_templates` WHERE 1 ', 'sys_email_templates', 'ID', '', '', '', 20, NULL, 'start', '', 'Module', 'NameSystem,Subject,Body', 'auto', 'Module', 'NameSystem', 'BxTemplStudioPolyglotEtemplates', ''),
@@ -3061,6 +3063,19 @@ INSERT INTO `sys_grid_actions` (`object`, `type`, `name`, `title`, `icon`, `conf
 ('sys_studio_forms_pre_values', 'single', 'edit', '', 'pencil', 0, 1),
 ('sys_studio_forms_pre_values', 'single', 'delete', '', 'remove', 1, 2);
 
+-- GRID: connections
+
+INSERT INTO `sys_objects_grid` (`object`, `source_type`, `source`, `table`, `field_id`, `field_order`, `paginate_url`, `paginate_per_page`, `paginate_simple`, `paginate_get_start`, `paginate_get_per_page`, `filter_fields`, `filter_mode`, `sorting_fields`, `visible_for_levels`, `override_class_name`, `override_class_file`) VALUES
+('sys_grid_connections', 'Sql', 'SELECT `p`.`id`, `added`, `mutual` FROM `sys_profiles` AS `p` {join_connections}', 'sys_profiles', 'id', 'added', '', 10, NULL, 'start', '', 'fullname', 'auto', '', 2147483647, 'BxDolGridConnections', '');
+
+INSERT INTO `sys_grid_fields` (`object`, `name`, `title`, `width`, `params`, `order`) VALUES
+('sys_grid_connections', 'name', '_sys_name', '70%', '', 1),
+('sys_grid_connections', 'actions', '', '30%', '', 2);
+
+INSERT INTO `sys_grid_actions` (`object`, `type`, `name`, `title`, `icon`, `confirm`, `order`) VALUES
+('sys_grid_connections', 'single', 'accept', '_sys_accept', '', 0, 1),
+('sys_grid_connections', 'single', 'delete', '', 'remove', 1, 2);
+
 
 -- --------------------------------------------------------
 

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

@@ -1333,6 +1333,7 @@
 	<string name="_powered_by"><![CDATA[Powered by]]></string>
 	<string name="_see_more"><![CDATA[see more]]></string>
 	<string name="_show_replacement"><![CDATA[Show]]></string>
+	<string name="_sys_accept"><![CDATA[Accept]]></string>
 	<string name="_sys_access_denied_to_private_content"><![CDATA[Access denied. This is private content.]]></string>
 	<string name="_sys_actions"><![CDATA[Actions]]></string>
 	<string name="_sys_active"><![CDATA[Active]]></string>
@@ -1755,6 +1756,7 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_mobile_profile_info"><![CDATA[Profile Info]]></string>
 	<string name="_sys_mobile_search"><![CDATA[Search]]></string>
 	<string name="_sys_mobile_status"><![CDATA[Status]]></string>
+    <string name="_sys_name"><![CDATA[Name]]></string>
     <string name="_sys_on"><![CDATA[on]]></string>
     <string name="_sys_off"><![CDATA[off]]></string>
 	<string name="_sys_page_block_title_about"><![CDATA[About]]></string>

+ 6 - 0
modules/boonex/persons/install/langs/en.xml

@@ -53,6 +53,8 @@
 	<string name="_bx_persons_page_title_sys_view_profile"><![CDATA[View Person's Profile]]></string>
 	<string name="_bx_persons_page_title_view_profile"><![CDATA[{display_name}]]></string>
 	<string name="_bx_persons_page_title_browse_recent"><![CDATA[Persons]]></string>
+	<string name="_bx_persons_page_title_sys_profile_friends"><![CDATA[Friends]]></string>
+	<string name="_bx_persons_page_title_profile_friends"><![CDATA[Friends]]></string>
 	<string name="_bx_persons_page_title_sys_profile_info"><![CDATA[Profile Info]]></string>
 	<string name="_bx_persons_page_title_profile_info"><![CDATA[Info about {display_name}]]></string>
 
@@ -80,6 +82,8 @@
     <string name="_bx_persons_menu_item_title_persons_profile"><![CDATA[Person]]></string>
     <string name="_bx_persons_menu_item_title_system_create_person"><![CDATA[Create Person]]></string>
     <string name="_bx_persons_menu_item_title_create_person"><![CDATA[Create Person]]></string>
+    <string name="_bx_persons_menu_item_title_system_view_person_friends"><![CDATA[Friends]]></string>
+    <string name="_bx_persons_menu_item_title_view_person_friends"><![CDATA[Friends]]></string>
     <string name="_bx_persons_menu_item_title_system_view_person_info"><![CDATA[Info]]></string>
     <string name="_bx_persons_menu_item_title_view_person_info"><![CDATA[Info]]></string>
     <string name="_bx_persons_menu_item_title_system_befriend"><![CDATA[Add friend]]></string>
@@ -96,6 +100,8 @@
     <string name="_bx_persons_menu_item_title_unsubscribe"><![CDATA[Unsubscribe]]></string>
     <string name="_bx_persons_menu_item_title_system_more_actions"><![CDATA[More Actions]]></string>
     <string name="_bx_persons_menu_item_title_more_actions"><![CDATA[]]></string>
+    <string name="_bx_persons_menu_item_title_system_friend_requests"><![CDATA[Friend requests]]></string>
+    <string name="_bx_persons_menu_item_title_friend_requests"><![CDATA[Friend requests]]></string>
 
     <string name="_bx_persons_txt_account_pending"><![CDATA[This profile is pending approval, please wait until it is activated.]]></string>
     <string name="_bx_persons_txt_account_suspended"><![CDATA[This profile is suspended.]]></string>

+ 2 - 2
modules/boonex/persons/install/sql/disable.sql

@@ -25,7 +25,7 @@ DELETE FROM `sys_objects_uploader` WHERE `object` IN('bx_persons_avatar', 'bx_pe
 -- PAGES
 
 DELETE FROM `sys_objects_page` WHERE `module` = 'bx_persons';
-DELETE FROM `sys_pages_blocks` WHERE `module` = 'bx_persons' OR `object` IN('bx_persons_create_profile', 'bx_persons_delete_profile', 'bx_persons_edit_profile', 'bx_persons_edit_profile_cover', 'bx_persons_view_profile', 'bx_persons_profile_info');
+DELETE FROM `sys_pages_blocks` WHERE `module` = 'bx_persons' OR `object` IN('bx_persons_create_profile', 'bx_persons_delete_profile', 'bx_persons_edit_profile', 'bx_persons_edit_profile_cover', 'bx_persons_view_profile', 'bx_persons_profile_info', 'bx_persons_profile_friends');
 
 -- MENU
 
@@ -38,4 +38,4 @@ DELETE `sys_acl_actions`, `sys_acl_matrix` FROM `sys_acl_actions`, `sys_acl_matr
 DELETE FROM `sys_acl_actions` WHERE `Module` = 'bx_persons';
 
 -- VIEWS
-DELETE FROM `sys_objects_view` WHERE `Name`='bx_persons';
+DELETE FROM `sys_objects_view` WHERE `Name`='bx_persons';

+ 14 - 1
modules/boonex/persons/install/sql/enable.sql

@@ -107,6 +107,14 @@ INSERT INTO `sys_objects_page`(`object`, `uri`, `title_system`, `title`, `module
 INSERT INTO `sys_pages_blocks`(`object`, `cell_id`, `module`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `order`) VALUES 
 ('bx_persons_profile_info', 1, 'bx_persons', '_bx_persons_page_block_title_profile_info', 11, 2147483647, 'service', 'a:2:{s:6:\"module\";s:10:\"bx_persons\";s:6:\"method\";s:12:\"profile_info\";}', 0, 0, 1);
 
+--
+-- Dumping data for 'bx_persons_profile_friends' page
+--
+INSERT INTO `sys_objects_page`(`object`, `uri`, `title_system`, `title`, `module`, `layout_id`, `visible_for_levels`, `visible_for_levels_editable`, `url`, `meta_description`, `meta_keywords`, `meta_robots`, `cache_lifetime`, `cache_editable`, `deletable`, `override_class_name`, `override_class_file`) VALUES 
+('bx_persons_profile_friends', 'persons-profile-friends', '_bx_persons_page_title_sys_profile_friends', '_bx_persons_page_title_profile_friends', 'bx_persons', 5, 2147483647, 1, 'page.php?i=persons-profile-friends', '', '', '', 0, 1, 0, 'BxPersonsPageProfile', 'modules/boonex/persons/classes/BxPersonsPageProfile.php');
+
+INSERT INTO `sys_pages_blocks`(`object`, `cell_id`, `module`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `order`) VALUES 
+('bx_persons_profile_friends', 1, 'bx_persons', '_bx_persons_page_block_title_profile_friends', 11, 2147483647, 'service', 'a:3:{s:6:\"module\";s:6:\"system\";s:6:\"method\";s:17:\"connections_table\";s:5:\"class\";s:23:\"TemplServiceConnections\";}', 0, 0, 1);
 
 
 -- Homepage
@@ -164,9 +172,14 @@ INSERT INTO `sys_menu_sets`(`set_name`, `module`, `title`, `deletable`) VALUES
 ('bx_persons_view_submenu', 'bx_persons', '_bx_persons_menu_set_title_view_person_submenu', 0);
 
 INSERT INTO `sys_menu_items`(`set_name`, `module`, `name`, `title_system`, `title`, `link`, `onclick`, `target`, `icon`, `submenu_object`, `visible_for_levels`, `active`, `copyable`, `order`) VALUES 
-('bx_persons_view_submenu', 'bx_persons', 'persons-profile-info', '_bx_persons_menu_item_title_system_view_person_info', '_bx_persons_menu_item_title_view_person_info', 'page.php?i=persons-profile-info&id={content_id}', '', '', '', '', 2147483647, 1, 0, 0);
+('bx_persons_view_submenu', 'bx_persons', 'persons-profile-info', '_bx_persons_menu_item_title_system_view_person_info', '_bx_persons_menu_item_title_view_person_info', 'page.php?i=persons-profile-info&id={content_id}', '', '', '', '', 2147483647, 1, 0, 0),
+('bx_persons_view_submenu', 'bx_persons', 'persons-profile-friends', '_bx_persons_menu_item_title_system_view_person_friends', '_bx_persons_menu_item_title_view_person_friends', 'page.php?i=persons-profile-friends&id={content_id}', '', '', '', '', 2147483647, 1, 0, 1);
 
 
+-- notifications menu in account popup
+SET @iNotifMenuOrder = (SELECT `order` FROM `sys_menu_items` WHERE `set_name` = 'sys_account_notifications' AND `active` = 1 ORDER BY `order` DESC LIMIT 1);
+INSERT INTO `sys_menu_items` (`set_name`, `module`, `name`, `title_system`, `title`, `link`, `onclick`, `target`, `icon`, `addon`, `submenu_object`, `visible_for_levels`, `active`, `copyable`, `order`) VALUES
+('sys_account_notifications', 'bx_persons', 'notifications-friend-requests', '_bx_persons_menu_item_title_system_friend_requests', '_bx_persons_menu_item_title_friend_requests', 'page.php?i=persons-profile-friends&id={profile_id}', '', '', 'users', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:21:"profile_notifications";s:6:"params";a:1:{i:0;s:20:"sys_profiles_friends";}s:5:"class";s:23:"TemplServiceConnections";}', '', 2147483646, 1, 0, IFNULL(@iAddMenuOrder, 0) + 1);
 
 
 -- ACL

+ 23 - 0
modules/boonex/uni/data/template/system/scripts/BxTemplServiceConnections.php

@@ -0,0 +1,23 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    DolphinCore Dolphin Core
+ * @{
+ */
+
+bx_import('BxBaseServiceConnections');
+
+/**
+ * @see BxBaseServiceLogin
+ */
+class BxTemplServiceConnections extends BxBaseServiceConnections 
+{
+    public function __construct() 
+    {
+        parent::__construct();
+    }
+}
+
+/** @} */

+ 4 - 0
template/css/grid.css

@@ -79,3 +79,7 @@ div.bx-grid-drag-handle {
 td:last-child .bx-grid-cell-single-actions-wrapper {
     float:right;
 }
+
+.bx-grid-table-wrapper td .bx-def-unit {
+    margin:0;
+}

+ 58 - 0
template/scripts/BxBaseServiceConnections.php

@@ -0,0 +1,58 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    DolphinCore Dolphin Core
+ * @{
+ */
+
+/**
+ * System services for connections.
+ */
+class BxBaseServiceConnections extends BxDol {
+
+    public function __construct() {
+        parent::__construct();
+    }
+
+    /**
+     * get grid with friends connections
+     */
+    public function serviceConnectionsTable ()
+    {
+        bx_import('BxDolGrid'); 
+        $oGrid = BxDolGrid::getObjectInstance('sys_grid_connections');
+        if (!$oGrid)
+            return false;
+
+        return $oGrid->getCode();
+    }
+
+    /**
+     * 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
+     * @return number
+     */
+    public function serviceGetUnconfirmedConnectionsNum ($sConnectionsObject, $mixedId = 0)
+    {
+        bx_import('BxDolConnection');
+        $oConnection = BxDolConnection::getObjectInstance($sConnectionsObject);
+        if (!$oConnection)
+            return 0;
+
+        if (!$mixedId)
+            $mixedId = bx_get_logged_profile_id();
+
+        $i = 0;
+        $a = $oConnection->getConnectedInitiators($mixedId, 0); // get received friend requests
+        foreach ($a as $iId)
+            if (BxDolProfile::getInstance($iId))
+                ++$i;
+
+        return $i;
+    }
+}
+
+/** @} */