Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Tue, Aug 5, 4:07 AM

in-portal

Index: trunk/kernel/units/categories/categories_tag_processor.php
===================================================================
--- trunk/kernel/units/categories/categories_tag_processor.php (revision 2585)
+++ trunk/kernel/units/categories/categories_tag_processor.php (revision 2586)
@@ -1,265 +1,279 @@
<?php
class CategoriesTagProcessor extends kDBTagProcessor {
function &GetList($params)
{
- if ( isset($params['parent_cat_id']) ) {
- $parent_cat_id = $params['parent_cat_id'];
- }
- else {
- $parent_cat_id = $this->Application->GetVar($this->Prefix.'_id');
- if (!$parent_cat_id) {
- $parent_cat_id = $this->Application->GetVar('m_cat_id');
- }
- if (!$parent_cat_id) {
- $parent_cat_id = 0;
- }
- }
+ $special = $this->BuildListSpecial($params);
- $prefix_special = $this->Prefix.'.-'.$parent_cat_id;
-
- $this->Special = '-'.$parent_cat_id;
+ $prefix_special = $this->Prefix.'.'.$special;
+ $this->Special = $special;
$params['skip_counting'] = true;
$list =& $this->Application->recallObject( $prefix_special, $this->Prefix.'_List',$params);
// $list->clearFilters();
// $list->addFilter('parent_filter', 'ParentId = '.$parent_cat_id, WHERE_FILTER, FLT_SYSTEM);
//unset($params['skip_counting']);
$this->Application->HandleEvent($event, $prefix_special.':SetPagination', $params );
$list->Query();
return $list;
}
function SubCatCount($params)
{
$cat_object =& $this->Application->recallObject($this->getPrefixSpecial(),$this->Prefix, $params);
$sql = ' SELECT COUNT(*) - 1
FROM '.$cat_object->TableName.'
WHERE ParentPath LIKE "'.$cat_object->GetDBField('ParentPath').'%"';
return $this->Conn->GetOne($sql);
}
function IsNew($params)
{
$object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params);
$ret = $object->GetDBField('IsNew') ? 1 : 0;
return $ret;
}
function IsPick($params)
{
$object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params);
$ret = $object->GetDBField('EditorsPick') ? 1 : 0;
return $ret;
}
function ItemIcon($params)
{
$object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params);
$status = $object->GetDBField('Status');
if($status == 1)
{
$ret = $object->GetDBField('IsNew') ? 'icon16_cat_new.gif' : 'icon16_cat.gif';
}
else
{
$ret = $status ? 'icon16_cat_pending.gif' : 'icon16_cat_disabled.gif';
}
return $ret;
}
function ItemCount($params)
{
$cat_object =& $this->Application->recallObject($this->getPrefixSpecial(),$this->Prefix, $params);
$ci_table = $this->Application->getUnitOption('ci','TableName');
$sql = ' SELECT COUNT(*)
FROM '.$cat_object->TableName.' c
LEFT JOIN '.$ci_table.' ci
ON c.CategoryId=ci.CategoryId
WHERE c.ParentPath LIKE "'.$cat_object->GetDBField('ParentPath').'%"
AND NOT (ci.CategoryId IS NULL)';
return $this->Conn->GetOne($sql);
}
function ListCategories($params)
{
return $this->PrintList2($params);
}
function RootCategoryName($params)
{
$root_phrase = $this->Application->ConfigValue('Root_Name');
$ret = $this->Application->Phrase($root_phrase);
return $ret;
}
function CheckModuleRoot($params)
{
$module_name = getArrayValue($params, 'module') ? $params['module'] : 'In-Commerce';
$module = $this->Application->recallObject('mod.'.$module_name);
$module_root_cat = $module->GetDBField('RootCat');
if ($this->Application->GetVar('m_cat_id') == $module_root_cat) {
$home_template = getArrayValue($params, 'home_template');
if (!$home_template) return;
$this->Application->Redirect($home_template, Array('pass'=>'all'));
};
}
function CategoryPath($params)
{
$module_name = getArrayValue($params, 'module') ? $params['module'] : 'In-Commerce';
$module = $this->Application->recallObject('mod.'.$module_name);
$module_root_cat = $module->GetDBField('RootCat');
$block_params['current'] = 0;
$block_params['separator'] = $params['separator'];
if(!isset($params['cat_id']))
{
$params['cat_id'] = getArrayValue($params, 'cat_id') ? $params['cat_id'] : $this->Application->GetVar('m_cat_id');
$block_params['current'] = 1;
}
$product_id = $this->Application->GetVar('p_id');
if ($product_id) {
$block_params['current'] = 0;
}
$block_params['is_module_root'] = ($params['cat_id'] == $module_root_cat) ? 1 : 0;
if($params['cat_id'] == 0)
{
$block_params['name'] = $this->SelectParam($params, 'root_cat_render_as,block_root_cat,rootcatblock');
return $this->Application->ParseBlock($block_params);
}
else
{
$block_params['name'] = $this->SelectParam($params,'render_as,block');
$cat_object = &$this->Application->recallObject( $this->getPrefixSpecial(), $this->Prefix.'_List' );
$sql = 'SELECT CategoryId, ParentId, Name FROM '.$cat_object->TableName.' WHERE CategoryId='.$params['cat_id'];
$res = $this->Conn->GetRow($sql);
$block_params['cat_name'] = $res['Name'];
$block_params['cat_id'] = $res['CategoryId'];
$parent_params = $params;
$parent_params['cat_id'] = $res['ParentId'];
// which block to parse as current ?
if ($block_params['is_module_root'] == 1) { // module root
$block_params['name'] = $this->SelectParam($params, 'module_root_render_as,block_module_root,rootmoduleblock');
}
if ($block_params['current'] == 1) { // current cat (label)
$block_params['name'] = $this->SelectParam($params, 'current_render_as,block_current,currentblock');
}
$this->Application->SetVar($this->Prefix.'_id', $res['CategoryId']);
$current_cat = $this->Application->ParseBlock($block_params, 1);
$this->Application->SetVar($this->Prefix.'_id', $res['ParentId']);
$parent_cat = $this->CategoryPath($parent_params);
return $parent_cat.$current_cat;
}
}
function CurrentCategoryName($params){
$cat_object = &$this->Application->recallObject( $this->getPrefixSpecial(), $this->Prefix.'_List' );
$cat_id = $this->Application->GetVar("m_cat_id");
$sql = 'SELECT Name FROM '.$cat_object->TableName.' WHERE CategoryId='.$cat_id;
return $this->Conn->GetOne($sql);
}
function InitMainPrefix($params)
{
if($main_prefix = $this->Application->GetVar('main_prefix'))
{
$this->Application->StoreVar('selector_main_prefix', $main_prefix);
}
}
function CategoryLink($params)
{
// 'p_id'=>'0', ??
$params = array_merge(array('pass'=>'m'), $params);
$cat_id = getArrayValue($params,'cat_id');
if (!$cat_id) {
// $cat_id = $this->Application->Parser->GetParam('cat_id');
$cat_id = $this->Application->GetVar($this->Prefix.'_id');
}
if($cat_id == 'Root')
{
$object =& $this->Application->recallObject('mod.'.$params['module']);
$params['m_cat_id'] = $object->GetDBField('RootCat');
unset($params['module']);
}
else{
$params['m_cat_id'] = $cat_id;
}
unset($params['cat_id']);
$main_processor =& $this->Application->recallObject('m_TagProcessor');
return $main_processor->T($params);
}
function CategoryList($params)
{
$object =& $this->Application->recallObject( $this->getPrefixSpecial() , $this->Prefix.'_List', $params );
if ($object->RecordsCount == 0)
{
if (isset($params['block_no_cats'])) {
$params['name'] = $params['block_no_cats'];
return $this->Application->ParseBlock($params);
}
else {
return '';
}
}
if(isset($params['block']))
{
return $this->PrintList($params);
}
else
{
$params['block'] = $params['block_main'];
$params['row_start_block'] = $params['block_row_start'];
$params['row_end_block'] = $params['block_row_end'];
return $this->PrintList2($params);
}
}
function Meta($params)
{
$name = getArrayValue($params, 'name');
$object =& $this->Application->recallObject($this->Prefix.'.-item');
$field = $object->GetField('Meta'.$name);
if ($field) return $field;
switch ($name) {
case 'Description':
$conf = 'Category_MetaDesc';
break;
case 'Keywords':
$conf = 'Category_MetaKey';
break;
}
return $this->Application->ConfigValue($conf);
}
+
+ function BuildListSpecial($params)
+ {
+ if ( isset($params['parent_cat_id']) ) {
+ $parent_cat_id = $params['parent_cat_id'];
+ }
+ else {
+ $parent_cat_id = $this->Application->GetVar($this->Prefix.'_id');
+ if (!$parent_cat_id) {
+ $parent_cat_id = $this->Application->GetVar('m_cat_id');
+ }
+ if (!$parent_cat_id) {
+ $parent_cat_id = 0;
+ }
+ }
+
+ $types = $this->SelectParam($params, 'types');
+ $except = $this->SelectParam($params, 'except');
+
+ if ($types.$except.$parent_cat_id == '') {
+ return parent::BuildListSpecial($params);
+ }
+
+ $special = crc32($types.$except.$parent_cat_id);
+ return $special;
+ }
}
?>
\ No newline at end of file
Property changes on: trunk/kernel/units/categories/categories_tag_processor.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.6
\ No newline at end of property
+1.7
\ No newline at end of property
Index: trunk/kernel/units/categories/categories_event_handler.php
===================================================================
--- trunk/kernel/units/categories/categories_event_handler.php (revision 2585)
+++ trunk/kernel/units/categories/categories_event_handler.php (revision 2586)
@@ -1,101 +1,226 @@
<?php
class CategoriesEventHandler extends InpDBEventHandler {
/**
* Goes one level up from current category
*
* @param kEvent $event
*/
function OnCategoryUp(&$event)
{
$category_table = $this->Application->getUnitOption($event->Prefix,'TableName');
$current_cat = $this->Application->GetVar('m_cat_id');
if($current_cat)
{
$sql = 'SELECT ParentId FROM '.$category_table.' WHERE CategoryId = '.$current_cat;
$cat_to_go = $this->Conn->GetOne($sql);
}
else
{
$cat_to_go = 0;
}
$event->redirect_params = Array('m_cat_id' => $cat_to_go);
}
/**
* Goes to home category
*
* @param kEvent $event
*/
function OnGoHome(&$event)
{
$cat_to_go = 0;
$event->redirect_params = Array('m_cat_id' => $cat_to_go);
}
/**
* Apply system filter to categories list
*
* @param kEvent $event
*/
function SetCustomQuery(&$event)
{
+ parent::SetCustomQuery($event);
+
+ $types=$event->getEventParam('types');
+ $except_types=$event->getEventParam('except');
+ $object =& $event->getObject();
+ $type_clauses = Array();
+
$object =& $event->getObject();
if ( $event->getEventParam('parent_cat_id') ) {
$parent_cat_id = $event->getEventParam('parent_cat_id');
}
else {
$parent_cat_id = $this->Application->GetVar('c_id');
if (!$parent_cat_id) {
$parent_cat_id = $this->Application->GetVar('m_cat_id');
}
if (!$parent_cat_id) {
$parent_cat_id = 0;
}
}
if ($parent_cat_id != 'any') {
if ($event->getEventParam('recursive')) {
$current_path = $this->Conn->GetOne('SELECT ParentPath FROM '.TABLE_PREFIX.'Category WHERE CategoryId='.$parent_cat_id);
$subcats = $this->Conn->GetCol('SELECT CategoryId FROM '.TABLE_PREFIX.'Category WHERE ParentPath LIKE "'.$current_path.'%" ');
$object->addFilter('parent_filter', 'ParentId IN ('.implode(', ', $subcats).')');
}
else {
$object->addFilter('parent_filter', 'ParentId = '.$parent_cat_id);
}
}
$object->addFilter('parent_filter', 'ParentId = '.$parent_cat_id);
$view_perm = 1;
$object->addFilter('perm_filter', 'PermId = '.$view_perm);
if (!defined('ADMIN')) {
$groups = explode(',',$this->Application->RecallVar('UserGroups'));
foreach ($groups as $group) {
$view_filters[] = 'FIND_IN_SET('.$group.', acl) || ((NOT FIND_IN_SET('.$group.',dacl)) AND acl=\'\')';
}
$view_filter = implode(' OR ', $view_filters);
$object->addFilter('perm_filter2', $view_filter);
}
if (!defined('ADMIN')) {
$object->addFilter('status_filter', $object->TableName.'.Status = 1');
}
+
+ if(strpos($types, 'category_related') !== false)
+ {
+ $object->removeFilter('parent_filter');
+ $resource_id = $this->Conn->GetOne('
+ SELECT ResourceId FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').'
+ WHERE CategoryId = '.$parent_cat_id
+ );
+
+ $sql = 'SELECT DISTINCT(TargetId) FROM '.TABLE_PREFIX.'Relationship
+ WHERE SourceId = '.$resource_id.' AND SourceType = 1';
+ $related_cats = $this->Conn->GetCol($sql);
+ $related_cats = is_array($related_cats) ? $related_cats : Array();
+ $sql = 'SELECT DISTINCT(SourceId) FROM '.TABLE_PREFIX.'Relationship
+ WHERE TargetId = '.$resource_id.' AND TargetType = 1 AND Type = 1';
+ $related_cats2 = $this->Conn->GetCol($sql);
+ $related_cats2 = is_array($related_cats2) ? $related_cats2 : Array();
+ $related_cats = array_unique( array_merge( $related_cats2, $related_cats ) );
+
+ if($related_cats)
+ {
+ $type_clauses['category_related']['include'] = '%1$s.ResourceId IN ('.implode(',', $related_cats).')';
+ $type_clauses['category_related']['except'] = '%1$s.ResourceId NOT IN ('.implode(',', $related_cats).')';
+ }
+ else
+ {
+ $type_clauses['category_related']['include'] = '0';
+ $type_clauses['category_related']['except'] = '1';
+ }
+ $type_clauses['category_related']['having_filter'] = false;
+ }
+
+ if(strpos($types, 'product_related') !== false)
+ {
+ $object->removeFilter('parent_filter');
+
+ $product_id = $event->getEventParam('product_id') ? $event->getEventParam('product_id') : $this->Application->GetVar('p_id');
+ $resource_id = $this->Conn->GetOne('
+ SELECT ResourceId FROM '.$this->Application->getUnitOption('p', 'TableName').'
+ WHERE ProductId = '.$product_id
+ );
+
+ $sql = 'SELECT DISTINCT(TargetId) FROM '.TABLE_PREFIX.'Relationship
+ WHERE SourceId = '.$resource_id.' AND TargetType = 1';
+ $related_cats = $this->Conn->GetCol($sql);
+ $related_cats = is_array($related_cats) ? $related_cats : Array();
+ $sql = 'SELECT DISTINCT(SourceId) FROM '.TABLE_PREFIX.'Relationship
+ WHERE TargetId = '.$resource_id.' AND SourceType = 1 AND Type = 1';
+ $related_cats2 = $this->Conn->GetCol($sql);
+ $related_cats2 = is_array($related_cats2) ? $related_cats2 : Array();
+ $related_cats = array_unique( array_merge( $related_cats2, $related_cats ) );
+
+ if($related_cats)
+ {
+ $type_clauses['product_related']['include'] = '%1$s.ResourceId IN ('.implode(',', $related_cats).')';
+ $type_clauses['product_related']['except'] = '%1$s.ResourceId NOT IN ('.implode(',', $related_cats).')';
+ }
+ else
+ {
+ $type_clauses['product_related']['include'] = '0';
+ $type_clauses['product_related']['except'] = '1';
+ }
+ $type_clauses['product_related']['having_filter'] = false;
+ }
+
+ /********************************************/
+
+ $includes_or_filter =& $this->Application->makeClass('kMultipleFilter');
+ $includes_or_filter->setType(FLT_TYPE_OR);
+
+ $excepts_and_filter =& $this->Application->makeClass('kMultipleFilter');
+ $excepts_and_filter->setType(FLT_TYPE_AND);
+
+ $includes_or_filter_h =& $this->Application->makeClass('kMultipleFilter');
+ $includes_or_filter_h->setType(FLT_TYPE_OR);
+
+ $excepts_and_filter_h =& $this->Application->makeClass('kMultipleFilter');
+ $excepts_and_filter_h->setType(FLT_TYPE_AND);
+
+ $except_types_array=explode(',', $types);
+
+ if ($types){
+ $types_array=explode(',', $types);
+ for ($i=0; $i<sizeof($types_array); $i++){
+ $type=trim($types_array[$i]);
+ if (isset($type_clauses[$type])){
+ if ($type_clauses[$type]['having_filter']){
+ $includes_or_filter_h->removeFilter('filter_'.$type);
+ $includes_or_filter_h->addFilter('filter_'.$type, $type_clauses[$type]['include']);
+ }else{
+ $includes_or_filter->removeFilter('filter_'.$type);
+ $includes_or_filter->addFilter('filter_'.$type, $type_clauses[$type]['include']);
+ }
+ }
+ }
+ }
+
+ if ($except_types){
+ $except_types_array=explode(',', $except_types);
+ for ($i=0; $i<sizeof($except_types_array); $i++){
+ $type=trim($except_types_array[$i]);
+ if (isset($type_clauses[$type])){
+ if ($type_clauses[$type]['having_filter']){
+ $excepts_and_filter_h->removeFilter('filter_'.$type);
+ $excepts_and_filter_h->addFilter('filter_'.$type, $type_clauses[$type]['except']);
+ }else{
+ $excepts_and_filter->removeFilter('filter_'.$type);
+ $excepts_and_filter->addFilter('filter_'.$type, $type_clauses[$type]['except']);
+ }
+ }
+ }
+ }
+
+ $object->addFilter('includes_filter', $includes_or_filter);
+ $object->addFilter('excepts_filter', $excepts_and_filter);
+
+ $object->addFilter('includes_filter_h', $includes_or_filter_h, HAVING_FILTER);
+ $object->addFilter('excepts_filter_h', $excepts_and_filter_h, HAVING_FILTER);
}
function GetPassedId(&$event)
{
if (defined('ADMIN')) return parent::getPassedID($event);
$ret = $this->Application->GetVar('m_cat_id');
if($ret) return $ret;
return parent::getPassedID($event);
}
}
?>
\ No newline at end of file
Property changes on: trunk/kernel/units/categories/categories_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.5
\ No newline at end of property
+1.6
\ No newline at end of property
Index: trunk/core/units/categories/categories_tag_processor.php
===================================================================
--- trunk/core/units/categories/categories_tag_processor.php (revision 2585)
+++ trunk/core/units/categories/categories_tag_processor.php (revision 2586)
@@ -1,265 +1,279 @@
<?php
class CategoriesTagProcessor extends kDBTagProcessor {
function &GetList($params)
{
- if ( isset($params['parent_cat_id']) ) {
- $parent_cat_id = $params['parent_cat_id'];
- }
- else {
- $parent_cat_id = $this->Application->GetVar($this->Prefix.'_id');
- if (!$parent_cat_id) {
- $parent_cat_id = $this->Application->GetVar('m_cat_id');
- }
- if (!$parent_cat_id) {
- $parent_cat_id = 0;
- }
- }
+ $special = $this->BuildListSpecial($params);
- $prefix_special = $this->Prefix.'.-'.$parent_cat_id;
-
- $this->Special = '-'.$parent_cat_id;
+ $prefix_special = $this->Prefix.'.'.$special;
+ $this->Special = $special;
$params['skip_counting'] = true;
$list =& $this->Application->recallObject( $prefix_special, $this->Prefix.'_List',$params);
// $list->clearFilters();
// $list->addFilter('parent_filter', 'ParentId = '.$parent_cat_id, WHERE_FILTER, FLT_SYSTEM);
//unset($params['skip_counting']);
$this->Application->HandleEvent($event, $prefix_special.':SetPagination', $params );
$list->Query();
return $list;
}
function SubCatCount($params)
{
$cat_object =& $this->Application->recallObject($this->getPrefixSpecial(),$this->Prefix, $params);
$sql = ' SELECT COUNT(*) - 1
FROM '.$cat_object->TableName.'
WHERE ParentPath LIKE "'.$cat_object->GetDBField('ParentPath').'%"';
return $this->Conn->GetOne($sql);
}
function IsNew($params)
{
$object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params);
$ret = $object->GetDBField('IsNew') ? 1 : 0;
return $ret;
}
function IsPick($params)
{
$object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params);
$ret = $object->GetDBField('EditorsPick') ? 1 : 0;
return $ret;
}
function ItemIcon($params)
{
$object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params);
$status = $object->GetDBField('Status');
if($status == 1)
{
$ret = $object->GetDBField('IsNew') ? 'icon16_cat_new.gif' : 'icon16_cat.gif';
}
else
{
$ret = $status ? 'icon16_cat_pending.gif' : 'icon16_cat_disabled.gif';
}
return $ret;
}
function ItemCount($params)
{
$cat_object =& $this->Application->recallObject($this->getPrefixSpecial(),$this->Prefix, $params);
$ci_table = $this->Application->getUnitOption('ci','TableName');
$sql = ' SELECT COUNT(*)
FROM '.$cat_object->TableName.' c
LEFT JOIN '.$ci_table.' ci
ON c.CategoryId=ci.CategoryId
WHERE c.ParentPath LIKE "'.$cat_object->GetDBField('ParentPath').'%"
AND NOT (ci.CategoryId IS NULL)';
return $this->Conn->GetOne($sql);
}
function ListCategories($params)
{
return $this->PrintList2($params);
}
function RootCategoryName($params)
{
$root_phrase = $this->Application->ConfigValue('Root_Name');
$ret = $this->Application->Phrase($root_phrase);
return $ret;
}
function CheckModuleRoot($params)
{
$module_name = getArrayValue($params, 'module') ? $params['module'] : 'In-Commerce';
$module = $this->Application->recallObject('mod.'.$module_name);
$module_root_cat = $module->GetDBField('RootCat');
if ($this->Application->GetVar('m_cat_id') == $module_root_cat) {
$home_template = getArrayValue($params, 'home_template');
if (!$home_template) return;
$this->Application->Redirect($home_template, Array('pass'=>'all'));
};
}
function CategoryPath($params)
{
$module_name = getArrayValue($params, 'module') ? $params['module'] : 'In-Commerce';
$module = $this->Application->recallObject('mod.'.$module_name);
$module_root_cat = $module->GetDBField('RootCat');
$block_params['current'] = 0;
$block_params['separator'] = $params['separator'];
if(!isset($params['cat_id']))
{
$params['cat_id'] = getArrayValue($params, 'cat_id') ? $params['cat_id'] : $this->Application->GetVar('m_cat_id');
$block_params['current'] = 1;
}
$product_id = $this->Application->GetVar('p_id');
if ($product_id) {
$block_params['current'] = 0;
}
$block_params['is_module_root'] = ($params['cat_id'] == $module_root_cat) ? 1 : 0;
if($params['cat_id'] == 0)
{
$block_params['name'] = $this->SelectParam($params, 'root_cat_render_as,block_root_cat,rootcatblock');
return $this->Application->ParseBlock($block_params);
}
else
{
$block_params['name'] = $this->SelectParam($params,'render_as,block');
$cat_object = &$this->Application->recallObject( $this->getPrefixSpecial(), $this->Prefix.'_List' );
$sql = 'SELECT CategoryId, ParentId, Name FROM '.$cat_object->TableName.' WHERE CategoryId='.$params['cat_id'];
$res = $this->Conn->GetRow($sql);
$block_params['cat_name'] = $res['Name'];
$block_params['cat_id'] = $res['CategoryId'];
$parent_params = $params;
$parent_params['cat_id'] = $res['ParentId'];
// which block to parse as current ?
if ($block_params['is_module_root'] == 1) { // module root
$block_params['name'] = $this->SelectParam($params, 'module_root_render_as,block_module_root,rootmoduleblock');
}
if ($block_params['current'] == 1) { // current cat (label)
$block_params['name'] = $this->SelectParam($params, 'current_render_as,block_current,currentblock');
}
$this->Application->SetVar($this->Prefix.'_id', $res['CategoryId']);
$current_cat = $this->Application->ParseBlock($block_params, 1);
$this->Application->SetVar($this->Prefix.'_id', $res['ParentId']);
$parent_cat = $this->CategoryPath($parent_params);
return $parent_cat.$current_cat;
}
}
function CurrentCategoryName($params){
$cat_object = &$this->Application->recallObject( $this->getPrefixSpecial(), $this->Prefix.'_List' );
$cat_id = $this->Application->GetVar("m_cat_id");
$sql = 'SELECT Name FROM '.$cat_object->TableName.' WHERE CategoryId='.$cat_id;
return $this->Conn->GetOne($sql);
}
function InitMainPrefix($params)
{
if($main_prefix = $this->Application->GetVar('main_prefix'))
{
$this->Application->StoreVar('selector_main_prefix', $main_prefix);
}
}
function CategoryLink($params)
{
// 'p_id'=>'0', ??
$params = array_merge(array('pass'=>'m'), $params);
$cat_id = getArrayValue($params,'cat_id');
if (!$cat_id) {
// $cat_id = $this->Application->Parser->GetParam('cat_id');
$cat_id = $this->Application->GetVar($this->Prefix.'_id');
}
if($cat_id == 'Root')
{
$object =& $this->Application->recallObject('mod.'.$params['module']);
$params['m_cat_id'] = $object->GetDBField('RootCat');
unset($params['module']);
}
else{
$params['m_cat_id'] = $cat_id;
}
unset($params['cat_id']);
$main_processor =& $this->Application->recallObject('m_TagProcessor');
return $main_processor->T($params);
}
function CategoryList($params)
{
$object =& $this->Application->recallObject( $this->getPrefixSpecial() , $this->Prefix.'_List', $params );
if ($object->RecordsCount == 0)
{
if (isset($params['block_no_cats'])) {
$params['name'] = $params['block_no_cats'];
return $this->Application->ParseBlock($params);
}
else {
return '';
}
}
if(isset($params['block']))
{
return $this->PrintList($params);
}
else
{
$params['block'] = $params['block_main'];
$params['row_start_block'] = $params['block_row_start'];
$params['row_end_block'] = $params['block_row_end'];
return $this->PrintList2($params);
}
}
function Meta($params)
{
$name = getArrayValue($params, 'name');
$object =& $this->Application->recallObject($this->Prefix.'.-item');
$field = $object->GetField('Meta'.$name);
if ($field) return $field;
switch ($name) {
case 'Description':
$conf = 'Category_MetaDesc';
break;
case 'Keywords':
$conf = 'Category_MetaKey';
break;
}
return $this->Application->ConfigValue($conf);
}
+
+ function BuildListSpecial($params)
+ {
+ if ( isset($params['parent_cat_id']) ) {
+ $parent_cat_id = $params['parent_cat_id'];
+ }
+ else {
+ $parent_cat_id = $this->Application->GetVar($this->Prefix.'_id');
+ if (!$parent_cat_id) {
+ $parent_cat_id = $this->Application->GetVar('m_cat_id');
+ }
+ if (!$parent_cat_id) {
+ $parent_cat_id = 0;
+ }
+ }
+
+ $types = $this->SelectParam($params, 'types');
+ $except = $this->SelectParam($params, 'except');
+
+ if ($types.$except.$parent_cat_id == '') {
+ return parent::BuildListSpecial($params);
+ }
+
+ $special = crc32($types.$except.$parent_cat_id);
+ return $special;
+ }
}
?>
\ No newline at end of file
Property changes on: trunk/core/units/categories/categories_tag_processor.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.6
\ No newline at end of property
+1.7
\ No newline at end of property
Index: trunk/core/units/categories/categories_event_handler.php
===================================================================
--- trunk/core/units/categories/categories_event_handler.php (revision 2585)
+++ trunk/core/units/categories/categories_event_handler.php (revision 2586)
@@ -1,101 +1,226 @@
<?php
class CategoriesEventHandler extends InpDBEventHandler {
/**
* Goes one level up from current category
*
* @param kEvent $event
*/
function OnCategoryUp(&$event)
{
$category_table = $this->Application->getUnitOption($event->Prefix,'TableName');
$current_cat = $this->Application->GetVar('m_cat_id');
if($current_cat)
{
$sql = 'SELECT ParentId FROM '.$category_table.' WHERE CategoryId = '.$current_cat;
$cat_to_go = $this->Conn->GetOne($sql);
}
else
{
$cat_to_go = 0;
}
$event->redirect_params = Array('m_cat_id' => $cat_to_go);
}
/**
* Goes to home category
*
* @param kEvent $event
*/
function OnGoHome(&$event)
{
$cat_to_go = 0;
$event->redirect_params = Array('m_cat_id' => $cat_to_go);
}
/**
* Apply system filter to categories list
*
* @param kEvent $event
*/
function SetCustomQuery(&$event)
{
+ parent::SetCustomQuery($event);
+
+ $types=$event->getEventParam('types');
+ $except_types=$event->getEventParam('except');
+ $object =& $event->getObject();
+ $type_clauses = Array();
+
$object =& $event->getObject();
if ( $event->getEventParam('parent_cat_id') ) {
$parent_cat_id = $event->getEventParam('parent_cat_id');
}
else {
$parent_cat_id = $this->Application->GetVar('c_id');
if (!$parent_cat_id) {
$parent_cat_id = $this->Application->GetVar('m_cat_id');
}
if (!$parent_cat_id) {
$parent_cat_id = 0;
}
}
if ($parent_cat_id != 'any') {
if ($event->getEventParam('recursive')) {
$current_path = $this->Conn->GetOne('SELECT ParentPath FROM '.TABLE_PREFIX.'Category WHERE CategoryId='.$parent_cat_id);
$subcats = $this->Conn->GetCol('SELECT CategoryId FROM '.TABLE_PREFIX.'Category WHERE ParentPath LIKE "'.$current_path.'%" ');
$object->addFilter('parent_filter', 'ParentId IN ('.implode(', ', $subcats).')');
}
else {
$object->addFilter('parent_filter', 'ParentId = '.$parent_cat_id);
}
}
$object->addFilter('parent_filter', 'ParentId = '.$parent_cat_id);
$view_perm = 1;
$object->addFilter('perm_filter', 'PermId = '.$view_perm);
if (!defined('ADMIN')) {
$groups = explode(',',$this->Application->RecallVar('UserGroups'));
foreach ($groups as $group) {
$view_filters[] = 'FIND_IN_SET('.$group.', acl) || ((NOT FIND_IN_SET('.$group.',dacl)) AND acl=\'\')';
}
$view_filter = implode(' OR ', $view_filters);
$object->addFilter('perm_filter2', $view_filter);
}
if (!defined('ADMIN')) {
$object->addFilter('status_filter', $object->TableName.'.Status = 1');
}
+
+ if(strpos($types, 'category_related') !== false)
+ {
+ $object->removeFilter('parent_filter');
+ $resource_id = $this->Conn->GetOne('
+ SELECT ResourceId FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').'
+ WHERE CategoryId = '.$parent_cat_id
+ );
+
+ $sql = 'SELECT DISTINCT(TargetId) FROM '.TABLE_PREFIX.'Relationship
+ WHERE SourceId = '.$resource_id.' AND SourceType = 1';
+ $related_cats = $this->Conn->GetCol($sql);
+ $related_cats = is_array($related_cats) ? $related_cats : Array();
+ $sql = 'SELECT DISTINCT(SourceId) FROM '.TABLE_PREFIX.'Relationship
+ WHERE TargetId = '.$resource_id.' AND TargetType = 1 AND Type = 1';
+ $related_cats2 = $this->Conn->GetCol($sql);
+ $related_cats2 = is_array($related_cats2) ? $related_cats2 : Array();
+ $related_cats = array_unique( array_merge( $related_cats2, $related_cats ) );
+
+ if($related_cats)
+ {
+ $type_clauses['category_related']['include'] = '%1$s.ResourceId IN ('.implode(',', $related_cats).')';
+ $type_clauses['category_related']['except'] = '%1$s.ResourceId NOT IN ('.implode(',', $related_cats).')';
+ }
+ else
+ {
+ $type_clauses['category_related']['include'] = '0';
+ $type_clauses['category_related']['except'] = '1';
+ }
+ $type_clauses['category_related']['having_filter'] = false;
+ }
+
+ if(strpos($types, 'product_related') !== false)
+ {
+ $object->removeFilter('parent_filter');
+
+ $product_id = $event->getEventParam('product_id') ? $event->getEventParam('product_id') : $this->Application->GetVar('p_id');
+ $resource_id = $this->Conn->GetOne('
+ SELECT ResourceId FROM '.$this->Application->getUnitOption('p', 'TableName').'
+ WHERE ProductId = '.$product_id
+ );
+
+ $sql = 'SELECT DISTINCT(TargetId) FROM '.TABLE_PREFIX.'Relationship
+ WHERE SourceId = '.$resource_id.' AND TargetType = 1';
+ $related_cats = $this->Conn->GetCol($sql);
+ $related_cats = is_array($related_cats) ? $related_cats : Array();
+ $sql = 'SELECT DISTINCT(SourceId) FROM '.TABLE_PREFIX.'Relationship
+ WHERE TargetId = '.$resource_id.' AND SourceType = 1 AND Type = 1';
+ $related_cats2 = $this->Conn->GetCol($sql);
+ $related_cats2 = is_array($related_cats2) ? $related_cats2 : Array();
+ $related_cats = array_unique( array_merge( $related_cats2, $related_cats ) );
+
+ if($related_cats)
+ {
+ $type_clauses['product_related']['include'] = '%1$s.ResourceId IN ('.implode(',', $related_cats).')';
+ $type_clauses['product_related']['except'] = '%1$s.ResourceId NOT IN ('.implode(',', $related_cats).')';
+ }
+ else
+ {
+ $type_clauses['product_related']['include'] = '0';
+ $type_clauses['product_related']['except'] = '1';
+ }
+ $type_clauses['product_related']['having_filter'] = false;
+ }
+
+ /********************************************/
+
+ $includes_or_filter =& $this->Application->makeClass('kMultipleFilter');
+ $includes_or_filter->setType(FLT_TYPE_OR);
+
+ $excepts_and_filter =& $this->Application->makeClass('kMultipleFilter');
+ $excepts_and_filter->setType(FLT_TYPE_AND);
+
+ $includes_or_filter_h =& $this->Application->makeClass('kMultipleFilter');
+ $includes_or_filter_h->setType(FLT_TYPE_OR);
+
+ $excepts_and_filter_h =& $this->Application->makeClass('kMultipleFilter');
+ $excepts_and_filter_h->setType(FLT_TYPE_AND);
+
+ $except_types_array=explode(',', $types);
+
+ if ($types){
+ $types_array=explode(',', $types);
+ for ($i=0; $i<sizeof($types_array); $i++){
+ $type=trim($types_array[$i]);
+ if (isset($type_clauses[$type])){
+ if ($type_clauses[$type]['having_filter']){
+ $includes_or_filter_h->removeFilter('filter_'.$type);
+ $includes_or_filter_h->addFilter('filter_'.$type, $type_clauses[$type]['include']);
+ }else{
+ $includes_or_filter->removeFilter('filter_'.$type);
+ $includes_or_filter->addFilter('filter_'.$type, $type_clauses[$type]['include']);
+ }
+ }
+ }
+ }
+
+ if ($except_types){
+ $except_types_array=explode(',', $except_types);
+ for ($i=0; $i<sizeof($except_types_array); $i++){
+ $type=trim($except_types_array[$i]);
+ if (isset($type_clauses[$type])){
+ if ($type_clauses[$type]['having_filter']){
+ $excepts_and_filter_h->removeFilter('filter_'.$type);
+ $excepts_and_filter_h->addFilter('filter_'.$type, $type_clauses[$type]['except']);
+ }else{
+ $excepts_and_filter->removeFilter('filter_'.$type);
+ $excepts_and_filter->addFilter('filter_'.$type, $type_clauses[$type]['except']);
+ }
+ }
+ }
+ }
+
+ $object->addFilter('includes_filter', $includes_or_filter);
+ $object->addFilter('excepts_filter', $excepts_and_filter);
+
+ $object->addFilter('includes_filter_h', $includes_or_filter_h, HAVING_FILTER);
+ $object->addFilter('excepts_filter_h', $excepts_and_filter_h, HAVING_FILTER);
}
function GetPassedId(&$event)
{
if (defined('ADMIN')) return parent::getPassedID($event);
$ret = $this->Application->GetVar('m_cat_id');
if($ret) return $ret;
return parent::getPassedID($event);
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/units/categories/categories_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.5
\ No newline at end of property
+1.6
\ No newline at end of property

Event Timeline