Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F4793849
ActionsReport.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
ActionsReport.php
View Options
<?php
namespace
Nasqueron\Notifications\Actions
;
use
Nasqueron\Notifications\Events\ReportEvent
;
use
Event
;
use
Response
;
class
ActionsReport
{
/**
* List of actions
*
* @var Action[]
*/
public
$actions
=
[];
/**
* Report created date
*
* @var int
*/
public
$created
;
/**
* The entry gate
*
* @var string
*/
public
$gate
;
/**
* The entry door
*
* @var string
*/
public
$door
;
/**
* Initializes a new instance of an actions report
*/
public
function
__construct
()
{
$this
->
created
=
time
();
$this
->
listenToReports
();
}
///
/// Properties
///
public
function
attachToGate
(
$gate
,
$door
)
{
$this
->
gate
=
$gate
;
$this
->
door
=
$door
;
}
/**
* Determines if one of the action has failed.
*
* @return bool
*/
public
function
containsError
()
{
foreach
(
$this
->
actions
as
$action
)
{
if
(
$action
->
error
!==
null
)
{
return
true
;
}
}
return
false
;
}
///
/// Output
///
/**
* Gets a JSON string representation of the current instance
*/
public
function
__toString
()
{
return
json_encode
(
$this
,
JSON_PRETTY_PRINT
);
}
/**
* Renders the report
*
* @return Illuminate\Http\Response
*/
public
function
render
()
{
return
Response
::
json
(
$this
)
->
setStatusCode
(
$this
->
getResponseStatusCode
());
}
/**
* Determines the HTTP status code of the response
*
* @return int 200 if all is fine, 503 if an error is present
*/
public
function
getResponseStatusCode
()
{
return
$this
->
containsError
()
?
503
:
200
;
}
///
/// Events
///
public
function
listenToReports
()
{
Event
::
listen
(
'Nasqueron
\N
otifications
\E
vents
\R
eportEvent'
,
function
(
ReportEvent
$event
)
{
$this
->
actions
[]
=
$event
->
action
;
}
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Feb 28, 22:47 (1 d, 2 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2438110
Default Alt Text
ActionsReport.php (2 KB)
Attached To
Mode
rNOTIF Notifications center
Attached
Detach File
Event Timeline
Log In to Comment