|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Alpha\Model; |
|
4
|
|
|
|
|
5
|
|
|
use Alpha\Model\Type\SmallText; |
|
6
|
|
|
use Alpha\Model\Type\Relation; |
|
7
|
|
|
use Alpha\Util\Logging\Logger; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* An action carried out be a person using the system can be logged using this class. Best |
|
11
|
|
|
* to call via Logger::action() method rather than directly here. |
|
12
|
|
|
* |
|
13
|
|
|
* @since 1.2.2 |
|
14
|
|
|
* |
|
15
|
|
|
* @author John Collins <[email protected]> |
|
16
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License |
|
17
|
|
|
* @copyright Copyright (c) 2019, John Collins (founder of Alpha Framework). |
|
18
|
|
|
* All rights reserved. |
|
19
|
|
|
* |
|
20
|
|
|
* <pre> |
|
21
|
|
|
* Redistribution and use in source and binary forms, with or |
|
22
|
|
|
* without modification, are permitted provided that the |
|
23
|
|
|
* following conditions are met: |
|
24
|
|
|
* |
|
25
|
|
|
* * Redistributions of source code must retain the above |
|
26
|
|
|
* copyright notice, this list of conditions and the |
|
27
|
|
|
* following disclaimer. |
|
28
|
|
|
* * Redistributions in binary form must reproduce the above |
|
29
|
|
|
* copyright notice, this list of conditions and the |
|
30
|
|
|
* following disclaimer in the documentation and/or other |
|
31
|
|
|
* materials provided with the distribution. |
|
32
|
|
|
* * Neither the name of the Alpha Framework nor the names |
|
33
|
|
|
* of its contributors may be used to endorse or promote |
|
34
|
|
|
* products derived from this software without specific |
|
35
|
|
|
* prior written permission. |
|
36
|
|
|
* |
|
37
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
|
38
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
39
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
40
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
41
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
|
42
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
43
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|
44
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
45
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
46
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
47
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
|
48
|
|
|
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
49
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
50
|
|
|
* </pre> |
|
51
|
|
|
*/ |
|
52
|
|
|
class ActionLog extends ActiveRecord |
|
53
|
|
|
{ |
|
54
|
|
|
/** |
|
55
|
|
|
* The HTTP user-agent client string. |
|
56
|
|
|
* |
|
57
|
|
|
* @var \Alpha\Model\Type\SmallText |
|
58
|
|
|
* |
|
59
|
|
|
* @since 1.2.2 |
|
60
|
|
|
*/ |
|
61
|
|
|
protected $client; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* The IP of the client. |
|
65
|
|
|
* |
|
66
|
|
|
* @var \Alpha\Model\Type\SmallText |
|
67
|
|
|
* |
|
68
|
|
|
* @since 1.2.2 |
|
69
|
|
|
*/ |
|
70
|
|
|
protected $IP; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* The action carried out by the person should be described here. |
|
74
|
|
|
* |
|
75
|
|
|
* @var \Alpha\Model\Type\SmallText |
|
76
|
|
|
* |
|
77
|
|
|
* @since 1.2.2 |
|
78
|
|
|
*/ |
|
79
|
|
|
protected $message; |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* The person who carried out the action. |
|
83
|
|
|
* |
|
84
|
|
|
* @var \Alpha\Model\Person |
|
85
|
|
|
* |
|
86
|
|
|
* @since 2.0 |
|
87
|
|
|
*/ |
|
88
|
|
|
protected $personID; |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* An array of data display labels for the class properties. |
|
92
|
|
|
* |
|
93
|
|
|
* @var array |
|
94
|
|
|
* |
|
95
|
|
|
* @since 1.2.2 |
|
96
|
|
|
*/ |
|
97
|
|
|
protected $dataLabels = array('ID' => 'Action Log ID#', 'client' => 'Client string', 'IP' => 'IP address', 'message' => 'Message', 'personID' => 'Owner'); |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* The name of the database table for the class. |
|
101
|
|
|
* |
|
102
|
|
|
* @var string |
|
103
|
|
|
* |
|
104
|
|
|
* @since 1.2.2 |
|
105
|
|
|
*/ |
|
106
|
|
|
const TABLE_NAME = 'ActionLog'; |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Trace logger. |
|
110
|
|
|
* |
|
111
|
|
|
* @var \Alpha\Util\Logging\Logger |
|
112
|
|
|
* |
|
113
|
|
|
* @since 1.2.2 |
|
114
|
|
|
*/ |
|
115
|
|
|
private static $logger = null; |
|
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Constructor. |
|
119
|
|
|
* |
|
120
|
|
|
* @since 1.0 |
|
121
|
|
|
*/ |
|
122
|
|
|
public function __construct() |
|
123
|
|
|
{ |
|
124
|
|
|
self::$logger = new Logger('ActionLog'); |
|
125
|
|
|
|
|
126
|
|
|
// ensure to call the parent constructor |
|
127
|
|
|
parent::__construct(); |
|
128
|
|
|
|
|
129
|
|
|
$this->client = new SmallText(); |
|
130
|
|
|
$this->IP = new SmallText(); |
|
131
|
|
|
$this->message = new SmallText(); |
|
132
|
|
|
|
|
133
|
|
|
$this->personID = new Relation(); |
|
134
|
|
|
$this->personID->setRelatedClass('Alpha\Model\Person'); |
|
135
|
|
|
$this->personID->setRelatedClassField('ID'); |
|
136
|
|
|
$this->personID->setRelatedClassDisplayField('username'); |
|
137
|
|
|
$this->personID->setRelationType('MANY-TO-ONE'); |
|
138
|
|
|
$this->personID->setValue($this->created_by->getValue()); |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|