How do I find a list of subclasses for a propel model with concrete inheritance - propel

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?

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;
}

Related

Propel2 Reverse second run has deleted columns

I am new to propel. There doesn't appear to be a version command built in, but composer shows propel2 in my description.
I reverse engineered my scheme and models from the database then took six months off the project, came back, remastered the database directly, deleted the generated-classes, and the generated-reversed-database.
I then ran
propel reverse "mysql:host=localhost;dbname=MyVanLog;user=**;password=**"
When that completed I opened my schema.xml file and visually verified that the fuel price column no longer exists.
<table name="LogEntries" idMethod="native" phpName="Logentries">
<column name="LogEntryId" phpName="Logentryid" type="INTEGER" primaryKey="true" autoIncrement="true" required="true"/>
<column name="UserId" phpName="Userid" type="INTEGER" primaryKey="true" required="true"/>
<column name="RvId" phpName="Rvid" type="INTEGER" primaryKey="true" required="true"/>
<column name="Title" phpName="Title" type="VARCHAR" size="45" required="true"/>
<column name="Description" phpName="Description" type="CLOB"/>
<column name="Longitude" phpName="Longitude" type="DECIMAL" size="10" scale="8"/>
<column name="Latitude" phpName="Latitude" type="DECIMAL" size="10" scale="8"/>
<column name="Temperature" phpName="Temperature" type="DECIMAL" size="3" scale="1"/>
<column name="Private" phpName="Private" type="VARCHAR" size="1" sqlType="bit(1)" required="true"/>
<column name="CreatedOnUTC" phpName="Createdonutc" type="TIMESTAMP" required="true"/>
<column name="ModifiedOnUTC" phpName="Modifiedonutc" type="TIMESTAMP" required="true"/>
<foreign-key foreignTable="Users" name="FK_36">
<reference local="UserId" foreign="UserId"/>
</foreign-key>
<foreign-key foreignTable="Rvs" name="FK_40">
<reference local="RvId" foreign="RvId"/>
<reference local="UserId" foreign="UserId"/>
</foreign-key>
<index name="fkIdx_36">
<index-column name="UserId"/>
</index>
<index name="fkIdx_40">
<index-column name="RvId"/>
<index-column name="UserId"/>
</index>
<vendor type="mysql">
<parameter name="Engine" value="InnoDB"/>
</vendor>
Then I run propel build to generate my models. I open my base/LogEntries file and it has all the methods to manipulate the field that is no longer there. I won't paste the entire file, but here is the get method.
/**
* Get the [fuelpriceinvalid] column value.
*
* #return string
*/
public function getFuelpriceinvalid()
{
return $this->fuelpriceinvalid;
}
Does anyone know what I missed?
I had an extra schema.xml file hanging out in the project directories that was being read instead of the one I generated causing the old fields to generate. This was likely just a mistake on my part, not a propel bug.

How to use single inheritance in propel schema

I need to make a 'Event' class and propel schema with Columns:
id
employee_id
date_start
date_end
type
How to implement the simple inheritance based on the type column.
All classes should extend the abstract Event class.
Initial sub-class:
JoinEvent
can anyone write a schema for it?
I have written schema but not sure whether it is correct or not.
<table name="event" phpName="Event">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
<column name="employee_id" type="integer" required="true" />
<column name="date_start" type="date" required="true" />
<column name="date_end" type="date" required="false" />
<column name="type" type="integer" inheritance="single">
<inheritance key="1" class="JoinEvent" extends="Event"/>
</column>
<foreign-key foreignTable="employee" name="FI_event_employee">
<reference local="employee_id" foreign="id" />
</foreign-key>
</table>
Please help me.

Slug regenerating it self

I'm using the sluggable behavior within Propel to work alongside my CMS/Framework.
Weird thing is, if you change something else on the page, other than the slug, the slug will automatically regenerate using what appears to be the values of the parent element, i.e.
from /slug to id-3-parentid-2-keywords-null-templateid-1-publishdate-null-slug-slug-sortablerank-2-createdat-null-updatedat-null-pagei18ns-pagei18n_0-id-3-locale-en_gb-title-tsadf-description-null-content-p-ssadf-p-page-recursion-pagei18n_1-id-3-locale-fr_fr-title-a which is rather odd.
The only solution I've found so far, is to simply call setSlug to a random value and then set the correct value afterwards.
$page->setSlug('x');
$page->setSlug($this->request->post->get('slug'));
and my schema:
<table name="page" phpName="Page">
<!-- Columns -->
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
<column name="parent_id" type="integer" required="false" />
<column name="title" type="varchar" size="255" required="true" />
<column name="description" type="varchar" size="255" required="false" />
<column name="keywords" type="varchar" size="255" required="false" />
<column name="content" type="longvarchar" required="false" />
<column name="template_id" type="integer" required="false" />
<column name="publish_date" type="date" required="false" />
<!-- Behaviors -->
<behavior name="i18n">
<parameter name="i18n_columns" value="title, description, content" />
<parameter name="default_locale" value="en_GB" />
</behavior>
<behavior name="sluggable">
<parameter name="permanent" value="true" />
</behavior>
<behavior name="sortable" />
<behavior name="timestampable" />
<!-- Foreign Keys -->
<foreign-key foreignTable="page_template">
<reference local="template_id" foreign="id"/>
</foreign-key>
<foreign-key foreignTable="page">
<reference local="parent_id" foreign="id"/>
</foreign-key>
</table>
Note: I've tried with and without the permanent param.
Any idea's anyone?

EXT.net - Grid Panel via Entity with DropDowns, Dates, Pin Editing and Deletion

Title sounds like a real mouthful, so let me try to explain this. I'm very strong with grinding out Web Forms and this is my second crack at using a framework and MVC (don't ask about the first one). Start with a table like this:
Title: Milestones
Id int - Auto, PK
Project_Id int - FK, Many Milestones to One Project, Provided static for now
Number int
Name varchar(50)
Status_Id int - FK One Status to One Milestone
PlannedDate date
LatestEstimate date
MilestoneType_ID int - FK One Type to One Milestone
These all sit on an SQL server, are pulled in by an Entity and then are pulled in by an ObjectDataSource, like this:
<asp:ObjectDataSource runat="server" ID="MilestonesObjectSource" SelectMethod="GetByProject"
DeleteMethod="DeleteMilestone" TypeName="TCProjectManagement.Models.MilestonesAddition">
<SelectParameters>
<asp:Parameter DefaultValue="6" Name="ProjectID" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Type="Int32" Name="Id" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Type="Int32" Name="Id" />
<asp:Parameter Type="Int32" Name="Number" />
<asp:Parameter Type="String" Name="Name" />
<asp:Parameter Type="Int32" Name="Status_Id" />
<asp:Parameter Type="DateTime" Name="PlannedDate" />
<asp:Parameter Type="DateTime" Name="LatestEstimate" />
<asp:Parameter Type="Int32" Name="MilestoneType_ID" />
</UpdateParameters>
</asp:ObjectDataSource>
Sofar so good. Data pull seems to work out okay. I've got a couple more Object Sources that deal exclusively with the Foriegn Keys, so I'll skip those since they seem to be working.
The problems I have are attempting to stitch together many examples that don't seem to go together well. My objectives, in no paticular order:
1) Pin Editing: Click a button to edit, click it again to confirm. Rather do this than have somebody infer to double click for a change. Sofar, this sorta works.
2) Drop Downs for Foriegn Keys: While not in edit mode, should display the "Name" field of the FK. While in edit it should be a Drop Down for options (there's only three). This stays blank dispite what I do.
3) Deletion: Press a button to blow away a row. I put the button there but it's a copy of the JS for editing. What do I need to use to have it be deletion?
4) Dates: This doesn't work at all. One of the weird parts is that from the SQL server's type of Date, it gets changed to DateTime in the Entity and stays that way throughout. However, I cannot get the desired control of ext:DateField to cooperate with the provided data since it displays a time and completely blanks out when editing.. I know I'm doing something wrong here.
5) Saving Changes: Not quite sure I set it up right (or at all).
Provisions of Javascript:
<script type="text/javascript">
var pinEditors = function (btn, pressed) {
var columnConfig = btn.column,
column = columnConfig.column;
if (pressed) {
column.pinOverComponent();
column.showComponent(columnConfig.record, true);
} else {
column.unpinOverComponent();
column.hideComponent(true);
}
};
var pinDeleters = function (btn, pressed) { };
</script>
And ASP Code:
<ext:GridPanel ID="MilestonesGridPanel" runat="server" Title="Milestones" Width="1000px"
Height="300px">
<Store>
<ext:Store ID="MilestonesGridStore" runat="server" DataSourceID="MilestonesObjectSource">
<Model>
<ext:Model runat="server" IDProperty="Id">
<Fields>
<ext:ModelField Name="Id" Type="Int" />
<ext:ModelField Name="Number" Type="Int" />
<ext:ModelField Name="Name" Type="String" />
<ext:ModelField Name="Status_Id" Type="Int" />
<ext:ModelField Name="PlannedDate" />
<ext:ModelField Name="LatestEstimate" />
<ext:ModelField Name="MilestoneType_ID" Type="Int" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel>
<Columns>
<ext:Column ID="IdColumn" runat="server" DataIndex="Id" Text="DBID" Visible="false" />
<ext:ComponentColumn ID="NumberColumn" runat="server" DataIndex="Number" OverOnly="true"
Pin="true" Flex="1" Text="Number" Editor="true">
<Component>
<ext:NumberField ID="NumberColumnNumberField" runat="server" />
</Component>
</ext:ComponentColumn>
<ext:ComponentColumn ID="NameColumn" runat="server" DataIndex="Name" OverOnly="true"
Pin="true" Flex="1" Text="Name" Editor="true">
<Component>
<ext:TextField ID="NameColumnTextField" runat="server" />
</Component>
</ext:ComponentColumn>
<ext:ComponentColumn ID="StatusColumn" runat="server" DataIndex="Status_Id" OverOnly="true"
Pin="true" Flex="1" Text="Status" Editor="true">
<Component>
<ext:ComboBox ID="StatusColumnDropDownBox" runat="server" QueryMode="Local" Editable="false"
StoreID="MilestoneStatusStore" DisplayField="Name" ValueField="ID" EmptyText="Empty" />
</Component>
</ext:ComponentColumn>
<ext:ComponentColumn ID="PlannedDateColumn" runat="server" DataIndex="PlannedDate"
OverOnly="true" Pin="true" Flex="1" Text="Planned Date" Editor="true">
<Renderer Format="Date" FormatArgs="'m/d/y'" />
<Component>
<ext:DateField ID="PlannedDateColumnTextField" runat="server" Format="MM/dd/yyyy"
EmptyText="Empty" />
</Component>
</ext:ComponentColumn>
<ext:ComponentColumn ID="LatestEstimateColumn" runat="server" DataIndex="LatestEstimate"
OverOnly="true" Pin="true" Flex="1" Text="Latest ETA" Editor="true">
<Renderer Format="Date" FormatArgs="'m/d/y'" />
<Component>
<ext:DateField ID="LatestEstimateColumnTextField" runat="server" Format="MM/dd/yyyy"
EmptyText="Empty" />
</Component>
</ext:ComponentColumn>
<ext:ComponentColumn ID="MilestoneTypeColumn" runat="server" DataIndex="MilestoneType_ID"
OverOnly="true" Pin="true" Flex="1" Text="Milestone Type" Editor="true">
<Component>
<ext:ComboBox ID="MilestoneTypeColumnComboBox" runat="server" QueryMode="Local" Editable="false"
StoreID="MilestoneTypesStore" DisplayField="Name" ValueField="ID" EmptyText="Empty" />
</Component>
</ext:ComponentColumn>
<ext:ComponentColumn ID="EditColumn" runat="server" Width="30" PinAllColumns="false"
AutoWidthComponent="false" OverOnly="true" Text="Edit" Sortable="False">
<Component>
<ext:Button ID="EditButton" runat="server" ToolTip="Pin Editors" Icon="Pencil" AllowDepress="true"
EnableToggle="true" Width="25">
<Listeners>
<Toggle Fn="pinEditors" />
</Listeners>
</ext:Button>
</Component>
</ext:ComponentColumn>
<ext:ComponentColumn ID="DeleteColumn" runat="server" Width="30" PinAllColumns="false"
AutoWidthComponent="false" OverOnly="true" Text="Delete" Sortable="False">
<Component>
<ext:Button ID="DeleteButton" runat="server" ToolTip="Delete Milestone" Icon="Delete"
AllowDepress="true" EnableToggle="false" Width="25">
<Listeners>
<Click Handler="#{MilestonesGridStore}.remove(this.parentMenu.dataRecord)" />
</Listeners>
</ext:Button>
</Component>
</ext:ComponentColumn>
</Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel runat="server" Mode="Single">
<Listeners>
<Select Handler="#{DeleteMilestoneGridButton}.enable();" />
<Deselect Handler="if (!#{MilestonesGridPanel}.selModel.hasSelection()) {
#{DeleteMilestoneGridButton}.disable();
}" />
</Listeners>
</ext:RowSelectionModel>
</SelectionModel>
<Buttons>
<ext:Button ID="AddtoMilestoneGridButton" runat="server" Text="Insert" Icon="Add">
<Listeners>
<Click Handler="#{MilestonesGridStore}.insert(0, {}); #{MilestonesGridPanel}.editingPlugin.startEditByPosition({row:0, column:0});" />
</Listeners>
</ext:Button>
<ext:Button ID="DeleteMilestoneGridButton" runat="server" Text="Delete" Icon="Delete"
Disabled="true">
<Listeners>
<Click Handler="#{MilestonesGridPanel}.deleteSelected();
if (!#{MilestonesGridPanel}.hasSelection()) {
#{DeleteMilestoneGridButton}.disable();
}" />
</Listeners>
</ext:Button>
<ext:Button ID="RefreshMilestonesGridButton" runat="server" Text="RefresH" Icon="Reload">
<Listeners>
<Click Handler="#{MilestonesGridStore}.load();" />
</Listeners>
</ext:Button>
<ext:Button ID="SaveMilestoneGridButton" runat="server" Text="Save" Icon="Disk">
<Listeners>
<Click Handler="#{MilestonesGridStore}.sync();" />
</Listeners>
</ext:Button>
</Buttons>
</ext:GridPanel>

How to configure Doctrine entities to handle compressed blobs in the database?

I'm using Doctrine 2 as an ORM to the database and i'm having an issue with compressed blobs.
I'm storing text in a compressed blob column in the database. How can i specify this in the entity mapping xml config? I'm currently using type="blob" for this column but this isn't returning a string. I could use type="text" but this returns garbage as it's not uncompressing it.
Can i specify somewhere in my entity config that this text need uncompressing on retrieval and compressing on persisting?
Here's my entity configuration:
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="AccountNote" table="tblAccountNote">
<id name="intAccountNoteId" type="integer">
<generator strategy="AUTO" />
</id>
<field name="intAccountId" type="integer" nullable="false" unique="no" />
<field name="bolHiddenNote" type="boolean" nullable="false" unique="no" />
<field name="binNote" type="blob" nullable="false" unique="no" />
<field name="strHash" type="string" length="32" nullable="true" unique="no" />
<field name="dtmCreated" type="datetime" nullable="false" unique="no" />
<field name="stmTimestamp" type="datetime" nullable="false" unique="no" />
<many-to-one field="objAccount" target-entity="Account" inversed-by="objNotes">
<join-column name="intAccountId" referenced-column-name="intAccountId" />
</many-to-one>
</entity>
</doctrine-mapping>
In the end we decided on handling the compression in the getter and setter and removing it from the schema.

Resources