Skip to content

Commit 59eed5b

Browse files
committed
MC-1426: \Magento\Cms\Model\ResourceModel\Page\CollectionFactory
- add advanced reporting support for CMS pages
1 parent b59da88 commit 59eed5b

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\PageBuilderAnalytics\Model;
8+
9+
10+
use Magento\Cms\Model\ResourceModel\Page\CollectionFactory;
11+
12+
/**
13+
* Provides PageBuilder content type report.
14+
*/
15+
class PageBuilderProvider
16+
{
17+
/**
18+
* @var \Magento\Cms\Model\ResourceModel\Page\CollectionFactory
19+
*/
20+
private $collectionFactory;
21+
22+
/**
23+
* PageBuilderProvider constructor.
24+
*
25+
* @param CollectionFactory $collectionFactory
26+
*/
27+
public function __construct(CollectionFactory $collectionFactory)
28+
{
29+
$this->collectionFactory = $collectionFactory;
30+
}
31+
32+
/**
33+
* Returns report data for CMS pages
34+
*
35+
* @return \IteratorIterator
36+
*/
37+
public function getReport()
38+
{
39+
// move content types elsewhere and load
40+
$contentTypes = ['row', 'column', 'tabs', 'tab-item', 'text', 'heading', 'buttons', 'button-item', 'divider',
41+
'html', 'image', 'video', 'banner', 'slider', 'slide', 'map', 'block', 'dynamic_block', 'products'];
42+
43+
/**
44+
* @var \Magento\Cms\Model\ResourceModel\Page\Collection
45+
*/
46+
$collection = $this->collectionFactory->create();
47+
// build select by iterating content types
48+
foreach ($contentTypes as $contentType) {
49+
$expr = 'sum((char_length(content) - char_length(replace(content, \'data-role=\"' . $contentType .
50+
'\", \'\'))) / ' . strlen($contentType) . ')';
51+
$collection->addExpressionFieldToSelect($contentType, $expr, 'content');
52+
}
53+
$contentTypeReport = $collection->getData();
54+
return new \IteratorIterator(new \ArrayIterator($contentTypeReport ?: []));
55+
}
56+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Analytics:etc/analytics.xsd">
9+
<file name="pba">
10+
<providers>
11+
<customProvider name="pba" class="Magento\PageBuilderAnalytics\Model\PageBuilderProvider"/>
12+
</providers>
13+
</file>
14+
</config>

0 commit comments

Comments
 (0)