Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

Commit

Permalink
* bugfixing on inheritance
Browse files Browse the repository at this point in the history
* updated to version 1.0.4
  • Loading branch information
schuer committed Aug 18, 2011
1 parent 64d686f commit 76e184f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 38 deletions.
2 changes: 1 addition & 1 deletion config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

$REX['ADDON']['rxid'][$mypage] = "840";
$REX['ADDON']['page'][$mypage] = $mypage;
$REX['ADDON']['version'][$mypage] = "1.0.3";
$REX['ADDON']['version'][$mypage] = "1.0.4";
$REX['ADDON']['author'][$mypage] = "Sven Kesting <[email protected]>, DECAF";

if ($REX['REDAXO']) // backend
Expand Down
77 changes: 40 additions & 37 deletions extensions/extension.decaf_custom_prio.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,34 @@ function decaf_custom_prio($params)

// init vars
$new_category_prio = false;
$new_article_prio = false;
$new_article_prio = false;

$cat_id = rex_get('category_id') ? rex_get('category_id') : 0;

if (isset($decaf_category_js_config[$cat_id])) // check entry for current category
$cat = OOCategory::getCategoryById($cat_id);
if ($cat)
{
$new_category_prio = $decaf_category_js_config[$cat_id]['new_category_prio'];
$new_article_prio = $decaf_category_js_config[$cat_id]['new_article_prio'];
}
// init inherited prios
$inherited_category_prio = $new_category_prio;
$inherited_article_prio = $new_article_prio;

if (!$new_category_prio) // check if prios are set in parent categories
{
$cat = OOCategory::getCategoryById($cat_id);
if ($cat)
{

$path = getCategoryPathAsArray($cat);
$path = getCategoryPathAsArray($cat, $cat_id);
foreach($path as $v) {

// use inherited prios (first)
$new_category_prio = $inherited_category_prio;
$new_article_prio = $inherited_article_prio;

// use specific prios if available
if (isset($decaf_category_js_config[$v])) // check entry for current category
{
$new_category_prio = $decaf_category_js_config[$v]['new_category_prio'];
$new_article_prio = $decaf_category_js_config[$v]['new_article_prio'];

foreach($path as $cat_id) {
if (isset($decaf_category_js_config[$cat_id]) && $decaf_category_js_config[$cat_id]['inherit']) // check entry for current category
{
$new_category_prio = $decaf_category_js_config[$cat_id]['new_category_prio'];
$new_article_prio = $decaf_category_js_config[$cat_id]['new_article_prio'];
break;
if ($decaf_category_js_config[$v]['inherit'] == true) {
// update inherited prios
$inherited_category_prio = $new_category_prio;
$inherited_article_prio = $new_article_prio;
}
}
}
Expand All @@ -65,22 +69,21 @@ function decaf_custom_prio($params)
}

// compat for REX4.2
if (!function_exists('getCategoryPathAsArray')) {
function getCategoryPathAsArray($cat) {
if (method_exists($cat, 'getPathAsArray')) {
$path = array_reverse($cat->getPathAsArray());
} else {
$p = explode('|',$cat->_path);
foreach($p as $k => $v)
{
if($v == '')
unset($p[$k]);
else
$p[$k] = (int) $v;
}
$path = array_values($p);
}
array_unshift($path,0); // add root category '0' to path
return $path;
}
}
function getCategoryPathAsArray($cat, $cat_id) {
if (method_exists($cat, 'getPathAsArray')) {
$path = $cat->getPathAsArray();
} else {
$p = explode('|',$cat->_path);
foreach($p as $k => $v)
{
if($v == '')
unset($p[$k]);
else
$p[$k] = (int) $v;
}
$path = array_values($p);
}
array_unshift($path,0); // add root category '0' to path
array_push($path, $cat_id); // add current category to path
return $path;
}

0 comments on commit 76e184f

Please sign in to comment.