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

Ticket #4971 - Build-in API support: Ads.

AntonLV 3 месяцев назад
Родитель
Сommit
b2dce25211

+ 13 - 1
modules/boonex/ads/classes/BxAdsMenuViewActions.php

@@ -33,7 +33,19 @@ class BxAdsMenuViewActions extends BxBaseModTextMenuViewActions
 
     protected function _getMenuItemInterested($aItem)
     {
-        return $this->_getMenuItemByNameActions($aItem);
+        $aResult = $this->_getMenuItemByNameActions($aItem);
+
+        if($this->_bIsApi && is_array($aResult)) {
+            return array_merge($aResult, [
+                'display_type' => 'callback',
+                'data' => [
+                    'request_url' => $this->_sModule . '/interested/&params[]=' . $this->_iContentId, 
+                    'on_callback' => 'hide'
+                ]
+            ]);
+        }
+
+        return $aResult;
     }
 
     protected function _getMenuItemAddToCart($aItem)

+ 17 - 9
modules/boonex/ads/classes/BxAdsModule.php

@@ -134,29 +134,36 @@ class BxAdsModule extends BxBaseModTextModule
 
     public function actionInterested()
     {
-        $CNF = &$this->_oConfig->CNF;
-
         $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
+        
+        $aResult = $this->serviceInterested($iContentId);
+
+        echoJson($aResult);
+    }
+
+    public function serviceInterested($iContentId, $iViewer = 0)
+    {
+        $CNF = &$this->_oConfig->CNF;
 
         $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
         if(empty($aContentInfo) || !is_array($aContentInfo))
-            return echoJson(array());
+            return [];
 
-        $iViewer = bx_get_logged_profile_id();        
+        $iViewer = $iViewer ?: bx_get_logged_profile_id();
         $oViewer = BxDolProfile::getInstance($iViewer);
         if(!$oViewer)
-            return echoJson(array());
+            return [];
 
         $iContentAuthor = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
         if($iContentAuthor == $iViewer)
-            return echoJson(array('msg' => _t('_bx_ads_txt_err_your_own')));
+            return ['msg' => _t('_bx_ads_txt_err_your_own')];
 
         if($this->_oDb->isInterested($iContentId, $iViewer))
-            return echoJson(array('msg' => _t('_bx_ads_txt_err_duplicate')));
+            return ['msg' => _t('_bx_ads_txt_err_duplicate')];
 
         $iInterestId = $this->_oDb->insertInterested(array('entry_id' => $iContentId, 'profile_id' => $iViewer));
         if(!$iInterestId)
-            return echoJson(array('msg' => _t('_bx_ads_txt_err_cannot_perform_action')));
+            return ['msg' => _t('_bx_ads_txt_err_cannot_perform_action')];
 
         /**
          * @hooks
@@ -189,7 +196,7 @@ class BxAdsModule extends BxBaseModTextModule
                 )))
             ));
 
-        return echoJson(array('msg' => _t('_bx_ads_txt_msg_author_notified')));
+        return ['msg' => _t('_bx_ads_txt_msg_author_notified')];
     }
 
     public function actionShow()
@@ -357,6 +364,7 @@ class BxAdsModule extends BxBaseModTextModule
     public function serviceGetSafeServices()
     {
         return array_merge(parent::serviceGetSafeServices(), [
+            'Interested' => '',
             'IsSourcesAvaliable' => '',
             'LoadEntryFromSource' => '',
             'LoadEntriesFromSourceByTerm' => '',