Данные для размеров зон сайта

parent b17f41b8
...@@ -64,6 +64,7 @@ return [ ...@@ -64,6 +64,7 @@ return [
$hpm->setService(\App\Entity\AmSystem\Campaign::class, new \Zend\Hydrator\ClassMethods()); $hpm->setService(\App\Entity\AmSystem\Campaign::class, new \Zend\Hydrator\ClassMethods());
$hpm->setService(\App\Entity\AmSystem\Banner::class, new \Zend\Hydrator\ClassMethods()); $hpm->setService(\App\Entity\AmSystem\Banner::class, new \Zend\Hydrator\ClassMethods());
$hpm->setService(\App\Entity\Zone::class, new \Zend\Hydrator\ClassMethods());
$hpm->setService(\App\Entity\Contacts::class, new \Zend\Hydrator\ClassMethods()); $hpm->setService(\App\Entity\Contacts::class, new \Zend\Hydrator\ClassMethods());
...@@ -251,6 +252,18 @@ return [ ...@@ -251,6 +252,18 @@ return [
$container->get(\Monolog\Logger::class) $container->get(\Monolog\Logger::class)
); );
}, },
\App\Model\Zones::class => function (ContainerInterface $container) {
return new \App\Model\Zones(
new Zend\Db\TableGateway\TableGateway(
'zones',
$container->get(Zend\Db\Adapter\Adapter::class),
new \Zend\Db\TableGateway\Feature\MetadataFeature(),
new \Zend\Db\ResultSet\HydratingResultSet($container->get(\Zend\Hydrator\DelegatingHydrator::class), new \App\Entity\Zone())
),
$container->get(\Zend\Hydrator\DelegatingHydrator::class),
$container->get(\Monolog\Logger::class)
);
},
\App\Model\FAQ\Categories::class => function (ContainerInterface $container) { \App\Model\FAQ\Categories::class => function (ContainerInterface $container) {
return new \App\Model\FAQ\Categories( return new \App\Model\FAQ\Categories(
new Zend\Db\TableGateway\TableGateway( new Zend\Db\TableGateway\TableGateway(
......
...@@ -241,7 +241,7 @@ $(document).ready(function () { ...@@ -241,7 +241,7 @@ $(document).ready(function () {
codeCities = JSON.parse($('#cities-codes').val()); codeCities = JSON.parse($('#cities-codes').val());
} }
//console.log('AAA dataStat = ', dataStat); //console.log('AAA dataStat = ', dataSitesStat);
function ShowCommonStatInfo() function ShowCommonStatInfo()
{ {
...@@ -537,7 +537,7 @@ $(document).ready(function () { ...@@ -537,7 +537,7 @@ $(document).ready(function () {
if (item['sub']) { if (item['sub']) {
for (var zone in item['sub']) { for (var zone in item['sub']) {
$row = $('<tr class="subcat" data-parent="' + item['site'] + '">'); $row = $('<tr class="subcat" data-parent="' + item['site'] + '">');
$row.append($('<td class="subcat-title">').html('зона [' + zone % 100 + '] (' + '300x250' + ')')); $row.append($('<td class="subcat-title">').html('зона [' + zone % 100 + '] (' + item['sub'][zone]['size'] + ')'));
activeLinesId.forEach(function(line){ activeLinesId.forEach(function(line){
$row.append($('<td class="stat '+ line +'">').html(valueFormatTable(item['sub'][zone][line], line))); $row.append($('<td class="stat '+ line +'">').html(valueFormatTable(item['sub'][zone][line], line)));
}); });
......
...@@ -45,13 +45,13 @@ class CabinetAmSystem extends Common ...@@ -45,13 +45,13 @@ class CabinetAmSystem extends Common
const ACTION_ITEM = 'item'; const ACTION_ITEM = 'item';
const CAMPAIGN_STAT_CATS = [ const CAMPAIGN_STAT_CATS = [
'views' => ['title' => 'Показы', 'color' => '#2CA02C'], 'views' => ['title' => 'Показы', 'color' => '#2CA02C'],
'clicks' => ['title' => 'Клики', 'color' => '#D62728'], 'clicks' => ['title' => 'Клики', 'color' => '#D62728'],
'money' => ['title' => 'Расход', 'color' => '#1F77B4'], 'money' => ['title' => 'Расход', 'color' => '#1F77B4'],
'reach' => ['title' => 'Охват', 'color' => '#FF7F0E'], 'reach' => ['title' => 'Охват', 'color' => '#FF7F0E'],
'ctr' => ['title' => 'CTR', 'color' => '#9467BD'], 'ctr' => ['title' => 'CTR', 'color' => '#9467BD'],
'cpm' => ['title' => 'eCPM', 'color' => '#33C7B6'], 'cpm' => ['title' => 'eCPM', 'color' => '#33C7B6'],
'cpc' => ['title' => 'eCPC', 'color' => '#7CADE2'] 'cpc' => ['title' => 'eCPC', 'color' => '#7CADE2']
]; ];
const IMG_DOMAIN_DEV = 'https://addcpm.app.dev.rew.to'; const IMG_DOMAIN_DEV = 'https://addcpm.app.dev.rew.to';
const IMG_DOMAIN_PROD = 'https://www.addcpm.com'; const IMG_DOMAIN_PROD = 'https://www.addcpm.com';
...@@ -86,6 +86,7 @@ class CabinetAmSystem extends Common ...@@ -86,6 +86,7 @@ class CabinetAmSystem extends Common
} }
elseif($request->getAttribute('action') == self::ACTION_LIST) elseif($request->getAttribute('action') == self::ACTION_LIST)
{ {
try { try {
/** @var UserService $auth */ /** @var UserService $auth */
...@@ -199,6 +200,25 @@ class CabinetAmSystem extends Common ...@@ -199,6 +200,25 @@ class CabinetAmSystem extends Common
$sites_stats = $stats->getCampaignsSitesStat((int)$campaign_id, $campaign->getTargetAction(), $dates); $sites_stats = $stats->getCampaignsSitesStat((int)$campaign_id, $campaign->getTargetAction(), $dates);
$regions_stats = $stats->getCampaignsRegionsStat((int)$campaign_id, $campaign->getTargetAction(), $dates); $regions_stats = $stats->getCampaignsRegionsStat((int)$campaign_id, $campaign->getTargetAction(), $dates);
// Добавляем размер зоны в данные по сайтам:
/** @var \App\Model\Zones $zonesModel */
$zonesModel = $this->container->get(\App\Model\Zones::class);
foreach ($sites_stats as $site_name => $site_data) {
if ($site_data['sub']) {
foreach ($site_data['sub'] as $zone_id => $zone_data) {
$zone = $zonesModel->findById($zone_id);
if ($zone) {
$zone_width = $zone->getWidth();
$zone_height = $zone->getHeight();
$zone_size = $zone_width.'x'.$zone_height;
} else {
$zone_size = null;
}
$sites_stats[$site_name]['sub'][$zone_id]['size'] = $zone_size;
}
}
}
$data['campaign'] = $campaign; $data['campaign'] = $campaign;
$data['countries'] = $countries; $data['countries'] = $countries;
......
<?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.
*
*
*/
namespace App\Entity;
/**
* Class Zone
* @package App\Entity
*/
class Zone extends Common
{
const NOT_HIDDEN = 0;
const HIDDEN = 1;
/**
* @var string
*/
protected $siteId;
protected $width;
protected $height;
/**
* @var boolean
*/
protected $hidden = 0;
/**
* @return string
*/
public function getSiteId()
{
return $this->siteId;
}
/**
* @param string $siteId
* @return Zone
*/
public function setSiteId($siteId)
{
$this->siteId = $siteId;
return $this;
}
/**
* @return string
*/
public function getWidth()
{
return $this->width;
}
/**
* @param string $width
* @return Zone
*/
public function setWidth($width)
{
$this->width = $width;
return $this;
}
/**
* @return string
*/
public function getHeight()
{
return $this->height;
}
/**
* @param string $height
* @return Zone
*/
public function setHeight($height)
{
$this->height = $height;
return $this;
}
/**
* @return int
*/
public function getMinWindowWidth()
{
return $this->minWindowWidth;
}
/**
* @param int $minwindowwidth
* @return Zone
*/
public function setMinWindowWidth($minwindowwidth)
{
$this->minWindowWidth = $minwindowwidth;
return $this;
}
/**
* @return int
*/
public function getMaxWindowWidth()
{
return $this->maxWindowWidth;
}
/**
* @param int $maxwindowwidth
* @return Zone
*/
public function setMaxWindowWidth($maxwindowwidth)
{
$this->maxWindowWidth = $maxwindowwidth;
return $this;
}
/**
* @return int
*/
public function getHidden()
{
return $this->hidden;
}
/**
* @param int $is_hidden
* @return Zone
*/
public function setHidden($is_hidden)
{
$this->hidden = $is_hidden;
return $this;
}
/**
* @return int
*/
public function getDisabled()
{
return $this->disabled;
}
/**
* @param int $is_disable
* @return Zone
*/
public function setDisabled($is_disable)
{
$this->disabled = $is_disable;
return $this;
}
/**
* @return int
*/
public function getDeleted()
{
return $this->deleted;
}
/**
* @param int $is_deleted
* @return Zone
*/
public function setDeleted($is_deleted)
{
$this->deleted = $is_deleted;
return $this;
}
/**
* @return string
*/
public function getSelectors()
{
return $this->selectors;
}
/**
* @param string $selectors
* @return Zone
*/
public function setSelectors($selectors)
{
$this->selectors = $selectors;
return $this;
}
/**
* @return string
*/
public function getMoreSelectors()
{
return $this->moreSelectors;
}
/**
* @param string $more_selectors
* @return Zone
*/
public function setMoreSelectors($more_selectors)
{
$this->moreSelectors = $more_selectors;
return $this;
}
/**
* @return string
*/
public function getTargets()
{
return $this->targets;
}
/**
* @param string $targets
* @return Zone
*/
public function setTargets($targets)
{
$this->targets = $targets;
return $this;
}
/**
* @return string
*/
public function getStyles()
{
return $this->styles;
}
/**
* @param string $styles
* @return Zone
*/
public function setStyles($styles)
{
$this->styles = $styles;
return $this;
}
/**
* @return string
*/
public function getSeq()
{
return $this->seq;
}
/**
* @param string $seq
* @return Zone
*/
public function setSeq($seq)
{
$this->seq = $seq;
return $this;
}
/**
* @return string
*/
public function getTpl()
{
return $this->tpl;
}
/**
* @param string $tpl
* @return Zone
*/
public function setTpl($tpl)
{
$this->tpl = $tpl;
return $this;
}
/**
* @return string
*/
public function getAddition()
{
return $this->addition;
}
/**
* @param string $addition
* @return Zone
*/
public function setAddition($addition)
{
$this->addition = $addition;
return $this;
}
/**
* @return string
*/
public function getComment()
{
return $this->comment;
}
/**
* @param string $comment
* @return Zone
*/
public function setComment($comment)
{
$this->comment = $comment;
return $this;
}
/**
* @return string
*/
public function getMinCpm()
{
return $this->minCpm;
}
/**
* @param string $minCpm
* @return Zone
*/
public function setMinCpm($minCpm)
{
$this->minCpm = $minCpm;
return $this;
}
}
\ No newline at end of file
<?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.
*
*
*/
namespace App\Model;
use App\Entity\Zone;
use Zend\Diactoros\Response\JsonResponse;
/**
* Class Zones
* @package App\Model
*/
class Zones extends Common
{
/**
* @param $id
* @return Zone[]
*/
public function findBySiteId($id)
{
/** @noinspection PhpIncompatibleReturnTypeInspection */
return $this->findAll(['site_id' => $id, 'hidden' => 0]);
}
/**
* @param $id
* @return int
*/
public function findCurrentIdBySiteId($id)
{
/** @noinspection PhpIncompatibleReturnTypeInspection */
$zones = $this->findAll(['site_id' => $id]);
$currentIdZone = $id * 100;
foreach ($zones as $zone) {
$currentIdZone = ($zone->getId() > $currentIdZone) ? $zone->getId(): $currentIdZone;
}
return $currentIdZone;
}
public function findSiteZones()
{
$adapter = $this->tableGateway->getAdapter();
$sql = 'SELECT site_id, COUNT(*) AS count'
. ' FROM ' . (string) $this->tableGateway->getTable()
. ' GROUP BY site_id';
$res = $adapter->query($sql, \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE);
$zonesCount = array();
if($res) {
foreach($res as $r) {
$zonesCount[$r['site_id']] = $r['count'];
}
}
return $zonesCount;
}
public function findZonesInfoSize()
{
$zones_list = [];
$zones = $this->findAll()->toArray();
foreach ($zones as $zone) {
$zones_list[$zone['id']]['size'] = $zone['width'].'x'.$zone['height'];
$zones_list[$zone['id']]['site_id'] = $zone['site_id'];
}
return $zones_list;
}
public function findZonesInfoSizeById($zones_id)
{
$zones_list = [];
$zones = $this->findAll(['id' => $zones_id])->toArray();
foreach ($zones as $zone) {
$zones_list[$zone['id']]['size'] = $zone['width'].'x'.$zone['height'];
}
return $zones_list;
}
/**
* @param \App\Entity\Common $entity
* @return int
* @throws \Exception
*/
public function create($entity)
{
$data = $this->delegatingHydrator->extract($entity);
// accept data columns only available at table
$data = array_intersect_key($data, array_fill_keys($this->tableGateway->getColumns(), 1));
$query = function($data) {
$this->tableGateway->insert($data);
$insertId = $this->tableGateway->lastInsertValue;
return $insertId;
};
try {
$this->tableGateway->getAdapter()->getDriver()->getConnection()->beginTransaction();
$id = $query($data);
$this->tableGateway->getAdapter()->getDriver()->getConnection()->commit();
} catch (\Exception $e) {
$this->tableGateway->getAdapter()->getDriver()->getConnection()->rollback();
throw $e;
}
return $id;
}
public function updateStatus($id, $status, $value)
{
$zone = $this->findById($id);
$data = [];
if ($zone) {
$hydrator = $this->delegatingHydrator;
$zone = $hydrator->hydrate([$status => $value], $zone);
try {
$this->save($zone);
$data['result'] = true;
} catch (\Exception $e) {
$data['result'] = false;
$data['msg'] = $e->getMessage();
}
} else {
$data = [
'result' => false,
'msg' => 'Zone not found',
];
}
$response = new JsonResponse($data);
return $response;
}
public function deleteBySiteId($site_id)
{
$zone_items = $this->findAll(['site_id' => $site_id]);
if ($zone_items)
{
foreach ($zone_items as $zone_item)
{
$result = $this->deleteById($zone_item->getId());
}
}
return $result;
}
public function createListZones()
{
$list_zones = [];
foreach($this->findAll()->toArray() as $zone_data) {
$list_zones[$zone_data['id']] = $zone_data['site_id'];
}
return $list_zones;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment