Is there a way to cause an arbitrary magical beast to gain character levels in a chosen class?

I was looking at this answer from our fine cheese collection, and it occurred to me that it would be quite a lot more practical if we could arrange for the assistance of a gorilla and war mammoth with barbarian levels (especially as that would allow the gorilla to take levels in Ride). Awakening them is easily enough done, at which point they’re in the same intelligence range as anyone else (and if they’re too dumb, you can awaken another one) but I’ve not found a way to actually apply class levels to them once that was done. The Leadership feat offers a mechanic for hanging on to them, but doesn’t seem to do anything for their further development. The Monstrous Companion feat actually does offer a way to inject class levels into an existing magical beast, but only of a specific list of magical beasts on offer.

So… is there something that I’m missing? Is there a way to turn a War Mammoth (awakened or otherwise) into a barbarian? I suppose I’d also accept a method for indefinitely turning a barbarian into a war mammoth, as long as the barbarian continued to enjoy the benefits of his class features. That one seems somewhat less likely, however.

The objective here is that the stack could be fielded by an appropriately designed party of characters, after enough levels had passed to gain appropriate resources, without having to pause to transform before battle every time. Whether the mammoth starts out as a PC or not is considered unimportant for the purposes of the question. likewise, if you can manage to cause a war mammoth (and gorilla) with appropriate class levels to come into being, it is assumed that you can come up with a way to convince them to hang around and rage-stack with you.