Skip to content

Commit c419fe2

Browse files
committed
Initiate the Segment Management Page
1 parent 7c16e03 commit c419fe2

File tree

8 files changed

+152
-0
lines changed

8 files changed

+152
-0
lines changed

plugins/CoreHome/stylesheets/dataTable/_entityTable.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ table.entityTable {
5252
}
5353
}
5454

55+
.table-action-cell {
56+
padding: 2px 16px;
57+
}
58+
5559
.table-action {
5660
padding: 16px;
5761
height: auto;

plugins/Morpheus/stylesheets/ui/_cards.less

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,9 @@ h1,
7272
margin: 25px 20px;
7373
}
7474
}
75+
76+
.card-content-overflow {
77+
margin: 0 -20px;
78+
overflow-x: auto;
79+
width: calc(~"100% + 40px");
80+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/**
4+
* Matomo - free/libre analytics platform
5+
*
6+
* @link https://matomo.org
7+
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8+
*/
9+
10+
namespace Piwik\Plugins\SegmentEditor;
11+
12+
use Piwik\Piwik;
13+
use Piwik\Plugins\SegmentEditor;
14+
use Piwik\Plugins\VisitsSummary;
15+
use Piwik\Request;
16+
use Piwik\View;
17+
18+
/**
19+
*/
20+
class Controller extends \Piwik\Plugin\Controller
21+
{
22+
23+
/** The requested period */
24+
protected $period;
25+
26+
public function __construct()
27+
{
28+
parent::__construct();
29+
30+
$this->period = Request::fromRequest()->getStringParameter('period' ,'day');
31+
$this->checkSitePermission();
32+
Piwik::checkUserHasViewAccess($this->idSite);
33+
}
34+
35+
public function manageSegments(): string
36+
{
37+
$view = new View('@SegmentEditor/manageSegments');
38+
$this->setGeneralVariablesView($view);
39+
$view->showMenu = true;
40+
41+
$view->segmentList = SegmentEditor\API::getInstance()->getAll($this->idSite);
42+
$view->segmentData = [];
43+
foreach ($view->segmentList as $index => $segment) {
44+
$view->segmentData[$index] = VisitsSummary\API::getInstance()
45+
->get($this->idSite, $this->period, $this->date, $segment['definition'])
46+
->getFirstRow()->getArrayCopy();
47+
}
48+
49+
return $view->render();
50+
}
51+
}

plugins/SegmentEditor/SegmentEditor.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,15 @@ public function registerEvents()
5757
'Db.getTablesInstalled' => 'getTablesInstalled',
5858
'SitesManager.deleteSite.end' => 'onDeleteSite',
5959
'UsersManager.deleteUser' => 'onDeleteUser',
60+
'API.getPagesComparisonsDisabledFor' => 'getPagesComparisonsDisabledFor',
6061
);
6162
}
6263

64+
public function getPagesComparisonsDisabledFor(&$pages)
65+
{
66+
$pages[] = 'General_Visitors.CoreHome_Segments';
67+
}
68+
6369
public function onDeleteSite($idSite)
6470
{
6571
$model = new Model();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/**
4+
* Matomo - free/libre analytics platform
5+
*
6+
* @link https://matomo.org
7+
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8+
*/
9+
10+
namespace Piwik\Plugins\SegmentEditor\Widgets;
11+
12+
use Piwik\Widget\WidgetConfig;
13+
14+
class ManageSegments extends \Piwik\Widget\Widget
15+
{
16+
public static function configure(WidgetConfig $config)
17+
{
18+
$idSite = \Piwik\Request::fromRequest()->getIntegerParameter('idSite', 0);
19+
20+
$config->setCategoryId('General_Visitors');
21+
$config->setSubcategoryId('CoreHome_Segments');
22+
$config->setName('CoreHome_Segments');
23+
$config->setIsNotWidgetizable();
24+
25+
if (empty($idSite)) {
26+
$config->disable();
27+
return;
28+
}
29+
30+
}
31+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/**
4+
* Matomo - free/libre analytics platform
5+
*
6+
* @link https://matomo.org
7+
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8+
*/
9+
10+
namespace Piwik\Plugins\SegmentEditor\Categories;
11+
12+
use Piwik\Category\Subcategory;
13+
14+
class ManageSegmentsSubcategory extends Subcategory
15+
{
16+
protected $categoryId = 'General_Visitors';
17+
protected $id = 'CoreHome_Segments';
18+
protected $order = 9999;
19+
}

plugins/SegmentEditor/lang/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"OperatorAND": "AND",
1919
"OperatorOR": "OR",
2020
"SaveAndApply": "Save &amp; Apply",
21+
"Segments": "Segments",
2122
"SegmentDisplayedAllWebsites": "all websites",
2223
"SegmentDisplayedThisWebsiteOnly": "this website only",
2324
"SegmentEditor": "Segment editor",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<div class="card">
2+
<div class="card-content">
3+
<h2 class="card-title">{{ 'CoreHome_Segments'|translate }}</h2>
4+
<div class="card-content-overflow">
5+
<table class="dataTable">
6+
<thead>
7+
<tr class="first">
8+
<th class="label">{{ 'General_Name'|translate }}</th>
9+
<th class="label">{{ 'General_ColumnNbUsers'|translate }}</th>
10+
<th class="label">{{ 'General_ColumnNbVisits'|translate }}</th>
11+
<th class="label">{{ 'General_ColumnActions'|translate }}</th>
12+
<th class="label"></th>
13+
</tr>
14+
</thead>
15+
<tbody>
16+
{% for segment in segmentList %}
17+
<tr>
18+
<td>{{ segment.name }}</td>
19+
<td>{{ segmentData[loop.index0].nb_users }}</td>
20+
<td>{{ segmentData[loop.index0].nb_visits }}</td>
21+
<td>{{ segmentData[loop.index0].nb_actions }}</td>
22+
<td class="table-action-cell">
23+
<button class="table-action icon-star" title="translate('General_Star')"></button>
24+
<button class="table-action icon-arrow-right" title="translate('General_Eye')"></button>
25+
<button class="table-action icon-edit" title="translate('General_Edit')"></button>
26+
<button class="table-action icon-delete" title="translate('General_Delete')"></button>
27+
</td>
28+
</tr>
29+
{% endfor %}
30+
</tbody>
31+
</table>
32+
</div>
33+
</div>
34+
</div>

0 commit comments

Comments
 (0)