Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F772955
in-portal
No One
Temporary
Actions
View 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
Sat, Feb 1, 9:45 PM
Size
41 KB
Mime Type
text/x-diff
Expires
Mon, Feb 3, 9:45 PM (1 d, 15 h)
Engine
blob
Format
Raw Data
Handle
556232
Attached To
rINP In-Portal
in-portal
View Options
Index: branches/unlabeled/unlabeled-1.22.2/kernel/units/categories/categories_event_handler.php
===================================================================
--- branches/unlabeled/unlabeled-1.22.2/kernel/units/categories/categories_event_handler.php (revision 5624)
+++ branches/unlabeled/unlabeled-1.22.2/kernel/units/categories/categories_event_handler.php (revision 5625)
@@ -1,464 +1,460 @@
<?php
class CategoriesEventHandler extends InpDBEventHandler {
/**
* Allows to override standart permission mapping
*
*/
function mapPermissions()
{
parent::mapPermissions();
$permissions = Array(
'OnRebuildCache' => Array('self' => 'add|edit'),
);
$this->permMapping = array_merge($this->permMapping, $permissions);
}
/**
* Apply system filter to categories list
*
* @param kEvent $event
*/
function SetCustomQuery(&$event)
{
parent::SetCustomQuery($event);
$types=$event->getEventParam('types');
$except_types=$event->getEventParam('except');
$object =& $event->getObject();
$type_clauses = Array();
$object =& $event->getObject();
if ( $event->getEventParam('parent_cat_id') ) {
$parent_cat_id = $event->getEventParam('parent_cat_id');
if ($parent_cat_id == 'Root') {
$module_name = $event->getEventParam('module') ? $event->getEventParam('module') : 'In-Commerce';
$module =& $this->Application->recallObject('mod.'.$module_name);
$parent_cat_id = $module->GetDBField('RootCat');
}
}
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 ($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('parent_filter', 'ParentId IN ('.implode(', ', $subcats).')');
}
else {
$object->addFilter('parent_filter', 'ParentId = '.$parent_cat_id);
}
}
$object->addFilter('parent_filter', 'ParentId = '.$parent_cat_id);
$object->addFilter('perm_filter', 'PermId = 1'); // check for CATEGORY.VIEW permission
if ($this->Application->GetVar('u_id') > 0) {
// apply permission filters to all users except "root"
$groups = explode(',',$this->Application->RecallVar('UserGroups'));
foreach ($groups as $group) {
$view_filters[] = 'FIND_IN_SET('.$group.', acl)';
}
$view_filter = implode(' OR ', $view_filters);
$object->addFilter('perm_filter2', $view_filter);
}
if (!$this->Application->IsAdmin()) {
// apply status filter only on front
$object->addFilter('status_filter', $object->TableName.'.Status = 1');
}
if(strpos($types, 'category_related') !== false)
{
$object->removeFilter('parent_filter');
$resource_id = $this->Conn->GetOne('
SELECT ResourceId FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').'
WHERE CategoryId = '.$parent_cat_id
);
$sql = 'SELECT DISTINCT(TargetId) FROM '.TABLE_PREFIX.'Relationship
WHERE SourceId = '.$resource_id.' AND SourceType = 1';
$related_cats = $this->Conn->GetCol($sql);
$related_cats = is_array($related_cats) ? $related_cats : Array();
$sql = 'SELECT DISTINCT(SourceId) FROM '.TABLE_PREFIX.'Relationship
WHERE TargetId = '.$resource_id.' AND TargetType = 1 AND Type = 1';
$related_cats2 = $this->Conn->GetCol($sql);
$related_cats2 = is_array($related_cats2) ? $related_cats2 : Array();
$related_cats = array_unique( array_merge( $related_cats2, $related_cats ) );
if($related_cats)
{
$type_clauses['category_related']['include'] = '%1$s.ResourceId IN ('.implode(',', $related_cats).')';
$type_clauses['category_related']['except'] = '%1$s.ResourceId NOT IN ('.implode(',', $related_cats).')';
}
else
{
$type_clauses['category_related']['include'] = '0';
$type_clauses['category_related']['except'] = '1';
}
$type_clauses['category_related']['having_filter'] = false;
}
if(strpos($types, 'product_related') !== false)
{
$object->removeFilter('parent_filter');
$product_id = $event->getEventParam('product_id') ? $event->getEventParam('product_id') : $this->Application->GetVar('p_id');
$resource_id = $this->Conn->GetOne('
SELECT ResourceId FROM '.$this->Application->getUnitOption('p', 'TableName').'
WHERE ProductId = '.$product_id
);
$sql = 'SELECT DISTINCT(TargetId) FROM '.TABLE_PREFIX.'Relationship
WHERE SourceId = '.$resource_id.' AND TargetType = 1';
$related_cats = $this->Conn->GetCol($sql);
$related_cats = is_array($related_cats) ? $related_cats : Array();
$sql = 'SELECT DISTINCT(SourceId) FROM '.TABLE_PREFIX.'Relationship
WHERE TargetId = '.$resource_id.' AND SourceType = 1 AND Type = 1';
$related_cats2 = $this->Conn->GetCol($sql);
$related_cats2 = is_array($related_cats2) ? $related_cats2 : Array();
$related_cats = array_unique( array_merge( $related_cats2, $related_cats ) );
if($related_cats)
{
$type_clauses['product_related']['include'] = '%1$s.ResourceId IN ('.implode(',', $related_cats).')';
$type_clauses['product_related']['except'] = '%1$s.ResourceId NOT IN ('.implode(',', $related_cats).')';
}
else
{
$type_clauses['product_related']['include'] = '0';
$type_clauses['product_related']['except'] = '1';
}
$type_clauses['product_related']['having_filter'] = false;
}
/********************************************/
$includes_or_filter =& $this->Application->makeClass('kMultipleFilter');
$includes_or_filter->setType(FLT_TYPE_OR);
$excepts_and_filter =& $this->Application->makeClass('kMultipleFilter');
$excepts_and_filter->setType(FLT_TYPE_AND);
$includes_or_filter_h =& $this->Application->makeClass('kMultipleFilter');
$includes_or_filter_h->setType(FLT_TYPE_OR);
$excepts_and_filter_h =& $this->Application->makeClass('kMultipleFilter');
$excepts_and_filter_h->setType(FLT_TYPE_AND);
$except_types_array=explode(',', $types);
if ($types){
$types_array=explode(',', $types);
for ($i=0; $i<sizeof($types_array); $i++){
$type=trim($types_array[$i]);
if (isset($type_clauses[$type])){
if ($type_clauses[$type]['having_filter']){
$includes_or_filter_h->removeFilter('filter_'.$type);
$includes_or_filter_h->addFilter('filter_'.$type, $type_clauses[$type]['include']);
}else{
$includes_or_filter->removeFilter('filter_'.$type);
$includes_or_filter->addFilter('filter_'.$type, $type_clauses[$type]['include']);
}
}
}
}
if ($except_types){
$except_types_array=explode(',', $except_types);
for ($i=0; $i<sizeof($except_types_array); $i++){
$type=trim($except_types_array[$i]);
if (isset($type_clauses[$type])){
if ($type_clauses[$type]['having_filter']){
$excepts_and_filter_h->removeFilter('filter_'.$type);
$excepts_and_filter_h->addFilter('filter_'.$type, $type_clauses[$type]['except']);
}else{
$excepts_and_filter->removeFilter('filter_'.$type);
$excepts_and_filter->addFilter('filter_'.$type, $type_clauses[$type]['except']);
}
}
}
}
$object->addFilter('includes_filter', $includes_or_filter);
$object->addFilter('excepts_filter', $excepts_and_filter);
$object->addFilter('includes_filter_h', $includes_or_filter_h, HAVING_FILTER);
$object->addFilter('excepts_filter_h', $excepts_and_filter_h, HAVING_FILTER);
}
function GetPassedId(&$event)
{
if ( $this->Application->IsAdmin() ) return parent::getPassedID($event);
$ret = $this->Application->GetVar('m_cat_id');
if($ret) return $ret;
return parent::getPassedID($event);
}
/**
* Adds calculates fields for item statuses
*
* @param kCatDBItem $object
* @param kEvent $event
*/
function prepareObject(&$object, &$event)
{
$object =& $event->getObject( Array('skip_autoload' => true) );
$object->addCalculatedField('IsNew', ' IF(%1$s.NewItem = 2,
IF(%1$s.CreatedOn >= (UNIX_TIMESTAMP() - '.
$this->Application->ConfigValue('Category_DaysNew').
'*3600*24), 1, 0),
%1$s.NewItem
)');
}
/**
* Set correct parent path for newly created categories
*
* @param kEvent $event
*/
function OnAfterCopyToLive(&$event)
{
if ($event->getEventParam('temp_id') == 0) {
$object =& $this->Application->recallObject($event->Prefix.'.-item', null, Array('skip_autoload' => true, 'live_table' => true));
$object->Load($event->getEventParam('id'));
if ($object->isLoaded()) {
// update path only for real categories (not including "Home" root category)
$fields_hash = Array('ParentPath' => $object->buildParentPath());
$this->Conn->doUpdate($fields_hash, $object->TableName, 'CategoryId = '.$object->GetID());
}
}
}
/**
* Set cache modification mark if needed
*
* @param kEvent $event
*/
function OnBeforeDeleteFromLive(&$event)
{
$id = $event->getEventParam('id');
// loding anyway, because this object is needed by "c-perm:OnBeforeDeleteFromLive" event
$temp_object =& $event->getObject( Array('skip_autoload' => true) );
$temp_object->Load($id);
if ($id == 0) {
if ($temp_object->isLoaded()) {
// new category -> update chache (not loaded when "Home" category)
$this->Application->StoreVar('PermCache_UpdateRequired', 1);
}
return ;
}
// existing category was edited, check if in-cache fields are modified
$live_object =& $this->Application->recallObject($event->Prefix.'.-item', null, Array('live_table' => true, 'skip_autoload' => true));
$live_object->Load($id);
$cached_fields = Array('Name', 'Filename', 'CategoryTemplate', 'ItemTemplate');
foreach ($cached_fields as $cached_field) {
if ($live_object->GetDBField($cached_field) != $temp_object->GetDBField($cached_field)) {
// use session instead of REQUEST because of permission editing in category can contain
// multiple submits, that changes data before OnSave event occurs
$this->Application->StoreVar('PermCache_UpdateRequired', 1);
break;
}
}
}
/**
* Checks cache update mark and redirect to cache if needed
*
* @param kEvent $event
*/
function OnSave(&$event)
{
$object =& $event->getObject();
if ($object->IsRoot()) {
$event->setEventParam('master_ids', Array(0));
}
parent::OnSave($event);
+ $this->UpdateCategoryCache($event);
+ }
+
+ /**
+ * Redirects to Category Cache Updater
+ *
+ * @param kEvent $event
+ */
+ function UpdateCategoryCache(&$event)
+ {
if ($event->status == erSUCCESS && $this->Application->RecallVar('PermCache_UpdateRequired')) {
// "catalog" should be in opener stack by now
$opener_stack = unserialize($this->Application->RecallVar('opener_stack'));
$opener_stack[0] = str_replace('catalog', 'categories/cache_updater', $opener_stack[0]);
$this->Application->StoreVar('opener_stack', serialize($opener_stack));
$this->Application->RemoveVar('PermCache_UpdateRequired');
}
}
/**
* 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)
{
if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) {
return;
}
// $event->status = erSUCCESS;
$ids = $this->StoreSelectedIDs($event);
if ($ids) {
$recursive_helper =& $this->Application->recallObject('RecursiveHelper');
foreach ($ids as $id) {
$recursive_helper->DeleteCategory($id);
}
}
$this->clearSelectedIDs($event);
}
/**
* Add selected items to clipboard with mode = COPY (CLONE)
*
* @param kEvent $event
*/
function OnCopy(&$event)
{
$clipboard_helper =& $this->Application->recallObject('ClipboardHelper');
$clipboard_helper->setClipboard($event, 'copy', $this->StoreSelectedIDs($event));
}
/**
* Add selected items to clipboard with mode = CUT
*
* @param kEvent $event
*/
function OnCut(&$event)
{
$clipboard_helper =& $this->Application->recallObject('ClipboardHelper');
$clipboard_helper->setClipboard($event, 'cut', $this->StoreSelectedIDs($event));
}
/**
* Controls all item paste operations. Can occur only with filled clipbord.
*
* @param kEvent $event
*/
function OnPasteClipboard(&$event)
{
$clipboard = unserialize( $this->Application->RecallVar('clipboard') );
foreach ($clipboard as $prefix => $clipboard_data) {
$paste_event = new kEvent($prefix.':OnPaste', Array('clipboard_data' => $clipboard_data));
$this->Application->HandleEvent($paste_event);
}
}
/**
* Paste categories with subitems from clipboard
*
* @param kEvent $event
*/
function OnPaste(&$event)
{
if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) {
return;
}
+ $clipboard_data = $event->getEventParam('clipboard_data');
-
- if ($ids) {
- $recursive_helper =& $this->Application->recallObject('RecursiveHelper');
- foreach ($ids as $id) {
- $recursive_helper->DeleteCategory($id);
- }
+ if (!$clipboard_data['cut'] && !$clipboard_data['copy']) {
+ return false;
}
- $this->clearSelectedIDs($event);
- /*$ids = $this->Application->RecallVar($event->getPrefixSpecial().'_clipboard');
- if ($ids == '') {
- $event->redirect = false;
- return;
+ $recursive_helper =& $this->Application->recallObject('RecursiveHelper');
+ if ($clipboard_data['cut']) {
+ $recursive_helper->MoveCategories($clipboard_data['cut']);
}
-
- $ids_arr = explode(',', $ids);
-
- if ($this->Application->RecallVar($event->getPrefixSpecial().'_clipboard_mode') == 'copy') {
- $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
-
- if ($ids_arr) {
- $temp->CloneItems($event->Prefix, $event->Special, $ids_arr);
+
+ if ($clipboard_data['copy']) {
+ foreach ($clipboard_data['copy'] as $id) {
+ $recursive_helper->PasteCategory($id);
}
}
- else { // mode == cut
- $object =& $this->Application->recallObject($event->getPrefixSpecial().'.item', $event->Prefix, Array('skip_autoload' => true));
-
- foreach ($ids_arr as $id) {
- $object->Load($id);
- $object->MoveToCat();
- }
+
+ if ($clipboard_data['cut'] || $clipboard_data['copy']) {
+ $this->UpdateCategoryCache($event);
}
- $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';
$object =& $this->Application->recallObject($event->Prefix.'.item', $event->Prefix, Array('skip_autoload' => true));
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->SetVar('m_cat_id', $saved_cat_id);
}
}*/
/**
* Cleares clipboard content
*
* @param kEvent $event
*/
function OnClearClipboard(&$event)
{
$this->Application->RemoveVar('clipboard');
}
}
?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.22.2/kernel/units/categories/categories_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.22.2.7
\ No newline at end of property
+1.22.2.8
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.22.2/core/units/categories/categories_event_handler.php
===================================================================
--- branches/unlabeled/unlabeled-1.22.2/core/units/categories/categories_event_handler.php (revision 5624)
+++ branches/unlabeled/unlabeled-1.22.2/core/units/categories/categories_event_handler.php (revision 5625)
@@ -1,464 +1,460 @@
<?php
class CategoriesEventHandler extends InpDBEventHandler {
/**
* Allows to override standart permission mapping
*
*/
function mapPermissions()
{
parent::mapPermissions();
$permissions = Array(
'OnRebuildCache' => Array('self' => 'add|edit'),
);
$this->permMapping = array_merge($this->permMapping, $permissions);
}
/**
* Apply system filter to categories list
*
* @param kEvent $event
*/
function SetCustomQuery(&$event)
{
parent::SetCustomQuery($event);
$types=$event->getEventParam('types');
$except_types=$event->getEventParam('except');
$object =& $event->getObject();
$type_clauses = Array();
$object =& $event->getObject();
if ( $event->getEventParam('parent_cat_id') ) {
$parent_cat_id = $event->getEventParam('parent_cat_id');
if ($parent_cat_id == 'Root') {
$module_name = $event->getEventParam('module') ? $event->getEventParam('module') : 'In-Commerce';
$module =& $this->Application->recallObject('mod.'.$module_name);
$parent_cat_id = $module->GetDBField('RootCat');
}
}
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 ($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('parent_filter', 'ParentId IN ('.implode(', ', $subcats).')');
}
else {
$object->addFilter('parent_filter', 'ParentId = '.$parent_cat_id);
}
}
$object->addFilter('parent_filter', 'ParentId = '.$parent_cat_id);
$object->addFilter('perm_filter', 'PermId = 1'); // check for CATEGORY.VIEW permission
if ($this->Application->GetVar('u_id') > 0) {
// apply permission filters to all users except "root"
$groups = explode(',',$this->Application->RecallVar('UserGroups'));
foreach ($groups as $group) {
$view_filters[] = 'FIND_IN_SET('.$group.', acl)';
}
$view_filter = implode(' OR ', $view_filters);
$object->addFilter('perm_filter2', $view_filter);
}
if (!$this->Application->IsAdmin()) {
// apply status filter only on front
$object->addFilter('status_filter', $object->TableName.'.Status = 1');
}
if(strpos($types, 'category_related') !== false)
{
$object->removeFilter('parent_filter');
$resource_id = $this->Conn->GetOne('
SELECT ResourceId FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').'
WHERE CategoryId = '.$parent_cat_id
);
$sql = 'SELECT DISTINCT(TargetId) FROM '.TABLE_PREFIX.'Relationship
WHERE SourceId = '.$resource_id.' AND SourceType = 1';
$related_cats = $this->Conn->GetCol($sql);
$related_cats = is_array($related_cats) ? $related_cats : Array();
$sql = 'SELECT DISTINCT(SourceId) FROM '.TABLE_PREFIX.'Relationship
WHERE TargetId = '.$resource_id.' AND TargetType = 1 AND Type = 1';
$related_cats2 = $this->Conn->GetCol($sql);
$related_cats2 = is_array($related_cats2) ? $related_cats2 : Array();
$related_cats = array_unique( array_merge( $related_cats2, $related_cats ) );
if($related_cats)
{
$type_clauses['category_related']['include'] = '%1$s.ResourceId IN ('.implode(',', $related_cats).')';
$type_clauses['category_related']['except'] = '%1$s.ResourceId NOT IN ('.implode(',', $related_cats).')';
}
else
{
$type_clauses['category_related']['include'] = '0';
$type_clauses['category_related']['except'] = '1';
}
$type_clauses['category_related']['having_filter'] = false;
}
if(strpos($types, 'product_related') !== false)
{
$object->removeFilter('parent_filter');
$product_id = $event->getEventParam('product_id') ? $event->getEventParam('product_id') : $this->Application->GetVar('p_id');
$resource_id = $this->Conn->GetOne('
SELECT ResourceId FROM '.$this->Application->getUnitOption('p', 'TableName').'
WHERE ProductId = '.$product_id
);
$sql = 'SELECT DISTINCT(TargetId) FROM '.TABLE_PREFIX.'Relationship
WHERE SourceId = '.$resource_id.' AND TargetType = 1';
$related_cats = $this->Conn->GetCol($sql);
$related_cats = is_array($related_cats) ? $related_cats : Array();
$sql = 'SELECT DISTINCT(SourceId) FROM '.TABLE_PREFIX.'Relationship
WHERE TargetId = '.$resource_id.' AND SourceType = 1 AND Type = 1';
$related_cats2 = $this->Conn->GetCol($sql);
$related_cats2 = is_array($related_cats2) ? $related_cats2 : Array();
$related_cats = array_unique( array_merge( $related_cats2, $related_cats ) );
if($related_cats)
{
$type_clauses['product_related']['include'] = '%1$s.ResourceId IN ('.implode(',', $related_cats).')';
$type_clauses['product_related']['except'] = '%1$s.ResourceId NOT IN ('.implode(',', $related_cats).')';
}
else
{
$type_clauses['product_related']['include'] = '0';
$type_clauses['product_related']['except'] = '1';
}
$type_clauses['product_related']['having_filter'] = false;
}
/********************************************/
$includes_or_filter =& $this->Application->makeClass('kMultipleFilter');
$includes_or_filter->setType(FLT_TYPE_OR);
$excepts_and_filter =& $this->Application->makeClass('kMultipleFilter');
$excepts_and_filter->setType(FLT_TYPE_AND);
$includes_or_filter_h =& $this->Application->makeClass('kMultipleFilter');
$includes_or_filter_h->setType(FLT_TYPE_OR);
$excepts_and_filter_h =& $this->Application->makeClass('kMultipleFilter');
$excepts_and_filter_h->setType(FLT_TYPE_AND);
$except_types_array=explode(',', $types);
if ($types){
$types_array=explode(',', $types);
for ($i=0; $i<sizeof($types_array); $i++){
$type=trim($types_array[$i]);
if (isset($type_clauses[$type])){
if ($type_clauses[$type]['having_filter']){
$includes_or_filter_h->removeFilter('filter_'.$type);
$includes_or_filter_h->addFilter('filter_'.$type, $type_clauses[$type]['include']);
}else{
$includes_or_filter->removeFilter('filter_'.$type);
$includes_or_filter->addFilter('filter_'.$type, $type_clauses[$type]['include']);
}
}
}
}
if ($except_types){
$except_types_array=explode(',', $except_types);
for ($i=0; $i<sizeof($except_types_array); $i++){
$type=trim($except_types_array[$i]);
if (isset($type_clauses[$type])){
if ($type_clauses[$type]['having_filter']){
$excepts_and_filter_h->removeFilter('filter_'.$type);
$excepts_and_filter_h->addFilter('filter_'.$type, $type_clauses[$type]['except']);
}else{
$excepts_and_filter->removeFilter('filter_'.$type);
$excepts_and_filter->addFilter('filter_'.$type, $type_clauses[$type]['except']);
}
}
}
}
$object->addFilter('includes_filter', $includes_or_filter);
$object->addFilter('excepts_filter', $excepts_and_filter);
$object->addFilter('includes_filter_h', $includes_or_filter_h, HAVING_FILTER);
$object->addFilter('excepts_filter_h', $excepts_and_filter_h, HAVING_FILTER);
}
function GetPassedId(&$event)
{
if ( $this->Application->IsAdmin() ) return parent::getPassedID($event);
$ret = $this->Application->GetVar('m_cat_id');
if($ret) return $ret;
return parent::getPassedID($event);
}
/**
* Adds calculates fields for item statuses
*
* @param kCatDBItem $object
* @param kEvent $event
*/
function prepareObject(&$object, &$event)
{
$object =& $event->getObject( Array('skip_autoload' => true) );
$object->addCalculatedField('IsNew', ' IF(%1$s.NewItem = 2,
IF(%1$s.CreatedOn >= (UNIX_TIMESTAMP() - '.
$this->Application->ConfigValue('Category_DaysNew').
'*3600*24), 1, 0),
%1$s.NewItem
)');
}
/**
* Set correct parent path for newly created categories
*
* @param kEvent $event
*/
function OnAfterCopyToLive(&$event)
{
if ($event->getEventParam('temp_id') == 0) {
$object =& $this->Application->recallObject($event->Prefix.'.-item', null, Array('skip_autoload' => true, 'live_table' => true));
$object->Load($event->getEventParam('id'));
if ($object->isLoaded()) {
// update path only for real categories (not including "Home" root category)
$fields_hash = Array('ParentPath' => $object->buildParentPath());
$this->Conn->doUpdate($fields_hash, $object->TableName, 'CategoryId = '.$object->GetID());
}
}
}
/**
* Set cache modification mark if needed
*
* @param kEvent $event
*/
function OnBeforeDeleteFromLive(&$event)
{
$id = $event->getEventParam('id');
// loding anyway, because this object is needed by "c-perm:OnBeforeDeleteFromLive" event
$temp_object =& $event->getObject( Array('skip_autoload' => true) );
$temp_object->Load($id);
if ($id == 0) {
if ($temp_object->isLoaded()) {
// new category -> update chache (not loaded when "Home" category)
$this->Application->StoreVar('PermCache_UpdateRequired', 1);
}
return ;
}
// existing category was edited, check if in-cache fields are modified
$live_object =& $this->Application->recallObject($event->Prefix.'.-item', null, Array('live_table' => true, 'skip_autoload' => true));
$live_object->Load($id);
$cached_fields = Array('Name', 'Filename', 'CategoryTemplate', 'ItemTemplate');
foreach ($cached_fields as $cached_field) {
if ($live_object->GetDBField($cached_field) != $temp_object->GetDBField($cached_field)) {
// use session instead of REQUEST because of permission editing in category can contain
// multiple submits, that changes data before OnSave event occurs
$this->Application->StoreVar('PermCache_UpdateRequired', 1);
break;
}
}
}
/**
* Checks cache update mark and redirect to cache if needed
*
* @param kEvent $event
*/
function OnSave(&$event)
{
$object =& $event->getObject();
if ($object->IsRoot()) {
$event->setEventParam('master_ids', Array(0));
}
parent::OnSave($event);
+ $this->UpdateCategoryCache($event);
+ }
+
+ /**
+ * Redirects to Category Cache Updater
+ *
+ * @param kEvent $event
+ */
+ function UpdateCategoryCache(&$event)
+ {
if ($event->status == erSUCCESS && $this->Application->RecallVar('PermCache_UpdateRequired')) {
// "catalog" should be in opener stack by now
$opener_stack = unserialize($this->Application->RecallVar('opener_stack'));
$opener_stack[0] = str_replace('catalog', 'categories/cache_updater', $opener_stack[0]);
$this->Application->StoreVar('opener_stack', serialize($opener_stack));
$this->Application->RemoveVar('PermCache_UpdateRequired');
}
}
/**
* 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)
{
if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) {
return;
}
// $event->status = erSUCCESS;
$ids = $this->StoreSelectedIDs($event);
if ($ids) {
$recursive_helper =& $this->Application->recallObject('RecursiveHelper');
foreach ($ids as $id) {
$recursive_helper->DeleteCategory($id);
}
}
$this->clearSelectedIDs($event);
}
/**
* Add selected items to clipboard with mode = COPY (CLONE)
*
* @param kEvent $event
*/
function OnCopy(&$event)
{
$clipboard_helper =& $this->Application->recallObject('ClipboardHelper');
$clipboard_helper->setClipboard($event, 'copy', $this->StoreSelectedIDs($event));
}
/**
* Add selected items to clipboard with mode = CUT
*
* @param kEvent $event
*/
function OnCut(&$event)
{
$clipboard_helper =& $this->Application->recallObject('ClipboardHelper');
$clipboard_helper->setClipboard($event, 'cut', $this->StoreSelectedIDs($event));
}
/**
* Controls all item paste operations. Can occur only with filled clipbord.
*
* @param kEvent $event
*/
function OnPasteClipboard(&$event)
{
$clipboard = unserialize( $this->Application->RecallVar('clipboard') );
foreach ($clipboard as $prefix => $clipboard_data) {
$paste_event = new kEvent($prefix.':OnPaste', Array('clipboard_data' => $clipboard_data));
$this->Application->HandleEvent($paste_event);
}
}
/**
* Paste categories with subitems from clipboard
*
* @param kEvent $event
*/
function OnPaste(&$event)
{
if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) {
return;
}
+ $clipboard_data = $event->getEventParam('clipboard_data');
-
- if ($ids) {
- $recursive_helper =& $this->Application->recallObject('RecursiveHelper');
- foreach ($ids as $id) {
- $recursive_helper->DeleteCategory($id);
- }
+ if (!$clipboard_data['cut'] && !$clipboard_data['copy']) {
+ return false;
}
- $this->clearSelectedIDs($event);
- /*$ids = $this->Application->RecallVar($event->getPrefixSpecial().'_clipboard');
- if ($ids == '') {
- $event->redirect = false;
- return;
+ $recursive_helper =& $this->Application->recallObject('RecursiveHelper');
+ if ($clipboard_data['cut']) {
+ $recursive_helper->MoveCategories($clipboard_data['cut']);
}
-
- $ids_arr = explode(',', $ids);
-
- if ($this->Application->RecallVar($event->getPrefixSpecial().'_clipboard_mode') == 'copy') {
- $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
-
- if ($ids_arr) {
- $temp->CloneItems($event->Prefix, $event->Special, $ids_arr);
+
+ if ($clipboard_data['copy']) {
+ foreach ($clipboard_data['copy'] as $id) {
+ $recursive_helper->PasteCategory($id);
}
}
- else { // mode == cut
- $object =& $this->Application->recallObject($event->getPrefixSpecial().'.item', $event->Prefix, Array('skip_autoload' => true));
-
- foreach ($ids_arr as $id) {
- $object->Load($id);
- $object->MoveToCat();
- }
+
+ if ($clipboard_data['cut'] || $clipboard_data['copy']) {
+ $this->UpdateCategoryCache($event);
}
- $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';
$object =& $this->Application->recallObject($event->Prefix.'.item', $event->Prefix, Array('skip_autoload' => true));
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->SetVar('m_cat_id', $saved_cat_id);
}
}*/
/**
* Cleares clipboard content
*
* @param kEvent $event
*/
function OnClearClipboard(&$event)
{
$this->Application->RemoveVar('clipboard');
}
}
?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.22.2/core/units/categories/categories_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.22.2.7
\ No newline at end of property
+1.22.2.8
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.2.2/kernel/units/general/helpers/recursive_helper.php
===================================================================
--- branches/unlabeled/unlabeled-1.2.2/kernel/units/general/helpers/recursive_helper.php (revision 5624)
+++ branches/unlabeled/unlabeled-1.2.2/kernel/units/general/helpers/recursive_helper.php (revision 5625)
@@ -1,99 +1,102 @@
<?php
class kRecursiveHelper extends kHelper {
function DeleteCategory($category_id)
{
$id_field = $this->Application->getUnitOption('c', 'IDField');
$table_name = $this->Application->getUnitOption('c', 'TableName');
$sql = 'SELECT '.$id_field.'
FROM '.$table_name.'
WHERE ParentId = '.$category_id;
$sub_categories = $this->Conn->GetCol($sql);
if ($sub_categories) {
foreach ($sub_categories as $sub_category_id) {
$this->DeleteCategory($sub_category_id);
}
}
$ci_table = $this->Application->getUnitOption('ci', 'TableName');
// 1. remove category items from this category if it is supplemental (non-primary) category to them
$sql = 'DELETE FROM '.$ci_table.'
WHERE ('.$id_field.' = '.$category_id.') AND (PrimaryCat = 0)';
$this->Conn->Query($sql);
$temp_handler =& $this->Application->recallObject('c_TempHandler', 'kTempTablesHandler');
// 2. delete items this have this category as primary
$sql = 'SELECT ItemPrefix, ItemResourceId
FROM '.$ci_table.'
WHERE ('.$id_field.' = '.$category_id.') AND (PrimaryCat = 1)';
$category_items = $this->Conn->GetCol($sql, 'ItemResourceId');
$delete_ids = Array();
foreach ($category_items as $resource_id => $item_prefix) {
$delete_ids[$item_prefix][] = $resource_id;
}
foreach ($delete_ids as $item_prefix => $resource_ids) {
if (!$item_prefix) {
// not ItemPrefix filled -> old categoryitem linking
continue;
}
$item_ids = $this->GetItemIDs($item_prefix, $resource_ids);
$temp_handler->BuildTables($item_prefix, $item_ids);
$temp_handler->DeleteItems($item_prefix, '', $item_ids);
}
// 3. delete this category
$temp_handler->BuildTables('c', Array($category_id));
$temp_handler->DeleteItems('c', '', Array($category_id));
}
/**
* Converts resource ids list to id field list for given prefix
*
* @param string $prefix
* @param Array $resource_ids
* @return Array
*/
function GetItemIDs($prefix, $resource_ids)
{
if (!$resource_ids) {
return Array();
}
$id_field = $this->Application->getUnitOption($prefix, 'IDField');
$table_name = $this->Application->getUnitOption($prefix, 'TableName');
$sql = 'SELECT '.$id_field.'
FROM '.$table_name.'
WHERE ResourceId IN ('.implode(',', $resource_ids).')';
return $this->Conn->GetCol($sql);
}
// moves selected categories to destination category
- function MoveCategory($category_ids, $dest_category_id)
+ function MoveCategories($category_ids, $dest_category_id)
{
if (!$category_ids) return ;
$id_field = $this->Application->getUnitOption('c', 'IDField');
$table_name = $this->Application->getUnitOption('c', 'TableName');
$sql = 'UPDATE '.$table_name.'
SET ParentId = '.$dest_category_id.'
WHERE '.$id_field.' IN ('.$category_ids.')';
$this->Conn->Query($sql);
$this->Application->StoreVar('PermCache_UpdateRequired', 1);
}
function PasteCategory($category_id)
{
- // mode == cut -> just update ParentId of category, items aren't changed, because category_id stays the same
+ // mode == copy - complete recusive clone with subitems for all items in clipboard
+
+// $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
+// $temp->CloneItems($event->Prefix, $event->Special, $ids_arr);
}
}
?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.2.2/kernel/units/general/helpers/recursive_helper.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.2.2.2
\ No newline at end of property
+1.2.2.3
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.2.2/core/units/general/helpers/recursive_helper.php
===================================================================
--- branches/unlabeled/unlabeled-1.2.2/core/units/general/helpers/recursive_helper.php (revision 5624)
+++ branches/unlabeled/unlabeled-1.2.2/core/units/general/helpers/recursive_helper.php (revision 5625)
@@ -1,99 +1,102 @@
<?php
class kRecursiveHelper extends kHelper {
function DeleteCategory($category_id)
{
$id_field = $this->Application->getUnitOption('c', 'IDField');
$table_name = $this->Application->getUnitOption('c', 'TableName');
$sql = 'SELECT '.$id_field.'
FROM '.$table_name.'
WHERE ParentId = '.$category_id;
$sub_categories = $this->Conn->GetCol($sql);
if ($sub_categories) {
foreach ($sub_categories as $sub_category_id) {
$this->DeleteCategory($sub_category_id);
}
}
$ci_table = $this->Application->getUnitOption('ci', 'TableName');
// 1. remove category items from this category if it is supplemental (non-primary) category to them
$sql = 'DELETE FROM '.$ci_table.'
WHERE ('.$id_field.' = '.$category_id.') AND (PrimaryCat = 0)';
$this->Conn->Query($sql);
$temp_handler =& $this->Application->recallObject('c_TempHandler', 'kTempTablesHandler');
// 2. delete items this have this category as primary
$sql = 'SELECT ItemPrefix, ItemResourceId
FROM '.$ci_table.'
WHERE ('.$id_field.' = '.$category_id.') AND (PrimaryCat = 1)';
$category_items = $this->Conn->GetCol($sql, 'ItemResourceId');
$delete_ids = Array();
foreach ($category_items as $resource_id => $item_prefix) {
$delete_ids[$item_prefix][] = $resource_id;
}
foreach ($delete_ids as $item_prefix => $resource_ids) {
if (!$item_prefix) {
// not ItemPrefix filled -> old categoryitem linking
continue;
}
$item_ids = $this->GetItemIDs($item_prefix, $resource_ids);
$temp_handler->BuildTables($item_prefix, $item_ids);
$temp_handler->DeleteItems($item_prefix, '', $item_ids);
}
// 3. delete this category
$temp_handler->BuildTables('c', Array($category_id));
$temp_handler->DeleteItems('c', '', Array($category_id));
}
/**
* Converts resource ids list to id field list for given prefix
*
* @param string $prefix
* @param Array $resource_ids
* @return Array
*/
function GetItemIDs($prefix, $resource_ids)
{
if (!$resource_ids) {
return Array();
}
$id_field = $this->Application->getUnitOption($prefix, 'IDField');
$table_name = $this->Application->getUnitOption($prefix, 'TableName');
$sql = 'SELECT '.$id_field.'
FROM '.$table_name.'
WHERE ResourceId IN ('.implode(',', $resource_ids).')';
return $this->Conn->GetCol($sql);
}
// moves selected categories to destination category
- function MoveCategory($category_ids, $dest_category_id)
+ function MoveCategories($category_ids, $dest_category_id)
{
if (!$category_ids) return ;
$id_field = $this->Application->getUnitOption('c', 'IDField');
$table_name = $this->Application->getUnitOption('c', 'TableName');
$sql = 'UPDATE '.$table_name.'
SET ParentId = '.$dest_category_id.'
WHERE '.$id_field.' IN ('.$category_ids.')';
$this->Conn->Query($sql);
$this->Application->StoreVar('PermCache_UpdateRequired', 1);
}
function PasteCategory($category_id)
{
- // mode == cut -> just update ParentId of category, items aren't changed, because category_id stays the same
+ // mode == copy - complete recusive clone with subitems for all items in clipboard
+
+// $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
+// $temp->CloneItems($event->Prefix, $event->Special, $ids_arr);
}
}
?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.2.2/core/units/general/helpers/recursive_helper.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.2.2.2
\ No newline at end of property
+1.2.2.3
\ No newline at end of property
Event Timeline
Log In to Comment