[eluser]kgill[/eluser]
I swear the question "Can I do this in CI?" gets asked often enough that I should just make this my sig. so all I have to do is an empty reply:
"CI is a just framework, not a language - it is still PHP, so if you can do it in PHP you can do it in CI."
CI has a few handy helpers and libraries to simplify things but for the most part, writing any of the complex code like this - you're supposed to do yourself. If you're lucky someone may have contributed a library but that's them sharing their code and not part of CI. Stop thinking of CI as some separate entity from PHP and just code like you would with PHP the only difference is you're breaking your code up into the different parts of a Model, View and Controller. CI is not some magic solution that will do everything for you, it's meant to help developers write apps not write them for them.
Now that said, google PHP tree traversal, store the data an multi-dimensional array. You're going to have to use recursion since you don't know how deep the structure is... so if you don't know what that is, start there.