Index: branches/5.2.x/core/units/category_items/category_items_event_handler.php =================================================================== --- branches/5.2.x/core/units/category_items/category_items_event_handler.php (revision 16094) +++ branches/5.2.x/core/units/category_items/category_items_event_handler.php (revision 16095) @@ -1,187 +1,187 @@ getObject(); /* @var $object kDBList */ $ml_formatter = $this->Application->recallObject('kMultiLanguage'); /* @var $ml_formatter kMultiLanguage */ $object->addCalculatedField('CategoryName', 'c.' . $ml_formatter->LangFieldName('CachedNavbar')); } /** * Set's new category as primary for product * * @param kEvent $event */ function OnSetPrimary($event) { $object = $event->getObject(Array ('skip_autoload' => true)); /* @var $object kDBItem */ $ids = $this->StoreSelectedIDs($event); if ( $ids ) { $id = array_shift($ids); $table_info = $object->getLinkedInfo(); $this->Conn->Query('UPDATE ' . $object->TableName . ' SET PrimaryCat = 0 WHERE ' . $table_info['ForeignKey'] . ' = ' . $table_info['ParentId']); $this->Conn->Query('UPDATE ' . $object->TableName . ' SET PrimaryCat = 1 WHERE (' . $table_info['ForeignKey'] . ' = ' . $table_info['ParentId'] . ') AND (CategoryId = ' . $id . ')'); } $event->SetRedirectParam('opener', 's'); } /** * Apply custom processing to item * * @param kEvent $event * @param string $type * @return void * @access protected */ protected function customProcessing(kEvent $event, $type) { if ( $event->Name == 'OnMassDelete' ) { $object = $event->getObject(); $table_info = $object->getLinkedInfo(); switch ($type) { case 'before': $ids = $event->getEventParam('ids'); if ( $ids ) { $sql = 'SELECT CategoryId FROM ' . $object->TableName . ' WHERE (PrimaryCat = 0) AND (' . $table_info['ForeignKey'] . '=' . $table_info['ParentId'] . ') AND CategoryId IN (' . implode(',', $ids) . ')'; $event->setEventParam('ids', $this->Conn->GetCol($sql)); } break; // not needed because 'before' does not allow to delete primary cat! /*case 'after': // set 1st not deleted category as primary $sql = 'SELECT COUNT(*) FROM ' . $object->TableName . ' WHERE (PrimaryCat = 1) AND (' . $table_info['ForeignKey'] . ' = ' . $table_info['ParentId'] . ')'; $has_primary = $this->Conn->GetOne($sql); if ( !$has_primary ) { $sql = 'SELECT CategoryId FROM ' . $object->TableName . ' WHERE ' . $table_info['ForeignKey'] . ' = ' . $table_info['ParentId']; $cat_id = $this->Conn->GetOne($sql); $sql = 'UPDATE ' . $object->TableName . ' SET PrimaryCat = 1 WHERE (' . $table_info['ForeignKey'] . ' = ' . $table_info['ParentId'] . ') AND (CategoryId = ' . $cat_id . ')'; $this->Conn->Query($sql); } break;*/ } } } /** * Removes primary mark from cloned category items record * * @param kEvent $event * @return void * @access protected */ protected function OnAfterClone(kEvent $event) { parent::OnAfterClone($event); $id = $event->getEventParam('id'); $table = $this->Application->getUnitOption($event->Prefix, 'TableName'); $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); $sql = 'UPDATE %s SET PrimaryCat = 0 WHERE %s = %s'; $this->Conn->Query(sprintf($sql, $table, $id_field, $id)); } /** * Deletes items of requested type from requested categories. * In case if item is deleted from it's last category, then delete item too. * * @param kEvent $event * @return void * @access protected */ protected function OnDeleteFromCategory($event) { $category_ids = $event->getEventParam('category_ids'); if ( !$category_ids ) { return ; } $item_prefix = $event->getEventParam('item_prefix'); $item = $this->Application->recallObject($item_prefix . '.-item', null, Array ('skip_autoload' => true)); /* @var $item kCatDBItem */ $ci_table = $this->Application->getUnitOption($event->Prefix, 'TableName'); $item_table = $this->Application->getUnitOption($item_prefix, 'TableName'); $sql = 'SELECT ItemResourceId, CategoryId FROM %1$s INNER JOIN %2$s ON (%1$s.ResourceId = %2$s.ItemResourceId) WHERE CategoryId IN (%3$s)'; $category_items = $this->Conn->Query( sprintf($sql, $item_table, $ci_table, implode(',', $category_ids)) ); $item_hash = Array (); foreach ($category_items as $ci_row) { $item_hash[ $ci_row['ItemResourceId'] ][] = $ci_row['CategoryId']; } foreach ($item_hash as $item_resource_id => $delete_category_ids) { $item->Load($item_resource_id, 'ResourceId'); $item->DeleteFromCategories($delete_category_ids); } } /** * Makes sure, that parent category item is loaded when coping back from temp table * * @param kEvent $event * * @return void * @see CategoryItems_DBItem::GetKeyClause() */ protected function OnAfterCopyToLive(kEvent $event) { // don't call parent, because it's unclear how from here we can get parent item's ID here } } \ No newline at end of file Index: branches/5.2.x/core/units/category_items/category_items_config.php =================================================================== --- branches/5.2.x/core/units/category_items/category_items_config.php (revision 16094) +++ branches/5.2.x/core/units/category_items/category_items_config.php (revision 16095) @@ -1,86 +1,86 @@ 'ci', 'ItemClass' => Array('class'=>'CategoryItems_DBItem','file'=>'category_items_dbitem.php','build_event'=>'OnItemBuild'), 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'), - 'EventHandlerClass' => Array('class'=>'CategoryItemsEventHander','file'=>'category_items_event_handler.php','build_event'=>'OnBuild'), + 'EventHandlerClass' => Array('class'=>'CategoryItemsEventHandler','file'=>'category_items_event_handler.php','build_event'=>'OnBuild'), 'TagProcessorClass' => Array('class'=>'CategoryItemsTagProcessor','file'=>'category_items_tag_processor.php','build_event'=>'OnBuild'), 'AutoLoad' => true, 'QueryString' => Array( 1 => 'id', 2 => 'Page', 3 => 'PerPage', 4 => 'event', ), 'IDField' => 'CategoryId', // in this case idfield doesn't exit in destination table 'StatusField' => Array('PrimaryCat'), // field, that is affected by Approve/Decline events 'TableName' => TABLE_PREFIX.'CategoryItems', 'ParentTableKey'=> 'ResourceId', 'ForeignKey' => 'ItemResourceId', // 'ParentPrefix' => 'p', 'AutoDelete' => true, 'AutoClone' => false, 'CalculatedFields' => Array( '' => Array ( 'DummyId' => 'IF(ISNULL(c.CategoryId),0,c.CategoryId)', 'CategoryStatus'=> 'c.Status', ) ), 'ListSQLs' => Array( ''=>' SELECT %1$s.* %2$s FROM %1$s LEFT JOIN '.TABLE_PREFIX.'Categories AS c ON c.CategoryId = %1$s.CategoryId', ), // key - special, value - list select sql 'ItemSQLs' => Array( ''=>'SELECT * FROM %s', ), 'ListSortings' => Array( '' => Array( 'Sorting' => Array('CategoryName' => 'asc'), ) ), 'Fields' => Array( 'DummyId' => Array(), 'CategoryId' => Array('type'=>'int','not_null'=>1,'default'=>0), 'ItemResourceId' => Array('type' => 'int', 'not_null' => 1, 'default' => 0), 'PrimaryCat' => Array('type' => 'int', 'not_null' => 1, 'default' => 0), 'ItemPrefix' => Array('type' => 'string','not_null'=>1,'default'=>''), 'Filename' => Array('type' => 'string','not_null'=>1,'default'=>''), ), 'VirtualFields' => Array ( 'CategoryName' => Array ('type' => 'string', 'default' => ''), 'DummyId' => Array ('type' => 'int', 'default' => 0), 'CategoryStatus' => Array ('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (1 => 'la_Active', 2 => 'la_Pending', 0 => 'la_Disabled' ), 'use_phrases' => 1, 'default' => 1), ), 'Grids' => Array ( 'Default' => Array ( 'Icons' => Array ( 'default' => 'icon16_item.png', 0 => 'icon16_item.png', 1 => 'icon16_primary.png', ), 'Fields' => Array ( 'CategoryName' => Array( 'title'=>'column:la_fld_Category', 'data_block' => 'grid_checkbox_category_td'), ), ), ), ); \ No newline at end of file