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

#4558 - Build-in API support (charts & ads)

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

+ 4 - 0
inc/classes/BxDolChart.php

@@ -126,6 +126,10 @@ class BxDolChart extends BxDolFactory implements iBxDolFactoryObject
         return "SELECT {field_date_formatted} AS `period`, COUNT(*) AS {object} FROM {table} WHERE 1 " . $sWhereClause . " {where_inteval} GROUP BY `period` ORDER BY {field_date} ASC";
         return "SELECT {field_date_formatted} AS `period`, COUNT(*) AS {object} FROM {table} WHERE 1 " . $sWhereClause . " {where_inteval} GROUP BY `period` ORDER BY {field_date} ASC";
     }
     }
 
 
+    public function getTimestamp($sDate, $isNowIfError = false)
+    {
+        return $this->_getTimestamp($sDate, $isNowIfError);
+    }
     protected function _getTimestamp($sDate, $isNowIfError = false)
     protected function _getTimestamp($sDate, $isNowIfError = false)
     {
     {
         $aDate = explode('-', $sDate); // YYYY-MM-DD
         $aDate = explode('-', $sDate); // YYYY-MM-DD

+ 7 - 0
modules/boonex/ads/classes/BxAdsFormEntry.php

@@ -274,6 +274,13 @@ class BxAdsFormEntry extends BxBaseModTextFormEntry
             'placeholder' => _t('_bx_ads_form_entry_input_source_paceholder'),
             'placeholder' => _t('_bx_ads_form_entry_input_source_paceholder'),
             'custom' => ['only_once' => true]
             'custom' => ['only_once' => true]
         ]);
         ]);
+        
+         if (bx_is_api()){
+             $aInput['ajax_get_suggestions'] = 'bx_ads/get_source_data&params[]=';
+             $aInput['type'] = 'suggestion';
+             $aInput['custom']['callback'] = 'bx_ads/load_entry_from_source&params[]=shopify_admin&params[]=';
+             return $aInput;
+        }
 
 
         return $this->genCustomInputUsernamesSuggestions($aInput);
         return $this->genCustomInputUsernamesSuggestions($aInput);
     }
     }

+ 13 - 3
modules/boonex/ads/classes/BxAdsModule.php

@@ -64,6 +64,14 @@ class BxAdsModule extends BxBaseModTextModule
     }
     }
 
 
     public function actionGetSource()
     public function actionGetSource()
+    {
+        $aEntries = $this->serviceGetSourceData();
+
+        header('Content-Type:text/javascript; charset=utf-8');
+        echo(json_encode($aEntries));
+    }
+    
+    public function serviceGetSourceData()
     {
     {
         $sSourceType = bx_get('source_type');
         $sSourceType = bx_get('source_type');
         if(empty($sSourceType)) {
         if(empty($sSourceType)) {
@@ -76,8 +84,7 @@ class BxAdsModule extends BxBaseModTextModule
 
 
         $aEntries = $this->serviceLoadEntriesFromSourceByTerm($sSourceType, $sTerm);
         $aEntries = $this->serviceLoadEntriesFromSourceByTerm($sSourceType, $sTerm);
 
 
-        header('Content-Type:text/javascript; charset=utf-8');
-        echo(json_encode($aEntries));
+        return $aEntries;
     }
     }
 
 
     public function actionLoadEntryFromSource()
     public function actionLoadEntryFromSource()
@@ -342,7 +349,8 @@ class BxAdsModule extends BxBaseModTextModule
             'BrowseCategory' => '',
             'BrowseCategory' => '',
             'RegisterImpression' => '',
             'RegisterImpression' => '',
             'RegisterClick' => '',
             'RegisterClick' => '',
-            'BlockSourcesDetails' => ''
+            'BlockSourcesDetails' => '',
+            'GetSourceData' => '',
         ]);
         ]);
     }
     }
 
 
@@ -2502,6 +2510,8 @@ class BxAdsModule extends BxBaseModTextModule
         if(bx_is_api()){
         if(bx_is_api()){
             $aResult['price'] = $sPrice;
             $aResult['price'] = $sPrice;
             $aResult['category_title'] = $sCategory;
             $aResult['category_title'] = $sCategory;
+            $aResult['register_click'] = $this->_oConfig->isPromotion() ? 'bx_ads/register_click&params[]=' . $aContentInfo[$CNF['FIELD_ID']] : false;
+            $aResult['register_impression'] = $this->_oConfig->isPromotion() ? 'bx_ads/register_impression&params[]=' . $aContentInfo[$CNF['FIELD_ID']] : false;
         }
         }
         else{
         else{
             $aResult['text'] = $this->_oTemplate->parseHtmlByName('timeline_post_text.html', array(
             $aResult['text'] = $this->_oTemplate->parseHtmlByName('timeline_post_text.html', array(

+ 10 - 11
modules/boonex/ads/classes/BxAdsTemplate.php

@@ -92,6 +92,10 @@ class BxAdsTemplate extends BxBaseModTextTemplate
         $oTemplate->addJs(['chart.min.js', 'BxDolChartGrowth.js']);
         $oTemplate->addJs(['chart.min.js', 'BxDolChartGrowth.js']);
         $oTemplate->addCss(['chart.css']);
         $oTemplate->addCss(['chart.css']);
 
 
+        if($this->_bIsApi){
+            return [bx_api_get_block('chart', ['type' => 'line', 'title' => 'Promotion for ' . $aContentInfo[$CNF['FIELD_TITLE']], 'form' =>  $oForm->getCodeApi(), 'endpoint' => 'system/get_data_by_interval/TemplChartServices', 'params' =>['object' => $aForm['inputs']['object']['values'][0]['key'], 'date_from' => $sDateFrom, 'date_to' => $sDateTo, 'content_id' => $aContentInfo[$CNF['FIELD_ID']]]])];
+        }
+        
         return $oTemplate->parseHtmlByName('chart_growth.html', [
         return $oTemplate->parseHtmlByName('chart_growth.html', [
             'controls' => $oForm->getCode(),
             'controls' => $oForm->getCode(),
             'date_from' => $sDateFrom,
             'date_from' => $sDateFrom,
@@ -116,11 +120,9 @@ class BxAdsTemplate extends BxBaseModTextTemplate
             $aTmplVarsDataSet['backgroundColor'][] = '#' . dechex(rand(0x000000, 0xFFFFFF));
             $aTmplVarsDataSet['backgroundColor'][] = '#' . dechex(rand(0x000000, 0xFFFFFF));
         }
         }
 
 
-        if($this->_bIsApi)
-            return [
-                'labels' => $aTmplVarsDataLabels,
-                'dataset' => $aTmplVarsDataSet
-            ];
+        if($this->_bIsApi){
+            return [bx_api_get_block('chart', ['type' => 'pie', 'title' => 'Summary', 'labels' => $aTmplVarsDataLabels, 'data' => $aTmplVarsDataSet])];
+        }
 
 
         $this->addJs(['chart.min.js']);
         $this->addJs(['chart.min.js']);
         $this->addCss(['chart.css']);
         $this->addCss(['chart.css']);
@@ -178,12 +180,9 @@ class BxAdsTemplate extends BxBaseModTextTemplate
 
 
         $fRoi = 100 * ($iValueLocal + $iValueSource - $iValueInvestment)/$iValueInvestment;
         $fRoi = 100 * ($iValueLocal + $iValueSource - $iValueInvestment)/$iValueInvestment;
 
 
-        if($this->_bIsApi)
-            return [
-                'labels' => $aTmplVarsDataLabels,
-                'dataset' => $aTmplVarsDataSet,
-                'roi' => $fRoi
-            ];
+        if($this->_bIsApi){
+            return [bx_api_get_block('chart', ['type' => 'pie', 'title' => 'Roi', 'labels' => $aTmplVarsDataLabels, 'data' => $aTmplVarsDataSet, 'text' => 'ROI: ' . $fRoi . '%'])];
+        }
 
 
         $this->addJs(['chart.min.js']);
         $this->addJs(['chart.min.js']);
         $this->addCss(['chart.css']);
         $this->addCss(['chart.css']);

+ 8 - 2
template/scripts/BxBaseChartServices.php

@@ -173,13 +173,19 @@ class BxBaseChartServices extends BxDol
         ));
         ));
     }
     }
 
 
-    public function serviceGetDataByInterval($sObject, $iFrom, $iTo)
+    public function serviceGetDataByInterval($sObject, $iFrom, $iTo, $iContentId = false)
     {
     {
         $oChart = BxDolChart::getObjectInstance($sObject);
         $oChart = BxDolChart::getObjectInstance($sObject);
         if($oChart === false)
         if($oChart === false)
             return [];
             return [];
+        
+        if($iContentId){
+            $oChart->addMarkers([
+                'content_id' => $iContentId
+            ]);
+        }
 
 
-        return $oChart->getDataByInterval($iFrom, $iTo);
+        return $oChart->getDataByInterval($oChart->getTimestamp($iFrom), $oChart->getTimestamp($iTo));
     }
     }
 }
 }
 
 

+ 27 - 0
template/scripts/BxBaseServiceGrid.php

@@ -0,0 +1,27 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaBaseView UNA Base Representation Classes
+ * @{
+ */
+
+
+class BxBaseServiceGrid extends BxDol
+{
+    public function servicePerfomActionApi($aParams = [])
+    {
+        $sObject = bx_process_input(bx_get('o'));
+        $oTemplate = BxDolStudioTemplate::getInstance();
+        $oGrid = BxDolGrid::getObjectInstance($sObject, $oTemplate);
+        $sAction = 'performAction' . bx_gen_method_name(bx_process_input(bx_get('a')));
+        if (method_exists($oGrid, $sAction)) {
+            return $oGrid->$sAction();
+            exit();
+        }
+       
+    }
+}
+
+/** @} */

+ 2 - 2
template/scripts/BxBaseServices.php

@@ -85,7 +85,8 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
             
             
             'GetChartGrowth' => 'BxBaseChartServices',
             'GetChartGrowth' => 'BxBaseChartServices',
             'GetChartStats' => 'BxBaseChartServices',
             'GetChartStats' => 'BxBaseChartServices',
-
+            'GetDataByInterval' => 'BxBaseChartServices',
+            
             'GetCartItemsCount' => 'BxBasePaymentsServices',
             'GetCartItemsCount' => 'BxBasePaymentsServices',
             'GetOrdersCount' => 'BxBasePaymentsServices',
             'GetOrdersCount' => 'BxBasePaymentsServices',
 
 
@@ -105,7 +106,6 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
             
             
             'PerfomActionApi' => 'BxBaseServiceGrid',
             'PerfomActionApi' => 'BxBaseServiceGrid',
             
             
-            'GetDataByInterval' => 'BxBaseChartServices',
         );
         );
     }
     }
 
 

+ 18 - 0
template/scripts_templ/BxTemplServiceGrid.php

@@ -0,0 +1,18 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaTemplate UNA Template Classes
+ * @{
+ */
+
+/**
+ * @see BxDolFavorite
+ */
+class BxTemplServiceGrid extends BxBaseServiceGrid
+{
+    
+}
+
+/** @} */