Index: trunk/core/units/general/cat_event_handler.php =================================================================== diff -u -r1583 -r2004 --- trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 1583) +++ trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 2004) @@ -55,13 +55,53 @@ $ids_arr = explode(',', $ids); foreach ($ids_arr as $id) { $object->Load($id); - $object->MoveToCat(); + $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'; + + + $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