[TYPO3-dev] EXTBASE :: Domain model inheritance for entities

Steffen Wickham steffen at gaming-inc.de
Fri Aug 16 16:15:32 CEST 2013


Hi Philipp,

many thanks for your help! I really appreciate it! :)
As far as I can tell, everything is looking good for now. But I can't
select what kind of question I add for this Quiz.

I'd devided the whole thing in two packages. The first package
(lg_quizbase) contains all base functionallity like the FE plugins and
base classes and the second package (lg_quizbasetypes) add the most
basic question types like multiple choice,  text input, sorting and so
on. Here are my snippets:

[TCA snippet of my "Question" model]:
=====================================================================================
$TCA['tx_lgquizbase_domain_model_question'] = array(
    //'ctrl' => $TCA['tx_lgquizbase_domain_model_question']['ctrl'],
    'ctrl' => array('type' => 'type'),
    ...
);


[TypoScript of lg_quizbasetypes]:
=====================================================================================
config.tx_extbase{
    persistence{
        classes{
            LinkGroup\LgQuizbase\Domain\Model\Question {
                subclasses {
                    Tx_LgQuizbasetypes_TextInputQuestion =
LinkGroup\LgQuizbasetypes\Domain\Model\TextInputQuestion
                    Tx_LgQuizbasetypes_MultipleChoiceQuestion =
LinkGroup\LgQuizbasetypes\Domain\Model\MultipleChoiceQuestion
                    Tx_LgQuizbasetypes_SortingQuestion =
LinkGroup\LgQuizbasetypes\Domain\Model\SortingQuestion
                  }
            }
            LinkGroup\LgQuizbasetypes\Domain\Model\TextInputQuestion {
                mapping {
                    tableName = tx_lgquizbase_domain_model_question
                    recordType = Tx_LgQuizbasetypes_TextInputQuestion
                }
            }
            LinkGroup\LgQuizbasetypes\Domain\Model\MultipleChoiceQuestion {
                mapping {
                    tableName = tx_lgquizbase_domain_model_question
                    recordType = Tx_LgQuizbasetypes_MultipleChoiceQuestion
                }
            }
            LinkGroup\LgQuizbasetypes\Domain\Model\SortingQuestion {
                mapping {
                    tableName = tx_lgquizbase_domain_model_question
                    recordType = Tx_LgQuizbasetypes_SortingQuestion
                }
            }
        }
    }
}


In the list view I can add a new quiz and be able to add Questions to
it. But there are only the fields of the base type available and no
select box for the question type :(
What can be wrong with it?

Best regards,
Steffen






Am 14.08.13 15:27, schrieb Philipp:
> Write question as a superclass and define it as superclass via
> typoscript. Now you can add 3 types to your TCA and set that types
> field as recordType via TA (extbase config for your question model).
> Each type is then connected to a model which just extends the question
> model.
>
> Some more specific chunks:
> [TCA]
> $TCA['tx_extension_domain_model_question'] = array (
>     'ctrl' => array (
>         'type' => 'type',
>     )
> );
>
> That type is a TCA select field which holds your options:
> Type 1: multiple
> Type 2: text
> Type 3: assignment
>
> [Typoscript:]
> config.tx_extbase.persistence.classes {
>
>     Vendor\Extension\Domain\Model\Question {
>         subclasses {
>             Vendor\Extension\Domain\Model\MultipleChoiceQuestion =
> Vendor\Extension\Domain\Model\MultipleChoiceQuestion
>             Vendor\Extension\Domain\Model\TextInputQuestion =
> Vendor\Extension\Domain\Model\TextInputQuestion
>             Vendor\Extension\Domain\Model\AssignmentQuestion =
> Vendor\Extension\Domain\Model\AssignmentQuestion
>         }
>     }
>     Vendor\Extension\Domain\Model\MultipleChoiceQuestion {
>         mapping {
>             tableName = tx_extension_domain_model_question
>             recordType = multiple
>         }
>     }
>     Vendor\Extension\Domain\Model\TextInputQuestion {
>         mapping {
>             tableName = tx_extension_domain_model_question
>             recordType = text
>         }
>     }
>     Vendor\Extension\Domain\Model\AssignmentQuestion {
>         mapping {
>             tableName = tx_extension_domain_model_question
>             recordType = assignment
>         }
>     }
> }
>
>
> Now you can request all types of questions via a QuestionRepository or
> only specifics via a MultipleChoiceQuestionRepository
>
> Your entity property in quiz would be like
> /**
> * @var
> \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Vendor\Extension\Domain\Model\Question>
> * @lazy
> * @cascade remove
> */
> protected $questions;
> _______________________________________________
> TYPO3-dev mailing list
> TYPO3-dev at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-dev




More information about the TYPO3-dev mailing list