[eluser]Bramme[/eluser]
It's really how you like it best. If you only need to do this once, you could keep it in your controller, if you need to do this several times, Don't Repeat Yourself (DRY, keep that in mind
) and put it in a library, model or helper, whatever suits your needs.