Ok, I am attempting my first perl subs here. This one is meant to be called by the add and move hooks for determining the actual category depth.
Would someone mind looking at this for possible errors (as I am not sure how to test until full routines are completed).
sub {
#Determine the directory depth for the current category &find_depth($category_id);
my $category_id = shift;
my $level = 0;
my $FatherID = $DB->table('Category')->select( 'FatherID',{ 'ID' => $category_id})->fetchrow_array;
# Loop until father = 0, incrementing level each time, thus determining depth of category
until ( $FatherID == 0) {
my $FatherID = $DB->table('Category')->select( 'FatherID',{ 'ID' => $category_id})->fetchrow_array;
$category_id = $FatherID; #just edited this
$level++;
}
return $level;
}
Would someone mind looking at this for possible errors (as I am not sure how to test until full routines are completed).
Code:
sub {
#Determine the directory depth for the current category &find_depth($category_id);
my $category_id = shift;
my $level = 0;
my $FatherID = $DB->table('Category')->select( 'FatherID',{ 'ID' => $category_id})->fetchrow_array;
# Loop until father = 0, incrementing level each time, thus determining depth of category
until ( $FatherID == 0) {
my $FatherID = $DB->table('Category')->select( 'FatherID',{ 'ID' => $category_id})->fetchrow_array;
$category_id = $FatherID; #just edited this
$level++;
}
return $level;
}