Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1376477
files_event_handler.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
Sun, Feb 1, 7:45 PM
Size
3 KB
Mime Type
text/x-php
Expires
Tue, Feb 3, 7:45 PM (3 h, 43 m)
Engine
blob
Format
Raw Data
Handle
884762
Attached To
rMINC Modules.In-Commerce
files_event_handler.php
View Options
<?php
class
FilesEventHandler
extends
kDBEventHandler
{
/**
* Get's special of main item for linking with subitem
*
* @param kEvent $event
* @return string
*/
function
getMainSpecial
(&
$event
)
{
if
(
$event
->
Special
==
'downl'
)
{
return
''
;
}
return
parent
::
getMainSpecial
(
$event
);
}
function
SetCustomQuery
(&
$event
)
{
$object
=&
$event
->
getObject
();
switch
(
$event
->
Special
)
{
case
'downl'
:
$object
->
addFilter
(
'is_active'
,
'%1$s.Status = 1'
);
break
;
}
}
function
prepareObject
(&
$object
,
&
$event
)
{
if
(
$this
->
Application
->
GetVar
(
'file_event'
)
==
'OnNew'
||
$this
->
Application
->
GetVar
(
'file_event'
)
==
'OnCreate'
)
{
$options
=
$object
->
getFieldOptions
(
'RealPath'
);
$options
[
'required'
]
=
1
;
$object
->
setFieldOptions
(
'RealPath'
,
$options
);
}
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function
OnBeforeItemUpdate
(&
$event
)
{
$object
=&
$event
->
getObject
();
if
(
$object
->
GetDBField
(
'IsPrimary'
))
{
$parent_info
=
$object
->
getLinkedInfo
(
$event
->
Special
);
$sql
=
'UPDATE '
.
$object
->
TableName
.
'
SET IsPrimary = 0
WHERE '
.
$parent_info
[
'ForeignKey'
].
' = '
.
$parent_info
[
'ParentId'
];
$this
->
Conn
->
Query
(
$sql
);
$object
->
SetDBField
(
'Status'
,
1
);
}
if
(
$object
->
GetDBField
(
'Name'
)
==
''
)
{
$object
->
SetDBField
(
'Name'
,
$object
->
GetDBField
(
'FilePath'
));
}
}
function
OnBeforeItemCreate
(&
$event
)
{
$this
->
OnBeforeItemUpdate
(
$event
);
$object
=&
$event
->
getObject
();
$parent_info
=
$object
->
getLinkedInfo
(
$event
->
Special
);
$sql
=
'SELECT FileId FROM '
.
$object
->
TableName
.
' WHERE IsPrimary = 1 AND '
.
$parent_info
[
'ForeignKey'
].
' = '
.
$parent_info
[
'ParentId'
];
if
(
!
$this
->
Conn
->
GetOne
(
$sql
)
)
{
$object
->
SetDBField
(
'IsPrimary'
,
1
);
$object
->
SetDBField
(
'Status'
,
1
);
}
$object
->
SetDBField
(
'AddedById'
,
$this
->
Application
->
RecallVar
(
'user_id'
));
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function
OnSetPrimary
(&
$event
)
{
$ids
=
$this
->
StoreSelectedIDs
(
$event
);
$id
=
array_shift
(
$ids
);
$object
=&
$event
->
getObject
(
Array
(
'skip_autoload'
=>
true
)
);
$object
->
Load
(
$id
);
$object
->
SetDBField
(
'IsPrimary'
,
1
);
$object
->
Update
();
}
/**
* Deletes all selected items.
* Automatically recurse into sub-items using temp handler, and deletes sub-items
* by calling its Delete method if sub-item has AutoDelete set to true in its config file
*
* @param kEvent $event
*/
function
OnMassDelete
(&
$event
)
{
$event
->
status
=
erSUCCESS
;
$temp
=&
$this
->
Application
->
recallObject
(
$event
->
getPrefixSpecial
().
'_TempHandler'
,
'kTempTablesHandler'
);
$ids
=
$this
->
StoreSelectedIDs
(
$event
);
$event
->
setEventParam
(
'ids'
,
$ids
);
$this
->
customProcessing
(
$event
,
'before'
);
$ids
=
$event
->
getEventParam
(
'ids'
);
$object
=&
$event
->
getObject
();
$parent_info
=
$object
->
getLinkedInfo
(
$event
->
Special
);
$sql
=
'SELECT FileId FROM '
.
$object
->
TableName
.
' WHERE IsPrimary = 1 AND '
.
$parent_info
[
'ForeignKey'
].
' = '
.
$parent_info
[
'ParentId'
];
$primary
=
$this
->
Conn
->
GetOne
(
$sql
);
if
(
$primary
&&
(
$key
=
array_search
(
$primary
,
$ids
))
)
{
$sql
=
'SELECT FileId FROM '
.
$object
->
TableName
.
' WHERE IsPrimary = 0 AND '
.
$parent_info
[
'ForeignKey'
].
' = '
.
$parent_info
[
'ParentId'
];
$res
=
$this
->
Conn
->
Query
(
$sql
);
if
(
$res
)
{
unset
(
$ids
[
$key
]);
}
}
if
(
$ids
)
{
$temp
->
DeleteItems
(
$event
->
Prefix
,
$event
->
Special
,
$ids
);
}
$this
->
clearSelectedIDs
(
$event
);
}
}
?>
Event Timeline
Log In to Comment