Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F804593
cat_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
Wed, Feb 26, 2:06 PM
Size
6 KB
Mime Type
text/x-php
Expires
Fri, Feb 28, 2:06 PM (10 h, 48 m)
Engine
blob
Format
Raw Data
Handle
577088
Attached To
rINP In-Portal
cat_event_handler.php
View Options
<?php
$application
=&
kApplication
::
Instance
();
$application
->
Factory
->
includeClassFile
(
'kDBEventHandler'
);
class
kCatDBEventHandler
extends
InpDBEventHandler
{
function
OnCopy
(&
$event
)
{
$object
=
$event
->
getObject
();
$this
->
StoreSelectedIDs
(
$event
);
$ids
=
$this
->
getSelectedIDs
(
$event
);
$this
->
Application
->
StoreVar
(
$event
->
getPrefixSpecial
().
'_clipboard'
,
implode
(
','
,
$ids
));
$this
->
Application
->
StoreVar
(
$event
->
getPrefixSpecial
().
'_clipboard_mode'
,
'copy'
);
$this
->
Application
->
StoreVar
(
'ClipBoard'
,
'COPY-0.'
.
$object
->
TableName
.
'.ResourceId=0'
);
$event
->
redirect_params
=
Array
(
'opener'
=>
's'
,
'pass_events'
=>
true
);
//do not go up - STAY
}
function
OnCut
(&
$event
)
{
$object
=
$event
->
getObject
();
$this
->
StoreSelectedIDs
(
$event
);
$ids
=
$this
->
getSelectedIDs
(
$event
);
$this
->
Application
->
StoreVar
(
$event
->
getPrefixSpecial
().
'_clipboard'
,
implode
(
','
,
$ids
));
$this
->
Application
->
StoreVar
(
$event
->
getPrefixSpecial
().
'_clipboard_mode'
,
'cut'
);
$this
->
Application
->
StoreVar
(
'ClipBoard'
,
'CUT-0.'
.
$object
->
TableName
.
'.ResourceId=0'
);
$event
->
redirect_params
=
Array
(
'opener'
=>
's'
,
'pass_events'
=>
true
);
//do not go up - STAY
}
function
OnPaste
(&
$event
)
{
$ids
=
$this
->
Application
->
RecallVar
(
$event
->
getPrefixSpecial
().
'_clipboard'
);
if
(
$ids
==
''
)
{
$event
->
redirect
=
false
;
return
;
}
//recalling by different name, because we may get kDBList, if we recall just by prefix
$object
=&
$this
->
Application
->
recallObject
(
$event
->
getPrefixSpecial
().
'.item'
,
$event
->
Prefix
);
$this
->
prepareObject
(
$object
,
$event
);
if
(
$this
->
Application
->
RecallVar
(
$event
->
getPrefixSpecial
().
'_clipboard_mode'
)
==
'copy'
)
{
$ids_arr
=
explode
(
','
,
$ids
);
$temp
=&
$this
->
Application
->
recallObject
(
$event
->
getPrefixSpecial
().
'_TempHandler'
,
'kTempTablesHandler'
);
if
(
$ids_arr
)
{
$temp
->
CloneItems
(
$event
->
Prefix
,
$event
->
Special
,
$ids_arr
);
}
}
else
{
// mode == cut
$ids_arr
=
explode
(
','
,
$ids
);
foreach
(
$ids_arr
as
$id
)
{
$object
->
Load
(
$id
);
$object
->
MoveToCat
();
}
}
$event
->
status
=
erSUCCESS
;
}
/**
* Occurs when pasting category
*
* @param kEvent $event
*/
function
OnCatPaste
(&
$event
)
{
$inp_clipboard
=
$this
->
Application
->
RecallVar
(
'ClipBoard'
);
$inp_clipboard
=
explode
(
'-'
,
$inp_clipboard
,
2
);
if
(
$inp_clipboard
[
0
]
==
'COPY'
)
{
$saved_cat_id
=
$this
->
Application
->
GetVar
(
'm_cat_id'
);
$cat_ids
=
$event
->
getEventParam
(
'cat_ids'
);
$id_field
=
$this
->
Application
->
getUnitOption
(
$event
->
Prefix
,
'IDField'
);
$table
=
$this
->
Application
->
getUnitOption
(
$event
->
Prefix
,
'TableName'
);
$ids_sql
=
'SELECT '
.
$id_field
.
' FROM '
.
$table
.
' WHERE ResourceId IN (%s)'
;
$resource_ids_sql
=
'SELECT ItemResourceId FROM '
.
TABLE_PREFIX
.
'CategoryItems WHERE CategoryId = %s AND PrimaryCat = 1'
;
$this
->
Application
->
setUnitOption
(
$event
->
Prefix
,
'AutoLoad'
,
false
);
$object
=&
$this
->
Application
->
recallObject
(
$event
->
Prefix
.
'.item'
,
$event
->
Prefix
);
foreach
(
$cat_ids
as
$source_cat
=>
$dest_cat
)
{
$item_resource_ids
=
$this
->
Conn
->
GetCol
(
sprintf
(
$resource_ids_sql
,
$source_cat
)
);
if
(!
$item_resource_ids
)
continue
;
$this
->
Application
->
SetVar
(
'm_cat_id'
,
$dest_cat
);
$item_ids
=
$this
->
Conn
->
GetCol
(
sprintf
(
$ids_sql
,
implode
(
','
,
$item_resource_ids
)
)
);
$temp
=&
$this
->
Application
->
recallObject
(
$event
->
getPrefixSpecial
().
'_TempHandler'
,
'kTempTablesHandler'
);
if
(
$item_ids
)
$temp
->
CloneItems
(
$event
->
Prefix
,
$event
->
Special
,
$item_ids
);
}
$this
->
Application
->
setUnitOption
(
$event
->
Prefix
,
'AutoLoad'
,
true
);
$this
->
Application
->
SetVar
(
'm_cat_id'
,
$saved_cat_id
);
}
}
/**
* Apply scope clause
*
* @param kEvent $event
*/
function
SetCustomQuery
(&
$event
)
{
$object
=&
$event
->
getObject
();
if
(
$event
->
Special
!=
'showall'
)
{
if
(
$event
->
getEventParam
(
'parent_cat_id'
)
)
{
$parent_cat_id
=
$event
->
getEventParam
(
'parent_cat_id'
);
}
else
{
$parent_cat_id
=
$this
->
Application
->
GetVar
(
'c_id'
);
if
(!
$parent_cat_id
)
{
$parent_cat_id
=
$this
->
Application
->
GetVar
(
'm_cat_id'
);
}
if
(!
$parent_cat_id
)
{
$parent_cat_id
=
0
;
}
}
if
((
string
)
$parent_cat_id
!=
'any'
)
{
if
(
$event
->
getEventParam
(
'recursive'
))
{
$current_path
=
$this
->
Conn
->
GetOne
(
'SELECT ParentPath FROM '
.
TABLE_PREFIX
.
'Category WHERE CategoryId='
.
$parent_cat_id
);
$subcats
=
$this
->
Conn
->
GetCol
(
'SELECT CategoryId FROM '
.
TABLE_PREFIX
.
'Category WHERE ParentPath LIKE "'
.
$current_path
.
'%" '
);
$object
->
addFilter
(
'category_filter'
,
TABLE_PREFIX
.
'CategoryItems.CategoryId IN ('
.
implode
(
', '
,
$subcats
).
')'
);
}
else
{
$object
->
addFilter
(
'category_filter'
,
TABLE_PREFIX
.
'CategoryItems.CategoryId = '
.
$parent_cat_id
);
}
}
}
else
{
$object
->
addFilter
(
'primary_filter'
,
'PrimaryCat = 1'
);
}
$view_perm
=
1
;
$object
->
addFilter
(
'perm_filter'
,
'perm.PermId = '
.
$view_perm
);
if
(!
defined
(
'ADMIN'
))
{
$groups
=
explode
(
','
,
$this
->
Application
->
RecallVar
(
'UserGroups'
));
foreach
(
$groups
as
$group
)
{
$view_filters
[]
=
'FIND_IN_SET('
.
$group
.
', perm.acl) || ((NOT FIND_IN_SET('
.
$group
.
',perm.dacl)) AND perm.acl=
\'\'
)'
;
}
$view_filter
=
implode
(
' OR '
,
$view_filters
);
$object
->
addFilter
(
'perm_filter2'
,
$view_filter
);
}
if
(!
defined
(
'ADMIN'
))
{
$object
->
addFilter
(
'status_filter'
,
$object
->
TableName
.
'.Status = 1'
);
}
/*$list_type = $event->getEventParam('ListType');
switch($list_type)
{
case 'favorites':
$fav_table = $this->Application->getUnitOption('fav','TableName');
$user_id =& $this->Application->GetVar('u_id');
$sql = 'SELECT DISTINCT f.ResourceId
FROM '.$fav_table.' f
LEFT JOIN '.$object->TableName.' p ON p.ResourceId = f.ResourceId
WHERE f.PortalUserId = '.$user_id;
$ids = $this->Conn->GetCol($sql);
if(!$ids) $ids = Array(-1);
$object->addFilter('category_filter', TABLE_PREFIX.'CategoryItems.PrimaryCat = 1');
$object->addFilter('favorites_filter', '%1$s.`ResourceId` IN ('.implode(',',$ids).')');
break;
case 'search':
$search_results_table = TABLE_PREFIX.'ses_'.$this->Application->GetVar('sid').'_'.TABLE_PREFIX.'Search';
$sql = ' SELECT DISTINCT ResourceId
FROM '.$search_results_table.'
WHERE ItemType=11';
$ids = $this->Conn->GetCol($sql);
if(!$ids) $ids = Array(-1);
$object->addFilter('search_filter', '%1$s.`ResourceId` IN ('.implode(',',$ids).')');
break;
} */
}
}
?>
Event Timeline
Log In to Comment