Alex Trofimov 10 лет назад
Родитель
Сommit
3a2c9be288

+ 13 - 18
inc/classes/BxDolGridConnections.php

@@ -14,12 +14,17 @@ class BxDolGridConnections extends BxTemplGrid
     protected $_bOwner = false;
     protected $_sContentModule = 'bx_persons';
     protected $_sObjectConnections = 'sys_profiles_friends';
+    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;
@@ -28,14 +33,10 @@ class BxDolGridConnections extends BxTemplGrid
         if (!$oProfile)
             return;
 
-        $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);
+        $aSQLParts = $this->_oConnection->getConnectedInitiatorsAsSQLParts('p', 'id', $oProfile->id(), $this->_bOwner ? false : true);
 
         $this->addMarkers(array(
             'profile_id' => $oProfile->id(),
@@ -56,9 +57,7 @@ class BxDolGridConnections extends BxTemplGrid
             exit;
         }
 
-        $oConn = BxDolConnection::getObjectInstance($this->_sObjectConnections);
-
-        $a = $oConn->actionAdd($iId, $iViewedId);
+        $a = $this->_oConnection->actionAdd($iId, $iViewedId);
         if (isset($a['err']) && $a['err'])
             echoJson(array('msg' => $a['msg']));
         else
@@ -77,12 +76,10 @@ class BxDolGridConnections extends BxTemplGrid
     {
         list ($iId, $iViewedId) = $this->_prepareIds();
 
-        $oConn = BxDolConnection::getObjectInstance($this->_sObjectConnections);
-
-        if ($oConn->isConnected($iViewedId, $iId, true))
-            $a = $oConn->actionRemove($iId, $iViewedId);
+        if ($this->_oConnection->isConnected($iViewedId, $iId, true))
+            $a = $this->_oConnection->actionRemove($iId, $iViewedId);
         else
-            $a = $oConn->actionReject($iId, $iViewedId);
+            $a = $this->_oConnection->actionReject($iId, $iViewedId);
 
         return isset($a['err']) && $a['err'] ? false : true;
     }
@@ -99,11 +96,10 @@ class BxDolGridConnections extends BxTemplGrid
     protected function _getCellInfo ($mixedValue, $sKey, $aField, $aRow)
     {
         $s = '';
-        $oConn = BxDolConnection::getObjectInstance($this->_sObjectConnections);
 
         // for friend requests display mutual friends
         if ($this->_bOwner && !$aRow['mutual']) {
-            $a = $oConn->getCommonContent($aRow['id'], bx_get_logged_profile_id(), true);
+            $a = $this->_oConnection->getCommonContent($aRow['id'], bx_get_logged_profile_id(), true);
             $i = count($a);
             if (1 == $i) {
                 $iProfileId = array_pop($a);
@@ -116,7 +112,7 @@ class BxDolGridConnections extends BxTemplGrid
 
         // display friends number if no other info is available
         if (!$s) {
-            $a = $oConn->getConnectedContent($aRow['id'], true);
+            $a = $this->_oConnection->getConnectedContent($aRow['id'], true);
             $i = count($a);
             $s = _t('_sys_txt_n_friends', $i);
         }
@@ -144,8 +140,7 @@ class BxDolGridConnections extends BxTemplGrid
         if ($this->_bOwner || $aRow['id'] == bx_get_logged_profile_id())
             return '';
 
-        $oConn = BxDolConnection::getObjectInstance($this->_sObjectConnections);
-        if ($oConn->isConnected($aRow['id'], bx_get_logged_profile_id()) || $oConn->isConnected(bx_get_logged_profile_id(), $aRow['id']))
+        if ($this->_oConnection->isConnected($aRow['id'], bx_get_logged_profile_id()) || $this->_oConnection->isConnected(bx_get_logged_profile_id(), $aRow['id']))
             return '';
 
         return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);

+ 2 - 0
modules/boonex/groups/classes/BxGroupsConfig.php

@@ -18,6 +18,7 @@ class BxGroupsConfig extends BxBaseModProfileConfig
         $aMenuItems2Methods = array (
             'view-group-profile' => 'checkAllowedView',
             'edit-group-profile' => 'checkAllowedEdit',
+            'edit-group-cover' => 'checkAllowedChangeCover',
             'delete-group-profile' => 'checkAllowedDelete',
             'profile-fan-add' => 'checkAllowedFanAdd',
             'profile-fan-remove' => 'checkAllowedFanRemove',
@@ -33,6 +34,7 @@ class BxGroupsConfig extends BxBaseModProfileConfig
 
             // database tables
             'TABLE_ENTRIES' => $aModule['db_prefix'] . 'data',
+            'TABLE_ADMINS' => $aModule['db_prefix'] . 'admins',
 
             // database fields
             'FIELD_ID' => 'id',

+ 28 - 0
modules/boonex/groups/classes/BxGroupsDb.php

@@ -18,6 +18,34 @@ class BxGroupsDb extends BxBaseModProfileDb
     {
         parent::__construct($oConfig);
     }
+
+    public function toAdmins ($iContentId, $mixedFansIds)
+    {
+        if (is_array($mixedFansIds))
+            foreach ($mixedFansIds as $iFanId)
+                $this->toAdmins ($iFanId);
+
+        $iFanId = (int)$mixedFansIds;
+        $sQuery = $this->prepare("INSERT IGNORE INTO `" . $this->_oConfig->CNF['TABLE_ADMINS'] . "` SET `content_id` = ?, `fan_id` = ?", $iContentId, $iFanId);
+        return $this->res($sQuery);
+    }
+
+    public function fromAdmins ($iContentId, $mixedFansIds)
+    {
+        if (is_array($mixedFansIds))
+            foreach ($mixedFansIds as $iFanId)
+                $this->toAdmins ($iFanId);
+
+        $iFanId = (int)$mixedFansIds;
+        $sQuery = $this->prepare("DELETE FROM `" . $this->_oConfig->CNF['TABLE_ADMINS'] . "` WHERE `content_id` = ? AND `fan_id` = ?", $iContentId, $iFanId);
+        return $this->res($sQuery);
+    }
+
+    public function isAdmin ($iContentId, $iFanId)
+    {
+        $sQuery = $this->prepare("SELECT `id` FROM `" . $this->_oConfig->CNF['TABLE_ADMINS'] . "` WHERE `content_id` = ? AND `fan_id` = ?", $iContentId, $iFanId);
+        return $this->getOne($sQuery) ? true : false;
+    }
 }
 
 /** @} */

+ 71 - 7
modules/boonex/groups/classes/BxGroupsGridConnections.php

@@ -12,6 +12,8 @@
 class BxGroupsGridConnections extends BxDolGridConnections
 {
     protected $_iContentId;
+    protected $_oModule;
+    protected $_oConnection;
 
     public function __construct ($aOptions, $oTemplate = false)
     {
@@ -28,19 +30,15 @@ class BxGroupsGridConnections extends BxDolGridConnections
         if (!$oProfile)
             return;
 
-        $oConnection = BxDolConnection::getObjectInstance($this->_sObjectConnections);
-        if (!$oConnection)
-            return;
-
         $aProfileInfo = $oProfile->getInfo();
         $this->_iContentId = $aProfileInfo['content_id'];
 
-        $oModule = BxDolModule::getInstance($aProfileInfo['type']);
+        $this->_oModule = BxDolModule::getInstance($aProfileInfo['type']);
         $aContentInfo = BxDolService::call($aProfileInfo['type'], 'get_content_info_by_id', array($this->_iContentId));
-        if (CHECK_ACTION_RESULT_ALLOWED === $oModule->checkAllowedEdit($aContentInfo) || $oProfile->id() == bx_get_logged_profile_id())
+        if (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedEdit($aContentInfo) || $oProfile->id() == bx_get_logged_profile_id())
             $this->_bOwner = true;
 
-        $aSQLParts = $oConnection->getConnectedInitiatorsAsSQLParts('p', 'id', $this->_iContentId, $this->_bOwner ? false : true);
+        $aSQLParts = $this->_oConnection->getConnectedInitiatorsAsSQLParts('p', 'id', $this->_iContentId, $this->_bOwner ? false : true);
         $this->addMarkers(array(
             'profile_id' => $oProfile->id(),
             'join_connections' => $aSQLParts['join'],
@@ -63,6 +61,72 @@ class BxGroupsGridConnections extends BxDolGridConnections
 
         return parent::_getActionDelete ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
     }
+
+    protected function _getActionToAdmins ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
+    {
+        if ($this->_oModule->_oDb->isAdmin($this->_iContentId, $aRow[$this->_aOptions['field_id']]))
+            return '';
+
+        return $this->_getAction_Admins ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
+    }
+
+    protected function _getActionFromAdmins ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
+    {
+        if (!$this->_oModule->_oDb->isAdmin($this->_iContentId, $aRow[$this->_aOptions['field_id']]))
+            return '';
+
+        return $this->_getAction_Admins ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
+    }
+
+    protected function _getAction_Admins ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
+    {
+        if (!$this->_oConnection->isConnected($aRow[$this->_aOptions['field_id']], $this->_iContentId, true))
+            return '';
+
+        if (CHECK_ACTION_RESULT_ALLOWED !== $this->_oModule->checkAllowedManageAdmins($this->_iContentId))
+            return '';
+
+        if (isset($aRow[$this->_aOptions['field_id']]))
+            $a['attr']['bx_grid_action_data'] = $aRow[$this->_aOptions['field_id']] . ':' . $this->_iContentId;
+
+        return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
+    }
+
+    /**
+     * 'To Admins' action handler
+     */
+    public function performActionToAdmins()
+    {
+        $this->_performActionAdmins('toAdmins');
+    }
+
+    /**
+     * 'From Admins' action handler
+     */
+    public function performActionFromAdmins()
+    {
+        $this->_performActionAdmins('fromAdmins');
+    }
+
+    public function _performActionAdmins($sFunc)
+    {
+        list ($iId, $iContentId) = $this->_prepareIds();
+
+        if (!$iId) {
+            echoJson(array('msg' => _t('_sys_txt_error_occured')));
+            exit;
+        }
+
+        if (CHECK_ACTION_RESULT_ALLOWED !== $this->_oModule->checkAllowedManageAdmins($iContentId)) {
+            echoJson(array('msg' => _t('_sys_txt_access_denied')));
+            exit;
+        }
+    
+        if (!$this->_oModule->_oDb->$sFunc($iContentId, $iId))
+            echoJson(array('msg' => _t('_sys_txt_error_occured')));
+        else
+            echoJson(array('grid' => $this->getCode(false), 'blink' => $iId));
+    }
 }
 
 /** @} */

+ 28 - 0
modules/boonex/groups/classes/BxGroupsModule.php

@@ -77,6 +77,34 @@ class BxGroupsModule extends BxBaseModProfileModule
             return CHECK_ACTION_RESULT_ALLOWED;
         return $this->_checkAllowedConnectContent ($aDataEntry, $isPerformAction, 'bx_groups_fans', false, true, false);
     }
+
+    public function checkAllowedManageAdmins ($mixedDataEntry, $isPerformAction = false)
+    {
+        $aDataEntry = is_array($mixedDataEntry) ? $mixedDataEntry : $this->_oDb->getContentInfoById((int)$mixedDataEntry);
+
+        return parent::checkAllowedEdit ($aDataEntry, $isPerformAction);
+    }
+
+    public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
+    {
+        if ($this->_oDb->isAdmin($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], bx_get_logged_profile_id()))
+            return CHECK_ACTION_RESULT_ALLOWED;
+        return parent::checkAllowedEdit ($aDataEntry, $isPerformAction);
+    }
+
+    public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
+    {
+        if ($this->_oDb->isAdmin($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], bx_get_logged_profile_id()))
+            return CHECK_ACTION_RESULT_ALLOWED;
+        return parent::checkAllowedChangeCover ($aDataEntry, $isPerformAction);
+    }
+
+    public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
+    {
+        if ($this->_oDb->isAdmin($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], bx_get_logged_profile_id()))
+            return CHECK_ACTION_RESULT_ALLOWED;
+        return parent::checkAllowedDelete ($aDataEntry, $isPerformAction);
+    }
 }
 
 /** @} */

+ 2 - 0
modules/boonex/groups/install/langs/en.xml

@@ -188,6 +188,8 @@
     <string name="_bx_groups_txt_account_suspended"><![CDATA[This group is suspended.]]></string>
     <string name="_bx_groups_txt_N_fans"><![CDATA[{0} members]]></string>
     <string name="_bx_groups_txt_sample_single"><![CDATA[group]]></string>
+    <string name="_bx_groups_txt_to_admins"><![CDATA[To Admins]]></string>
+    <string name="_bx_groups_txt_from_admins"><![CDATA[From Admins]]></string>
 
     <string name="_bx_groups_pre_lists_cats"><![CDATA[Group categories]]></string>
     <string name="_bx_groups_cat_General"><![CDATA[General]]></string>

+ 2 - 0
modules/boonex/groups/install/langs/ru.xml

@@ -187,6 +187,8 @@
     <string name="_bx_groups_txt_account_suspended"><![CDATA[Эта группа заблокирована.]]></string>
     <string name="_bx_groups_txt_N_fans"><![CDATA[{0} участников]]></string>
     <string name="_bx_groups_txt_sample_single"><![CDATA[Группа]]></string>
+    <string name="_bx_groups_txt_to_admins"><![CDATA[В админы]]></string>
+    <string name="_bx_groups_txt_from_admins"><![CDATA[Из админов]]></string>
 
     <string name="_bx_groups_pre_lists_cats"><![CDATA[Категории групп]]></string>
     <string name="_bx_groups_cat_General"><![CDATA[Обобщение]]></string>

+ 5 - 3
modules/boonex/groups/install/sql/enable.sql

@@ -300,12 +300,14 @@ INSERT INTO `sys_objects_grid` (`object`, `source_type`, `source`, `table`, `fie
 ('bx_groups_fans', '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, 'BxGroupsGridConnections', 'modules/boonex/groups/classes/BxGroupsGridConnections.php');
 
 INSERT INTO `sys_grid_fields` (`object`, `name`, `title`, `width`, `params`, `order`) VALUES
-('bx_groups_fans', 'name', '_sys_name', '70%', '', 10),
-('bx_groups_fans', 'actions', '', '30%', '', 20);
+('bx_groups_fans', 'name', '_sys_name', '50%', '', 10),
+('bx_groups_fans', 'actions', '', '50%', '', 20);
 
 INSERT INTO `sys_grid_actions` (`object`, `type`, `name`, `title`, `icon`, `confirm`, `order`) VALUES
 ('bx_groups_fans', 'single', 'accept', '_sys_accept', '', 0, 10),
-('bx_groups_fans', 'single', 'delete', '', 'remove', 1, 20);
+('bx_groups_fans', 'single', 'to_admins', '_bx_groups_txt_to_admins', '', 0, 20),
+('bx_groups_fans', 'single', 'from_admins', '_bx_groups_txt_from_admins', '', 0, 30),
+('bx_groups_fans', 'single', 'delete', '', 'remove', 1, 40);
 
 -- GRIDS: administration
 

+ 9 - 0
modules/boonex/groups/install/sql/install.sql

@@ -77,6 +77,15 @@ CREATE TABLE IF NOT EXISTS `bx_groups_fans` (
   KEY `content` (`content`)
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
+-- TABLE: admins
+CREATE TABLE IF NOT EXISTS `bx_groups_admins` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `content_id` int(10) unsigned NOT NULL,
+  `fan_id` int(10) unsigned NOT NULL,
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `admin` (`content_id`,`fan_id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+
 -- STORAGES & TRANSCODERS
 
 INSERT INTO `sys_objects_storage` (`object`, `engine`, `params`, `token_life`, `cache_control`, `levels`, `table_files`, `ext_mode`, `ext_allow`, `ext_deny`, `quota_size`, `current_size`, `quota_number`, `current_number`, `max_file_size`, `ts`) VALUES

+ 1 - 1
modules/boonex/groups/install/sql/uninstall.sql

@@ -1,7 +1,7 @@
 
 -- TABLES
 
-DROP TABLE IF EXISTS `bx_groups_data`, `bx_groups_pics`, `bx_groups_pics_resized`, `bx_groups_views_track`, `bx_groups_meta_keywords`, `bx_groups_fans`;
+DROP TABLE IF EXISTS `bx_groups_data`, `bx_groups_pics`, `bx_groups_pics_resized`, `bx_groups_views_track`, `bx_groups_meta_keywords`, `bx_groups_fans`, `bx_groups_admins`;
 
 -- PROFILES