Short version: I need a behavior be both, a CActiveRecordbehavior and a CModel.
Long version.
One of my tables has a text column containing XML data (the AssessmentQuestion
.data
column), and since I don't know how the XML format would evolve over time, I decided to use a behavior to handle it according to two parameters: an xml format version and a type (currently it can be only "multichoice").
So far so good. The next decision I've made was to use a generalized AssessmentQuestionbehavior which should be inherited by classes like AssessmentQuestionbehavior_multichoice_1_1 and contain much of the underlying functionality for all the questions.
Beside that, AssessmentQuestionbehavior should actually follow the broker pattern, and detach itself in AssessmentQuestionbehavior::afterFind() & co in the detriment of the right class for the given type/version of the question (actually I plan to make it degradable, if it doesn't find version 2.4, it should iterate backwards until it finds a class, but that's another story).
Now, the problem is that questions should receive parameters over $_GET/$_POST, so each behavior should be able to use validators, scenarios, and all the features a CModel has. At the beginning I thought I wouldn't need to copy that much from CModel (only the functionality around CValidator::createValidator), but after 30 minutes of copying around I ended up with almost the entire code from CModel (since validators call addError() & co.).
Since I hate code duplication, right now I think about using a dummy CModel and wrap around it inside AssessmentQuestionbehavior (I think it's called the composite pattern).
What other alternatives would I have, especially tightly integrated into Yii?
Thanks.