Procházet zdrojové kódy

Ticket #622 - Base functionality.

AntonLV před 9 roky
rodič
revize
d7cfd0db09

+ 101 - 0
inc/classes/BxDolGridSubscribedMe.php

@@ -0,0 +1,101 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaCore UNA Core
+ * @{
+ */
+
+require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
+
+class BxDolGridSubscribedMe extends BxTemplGrid
+{
+    protected $_bOwner = false;
+    protected $_sObjectConnections = 'sys_profiles_subscriptions';
+    protected $_oConnection;
+
+    public function __construct ($aOptions, $oTemplate = false)
+    {
+        parent::__construct ($aOptions, $oTemplate);
+        $this->_sDefaultSortingOrder = 'DESC';
+
+        $this->_oConnection = BxDolConnection::getObjectInstance($this->_sObjectConnections);
+        if (!$this->_oConnection)
+            return;
+
+        $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
+        if (!$iProfileId)
+            return;
+
+        $oProfile = BxDolProfile::getInstance($iProfileId);
+        if (!$oProfile)
+            return;
+
+        if ($oProfile->id() == bx_get_logged_profile_id())
+            $this->_bOwner = true;
+
+        $aSQLParts = $this->_oConnection->getConnectedInitiatorsAsSQLParts('p', 'id', $oProfile->id());
+
+        $this->addMarkers(array(
+            'profile_id' => $oProfile->id(),
+            'join_connections' => $aSQLParts['join']
+        ));
+    }
+
+    /**
+     * 'accept' action handler
+     */
+    public function performActionSubscribe()
+    {
+        list($iId, $iViewedId) = $this->_prepareIds();
+        if(!$iId)
+            return echoJson(array('msg' => _t('_sys_txt_error_occured')));
+
+        $a = $this->_oConnection->actionAdd($iId, $iViewedId);
+        if(!empty($a['err']))
+            return echoJson(array('msg' => $a['msg']));
+
+        return echoJson(array('grid' => $this->getCode(false), 'blink' => $iId));
+    }
+
+    protected function _getCellName ($mixedValue, $sKey, $aField, $aRow)
+    {
+        $oProfile = BxDolProfile::getInstance($aRow['id']);
+        if (!$oProfile)
+            return _t('_sys_txt_error_occured');
+
+        return parent::_getCellDefault ($oProfile->getUnit(), $sKey, $aField, $aRow);
+    }
+
+    protected function _getActionSubscribe ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
+    {
+        if(!isLogged() || $this->_oConnection->isConnected(bx_get_logged_profile_id(), $aRow['id']))
+            return '';
+
+        return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
+    }
+
+    protected function _prepareIds ()
+    {
+        $iViewedId = bx_get_logged_profile_id();
+
+        $iId = 0;
+        $aIds = bx_get('ids');
+        if($aIds && is_array($aIds))
+            $mixedId = array_pop($aIds);
+
+        if(strpos($mixedId, ':') !== false) {
+            list($iId, $iViewedId) = explode (':', $mixedId);
+
+            $iId = (int)$iId;
+            $iViewedId = (int)$iViewedId;
+        }
+        else 
+            $iId = (int)$mixedId;
+
+        return array($iId, $iViewedId);
+    }
+}
+
+/** @} */

+ 95 - 0
inc/classes/BxDolGridSubscriptions.php

@@ -0,0 +1,95 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaCore UNA Core
+ * @{
+ */
+
+require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
+
+class BxDolGridSubscriptions extends BxTemplGrid
+{
+    protected $_bOwner = false;
+    protected $_sObjectConnections = 'sys_profiles_subscriptions';
+    protected $_oConnection;
+
+    public function __construct ($aOptions, $oTemplate = false)
+    {
+        parent::__construct ($aOptions, $oTemplate);
+        $this->_sDefaultSortingOrder = 'DESC';
+
+        $this->_oConnection = BxDolConnection::getObjectInstance($this->_sObjectConnections);
+        if (!$this->_oConnection)
+            return;
+
+        $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
+        if (!$iProfileId)
+            return;
+
+        $oProfile = BxDolProfile::getInstance($iProfileId);
+        if (!$oProfile)
+            return;
+
+        if ($oProfile->id() == bx_get_logged_profile_id())
+            $this->_bOwner = true;
+
+        $aSQLParts = $this->_oConnection->getConnectedContentAsSQLParts('p', 'id', $oProfile->id());
+
+        $this->addMarkers(array(
+            'profile_id' => $oProfile->id(),
+            'join_connections' => $aSQLParts['join']
+        ));
+    }
+
+    protected function _delete ($mixedId)
+    {
+        list($iId, $iViewedId) = $this->_prepareIds();
+
+        if(!$this->_oConnection->isConnected($iViewedId, $iId))
+            return true;
+
+        return $this->_oConnection->removeConnection($iViewedId, $iId);
+    }
+
+    protected function _getCellName ($mixedValue, $sKey, $aField, $aRow)
+    {
+        $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 (!isLogged() || !$this->_bOwner)
+            return '';
+
+        return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
+    }
+
+    protected function _prepareIds ()
+    {
+        $iViewedId = bx_get_logged_profile_id();
+
+        $iId = 0;
+        $aIds = bx_get('ids');
+        if($aIds && is_array($aIds))
+            $mixedId = array_pop($aIds);
+
+        if(strpos($mixedId, ':') !== false) {
+            list($iId, $iViewedId) = explode (':', $mixedId);
+
+            $iId = (int)$iId;
+            $iViewedId = (int)$iViewedId;
+        }
+        else 
+            $iId = (int)$mixedId;
+
+        return array($iId, $iViewedId);
+    }
+}
+
+/** @} */

+ 15 - 3
install/sql/system.sql

@@ -3455,17 +3455,29 @@ INSERT INTO `sys_grid_actions` (`object`, `type`, `name`, `title`, `icon`, `icon
 
 
 -- GRID: connections
 -- GRID: connections
 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`, `visible_for_levels`, `override_class_name`, `override_class_file`) VALUES
 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`, `visible_for_levels`, `override_class_name`, `override_class_file`) VALUES
-('sys_grid_connections', 'Sql', 'SELECT `p`.`id`, `c`.`added`, `c`.`mutual` FROM `sys_profiles` AS `p` INNER JOIN `sys_accounts` AS `a` ON (`a`.`id` = `p`.`account_id`) {join_connections}', 'sys_profiles', 'id', 'c`.`added', '', '', 10, NULL, 'start', '', 'name,email', '', 'auto', '', '', 2147483647, 'BxDolGridConnections', '');
+('sys_grid_connections', 'Sql', 'SELECT `p`.`id`, `c`.`added`, `c`.`mutual` FROM `sys_profiles` AS `p` INNER JOIN `sys_accounts` AS `a` ON (`a`.`id` = `p`.`account_id`) {join_connections}', 'sys_profiles', 'id', 'c`.`added', '', '', 10, NULL, 'start', '', 'name,email', '', 'auto', '', '', 2147483647, 'BxDolGridConnections', ''),
+('sys_grid_subscriptions', 'Sql', 'SELECT `p`.`id`, `c`.`added` FROM `sys_profiles` AS `p` INNER JOIN `sys_accounts` AS `a` ON (`a`.`id` = `p`.`account_id`) {join_connections}', 'sys_profiles', 'id', 'c`.`added', '', '', 10, NULL, 'start', '', 'name,email', '', 'auto', '', '', 2147483647, 'BxDolGridSubscriptions', ''),
+('sys_grid_subscribed_me', 'Sql', 'SELECT `p`.`id`, `c`.`added` FROM `sys_profiles` AS `p` INNER JOIN `sys_accounts` AS `a` ON (`a`.`id` = `p`.`account_id`) {join_connections}', 'sys_profiles', 'id', 'c`.`added', '', '', 10, NULL, 'start', '', 'name,email', '', 'auto', '', '', 2147483647, 'BxDolGridSubscribedMe', '');
 
 
 INSERT INTO `sys_grid_fields` (`object`, `name`, `title`, `width`, `params`, `order`) VALUES
 INSERT INTO `sys_grid_fields` (`object`, `name`, `title`, `width`, `params`, `order`) VALUES
 ('sys_grid_connections', 'name', '_sys_name', '40%', '', 1),
 ('sys_grid_connections', 'name', '_sys_name', '40%', '', 1),
 ('sys_grid_connections', 'info', '', '30%', '', 2),
 ('sys_grid_connections', 'info', '', '30%', '', 2),
-('sys_grid_connections', 'actions', '', '30%', '', 3);
+('sys_grid_connections', 'actions', '', '30%', '', 3),
+
+('sys_grid_subscriptions', 'name', '_sys_name', '70%', '', 1),
+('sys_grid_subscriptions', 'actions', '', '30%', '', 2),
+
+('sys_grid_subscribed_me', 'name', '_sys_name', '70%', '', 1),
+('sys_grid_subscribed_me', 'actions', '', '30%', '', 2);
 
 
 INSERT INTO `sys_grid_actions` (`object`, `type`, `name`, `title`, `icon`, `confirm`, `order`) VALUES
 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', 'accept', '_sys_accept', '', 0, 1),
 ('sys_grid_connections', 'single', 'delete', '', 'remove', 1, 2),
 ('sys_grid_connections', 'single', 'delete', '', 'remove', 1, 2),
-('sys_grid_connections', 'single', 'add_friend', '_sys_add_friend', 'plus', 0, 3);
+('sys_grid_connections', 'single', 'add_friend', '_sys_add_friend', 'plus', 0, 3),
+
+('sys_grid_subscriptions', 'single', 'delete', '', 'remove', 1, 1),
+
+('sys_grid_subscribed_me', 'single', 'subscribe', '_sys_subscribe', 'check', 0, 1);
 
 
 -- --------------------------------------------------------
 -- --------------------------------------------------------
 
 

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

@@ -2258,6 +2258,7 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_storage_restriction_size"><![CDATA[Maximum file size limit is {0}]]></string>
 	<string name="_sys_storage_restriction_size"><![CDATA[Maximum file size limit is {0}]]></string>
 	<string name="_sys_switch_profile"><![CDATA[Switch profile]]></string>
 	<string name="_sys_switch_profile"><![CDATA[Switch profile]]></string>
 	<string name="_sys_submit"><![CDATA[Submit]]></string>
 	<string name="_sys_submit"><![CDATA[Submit]]></string>
+	<string name="_sys_subscribe"><![CDATA[Subscribe]]></string>
 
 
 	<string name="_sys_tour_launcher_welcome_title"><![CDATA[Welcome to UNA Studio!]]></string>
 	<string name="_sys_tour_launcher_welcome_title"><![CDATA[Welcome to UNA Studio!]]></string>
 	<string name="_sys_tour_launcher_welcome_txt"><![CDATA[Studio is where you customise your site; add and manage apps; control languages and design; set membership levels and permissions; build pages and navigation, and a lot more. You are now in Studio Launcher.]]></string>
 	<string name="_sys_tour_launcher_welcome_txt"><![CDATA[Studio is where you customise your site; add and manage apps; control languages and design; set membership levels and permissions; build pages and navigation, and a lot more. You are now in Studio Launcher.]]></string>

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

@@ -2256,6 +2256,7 @@
 	<string name="_sys_storage_restriction_size"><![CDATA[Максимальный разрешённый размер файла {0}]]></string>
 	<string name="_sys_storage_restriction_size"><![CDATA[Максимальный разрешённый размер файла {0}]]></string>
 	<string name="_sys_switch_profile"><![CDATA[Переключить профиль]]></string>
 	<string name="_sys_switch_profile"><![CDATA[Переключить профиль]]></string>
 	<string name="_sys_submit"><![CDATA[Выполнить]]></string>
 	<string name="_sys_submit"><![CDATA[Выполнить]]></string>
+	<string name="_sys_subscribe"><![CDATA[Подписаться]]></string>
 
 
 
 
 	<string name="_sys_tour_launcher_welcome_title"><![CDATA[Добро пожаловать в UNA Студию!]]></string>
 	<string name="_sys_tour_launcher_welcome_title"><![CDATA[Добро пожаловать в UNA Студию!]]></string>

+ 72 - 0
template/scripts/BxBaseServiceConnections.php

@@ -53,6 +53,78 @@ class BxBaseServiceConnections extends BxDol
         return $i;
         return $i;
     }
     }
 
 
+    /**
+     * get number of initiated connections (like "my subscriptions")
+     * @param $sConnectionsObject connections object to get connections from
+     * @param $mixedId id to get connections for, if omitted then logged-in profile id is used
+     * @return number
+     */
+    public function serviceGetConnectedContentNum ($sConnectionsObject, $mixedId = 0)
+    {
+        $oConnection = BxDolConnection::getObjectInstance($sConnectionsObject);
+        if (!$oConnection)
+            return 0;
+
+        if (!$mixedId)
+            $mixedId = bx_get_logged_profile_id();
+
+        $i = 0;
+        $a = $oConnection->getConnectedContent($mixedId); // get received friend requests
+        foreach ($a as $iId)
+            if (BxDolProfile::getInstance($iId))
+                ++$i;
+
+        return $i;
+    }
+
+    /**
+     * get number of received connections (like "subscribed me")
+     * @param $sConnectionsObject connections object to get connections from
+     * @param $mixedId id to get connections for, if omitted then logged-in profile id is used
+     * @return number
+     */
+    public function serviceGetConnectedInitiatorsNum ($sConnectionsObject, $mixedId = 0)
+    {
+        $oConnection = BxDolConnection::getObjectInstance($sConnectionsObject);
+        if (!$oConnection)
+            return 0;
+
+        if (!$mixedId)
+            $mixedId = bx_get_logged_profile_id();
+
+        $i = 0;
+        $a = $oConnection->getConnectedInitiators($mixedId); // get received friend requests
+        foreach ($a as $iId)
+            if (BxDolProfile::getInstance($iId))
+                ++$i;
+
+        return $i;
+    }
+
+	/**
+     * get grid with subscriptions connections
+     */
+    public function serviceSubscriptionsTable ()
+    {
+        $oGrid = BxDolGrid::getObjectInstance('sys_grid_subscriptions');
+        if (!$oGrid)
+            return false;
+
+        return $oGrid->getCode();
+    }
+
+	/**
+     * get grid with subscribed me connections
+     */
+    public function serviceSubscribedMeTable ()
+    {
+        $oGrid = BxDolGrid::getObjectInstance('sys_grid_subscribed_me');
+        if (!$oGrid)
+            return false;
+
+        return $oGrid->getCode();
+    }
+
     /*
     /*
      * Get notification data for Notifications module. 
      * Get notification data for Notifications module. 
      */
      */