Question

I'm building a mini-cms for my local charity (yes, I know I could use a floss project, but they want custom coded)

My propel schema currently looks as such:-

<?xml version="1.0" encoding="UTF-8"?>
<database name="sja" defaultIdMethod="native">
    <table name="section">
        <column name="id" type="INTEGER" primaryKey="true" required="true" autoIncrement="true" />
        <column name="title" type="VARCHAR" required="true" />
        <column name="slug" type="VARCHAR" required="true" />
    </table>
    <table name="page">
        <column name="id" type="INTEGER" primaryKey="true" required="true" autoIncrement="true" />
        <column name="title" type="VARCHAR" required="true" />
        <column name="section_id" type="INTEGER" required="true" />
        <foreign-key foreignTable="section">
            <reference local="section_id" foreign="id" />
        </foreign-key>
    </table>
    <table name="static_page">
        <behavior name="concrete_inheritance">
            <parameter name="extends" value="page" />
        </behavior>
        <column name="content" type="LONGVARCHAR" required="true" />
    </table>
    <table name="home_page">
        <behavior name="concrete_inheritance">
            <parameter name="extends" value="page" />
        </behavior>
        <column name="standfirst_title" type="VARCHAR" />
        <column name="standfirst_image" type="VARCHAR" />
        <column name="standfirst_content" type="VARCHAR" />
    </table>

</database>

I want to be able to get a list that would include "home_page" and "static_page" - without having to create this manually whenever I add a new page type.

Is there an easy way to get a list like this, or do I have to write some magic stuff with Reflection Classes, etc?

Was it helpful?

Solution

After a poke in the right direction from #propel on freenode - I've come up with this for a base concept - haven't tested it yet though

function getSubClasses()
{
    $map = $this->getDatabaseMap();
    $children = array();
    foreach ($map->getRelations() AS $relation)
    {
        $behaviours = $relation->getRightTable()->getBehaviours();

        if (issset($behaviours['concrete_inheritance']['extends']) AND $behaviours['concrete_inheritance']['extends'] == $this->getDatabaseMap()->getClassName())
        {
            $children[] = $relation->getRightTable()->getClassName();
        }
    }
    return $children;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top