Index: trunk/core/units/categories/categories_event_handler.php =================================================================== diff -u -r6625 -r7391 --- trunk/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 6625) +++ trunk/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 7391) @@ -36,18 +36,30 @@ $selected_ids = implode(',', $this->StoreSelectedIDs($event)); } else { - $selected_ids = $this->Application->RecallVar($event->getPrefixSpecial().'_selected_ids'); + $selected_ids = implode(',', $this->getSelectedIDs($event, true)); } $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); - $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName'); - $sql = 'SELECT '.$id_field.', CreatedById - FROM '.$table_name.' item_table - WHERE '.$id_field.' IN ('.$selected_ids.')'; - $items = $this->Conn->Query($sql, $id_field); + if (strlen($selected_ids) > 0) { + $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName'); + $sql = 'SELECT '.$id_field.', CreatedById + FROM '.$table_name.' item_table + WHERE '.$id_field.' IN ('.$selected_ids.')'; + $items = $this->Conn->Query($sql, $id_field); + } + else { + // when creating new category, then no IDs are stored in session + $parent_cat = $this->Application->RecallVar('m_cat_id'); + $items[$parent_cat] = Array ( + $id_field => $parent_cat, + 'CreatedById' => $this->Application->RecallVar('user_id'), + ); + } $perm_value = true; $perm_helper =& $this->Application->recallObject('PermissionsHelper'); + /* @var $perm_helper kPermissionsHelper */ + foreach ($items as $item_id => $item_data) { if ($perm_helper->ModifyCheckPermission($item_data['CreatedById'], $item_data[$id_field], $event->Prefix) == 0) { // one of items selected has no permission @@ -81,7 +93,11 @@ $type_clauses = Array(); $object =& $event->getObject(); + /* @var $object kDBList */ + // hide categories with status = 4 (system categories) + $object->addFilter('system_categories', '%1$s.Status <> 4'); + if ( $event->getEventParam('parent_cat_id') ) { $parent_cat_id = $event->getEventParam('parent_cat_id'); @@ -114,7 +130,7 @@ } $object->addFilter('perm_filter', 'PermId = 1'); // check for CATEGORY.VIEW permission - if ($this->Application->GetVar('u_id') != -1) { + if ($this->Application->RecallVar('user_id') != -1) { // apply permission filters to all users except "root" $groups = explode(',',$this->Application->RecallVar('UserGroups')); foreach ($groups as $group) { @@ -248,15 +264,26 @@ $object->addFilter('excepts_filter_h', $excepts_and_filter_h, HAVING_FILTER); } + /** + * Enter description here... + * + * @param kEvent $event + * @return int + */ function GetPassedId(&$event) { - if ( $this->Application->IsAdmin() ) { - return parent::getPassedID($event); + if ( $this->Application->IsAdmin()) { + return parent::getPassedID($event); } return $this->Application->GetVar('m_cat_id'); } + function ParentGetPassedId(&$event) + { + return parent::GetPassedId($event); + } + /** * Adds calculates fields for item statuses * @@ -282,15 +309,25 @@ */ function OnAfterCopyToLive(&$event) { + $parent_path = false; + $object =& $this->Application->recallObject($event->Prefix.'.-item', null, Array('skip_autoload' => true, 'live_table' => true)); + $object->Load($event->getEventParam('id')); 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()); + $parent_path = $fields_hash['ParentPath']; } } + else { + $parent_path = $object->GetDBField('ParentPath'); + } + if ($parent_path) { + $cache_updater =& $this->Application->recallObject('kPermCacheUpdater', null, array('strict_path' => $parent_path)); + $cache_updater->OneStepRun(); + $cache_updater->StrictPath = false; + } } /** @@ -318,7 +355,7 @@ $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'); + $cached_fields = Array('Name', 'Filename', 'CategoryTemplate', 'ParentId'); foreach ($cached_fields as $cached_field) { if ($live_object->GetDBField($cached_field) != $temp_object->GetDBField($cached_field)) { @@ -331,6 +368,17 @@ } /** + * Calls kDBEventHandler::OnSave original event + * Used in proj-cms:StructureEventHandler->OnSave + * + * @param kEvent $event + */ + function parentOnSave(&$event) + { + parent::OnSave($event); + } + + /** * Checks cache update mark and redirect to cache if needed * * @param kEvent $event @@ -345,9 +393,12 @@ parent::OnSave($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')); + $wid = $this->Application->GetVar('m_wid'); + $stack_name = rtrim('opener_stack_'.$wid, '_'); + + $opener_stack = unserialize($this->Application->RecallVar($stack_name)); $opener_stack[0] = str_replace('catalog', 'categories/cache_updater', $opener_stack[0]); - $this->Application->StoreVar('opener_stack', serialize($opener_stack)); + $this->Application->StoreVar($stack_name, serialize($opener_stack)); $this->Application->RemoveVar('PermCache_UpdateRequired'); } } @@ -370,8 +421,10 @@ $ids = $this->StoreSelectedIDs($event); if ($ids) { $recursive_helper =& $this->Application->recallObject('RecursiveHelper'); + /* @var $recursive_helper kRecursiveHelper */ + foreach ($ids as $id) { - $recursive_helper->DeleteCategory($id); + $recursive_helper->DeleteCategory($id, $event->Prefix); } } $this->clearSelectedIDs($event); @@ -437,13 +490,15 @@ } $recursive_helper =& $this->Application->recallObject('RecursiveHelper'); + /* @var $recursive_helper kRecursiveHelper */ + if ($clipboard_data['cut']) { $recursive_helper->MoveCategories($clipboard_data['cut'], $this->Application->GetVar('m_cat_id')); } if ($clipboard_data['copy']) { foreach ($clipboard_data['copy'] as $id) { - $recursive_helper->PasteCategory($id); + $recursive_helper->PasteCategory($id, $event->Prefix); } }