project */ $sort_map = array(); foreach($projects as &$proj) { if($proj['pid'] == $p['pid']) { /* Skip the project we're calculating the number for, we're going to add * the alterate version ($p) below, it has the nubmer and sort filled out */ continue; } if($proj['number_sort'] !== NULL) { $sort_map[$proj['number_sort']] = &$proj; } } /* Add the new project sort too */ $sort_map[$p['number_sort']] = &$p; /* Sort keys by number_sort */ ksort($sort_map); /* Iterate through the sort list in order by keys * (number_sort), assign a floor_number, and adjust any * overlapping floor numbers */ $last_floor_number = 0; foreach($sort_map as $ps=>&$proj) { /* Find us, assign floor number */ if($proj['pid'] == $p['pid']) { $p['floor_number'] = $last_floor_number + 1; project_save($mysqli, $p); } /* Check current floor number with last one, if they are the same, increment * our floor number */ if($proj['floor_number'] == $last_floor_number) { /* The current number needs to be incremented */ $proj['floor_number'] = $last_floor_number + 1; $current_floor_number = $proj['floor_number']; project_save($mysqli, $proj); } $last_floor_number = $current_floor_number; } } break; case 'X4': /* Project gets the first unused floor number */ $p['floor_number'] = $first_unused_floor_number; $p['number_sort'] = $first_unused_floor_number; $p['number'] = sprintf("%04d", $first_unused_floor_number); break; case 'c_X3_h': /* Project gets the first unused floor number */ $p['floor_number'] = $first_unused_floor_number; $p['number_sort'] = $first_unused_floor_number; $p['number'] = $categories[$p['cat_id']]['shortform'].' '.sprintf("%03d", $first_unused_floor_number).' '.$challenges[$p['challenge_id']]['shortform']; debug("number = {$p['number']}\n"); break; default: print("Unknown Project Number Format!"); exit(); } return true; } ?>