Zurnal   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 21
c 1
b 0
f 0
dl 0
loc 76
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 3
A getLastChange() 0 8 2
A getAllChanges() 0 15 3
1
<?php
2
/**
3
 * FlexiPeeHP - Objekt Žurnálu.
4
 *
5
 * @author     Vítězslav Dvořák <[email protected]>
6
 * @copyright  (C) 2017 Spoje.Net
7
 */
8
9
namespace FlexiPeeHP;
10
11
/**
12
 * Žurnál změn
13
 * Journal of Changes
14
 *
15
 * @link https://demo.flexibee.eu/c/demo/adresar/properties položky evidence
16
 */
17
class Zurnal extends RO
18
{
19
    /**
20
     * Evidence užitá objektem.
21
     *
22
     * @var string
23
     */
24
    public $evidence = 'zurnal';
25
26
    /**
27
     *
28
     * @var array
29
     */
30
    public static $evidenceToDb = ['faktura-vydana' => 'ddoklfak'];
31
32
    /**
33
     * Class for read only interaction with FlexiBee.
34
     *
35
     * @param mixed $init default record id or initial data
36
     * @param array $options Connection settings and other options override
37
     */
38
    public function __construct($init = null, $options = [])
39
    {
40
        parent::__construct($init, $options);
41
        foreach (EvidenceList::$evidences as $evidenceName => $evidenceProperties) {
42
            if (array_key_exists('dbName', $evidenceProperties)) {
43
                self::$evidenceToDb[$evidenceName] = $evidenceProperties['dbName'];
44
            }
45
        }
46
    }
47
48
    /**
49
     * obtain all record changes array
50
     *
51
     * Note: Do not use this method in production environment!
52
     *
53
     *       If you have no other choice pleas add indexes into wzurnal
54
     *       postgesql table:
55
     *
56
     *       CREATE INDEX CONCURRENTLY tname_index ON wzurnal (tabulka);
57
     *       CREATE INDEX CONCURRENTLY rid_index ON wzurnal (idZaznamu);
58
     *
59
     * @param RO $object
60
     * @return array changes history
61
     */
62
    public function getAllChanges($object)
63
    {
64
        $changesArray = [];
65
66
        $evidence = $object->getEvidence();
67
        if (array_key_exists($evidence, self::$evidenceToDb)) {
68
            $dbTable = self::$evidenceToDb[$evidence];
69
            $changes = $this->getColumnsFromAbraFlexi('*',
70
                ['tabulka' => $dbTable, 'idZaznamu' => $object->getMyKey()]);
71
72
            foreach ($changes as $change) {
73
                $changesArray[$change['datCas']][$change['sloupec']] = $change;
74
            }
75
        }
76
        return $changesArray;
77
    }
78
79
    /**
80
     * obtain last change array
81
     *
82
     * @param RO $object
83
     * @return array Old/New values pairs
84
     */
85
    public function getLastChange($object)
86
    {
87
        $lastChange = null;
88
        $allChanges = $this->getAllChanges($object);
89
        if (count($allChanges)) {
90
            $lastChange = end($allChanges);
91
        }
92
        return $lastChange;
93
    }
94
}
95