Bladeren bron

Ticket #4575 - Events: Enhancements.

AntonLV 2 jaren geleden
bovenliggende
commit
481c92606f

+ 21 - 12
inc/classes/BxDolGridConnections.php

@@ -71,17 +71,16 @@ class BxDolGridConnections extends BxTemplGrid
     public function performActionAccept()
     {
         list ($iId, $iViewedId) = $this->_prepareIds();
-
-        if (!$iId) {
-            echoJson(array('msg' => _t('_sys_txt_error_occured')));
-            exit;
-        }
+        if(!$iId)
+            return $this->_bIsApi ? [] : echoJson(['msg' => _t('_sys_txt_error_occured')]);
 
         $a = $this->_oConnection->actionAdd($iId, $iViewedId);
         if (isset($a['err']) && $a['err'])
-            echoJson(array('msg' => $a['msg']));
+            $aResult = ['msg' => $a['msg']];
         else
-            echoJson(array('grid' => $this->getCode(false), 'blink' => $iId));
+            $aResult = !$this->_bIsApi ? ['grid' => $this->getCode(false), 'blink' => $iId] : [];
+
+        return $this->_bIsApi ? $aResult : echoJson($aResult);
     }
 
     /**
@@ -109,6 +108,9 @@ class BxDolGridConnections extends BxTemplGrid
 
     protected function _getCellName ($mixedValue, $sKey, $aField, $aRow)
     {
+        if($this->_bIsApi)
+            return ['type' => 'profile', 'data' => BxDolProfile::getData($aRow['id'])];
+
         $oProfile = BxDolProfile::getInstance($aRow['id']);
         if (!$oProfile)
             return _t('_sys_txt_error_occured');
@@ -147,14 +149,18 @@ class BxDolGridConnections extends BxTemplGrid
     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);
+            return $this->_bIsApi ? [] : '';
+
+        return parent::_getActionDelete($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 $this->_bIsApi ? [] : '';
+
+        if($this->_bIsApi)
+            return array_merge($a, ['name' => $sKey, 'type' => 'callback']);
 
         return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
     }
@@ -162,10 +168,13 @@ class BxDolGridConnections extends BxTemplGrid
     protected function _getActionAddFriend ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
     {
         if (!isLogged() || $this->_bOwner || $aRow['id'] == bx_get_logged_profile_id())
-            return '';
+            return $this->_bIsApi ? [] : '';
 
         if ($this->_oConnection->isConnected($aRow['id'], bx_get_logged_profile_id()) || $this->_oConnection->isConnected(bx_get_logged_profile_id(), $aRow['id']))
-            return '';
+            return $this->_bIsApi ? [] : '';
+
+        if($this->_bIsApi)
+            return array_merge($a, ['name' => $sKey, 'type' => 'callback']);
 
         return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
     }

+ 46 - 18
modules/base/groups/classes/BxBaseModGroupsGridConnections.php

@@ -182,7 +182,7 @@ class BxBaseModGroupsGridConnections extends BxDolGridConnections
     protected function _getCellHeaderRoleAdded($sKey, $aField)
     {
         if(!$this->_bPaidJoin || !($this->_bMember || $this->_bManageMembers))
-            return '';
+            return $this->_bIsApi ? [] : '';
 
         return parent::_getCellHeaderDefault ($sKey, $aField);
     }
@@ -190,15 +190,26 @@ class BxBaseModGroupsGridConnections extends BxDolGridConnections
     protected function _getCellRoleAdded($mixedValue, $sKey, $aField, $aRow)
     {
         $mixedValue = '';
-
         if(!$this->_bPaidJoin || !($this->_bMember || $this->_bManageMembers))
-            return $mixedValue;
+            return $this->_bIsApi ? [] : $mixedValue;
 
         $iProfileId = (int)$aRow[$this->_aOptions['field_id']];
         if($this->_bManageMembers || $iProfileId == bx_get_logged_profile_id()) {
             $aRole = $this->_oModule->_oDb->getRoles(array('type' => 'by_gf_id', 'group_profile_id' => $this->_iGroupProfileId, 'fan_id' => $iProfileId));
-            if(!empty($aRole) && is_array($aRole))
-                $mixedValue = !empty($aRole['added']) ? bx_time_js($aRole['added'], BX_FORMAT_DATE, true) : '';
+            if(!empty($aRole) && is_array($aRole)) {
+                if(!empty($aRole['added'])) {
+                    if($this->_bIsApi)
+                        return ['type' => 'time', 'data' => $aRole['added']];
+
+                    $mixedValue = bx_time_js($aRole['added'], BX_FORMAT_DATE, true);
+                }
+                else {
+                    if($this->_bIsApi)
+                        return ['type' => 'text', 'data' => ''];
+
+                    $mixedValue = '';
+                }
+            }
         }
 
         return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
@@ -207,7 +218,7 @@ class BxBaseModGroupsGridConnections extends BxDolGridConnections
     protected function _getCellHeaderRoleExpired($sKey, $aField)
     {
         if(!$this->_bPaidJoin || !($this->_bMember || $this->_bManageMembers))
-            return '';
+            return $this->_bIsApi ? [] : '';
         
         return parent::_getCellHeaderDefault ($sKey, $aField);
     }
@@ -215,15 +226,26 @@ class BxBaseModGroupsGridConnections extends BxDolGridConnections
     protected function _getCellRoleExpired($mixedValue, $sKey, $aField, $aRow)
     {
         $mixedValue = '';
-
         if(!$this->_bPaidJoin || !($this->_bMember || $this->_bManageMembers))
-            return '';
+            return $this->_bIsApi ? [] : '';
 
         $iProfileId = (int)$aRow[$this->_aOptions['field_id']];
         if($this->_bManageMembers || $iProfileId == bx_get_logged_profile_id()) {
             $aRole = $this->_oModule->_oDb->getRoles(array('type' => 'by_gf_id', 'group_profile_id' => $this->_iGroupProfileId, 'fan_id' => $iProfileId));
-            if(!empty($aRole) && is_array($aRole))
-                $mixedValue = !empty($aRole['expired']) ? bx_time_js($aRole['expired'], BX_FORMAT_DATE, true) : '';
+            if(!empty($aRole) && is_array($aRole)) {
+                if(!empty($aRole['expired'])) {
+                    if($this->_bIsApi)
+                        return ['type' => 'time', 'data' => $aRole['expired']];
+
+                    $mixedValue = bx_time_js($aRole['expired'], BX_FORMAT_DATE, true);
+                }
+                else {
+                    if($this->_bIsApi)
+                        return ['type' => 'text', 'data' => ''];
+
+                    $mixedValue = '';
+                }
+            }
         }
 
         return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
@@ -231,21 +253,27 @@ class BxBaseModGroupsGridConnections extends BxDolGridConnections
 
     protected function _getActionSetRole ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
     {
+        /**
+         * Note. The feature isn't available in API for now.
+         */
+        if($this->_bIsApi)
+            return [];
+
         if ($this->_oModule->checkAllowedManageAdmins($this->_iGroupProfileId) !== CHECK_ACTION_RESULT_ALLOWED)
-            return '';
+            return $this->_bIsApi ? [] : '';
 
         return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
     }
 
     protected function _getActionSetRoleSubmit ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
     {
-        return '';
+        return $this->_bIsApi ? [] : '';
     }
 
     protected function _getActionQuestionnaire ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
     {
         if($aRow['mutual'])
-            return '';
+            return $this->_bIsApi ? [] : '';
 
         return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
     }
@@ -253,26 +281,26 @@ class BxBaseModGroupsGridConnections extends BxDolGridConnections
     protected function _getActionAccept ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
     {
         if ($aRow['mutual'])
-            return '';
+            return $this->_bIsApi ? [] : '';
 
         if ($this->_oModule->checkAllowedManageFans($this->_iGroupProfileId) !== CHECK_ACTION_RESULT_ALLOWED)
-            return '';
+            return $this->_bIsApi ? [] : '';
 
         if (isset($aRow[$this->_aOptions['field_id']]))
             $a['attr']['bx_grid_action_data'] = $aRow[$this->_aOptions['field_id']] . ':' . $this->_iGroupProfileId;
 
-        return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
+        return parent::_getActionAccept($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
     }
 
     protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
     {
         if ($this->_oModule->checkAllowedManageFans($this->_iGroupProfileId) !== CHECK_ACTION_RESULT_ALLOWED)
-            return '';
+            return $this->_bIsApi ? [] : '';
 
         if (isset($aRow[$this->_aOptions['field_id']]))
             $a['attr']['bx_grid_action_data'] = $aRow[$this->_aOptions['field_id']] . ':' . $this->_iGroupProfileId;
 
-        return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
+        return parent::_getActionDelete($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
     }
 
     /**

+ 22 - 13
template/scripts/BxBaseGrid.php

@@ -79,14 +79,13 @@ class BxBaseGrid extends BxDolGrid
 
     public function performActionDelete()
     {
-        $aResult = [];
-
         $this->_replaceMarkers ();
 
+        $aResult = [];
         $iAffected = 0;
         $aIds = bx_get('ids');
         if (!$aIds || !is_array($aIds))
-            return echoJson($aResult);
+            return $this->_bIsApi ? $aResult : echoJson($aResult);
 
         foreach ($aIds as $mixedId)
             $iAffected += $this->_delete($mixedId) ? 1 : 0;
@@ -414,12 +413,18 @@ class BxBaseGrid extends BxDolGrid
     protected function _getRowHeadAPI()
     {
         $aHeader = [];
-        foreach($this->_aOptions['fields'] as $sKey => $aField)
-            $aHeader[] = [
-                'name' => bx_process_output($aField['name']),
-                'title' => bx_process_output($aField['title']),
-                'width' => $aField['width']
-            ];
+
+        foreach($this->_aOptions['fields'] as $sKey => $aField) {
+            $sMethod = '_getCellHeader' . $this->_genMethodName($sKey);
+            if(method_exists($this, $sMethod))
+                $aHeader[] = $this->$sMethod($sKey, $a);
+            else
+                $aHeader[] = [
+                    'name' => bx_process_output($aField['name']),
+                    'title' => bx_process_output($aField['title']),
+                    'width' => $aField['width']
+                ];
+        }
 
         return $aHeader;
     }
@@ -762,12 +767,16 @@ class BxBaseGrid extends BxDolGrid
         if ($a['icon_only'] && empty($a['attr']['title']) && !empty($a['title']))
             $a['attr']['title'] = $a['title'];
 
-        if ($this->_bIsApi){
+        if ($this->_bIsApi) {
             $sFunc = '_getAction' . $this->_genMethodName($sType . '_' . $sKey);
-            if (method_exists($this, $sFunc)){
-                return array_merge($a, ['name' => $sKey], $this->$sFunc($a, ['id'=> $aRow[$this->_aOptions['field_id']]]));
+            if (method_exists($this, $sFunc)) {
+                $aAction = $this->$sFunc($a, ['id'=> $aRow[$this->_aOptions['field_id']]]);
+                if(empty($aAction) || !is_array($aAction))
+                    return [];
+
+                return array_merge($a, ['name' => $sKey], $aAction);
             }
-            else{
+            else {
                 return array_merge($a, ['name' => $sKey, 'type' => 'modal', 'action' => $sKey, 'params' => '&id=' . $aRow[$this->_aOptions['field_id']] ]);
             }