Index: branches/RC/core/units/categories/categories_event_handler.php =================================================================== diff -u -r9617 -r9705 --- branches/RC/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 9617) +++ branches/RC/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 9705) @@ -196,6 +196,13 @@ $object->addFilter('status_filter', $object->TableName.'.Status = 1'); } + /* TO DO + if(strpos($types, 'related') !== false) + { + $type_clauses = $this->getTypeClauses($event); + } + */ + if(strpos($types, 'category_related') !== false) { $object->removeFilter('parent_filter'); @@ -262,6 +269,8 @@ /********************************************/ + + $includes_or_filter =& $this->Application->makeClass('kMultipleFilter'); $includes_or_filter->setType(FLT_TYPE_OR); @@ -518,7 +527,7 @@ { if ($event->Name == 'OnMassDelete' && $type == 'before') { $ids = $event->getEventParam('ids'); - if (!$ids || $this->Application->ConfigValue('m_AllowDeleteRootCats')) { + if (!$ids || $this->Application->ConfigValue('AllowDeleteRootCats')) { return ; } @@ -776,6 +785,89 @@ return parent::getPerPage($event); } + + /** + * Return type clauses for list bulding on front + * + * @param kEvent $event + * @return Array + */ + function getTypeClauses(&$event) + { + $types = $event->getEventParam('types'); + $types = $types ? explode(',', $types) : Array (); + + $except_types = $event->getEventParam('except'); + $except_types = $except_types ? explode(',', $except_types) : Array (); + + $type_clauses = Array(); + + if (in_array('related', $types) || in_array('related', $except_types)) { + + + $related_to = $event->getEventParam('related_to'); + if (!$related_to) { + $related_prefix = $event->Prefix; + } + else { + $sql = 'SELECT Prefix + FROM '.TABLE_PREFIX.'ItemTypes + WHERE ItemName = '.$this->Conn->qstr($related_to); + $related_prefix = $this->Conn->GetOne($sql); + } + + $rel_table = $this->Application->getUnitOption('rel', 'TableName'); + $item_type = $this->Application->getUnitOption($event->Prefix, 'ItemType'); + + $p_item =& $this->Application->recallObject($related_prefix.'.current', null, Array('skip_autoload' => true)); + + $cat_id = $this->Application->GetVar('c_id'); + if (!$cat_id) { + $cat_id = $this->Application->GetVar('m_cat_id'); + } + if (!$cat_id) { + $cat_id = 0; + } + + $p_item->Load($cat_id); + + $p_resource_id = $p_item->GetDBField('ResourceId'); + + $sql = 'SELECT SourceId, TargetId FROM '.$rel_table.' + WHERE + (Enabled = 1) + AND ( + (Type = 0 AND SourceId = '.$p_resource_id.' AND TargetType = '.$item_type.') + OR + (Type = 1 + AND ( + (SourceId = '.$p_resource_id.' AND TargetType = '.$item_type.') + OR + (TargetId = '.$p_resource_id.' AND SourceType = '.$item_type.') + ) + ) + )'; + + $related_ids_array = $this->Conn->Query($sql); + $related_ids = Array(); + + foreach ($related_ids_array as $key => $record) { + $related_ids[] = $record[ $record['SourceId'] == $p_resource_id ? 'TargetId' : 'SourceId' ]; + } + + if (count($related_ids) > 0) { + $type_clauses['related']['include'] = '%1$s.ResourceId IN ('.implode(',', $related_ids).')'; + $type_clauses['related']['except'] = '%1$s.ResourceId NOT IN ('.implode(',', $related_ids).')'; + } + else { + $type_clauses['related']['include'] = '0'; + $type_clauses['related']['except'] = '1'; + } + $type_clauses['related']['having_filter'] = false; + } + + return $type_clauses; + } } ?> \ No newline at end of file