Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Formatter.php « FileSynchronizer « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1f10bbf8c1ec8fd3b4af5411332580b6f1a2ad84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
 * Copyright (C) Piwik PRO - All rights reserved.
 *
 * Using this code requires that you first get a license from Piwik PRO.
 * Unauthorized copying of this file, via any medium is strictly prohibited.
 *
 * @link http://piwik.pro
 */

namespace Piwik\Plugins\FileSynchronizer;

use Piwik\Container\StaticContainer;
use Piwik\Date;
use Piwik\Db;
use Piwik\Metrics\Formatter as MetricsFormatter;

class Formatter
{

    public function addTimeAgoAsSentence($files)
    {
        $formatter = new MetricsFormatter();
        $now = StaticContainer::get('FileSynchronizer.currentTimestamp');

        foreach ($files as &$file) {
            $diff = $now - Date::factory($file['start_date'])->getTimestamp();
            $file['time_ago'] = $formatter->getPrettyTimeFromSeconds($diff, true);
        }

        return $files;
    }

    public function formatSyncedFiles($files)
    {
        $formatter = new MetricsFormatter();

        foreach ($files as &$syncedFile) {
            $syncedFile['source_filename'] = basename($syncedFile['source']);
            $syncedFile['date'] = substr($syncedFile['start_date'], 0, 10);
            $syncedFile['duration'] = $syncedFile['duration_in_ms'] . 'ms';
            $syncedFile['size_human'] = $formatter->getPrettySizeFromBytes($syncedFile['file_size']);
        }

        return $files;
    }

}