This repository has been archived by the owner on Jun 27, 2020. It is now read-only.
/
statusupdateevent.php
190 lines (171 loc) · 8.42 KB
/
statusupdateevent.php
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
/**
* SOFTWARE NAME: autostatus
* SOFTWARE RELEASE: 0.2
* COPYRIGHT NOTICE: Copyright (C) 2009-2011 Damien POBEL
* SOFTWARE LICENSE: GNU General Public License v2.0
* NOTICE: >
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.0 of the GNU General
* Public License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of version 2.0 of the GNU General
* Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
/**
* eZPersistent object implementation used to store
* updates launched by autostatus extension
*
* @uses eZPersistentObject
* @author Damien Pobel
*/
class statusUpdateEvent extends eZPersistentObject
{
const NORMAL = 0;
const EXCEPTION = 1;
const ERROR = 2;
static $statusText = array( self::NORMAL => 'normal',
self::EXCEPTION => 'exception',
self::ERROR => 'error' );
protected $ID;
protected $WorkflowEventID;
protected $UserID;
protected $ContentObjectID;
protected $StatusMessage;
protected $Created;
protected $Modified;
protected $ErrorMessage;
protected $Status;
static function definition()
{
static $definition = array( 'fields' => array( 'id' => array( 'name' => 'ID',
'datatype' => 'integer',
'default' => 0,
'required' => true ),
'event_id' => array( 'name' => 'WorkflowEventID',
'datatype' => 'integer',
'default' => 0,
'required' => true ),
'user_id' => array( 'name' => 'UserID',
'datatype' => 'integer',
'default' => 0,
'required' => true ),
'contentobject_id' => array( 'name' => 'ContentObjectID',
'datatype' => 'integer',
'default' => 0,
'required' => true ),
'message' => array( 'name' => 'StatusMessage',
'datatype' => 'string',
'default' => '',
'required' => true ),
'created' => array( 'name' => 'Created',
'datatype' => 'integer',
'default' => 0,
'required' => true ),
'modified' => array( 'name' => 'Modified',
'datatype' => 'integer',
'default' => 0,
'required' => true ),
'status' => array( 'name' => 'Status',
'datatype' => 'integer',
'default' => 0,
'required' => true ),
'error_msg' => array( 'name' => 'ErrorMessage',
'datatype' => 'string',
'default' => '',
'required' => true ) ),
'keys' => array( 'id' ),
'increment_key' => 'id',
'function_attributes' => array( 'event' => 'fetchEvent',
'user' => 'fetchUser',
'object' => 'fetchContentObject',
'status_text' => 'statusText',
'is_error' => 'isError' ),
'class_name' => 'statusUpdateEvent',
'name' => 'statusupdateevent' );
return $definition;
}
function fetchUser()
{
return eZUser::fetch( $this->UserID );
}
function fetchContentObject()
{
return eZContentObject::fetch( $this->ContentObjectID );
}
function fetchEvent()
{
$eventID = $this->attribute( 'event_id' );
return eZWorkflowEvent::fetch( $eventID );
}
function isError()
{
return ( $this->Status !== self::NORMAL );
}
function statusText()
{
return self::$statusText[$this->Status];
}
/**
* Create an statusUpdateEvent instance
*
* @param int $eventID workflow event id
* @param string $message message used to update status
* @param string $errorMsg error message
* @param int $status status code
* @param int $userID user id that sends the update
* @param int $contentObjectID content object id
* @static
* @access public
* @return statusUpdateEvent
*/
static function create( $eventID, $message, $errorMsg, $status, $userID, $contentObjectID )
{
$row = array( 'event_id' => $eventID,
'created' => time(),
'modified' => time(),
'message' => $message,
'error_msg' => (string) $errorMsg,
'status' => $status,
'user_id' => $userID,
'contentobject_id' => $contentObjectID );
return new statusUpdateEvent( $row );
}
static function fetch( $id )
{
return eZPersistentObject::fetchObject( self::definition(),
null,
array( 'id' => $id ),
true );
}
static function fetchList( $conditions, $offset, $limit )
{
$result = eZPersistentObject::fetchObjectList( self::definition(),
null, // field filters
$conditions,
array( 'modified' => 'desc' ),
array( 'limit' => $limit, 'offset' => $offset ),
true );
return $result;
}
static function fetchListCount( $conditions = array() )
{
return eZPersistentObject::count( self::definition(), $conditions );
}
function store( $fieldFilters = null )
{
if ( $this->ID )
{
$this->Modified = time();
}
parent::store( $fieldFilters );
}
}
?>