Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
A
addcpm-json
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Александр Чаплыгин
addcpm-json
Commits
f1e25e72
Commit
f1e25e72
authored
Jan 16, 2019
by
Александр Чаплыгин
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добвил контроллер для статистики Statisctics
parent
a1df3c52
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
345 additions
and
353 deletions
+345
-353
dependencies.global.php
src/config/autoload/dependencies.global.php
+3
-3
Statistics.php
src/src/App/Action/Statistics.php
+321
-0
Cabinet.php
src/src/App/Action/User/Cabinet.php
+9
-2
Statistics.php
src/src/App/Model/Statistics.php
+9
-347
cabinet-feed.phtml
src/templates/app/user/cabinet-feed.phtml
+3
-1
No files found.
src/config/autoload/dependencies.global.php
View file @
f1e25e72
...
@@ -263,9 +263,9 @@ return [
...
@@ -263,9 +263,9 @@ return [
},
},
\App\Model\Statistics
::
class
=>
function
(
ContainerInterface
$container
)
{
\App\Model\Statistics
::
class
=>
function
(
ContainerInterface
$container
)
{
return
new
\App\Model\Statistics
(
return
new
\App\Model\Statistics
(
$container
->
get
(
\App\Model\Sites
::
class
),
//
$container->get(\App\Model\Sites::class),
$container
->
get
(
\App\Model\Zones
::
class
),
//
$container->get(\App\Model\Zones::class),
$container
->
get
(
'config'
)[
'country_codes'
]
//
$container->get('config')['country_codes']
);
);
},
},
],
],
...
...
src/src/App/Action/Statistics.php
0 → 100644
View file @
f1e25e72
<?php
/**
* Copyright (c) 2016 Serhii Borodai <clarifying@gmail.com>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*
*/
/**
* http api
*
* 1. summary report
* 2.
*
*
*
*
*
*
*
*
*
*
*/
namespace
App\Action
;
use
App\Authentication\UserService
;
use
App\Authentication\AggregateAuth
;
use
App\Model\Users
;
use
App\Model\Sites
;
use
Psr\Http\Message\ResponseInterface
;
use
Psr\Http\Message\ServerRequestInterface
;
use
Zend\Diactoros\Response\HtmlResponse
;
use
Zend\Diactoros\Response\JsonResponse
;
/**
* Class Statistics
* @package App\Action
*/
class
Statistics
extends
Common
{
const
ACTION_SUMMARY_REPORT
=
'summary'
;
const
ACTION_LINECHART_REPORT
=
'linechart'
;
const
ACTION_SUBDOMAINS_LIST
=
'subdomains'
;
const
ACTION_SITESSTAT_REPORT
=
'sitesstat'
;
const
ACTION_REPORT_LIST
=
[
'minstat'
,
'bidstat'
,
'pagestat'
,
'blockstat'
,
'winstat'
,
'ndspstat'
,
'providersblockstat'
];
const
ACTION_GEO_LIST
=
'geolist'
;
const
ACTION_SITES_LIST
=
'siteslist'
;
const
ACTION_ZONES_LIST
=
'zoneslist'
;
const
ACTION_CODESTAT_GLOBAL_REPORT
=
'codestatglobal'
;
const
ACTION_CODESTAT_REPORT
=
'codestat'
;
/**
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param callable|null $next
* @return HtmlResponse
*/
function
__invoke
(
ServerRequestInterface
$request
,
ResponseInterface
$response
,
callable
$next
=
null
)
{
/** @var Sites $sitesModel */
$sitesModel
=
$this
->
container
->
get
(
Sites
::
class
);
/** @var UserService $auth */
$auth
=
$this
->
container
->
get
(
UserService
::
class
);
/** @var AggregateAuth $aggregateAuth */
$aggregateAuth
=
$this
->
container
->
get
(
AggregateAuth
::
class
);
/** @var Statistics $stats */
$stats
=
$this
->
container
->
get
(
\App\Model\Statistics
::
class
);
/** @var Users $usersModel */
$usersModel
=
$this
->
container
->
get
(
Users
::
class
);
//$isAdmin = ($aggregateAuth->getIdentity()->getRoleId() == 'admin');
$isAdmin
=
in_array
(
$aggregateAuth
->
getIdentity
()
->
getRoleId
(),
[
'admin'
,
'marker'
]);
$isManager
=
(
$aggregateAuth
->
getIdentity
()
->
getRoleId
()
==
'manager'
);
$params
=
$request
->
getParsedBody
();
if
((
!
$isAdmin
&&
!
$isManager
)
||
$params
[
'userid'
])
{
// Список сайтов пользователей
$userId
=
(
$params
[
'userid'
])
?
$params
[
'userid'
]
:
$auth
->
getIdentity
()
->
getId
();
$user
=
$usersModel
->
findById
(
$userId
);
$currency
=
$user
->
getCurrencyCode
();
$listSites
=
$sitesModel
->
findByUserId
(
$userId
)
->
buffer
();
$listDomains
=
array
();
foreach
(
$listSites
as
$site
)
{
$listDomains
[]
=
$site
->
getDomain
();
// Добавляем в список алиасы:
if
(
$site
->
getAlias
())
{
$site_aliases
=
explode
(
","
,
$site
->
getAlias
());
foreach
(
$site_aliases
as
$site_alias
)
{
if
(
$site_alias
!=
$site
->
getDomain
())
{
$listDomains
[]
=
$site_alias
;
}
}
}
}
// Добавлям домены доступных сайтов
/** @var \App\Model\AccessUsersSites $accessUsersSitesModel */
$accessUsersSitesModel
=
$this
->
container
->
get
(
\App\Model\AccessUsersSites
::
class
);
$listAccessSites
=
$accessUsersSitesModel
->
findSitesByUserId
(
$userId
);
foreach
(
$listAccessSites
as
$site
)
{
$listDomains
[]
=
$site
->
getDomain
();
}
}
else
if
(
$isManager
)
{
// Список сайтов менеджера
$currency
=
(
isset
(
$_COOKIE
[
"adminCurrency"
]))
?
$_COOKIE
[
"adminCurrency"
]
:
'USD'
;
$manager_id
=
$aggregateAuth
->
getIdentity
()
->
getId
();
$manager_users
=
$usersModel
->
findBySupportId
(
$manager_id
);
$managerSites
=
$sitesModel
->
findByUserId
(
$manager_users
)
->
buffer
();
$listDomains
=
array
();
foreach
(
$managerSites
as
$site
)
{
if
(
!
in_array
(
$site
->
getDomain
(),
$listDomains
))
{
$listDomains
[]
=
$site
->
getDomain
();
}
}
/*
} else if ($params['managerid']) { // Список сайтов менеджера
$currency = (isset($_COOKIE["adminCurrency"])) ? $_COOKIE["adminCurrency"] : 'USD';
$listUsersId = $usersModel->findBySupportId($params['managerid']);
$listDomains = array();
$managerSites = $sitesModel->findByUserId($listUsersId)->buffer();
foreach($managerSites as $site) {
if (!in_array($site->getDomain(), $listDomains)) {
$listDomains[] = $site->getDomain();
}
}
*/
}
else
{
// Список сайтов админа
$currency
=
(
isset
(
$_COOKIE
[
"adminCurrency"
]))
?
$_COOKIE
[
"adminCurrency"
]
:
'USD'
;
$listDomains
=
array
();
$adminSites
=
$sitesModel
->
findAllSites
();
foreach
(
$adminSites
as
$site
)
{
$listDomains
[]
=
$site
;
}
}
$month
=
trim
(
$params
[
'month'
]);
if
(
!
preg_match
(
'/^\d{4,4}-\d{2,2}$/'
,
$month
))
{
$month
=
''
;
}
$sites
=
trim
(
$params
[
'domains'
]);
if
(
!
$sites
)
{
$sites
=
array
();
}
else
{
$sites
=
array_filter
(
array_map
(
'trim'
,
explode
(
','
,
$sites
)));
}
foreach
(
$sites
as
$i
=>
$requestSite
)
{
$is_valid
=
false
;
foreach
(
$listDomains
as
$validDomain
)
{
if
(
preg_match
(
'/'
.
$validDomain
.
'$/'
,
$requestSite
))
{
$is_valid
=
true
;
break
;
}
}
if
(
!
$is_valid
)
{
unset
(
$sites
[
$i
]);
}
}
$subdomains
=
trim
(
$params
[
'subdomains'
]);
$subdomains
=
(
$subdomains
==
1
)
?
true
:
false
;
$domain
=
trim
(
$params
[
'domain'
]);
$domains
=
array
(
$domain
);
$allStat
=
((
$isAdmin
||
$isManager
)
&&
!
$params
[
'userid'
]);
$group
=
(
$isAdmin
&&
isset
(
$params
[
'group'
])
&&
!
$params
[
'userid'
]
&&
!
$params
[
'managerid'
])
?
trim
(
$params
[
'group'
])
:
"false"
;
$action
=
$params
[
'action'
];
$metrics_types
=
$this
->
container
->
get
(
'config'
)[
'metrics'
];
$dates
=
$params
[
'dates'
];
$geo
=
(
$params
[
'geo'
]
!=
''
)
?
$params
[
'geo'
]
:
null
;
$sites_id
=
(
$params
[
'sites_id'
]
!=
''
)
?
$params
[
'sites_id'
]
:
null
;
$zones_id
=
(
$params
[
'zones_id'
]
!=
''
)
?
$params
[
'zones_id'
]
:
null
;
// Формируем список id сайтов для codestat:
$sites_id_code
=
(
$params
[
'sites'
]
!=
''
)
?
$params
[
'sites'
]
:
null
;
if
(
!
is_null
(
$sites_id_code
))
{
$sites_id_code
=
array_map
(
function
(
$id
){
return
(
int
)
$id
;},
$sites_id_code
);
}
$codes
=
$params
[
'codes'
];
// Формируем фильтры:
if
(
!
is_null
(
$sites_id
))
{
$sites_id
[
'list'
]
=
array_map
(
function
(
$id
){
return
(
int
)
$id
;},
$sites_id
[
'list'
]);
}
if
(
!
is_null
(
$zones_id
))
{
$zones_id
[
'list'
]
=
array_map
(
function
(
$id
){
return
(
int
)
$id
;},
$zones_id
[
'list'
]);
}
if
(
$params
[
'action'
]
==
self
::
ACTION_SUMMARY_REPORT
)
{
$data
=
$stats
->
getSummuryReport
(
$sites
,
$currency
,
$subdomains
,
$allStat
,
$group
);
}
elseif
(
$params
[
'action'
]
==
self
::
ACTION_LINECHART_REPORT
)
{
list
(
$data
)
=
$stats
->
getPeriodReport
(
$month
,
$sites
,
$currency
,
$subdomains
,
$allStat
,
$group
);
}
elseif
(
$params
[
'action'
]
==
self
::
ACTION_SITESSTAT_REPORT
)
{
$data
=
$stats
->
getSitesReport
(
$month
,
$sites
,
$currency
,
$subdomains
,
$allStat
,
$group
);
}
elseif
(
$params
[
'action'
]
==
self
::
ACTION_SUBDOMAINS_LIST
)
{
$data
=
$stats
->
getSubDomains
(
$domains
);
}
elseif
(
in_array
(
$params
[
'action'
],
self
::
ACTION_REPORT_LIST
))
{
$type
=
$metrics_types
[
$action
][
'type'
];
$fields
=
$metrics_types
[
$action
][
'fields'
];
if
(
!
in_array
(
'ZoneID'
,
$metrics_types
[
$action
][
'filters'
]))
{
$zones_id
=
null
;
}
$data
=
$stats
->
getStatReport
(
$action
,
$type
,
$fields
,
$dates
,
$geo
,
$sites_id
,
$zones_id
,
$params
[
'by_sites'
],
$params
[
'by_zones'
],
$params
[
'by_countries'
]);
}
elseif
(
$params
[
'action'
]
==
self
::
ACTION_GEO_LIST
)
{
$metric
=
$params
[
'metric'
];
$type
=
$metrics_types
[
$metric
][
'type'
];
$fields
=
$metrics_types
[
$metric
][
'fields'
];
$data
=
$this
->
getGeoList
(
$type
,
$fields
);
}
elseif
(
$params
[
'action'
]
==
self
::
ACTION_SITES_LIST
)
{
$data
=
$this
->
getSitesList
();
}
elseif
(
$params
[
'action'
]
==
self
::
ACTION_ZONES_LIST
)
{
$data
=
$this
->
getZonesList
();
}
elseif
(
$params
[
'action'
]
==
self
::
ACTION_CODESTAT_GLOBAL_REPORT
)
{
$data
=
$stats
->
getCodestatGlobalReport
(
$sites_id_code
,
$codes
);
}
elseif
(
$params
[
'action'
]
==
self
::
ACTION_CODESTAT_REPORT
)
{
list
(
$data
)
=
$stats
->
getCodestatReport
(
$month
,
$sites_id_code
,
$codes
);
}
return
new
JsonResponse
(
$data
);
}
private
function
getGeoList
(
$type
,
$fields
)
{
/** @var \App\Model\Statistics $stats */
$stats
=
$this
->
container
->
get
(
\App\Model\Statistics
::
class
);
// Определяем список наиболее популярных стран:
//$geo_popular = $stats->getStatReportCountries($type, $fields);
if
(
$geo_popular
)
{
$list_codes
=
$this
->
container
->
get
(
'config'
)[
'country_codes'
];
foreach
(
array_keys
(
$geo_popular
)
as
$code
)
{
$geo_popular
[
$code
]
=
$list_codes
[
$code
];
}
}
else
{
$geo_popular
=
$this
->
container
->
get
(
'config'
)[
'site_countries'
];
}
return
$geo_popular
;
}
private
function
getSitesList
()
{
/** @var \App\Model\Sites $sitesModel */
$sitesModel
=
$this
->
container
->
get
(
\App\Model\Sites
::
class
);
$sites
=
array
();
foreach
(
$sitesModel
->
findAll
(
null
,
'domain ASC'
)
as
$site
)
{
$sites
[]
=
array
(
'id'
=>
$site
->
getId
(),
'domain'
=>
$site
->
getDomain
(),
);
}
return
$sites
;
}
private
function
getZonesList
()
{
/** @var \App\Model\Sites $sitesModel */
$sitesModel
=
$this
->
container
->
get
(
\App\Model\Sites
::
class
);
/** @var \App\Model\Sites $zonesModel */
$zonesModel
=
$this
->
container
->
get
(
\App\Model\Zones
::
class
);
$zones
=
array
();
foreach
(
$zonesModel
->
findAll
(
$where
?:
null
,
'id ASC'
)
as
$zone
)
{
$site
=
$sitesModel
->
findOne
([
'id'
=>
$zone
->
getSiteId
()]);
$site_domain
=
$site
->
getDomain
();
$zones
[
$zone
->
getId
()]
=
array
(
'domain'
=>
$site_domain
,
'site_id'
=>
$zone
->
getSiteId
(),
'size'
=>
$zone
->
getWidth
()
.
'x'
.
$zone
->
getHeight
(),
);
}
return
$zones
;
}
}
\ No newline at end of file
src/src/App/Action/User/Cabinet.php
View file @
f1e25e72
...
@@ -58,6 +58,9 @@ class Cabinet extends Common
...
@@ -58,6 +58,9 @@ class Cabinet extends Common
function
__invoke
(
ServerRequestInterface
$request
,
ResponseInterface
$response
,
callable
$next
=
null
)
function
__invoke
(
ServerRequestInterface
$request
,
ResponseInterface
$response
,
callable
$next
=
null
)
{
{
/** @var \App\Model\Statistics $stats */
$stats
=
$this
->
container
->
get
(
Statistics
::
class
);
if
(
$request
->
getMethod
()
==
'POST'
)
{
if
(
$request
->
getMethod
()
==
'POST'
)
{
try
{
try
{
...
@@ -109,7 +112,8 @@ class Cabinet extends Common
...
@@ -109,7 +112,8 @@ class Cabinet extends Common
$statsDaysModel
=
$this
->
container
->
get
(
StatsDays
::
class
);
$statsDaysModel
=
$this
->
container
->
get
(
StatsDays
::
class
);
//$stats = $statsDaysModel->findAll(['FeedID' => $feed_id_list])->toArray();
//$stats = $statsDaysModel->findAll(['FeedID' => $feed_id_list])->toArray();
$periodStats
=
$statsDaysModel
->
getStatsByDate
(
$feed_id_list
,
$dates
);
$periodStats
=
$statsDaysModel
->
getStatsByDate
(
$feed_id_list
,
$dates
);
$campaignStats
=
$statsDaysModel
->
getStatsByFeeds
(
$feed_id_list
,
$dates
);
$stat
=
$stats
->
getStatData
(
$metric
,
$type
);
//$campaignStats = $statsDaysModel->getStatsByFeeds($feed_id_list, $dates);
$cats
=
[
$cats
=
[
'shows'
=>
'Показы'
,
'shows'
=>
'Показы'
,
...
@@ -119,6 +123,7 @@ class Cabinet extends Common
...
@@ -119,6 +123,7 @@ class Cabinet extends Common
'admoney'
=>
'admoney'
'admoney'
=>
'admoney'
];
];
/*
if ($campaignStats || count($campaignStats['period'])>0) {
if ($campaignStats || count($campaignStats['period'])>0) {
$feeds_names = [];
$feeds_names = [];
foreach($campaignStats['period'] as $feed_id) {
foreach($campaignStats['period'] as $feed_id) {
...
@@ -127,6 +132,7 @@ class Cabinet extends Common
...
@@ -127,6 +132,7 @@ class Cabinet extends Common
}
}
$campaignStats['period'] = $feeds_names;
$campaignStats['period'] = $feeds_names;
}
}
*/
break
;
break
;
case
'transaction'
:
case
'transaction'
:
...
@@ -165,8 +171,9 @@ class Cabinet extends Common
...
@@ -165,8 +171,9 @@ class Cabinet extends Common
$data
[
'report'
]
=
$report_type
;
$data
[
'report'
]
=
$report_type
;
$data
[
'current_period'
]
=
$current_period
;
$data
[
'current_period'
]
=
$current_period
;
$data
[
'dates'
]
=
$dates
;
$data
[
'dates'
]
=
$dates
;
$data
[
'stat'
]
=
$stat
;
$data
[
'periodStats'
]
=
$periodStats
;
$data
[
'periodStats'
]
=
$periodStats
;
$data
[
'campaignStats'
]
=
$campaignStats
;
//
$data['campaignStats'] = $campaignStats;
$data
[
'cats'
]
=
$cats
;
$data
[
'cats'
]
=
$cats
;
$data
[
'periods_list'
]
=
$this
->
container
->
get
(
'config'
)[
'feed_conf'
][
'periods_list'
];
$data
[
'periods_list'
]
=
$this
->
container
->
get
(
'config'
)[
'feed_conf'
][
'periods_list'
];
$data
[
'colors_active_lines'
]
=
$this
->
container
->
get
(
'config'
)[
'feed_conf'
][
'colors_active_lines'
];
$data
[
'colors_active_lines'
]
=
$this
->
container
->
get
(
'config'
)[
'feed_conf'
][
'colors_active_lines'
];
...
...
src/src/App/Model/Statistics.php
View file @
f1e25e72
...
@@ -2,227 +2,28 @@
...
@@ -2,227 +2,28 @@
namespace
App\Model
;
namespace
App\Model
;
use
App\Model\Sites
;
//
use App\Model\Sites;
use
App\Model\Zones
;
//
use App\Model\Zones;
class
Statistics
class
Statistics
{
{
private
$hashSolt
=
''
;
private
$hashSolt
=
''
;
public
function
__construct
(
Sites
$sites
,
Zones
$zones
,
$countries
)
public
function
__construct
(
/*Sites $sites, Zones $zones, $countries*/
)
{
{
$this
->
hashSolt
=
'FsRpCKc021PzwqOR8o1mXLe8AIS6YmnfkDvECBY6MzGWHhceS4EvdOnW7dYHt7AA'
;
$this
->
hashSolt
=
'FsRpCKc021PzwqOR8o1mXLe8AIS6YmnfkDvECBY6MzGWHhceS4EvdOnW7dYHt7AA'
;
$this
->
sitesModel
=
$sites
;
//
$this->sitesModel = $sites;
$this
->
zonesModel
=
$zones
;
//
$this->zonesModel = $zones;
$this
->
countryCodes
=
$countries
;
//
$this->countryCodes = $countries;
}
}
// Список поддоменов
public
function
getSubdomains
(
array
$sites
)
{
if
(
!
$sites
)
{
return
array
();
}
$res
=
$this
->
apiRequest
(
array
(
'method'
=>
'subdomains'
,
'data'
=>
array
(
'domains'
=>
$sites
)
));
$allSubdomains
=
array
();
foreach
(
$res
as
$domain
=>
$subDomains
)
{
$allSubdomains
=
array_merge
(
$allSubdomains
,
$subDomains
);
}
sort
(
$allSubdomains
);
return
$allSubdomains
;
}
// Сводная таблица (над графиком)
public
function
getSummuryReport
(
array
$sites
,
$currency
,
$subdomains
,
$allStat
,
$group
)
{
if
(
!
count
(
$sites
)
&&
(
$group
!=
'all'
))
{
return
array
();
}
$dataRequest
=
array
(
'method'
=>
'global_stat'
,
'data'
=>
array
(
'subdomains'
=>
$subdomains
,
'currency'
=>
$currency
,
)
);
if
(
$allStat
)
{
$dataRequest
[
'data'
][
'all_stat'
]
=
true
;
}
if
(
$group
==
'all'
)
{
$dataRequest
[
'data'
][
'group'
]
=
'all'
;
}
else
{
$dataRequest
[
'data'
][
'domains'
]
=
$sites
;
}
/*
$dataRequest = array(
'method' => 'global_stat',
'data' => array(
'subdomains' => false,
'currency' => "USD",
'domains' => ["ua.sinoptik.ua"]
)
);
$summaryReport = $this->apiRequest($dataRequest);
return $summaryReport;
*/
$summaryReport
=
$this
->
apiRequest
(
$dataRequest
);
$summaryReport
=
$summaryReport
[
'stat'
]
?:
array
();
return
$summaryReport
;
}
// График и таблица под графиком
public
function
getPeriodReport
(
$month
,
array
$sites
,
$currency
,
$subdomains
,
$allStat
,
$group
)
{
if
(
!
count
(
$sites
)
&&
(
$group
!=
'all'
))
{
return
array
();
}
$dataRequest
=
array
(
'method'
=>
'date_stat'
,
'data'
=>
array
(
'subdomains'
=>
$subdomains
,
'month'
=>
$month
,
'currency'
=>
$currency
)
);
if
(
$allStat
)
{
$dataRequest
[
'data'
][
'all_stat'
]
=
true
;
}
if
(
$group
==
'all'
)
{
$dataRequest
[
'data'
][
'group'
]
=
'all'
;
}
else
{
$dataRequest
[
'data'
][
'domains'
]
=
$sites
;
}
$res
=
$this
->
apiRequest
(
$dataRequest
);
$stats
=
$res
[
'stat'
]
?:
array
();
$dates
=
array
(
'min'
=>
$res
[
'min_month'
]
?
$res
[
'min_month'
]
.
'-01'
:
date
(
'Y-m-01'
),
'max'
=>
$res
[
'max_month'
]
?
$res
[
'max_month'
]
.
'-01'
:
date
(
'Y-m-01'
),
);
//$dates = array('min' => date('Y-m', time()-86400*30*5), 'max' => date('Y-m'));
$current
=
new
\DateTime
();
$start
=
\DateTime
::
createFromFormat
(
'Y-m-d'
,
$month
.
'-01'
);
if
(
$start
->
format
(
'Y-m'
)
==
$current
->
format
(
'Y-m'
))
{
$end
=
$current
;
$end
->
modify
(
'+1 day'
);
// Для прогона цикла foreach $dateRange по всему интервалу включительно
}
else
{
$end
=
\DateTime
::
createFromFormat
(
'Y-m-d'
,
$month
.
'-01'
);
$end
->
add
(
new
\DateInterval
(
'P'
.
$end
->
format
(
't'
)
.
'D'
));
}
$dateRange
=
new
\DatePeriod
(
$start
,
new
\DateInterval
(
'P1D'
),
$end
);
$periodStats
=
array
();
foreach
(
$dateRange
as
$date
)
{
$dateValue
=
$date
->
format
(
'Y-m-d'
);
$periodStats
[
'period'
][]
=
$dateValue
;
$periodStats
[
'hits'
][]
=
intVal
(
$stats
[
$dateValue
][
'hits'
]);
$periodStats
[
'money'
][]
=
floatVal
(
$stats
[
$dateValue
][
'money'
]);
$periodStats
[
'block_hits'
][]
=
intVal
(
$stats
[
$dateValue
][
'block_hits'
]);
$periodStats
[
'block_money'
][]
=
floatVal
(
$stats
[
$dateValue
][
'block_money'
]);
if
(
$allStat
)
{
$periodStats
[
'income'
][]
=
floatVal
(
$stats
[
$dateValue
][
'income'
]);
}
}
return
array
(
$periodStats
,
$dates
);
}
// Данные по сайтам
public
function
getSitesReport
(
$month
,
array
$sites
,
$currency
,
$subdomains
,
$allStat
,
$group
)
{
if
(
!
count
(
$sites
)
&&
(
$group
!=
'subdomain'
))
{
return
array
();
}
$dataRequest
=
array
(
'method'
=>
'month_stat'
,
'data'
=>
array
(
'subdomains'
=>
$subdomains
,
'month'
=>
$month
,
'currency'
=>
$currency
,
'group'
=>
$group
,
)
);
if
(
$allStat
)
{
$dataRequest
[
'data'
][
'all_stat'
]
=
true
;
}
if
(
$group
!=
'subdomain'
)
{
$dataRequest
[
'data'
][
'domains'
]
=
$sites
;
}
$res
=
$this
->
apiRequest
(
$dataRequest
);
if
(
$res
==
null
)
{
$res
=
[];
foreach
(
$sites
as
$siteItem
)
{
$res
[]
=
array
(
'site'
=>
$siteItem
,
'hits'
=>
0
,
'money'
=>
0
,
'block_hits'
=>
0
,
'block_money'
=>
0
,
'income'
=>
0
);
}
usort
(
$res
,
function
(
$f1
,
$f2
){
return
(
$f1
[
'site'
]
<
$f2
[
'site'
])
?
-
1
:
1
;});
}
return
$res
;
}
// Данные по сайтам за вчерашние сутки
public
function
getSitesReportYestarday
(
$month
,
array
$sites
,
$currency
,
$subdomains
,
$allStat
,
$group
)
{
if
(
!
count
(
$sites
)
&&
(
$group
!=
'subdomain'
))
{
return
array
();
}
$dataRequest
=
array
(
'method'
=>
'site_stat'
,
'data'
=>
array
(
'subdomains'
=>
$subdomains
,
'day'
=>
$month
,
'currency'
=>
$currency
,
'group'
=>
$group
,
'all_stat'
=>
true
)
);
$res
=
$this
->
apiRequest
(
$dataRequest
);
return
$res
;
}
// Данные по метрикам
// Данные по метрикам
public
function
getStat
Report
(
$metric
,
$type
,
$fields
,
$dates
,
$geo
,
$sites_id
,
$zones_id
,
$by_sites
,
$by_zones
,
$by_countries
)
public
function
getStat
Data
(
$metric
,
$type
)
{
{
return
567
;
$timeDiff
=
(
strtotime
(
$dates
[
1
])
-
strtotime
(
$dates
[
0
]))
/
(
24
*
60
*
60
);
$timeDiff
=
(
strtotime
(
$dates
[
1
])
-
strtotime
(
$dates
[
0
]))
/
(
24
*
60
*
60
);
$by_days
=
(
bool
)
$dates
[
2
];
$by_days
=
(
bool
)
$dates
[
2
];
$by_sites
=
(
bool
)
$by_sites
?
(
int
)
$by_sites
:
false
;
$by_sites
=
(
bool
)
$by_sites
?
(
int
)
$by_sites
:
false
;
...
@@ -767,145 +568,6 @@ class Statistics
...
@@ -767,145 +568,6 @@ class Statistics
return
$stats
;
return
$stats
;
}
}
// Популярные страны по метрикам:
public
function
getStatReportCountries
(
$type
,
$fields
)
{
foreach
([
'sspProvider'
,
'blockProvider'
,
'argonProvider'
]
as
$field
)
{
$provider_field
=
(
in_array
(
$field
,
$fields
))
?
$field
:
$provider_field
;
}
$is_providers_metric
=
(
$provider_field
)
?
true
:
false
;
$start
=
(
$is_providers_metric
)
?
120
:
7
;
$dataRequest
=
array
(
'method'
=>
"reports"
,
'data'
=>
array
(
'type'
=>
$type
,
'fields'
=>
array_merge
(
$fields
,
[
"Country"
]),
'dates'
=>
array
(
'group'
=>
"Day"
,
'start'
=>
date
(
"Y-m-d"
,
strtotime
(
date
(
"Y-m-d"
))
-
$start
*
24
*
60
*
60
),
'end'
=>
date
(
"Y-m-d"
),
),
)
);
$stats
=
$this
->
apiRequest
(
$dataRequest
);
$countries_codes
=
[];
if
(
$is_providers_metric
)
{
foreach
(
$stats
[
'data'
][
'Day'
]
as
$day
)
{
foreach
(
$day
[
$provider_field
]
as
$provider
=>
$data
)
{
$day_countries
=
array_keys
(
$data
[
'Country'
]);
foreach
(
$day_countries
as
$code
)
{
if
(
!
in_array
(
$code
,
array_keys
(
$countries_codes
)))
{
$countries_codes
[
$code
]
=
1
;
}
else
{
$countries_codes
[
$code
]
++
;
}
}
}
}
}
else
{
foreach
(
$stats
[
'data'
][
'Day'
]
as
$day
)
{
$day_countries
=
array_keys
(
$day
[
'Country'
]);
foreach
(
$day_countries
as
$code
)
{
if
(
!
in_array
(
$code
,
array_keys
(
$countries_codes
)))
{
$countries_codes
[
$code
]
=
1
;
}
else
{
$countries_codes
[
$code
]
++
;
}
}
}
}
arsort
(
$countries_codes
);
$popular_countries
=
array_slice
(
$countries_codes
,
0
,
5
);
return
$popular_countries
;
}
// Codestat global - сводная таблица над графиком
public
function
getCodestatGlobalReport
(
array
$sites
,
$codes
)
{
if
(
!
count
(
$sites
))
{
return
array
();
}
$dataRequest
=
array
(
'method'
=>
'code_global_stat'
,
'data'
=>
array
(
'codes'
=>
$codes
,
//["adpartner"]
'sites'
=>
$sites
,
//[50000, 50095]
'currency'
=>
"USD"
)
);
$report
=
$this
->
apiRequest
(
$dataRequest
);
// Добавляем поле CTR:
if
(
$report
[
'stat'
])
{
foreach
(
$report
[
'stat'
]
as
$period
=>
$data
)
{
$report
[
'stat'
][
$period
][
'ctr'
]
=
(
$data
[
'views'
]
==
0
)
?
0
:
$data
[
'clicks'
]
/
$data
[
'views'
]
*
1
;
}
}
$report
=
$report
[
'stat'
]
?:
array
();
return
$report
;
}
// Codestat - график и таблица под графиком
public
function
getCodestatReport
(
$month
,
array
$sites
,
$codes
)
{
//$month = "2018-04";
$dataRequest
=
array
(
'method'
=>
'code_date_stat'
,
'data'
=>
array
(
'codes'
=>
$codes
,
//["adpartner"]
'sites'
=>
$sites
,
//[50000, 50095]
'month'
=>
$month
,
'currency'
=>
"USD"
,
)
);
$res
=
$this
->
apiRequest
(
$dataRequest
);
$stats
=
$res
[
'stat'
]
?:
array
();
$dates
=
array
(
'min'
=>
$res
[
'min_month'
]
?
$res
[
'min_month'
]
.
'-01'
:
date
(
'Y-m-01'
),
'max'
=>
$res
[
'max_month'
]
?
$res
[
'max_month'
]
.
'-01'
:
date
(
'Y-m-01'
),
);
$current
=
new
\DateTime
();
$start
=
\DateTime
::
createFromFormat
(
'Y-m-d'
,
$month
.
'-01'
);
if
(
$start
->
format
(
'Y-m'
)
==
$current
->
format
(
'Y-m'
))
{
$end
=
$current
;
$end
->
modify
(
'+1 day'
);
}
else
{
$end
=
\DateTime
::
createFromFormat
(
'Y-m-d'
,
$month
.
'-01'
);
$end
->
add
(
new
\DateInterval
(
'P'
.
$end
->
format
(
't'
)
.
'D'
));
}
$dateRange
=
new
\DatePeriod
(
$start
,
new
\DateInterval
(
'P1D'
),
$end
);
$periodStats
=
array
();
foreach
(
$dateRange
as
$date
)
{
$dateValue
=
$date
->
format
(
'Y-m-d'
);
$periodStats
[
'period'
][]
=
$dateValue
;
$views_value
=
intVal
(
$stats
[
$dateValue
][
'views'
]);
$clicks_value
=
intVal
(
$stats
[
$dateValue
][
'clicks'
]);
$periodStats
[
'views'
][]
=
$views_value
;
$periodStats
[
'clicks'
][]
=
$clicks_value
;
$periodStats
[
'ctr'
][]
=
(
$views_value
==
0
)
?
0
:
$clicks_value
/
$views_value
*
1
;
}
return
array
(
$periodStats
,
$dates
);
}
...
...
src/templates/app/user/cabinet-feed.phtml
View file @
f1e25e72
...
@@ -152,6 +152,8 @@ $system_link = $this->url('adm.system.actions');
...
@@ -152,6 +152,8 @@ $system_link = $this->url('adm.system.actions');
<div
id=
"chart-graph-stat"
style=
"height: 370px;"
data-colors=
<?=
(
$colors_active_lines
?
json_encode
(
$colors_active_lines
)
:
''
)
?>
>
</div
>
<div
id=
"chart-graph-stat"
style=
"height: 370px;"
data-colors=
<?=
(
$colors_active_lines
?
json_encode
(
$colors_active_lines
)
:
''
)
?>
>
</div
>
<?php
endif
?>
<?php
endif
?>
<?php
print_r
(
$stat
);
?>
<?php
/* Таблица */
?>
<?php
/* Таблица */
?>
<div
id=
"table-stat"
class=
"b-table_wrapp"
>
<div
id=
"table-stat"
class=
"b-table_wrapp"
>
<div
class=
"b-content__loading"
></div>
<div
class=
"b-content__loading"
></div>
...
@@ -160,7 +162,7 @@ $system_link = $this->url('adm.system.actions');
...
@@ -160,7 +162,7 @@ $system_link = $this->url('adm.system.actions');
<tr>
<tr>
<th>
<th>
<?php
if
(
$report
==
'common'
)
:
?>
<?php
if
(
$report
==
'common'
)
:
?>
<b
class=
"main-cat date selected"
>
<?=
_t
(
'Дата'
)
?>
</b>
/
<b
class=
"main-cat campaign"
>
<?=
_t
(
'Кампания'
)
?>
</b
>
<b
class=
"main-cat date selected"
>
<?=
_t
(
'Дата'
)
?>
</b>
<?php
/* ?> / <b class="main-cat campaign"><?= _t('Кампания')?></b><?php */
?
>
<?php
else
:
?>
<?php
else
:
?>
<b
class=
"main-cat date selected"
>
<?=
_t
(
'Транзакция'
)
?>
</b>
<b
class=
"main-cat date selected"
>
<?=
_t
(
'Транзакция'
)
?>
</b>
<?php
endif
;
?>
<?php
endif
;
?>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment