Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1375695
categories_tag_processor.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Feb 1, 12:22 PM
Size
12 KB
Mime Type
text/x-php
Expires
Tue, Feb 3, 12:22 PM (6 h, 47 m)
Engine
blob
Format
Raw Data
Handle
884435
Attached To
rINP In-Portal
categories_tag_processor.php
View Options
<?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
;
}
}
$prefix_special
=
$this
->
Prefix
.
'.-'
.
$parent_cat_id
;
$this
->
Special
=
'-'
.
$parent_cat_id
;
$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
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 PrintListTest($params)
{
$stack_cat_id = $this->Application->GetVar('m_cat_id');
$prefix_special = $this->getPrefixSpecial();
$list =& $this->Application->recallObject( $prefix_special, $this->Prefix.'_List',$params);
if ( !($list->OriginalParams == $params) ) {
$this->Application->removeObject($prefix_special);
$list =& $this->Application->recallObject($prefix_special,$this->Prefix.'_List',$params);
}
$cat_id = $this->Application->GetVar('m_cat_id') ? $this->Application->GetVar('m_cat_id') : 0;
$list->addFilter( 'category_scope_filter', 'ParentId = '.$this->Application->GetVar('m_cat_id') );
$list->Query();
$record_ids_array = array();
foreach ($list->Records as $record_id){
$record_ids_array[] = $record_id['CategoryId'];
}
$parent_records=$list->Records;
$records_list = implode(', ', $record_ids_array);
$or_filter =& $this->Application->makeClass('kMultipleFilter');
$or_filter->setType(FLT_TYPE_OR);
$or_filter->addFilter('parent_filter', 'ParentId IN ('.$records_list.')');
$or_filter->addFilter('category_filter', 'CategoryId IN ('.$records_list.')');
$list->clearFilters();
$list->addFilter('parent_filter', $or_filter);
$list->AddOrderField('CachedNavbar', 'ASC');
$list->Query();
$unsorted_cats=$list->Records;
$parent_cats=array();
$child_cats=array();
$all_records=array();
for ($i=0; $i<sizeof($unsorted_cats); $i++) {
if($unsorted_cats[$i]['ParentId']==$cat_id){
$parent_cats[]=$unsorted_cats[$i];
}else{
$child_cats[$unsorted_cats[$i]['ParentId']][]=$unsorted_cats[$i];
}
}
for ($i=0; $i<sizeof($parent_cats); $i++){
$all_records[]=$parent_cats[$i];
if (isset($child_cats[$parent_cats[$i]['CategoryId']])){
for ($j=0; $j<sizeof($child_cats[$parent_cats[$i]['CategoryId']]); $j++){
$all_records[]=$child_cats[$parent_cats[$i]['CategoryId']][$j];
}
}
}
// print_pre($all_records);
$list->Records=$all_records;
$o = '';
$list->GoFirst();
$block_params=$this->prepareTagParams($params);
$block_params['name']=$params['block'];
$block_params['pass_params']='true';
while (!$list->EOL())
{
//if ($list->GetDBField('ParentId') == $cat_id) {
$block_params['cat_id'] = $list->GetDBField('CategoryId');
$block_params['parent_id']=$list->GetDBField('CategoryId');
$this->Application->SetVar('m_cat_id', $list->GetDBField('CategoryId') );
// for edit/delete links using GET
$o.= $this->Application->ParseBlock($block_params, 1);
//}else{
$list->GoNext();
//}
}
$this->Application->SetVar('m_cat_id', $stack_cat_id);
return $o;
}
function ListSubCategories($params)
{
return $this->PrintSubCategories($params);
}
function PrintSubCategories($params){
$list =& $this->Application->recallObject( $this->getPrefixSpecial(), $this->Prefix.'_List',$params);
$id_field = $this->Application->getUnitOption($this->Prefix,'IDField');
$o = '';
$block_params=$this->prepareTagParams($params);
$block_params['pass_params']='true';
$parent_cat = $list->GetDBField('CategoryId');
$is_first=1;
$current_item=1;
$show_more_link=true;
$list->GoNext();
while (!$list->EOL() && $list->GetDBField('ParentId') == $parent_cat)
{
if ($current_item > $params['max_sub_cats']){
$is_first=0;
if ($show_more_link && isset($params['block_more'])){
$more_params=$this->prepareTagParams($params);
$more_params['name']=$params['block_more'];
$this->Application->SetVar( 'm_cat_id', $list->GetDBField('ParentId') );
$o.= $this->Application->ParseBlock($more_params, 1);
$show_more_link=false;
}
$list->GoNext();
continue;
}
$block_params['cat_id'] = $list->GetDBField('CategoryId');
$block_params['is_first']=$is_first;
$this->Application->SetVar( $this->getPrefixSpecial().'_id', $list->GetDBField('CategoryId') );
$this->Application->SetVar( 'm_cat_id', $list->GetDBField('CategoryId') );
$o.= $this->Application->ParseBlock($block_params, 1);
$list->GoNext();
$is_first=0;
$current_item++;
}
$list->GoPrev();
// $this->Application->SetVar('m_cat_id', $parent_cat);
return $o;
}
function PrintList2($params)
{
$list =& $this->Application->recallObject( $this->getPrefixSpecial(), $this->Prefix.'_List',$params);
$id_field = $this->Application->getUnitOption($this->Prefix,'IDField');
$list->Query();
$o = '';
$list->GoFirst();
$direction = (isset($params['direction']) && $params['direction']=="H")?"H":"V";
$columns = (isset($params['columns']))?$params['columns']:1;
if ($columns>1 && $direction=="V") {
$list->Records = $this->LinearToVertical($list->Records, $columns, $params['per_page']);
}
$list->GoFirst();
if($list->EOL())
{
$block_params['name'] = 'no_categories';
return $this->Application->ParseBlock($block_params);
}
$block_params=$this->prepareTagParams($params);
$block_params['name']=$params['block'];
$block_params['pass_params']='true';
$block_start_row_params=$this->prepareTagParams($params);
$block_start_row_params['name']=$params['row_start_block'];
$block_end_row_params=$this->prepareTagParams($params);
$block_end_row_params['name']=$params['row_end_block'];
$i=0;
while (!$list->EOL())
{
$block_params['cat_id'] = $list->GetDBField('CategoryId');
$this->Application->SetVar( $this->getPrefixSpecial().'_id', $list->GetDBField($id_field) ); // for edit/delete links using GET
$list->UpdateFormattersSubFields();
if ($i%$params['columns'] == 0) $o.= $this->Application->ParseBlock($block_start_row_params, 1);
$this->Application->SetVar( $this->getPrefixSpecial().'_id', $list->GetDBField($id_field) );
$o.= $this->Application->ParseBlock($block_params, 1);
if (($i+1)%$params['columns'] == 0) $o.= $this->Application->ParseBlock($block_end_row_params, 1);
$list->GoNext();
$i++;
}
$this->Application->SetVar( $this->getPrefixSpecial().'_id', '');
return $o;
}
*/
}
?>
Event Timeline
Log In to Comment