Просмотр исходного кода

#4148 - Build-in API support (feed edit/delete)

roman.lesnikov@gmail.com 3 лет назад
Родитель
Сommit
a08d89efdc

+ 1 - 1
inc/classes/BxDolForm.php

@@ -986,7 +986,7 @@ class BxDolForm extends BxDol implements iBxDolReplaceable
             $oRv =  $oChecker->get ($sName);
         
         // process comma separated string for api values
-        if (bx_is_api() && isset($this->aInputs[$sName]['type']) && in_array($this->aInputs[$sName]['type'], ['checkbox_set', 'files', 'select_multiple']))
+        if (bx_is_api() && isset($this->aInputs[$sName]['type']) && !empty($oRv) && in_array($this->aInputs[$sName]['type'], ['checkbox_set', 'files', 'select_multiple']))
             $oRv = explode(',', $oRv);
             
         return $oRv;

+ 1 - 1
modules/boonex/timeline/classes/BxTimelineDb.php

@@ -623,7 +623,7 @@ class BxTimelineDb extends BxBaseModNotificationsDb
         $sSqlMask = "SELECT {select}
             FROM `{$this->_sTable}`
             LEFT JOIN `{$this->_sTableHandlers}` ON `{$this->_sTable}`.`type`=`{$this->_sTableHandlers}`.`alert_unit` AND `{$this->_sTable}`.`action`=`{$this->_sTableHandlers}`.`alert_action` 
-            INNER JOIN `sys_profiles` ON `{$this->_sTable}`.`object_owner_id`=`sys_profiles`.`id` {$sJoinClauseAddon} {join}
+            INNER JOIN `sys_profiles` ON ABS(`{$this->_sTable}`.`object_owner_id`)=`sys_profiles`.`id` {$sJoinClauseAddon} {join}
             WHERE 1 AND `sys_profiles`.`status`='active' {where} {order} {limit}";
 
         if(is_string($mixedWhereClause)) {

+ 20 - 8
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -640,6 +640,18 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
 
         echoJson($this->getFormEdit($iId, array('dynamic_mode' => true), $aParams));
     }
+    
+    public function serviceGetEditForm($iId)
+    {
+        $aFrm = $this->getFormEdit($iId)['form'];
+        $aFrm['inputs']['tlb_do_submit'] = $aFrm['inputs']['controls'][0];
+        unset($aForm['inputs']['controls']);
+        $aRv['form'] = ['id' => 'bx_timeline', 'type' => 'form', 'name' => 'feed_edit', 'data' => $aFrm, 'request' => ['immutable' => true]];
+        $aItemData = $this->getItemData($iId);
+        if(is_array($aItemData) && !empty($aItemData['event']))
+            $aRv['item'] = $this->_oTemplate->_getPostApi($aItemData['event']);
+        return $aRv;
+    }
 
     public function actionGetComments()
     {
@@ -909,7 +921,9 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             'GetBlockViewAccount' => '',
             'GetBlockViewAccountOutline' => '',
             'GetPosts' => '',
-            'Repost' => ''
+            'Repost' => '',
+            'Delete' => '',
+            'GetEditForm' => '',
         ));
     }
 
@@ -3687,7 +3701,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             return [];
 
         if(($mixedCheck = $this->isAllowedEdit($aEvent)) !== true)
-            return ['message' => $mixedCheck !== false ? $mixedCheck : _t('_sys_txt_access_denied')];
+            return bx_is_api() ? bx_api_get_msg($mixedCheck !== false ? $mixedCheck : _t('_sys_txt_access_denied')) : ['message' => $mixedCheck !== false ? $mixedCheck : _t('_sys_txt_access_denied')];
         
         $aContent = unserialize($aEvent['content']);
         if(is_array($aContent) && !empty($aContent['text']))
@@ -3789,14 +3803,14 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
                 $oForm->aInputs['text']['error'] =  _t('_bx_timeline_txt_err_empty_post');
                 $oForm->setValid(false);
 
-            	return $this->_prepareResponse([
+            	return bx_is_api ? ['form' => $oForm->getCodeAPI()] : $this->_prepareResponse([
                     'form' => $sCodeAdd . $oForm->getCode($bDynamicMode), 
                     'form_id' => $oForm->id
                 ], $bAjaxMode);
             }
 
             if($oForm->update($iId, $aValsToAdd) === false)
-                return ['message' => _t('_bx_timeline_txt_err_cannot_perform_action')];
+                 return bx_is_api() ? bx_api_get_msg(_t('_bx_timeline_txt_err_cannot_perform_action')) : ['message' => _t('_bx_timeline_txt_err_cannot_perform_action')];
 
             $this->isAllowedEdit($aEvent, true);
 
@@ -3817,12 +3831,10 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
 
             $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iId);
 
-            return [
-                'id' => $iId
-            ];
+            return bx_is_api() ? [ 'id' => $iId ] : [ 'id' => $iId ];
         }
 
-        return [
+        return bx_is_api() ? ['form' => $oForm->getCodeAPI()] : [
             'id' => $iId, 
             'form' => $sCodeAdd . $oForm->getCode($bDynamicMode), 
             'form_id' => $oForm->id,

+ 1 - 1
modules/boonex/timeline/classes/BxTimelineTemplate.php

@@ -1885,7 +1885,7 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
         return $this->parseHtmlByContent($sTmplCode, $aTmplVars);
     }
 
-    protected function _getPostApi(&$aEvent, $aParams = [], $aEventAdd = [])
+    public function _getPostApi(&$aEvent, $aParams = [], $aEventAdd = [])
     {
         $oModule = $this->getModule();