Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F804766
file_eh.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Feb 26, 5:01 PM
Size
2 KB
Mime Type
text/x-php
Expires
Fri, Feb 28, 5:01 PM (12 h, 40 m)
Engine
blob
Format
Raw Data
Handle
577176
Attached To
rINP In-Portal
file_eh.php
View Options
<?php
class
FileEventHandler
extends
kDBEventHandler
{
/**
* Allows to override standart permission mapping
*
*/
function
mapPermissions
()
{
parent
::
mapPermissions
();
$permissions
=
Array
(
'OnDownloadFile'
=>
Array
(
'subitem'
=>
'view'
),
);
$this
->
permMapping
=
array_merge
(
$this
->
permMapping
,
$permissions
);
}
/**
* [HOOK] Allows to apply file functionality to specific config
* When main item is created, then #file config is cloned
*
* @param kEvent $event
*/
function
OnDefineFiles
(&
$event
)
{
$clones
=
$this
->
Application
->
getUnitOption
(
'#file'
,
'Clones'
);
$clones
[
$event
->
MasterEvent
->
Prefix
.
'-file'
]
=
Array
(
'ParentPrefix'
=>
$event
->
MasterEvent
->
Prefix
,
);
$this
->
Application
->
setUnitOption
(
'#file'
,
'Clones'
,
$clones
);
}
/**
* Remembers user, who is created file record. Makes file primary if no other files are uploaded.
*
* @param kEvent $event
*/
function
OnBeforeItemCreate
(&
$event
)
{
$object
=&
$event
->
getObject
();
$object
->
SetDBField
(
'CreatedById'
,
$this
->
Application
->
RecallVar
(
'user_id'
));
}
/**
* Resets primary file mark when more then one file is marked as primary
*
* @param kEvent $event
*/
function
OnBeforeItemUpdate
(&
$event
)
{
$object
=&
$event
->
getObject
();
if
(!
$object
->
GetDBField
(
'FileName'
))
{
$object
->
SetDBField
(
'FileName'
,
basename
(
$object
->
GetDBField
(
'FilePath'
)));
}
}
function
SetCustomQuery
(&
$event
)
{
parent
::
SetCustomQuery
(
$event
);
$object
=&
$event
->
getObject
();
if
(!
$this
->
Application
->
IsAdmin
())
{
$object
->
addFilter
(
'active_filter'
,
'%1$s.Status = '
.
STATUS_ACTIVE
);
}
}
/**
* Returns file contents associated with item
*
* @param kEvent $event
*/
function
OnDownloadFile
(&
$event
)
{
$object
=&
$event
->
getObject
();
/* @var $object kDBItem */
$file_helper
=&
$this
->
Application
->
recallObject
(
'FileHelper'
);
/* @var $file_helper FileHelper */
$filename
=
$object
->
GetField
(
'FilePath'
,
'full_path'
);
$file_helper
->
DownloadFile
(
$filename
);
$event
->
status
=
erSTOP
;
}
}
?>
Event Timeline
Log In to Comment