+ $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.')');
+ $ids = $this->Conn->GetCol('SELECT CategoryId FROM '.$object->TableName.' WHERE (PrimaryCat=0) AND ('.$table_info['ForeignKey'].'='.$table_info['ParentId'].') AND CategoryId IN ('.implode(',',$ids).')');
+ $event->setEventParam('ids',$ids);
+ }
+ break;
+
+ // not needed because 'before' does not allow to delete primary cat!
+ /*case 'after':
+ // set 1st not deleted category as primary
+ $has_primary = $this->Conn->GetOne('SELECT COUNT(*) FROM '.$object->TableName.' WHERE (PrimaryCat=1) AND ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].')');
+ if(!$has_primary)
+ {
+ $cat_id = $this->Conn->GetOne('SELECT CategoryId FROM '.$object->TableName.' 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 = '.$cat_id.')');
+ }
+ break;*/
+ }
+ }
+ }
+
+ /**
+ * Removes primary mark from cloned category items record
+ $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.')');
+ $ids = $this->Conn->GetCol('SELECT CategoryId FROM '.$object->TableName.' WHERE (PrimaryCat=0) AND ('.$table_info['ForeignKey'].'='.$table_info['ParentId'].') AND CategoryId IN ('.implode(',',$ids).')');
+ $event->setEventParam('ids',$ids);
+ }
+ break;
+
+ // not needed because 'before' does not allow to delete primary cat!
+ /*case 'after':
+ // set 1st not deleted category as primary
+ $has_primary = $this->Conn->GetOne('SELECT COUNT(*) FROM '.$object->TableName.' WHERE (PrimaryCat=1) AND ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].')');
+ if(!$has_primary)
+ {
+ $cat_id = $this->Conn->GetOne('SELECT CategoryId FROM '.$object->TableName.' 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 = '.$cat_id.')');
+ }
+ break;*/
+ }
+ }
+ }
+
+ /**
+ * Removes primary mark from cloned category items record