I implemented by this time 3 of custom templates (_fck, _img, _audio). Last one uses a control similar to fileasset, it uploads an audio file and displays an audio preview in form of a flash player.
Please note that I use Qcodo 0.3.24 . I didn't have the time to switch all my customizations to the new version of Qcodo. I would like to do this...
What exactly I did:
- put a modified version of db_orm_edit_form_base.tpl in the includes/qcodo/codegen/templates
<template OverwriteFlag="true" DocrootFlag="false" DirectorySuffix="" TargetDirectory="<%= __FORMBASE_CLASSES__ %>" TargetFileName="<%= $objTable->ClassName %>EditFormBase.class.php"/>
<?php
/**
* This is the abstract Form class for the Create, Edit, and Delete functionality
* of the <%= $objTable->ClassName %> class. This code-generated class
* contains all the basic Qform elements to display an HTML form that can
* manipulate a single <%= $objTable->ClassName %> object.
*
* To take advantage of some (or all) of these control objects, you
* must create a new Form which extends this <%= $objTable->ClassName %>EditFormBase
* class.
*
* Any and all changes to this file will be overwritten with any subsequent re-
* code generation.
*
* @package <%= QCodeGen::$ApplicationName; %>
* @subpackage FormBaseObjects
*
*/
abstract class <%= $objTable->ClassName %>EditFormBase extends QForm {
// General Form Variables
protected $<%= $objCodeGen->VariableNameFromTable($objTable->Name); %>;
protected $strTitleVerb;
protected $blnEditMode;
// Controls for <%= $objTable->ClassName %>'s Data Fields
<% foreach ($objTable->ColumnArray as $objColumn) { %>
protected $<%= $objCodeGen->FormControlVariableNameForColumn($objColumn); %>;
<% } %>
// Other ListBoxes (if applicable) via Unique ReverseReferences and ManyToMany References
<% foreach ($objTable->ReverseReferenceArray as $objReverseReference) { %>
<% if ($objReverseReference->Unique) { %>
protected $<%= $objCodeGen->FormControlVariableNameForUniqueReverseReference($objReverseReference); %>;
<% } %>
<% } %>
<% foreach ($objTable->ManyToManyReferenceArray as $objManyToManyReference) { %>
protected $<%= $objCodeGen->FormControlVariableNameForManyToManyReference($objManyToManyReference); %>;
<% } %>
// Button Actions
protected $btnSave;
protected $btnCancel;
protected $btnDelete;
protected function Setup<%= $objTable->ClassName %>() {
// Lookup Object PK information from Query String (if applicable)
// Set mode to Edit or New depending on what's found
<% foreach ($objTable->PrimaryKeyColumnArray as $objColumn) { %>
$<%= $objColumn->VariableName %> = QApplication::QueryString('<%= $objColumn->VariableName %>');
<% } %>
if (<% foreach ($objTable->PrimaryKeyColumnArray as $objColumn) { %>($<%= $objColumn->VariableName %>) || <% } %><%----%>) {
$this-><%= $objCodeGen->VariableNameFromTable($objTable->Name); %> = <%= $objTable->ClassName %>::Load(<% foreach ($objTable->PrimaryKeyColumnArray as $objColumn) { %>($<%= $objColumn->VariableName %>), <% } %><%--%>);
if (!$this-><%= $objCodeGen->VariableNameFromTable($objTable->Name) %>)
throw new Exception('Could not find a <%= $objTable->ClassName %> object with PK arguments: ' . <% foreach ($objTable->PrimaryKeyColumnArray as $objColumn) { %>$<%= $objColumn->VariableName %> . ', ' . <% } %><%----------%>);
$this->strTitleVerb = QApplication::Translate('Edit');
$this->blnEditMode = true;
} else {
$this-><%= $objCodeGen->VariableNameFromTable($objTable->Name); %> = new <%= $objTable->ClassName %>();
$this->strTitleVerb = QApplication::Translate('Create');
$this->blnEditMode = false;
}
}
protected function Form_Create() {
// Call Setup<%= $objTable->ClassName %> to either Load/Edit Existing or Create New
$this->Setup<%= $objTable->ClassName %>();
// Create/Setup Controls for <%= $objTable->ClassName %>'s Data Fields
<% foreach ($objTable->ColumnArray as $objColumn) { %>
$this-><%= $objCodeGen->FormControlVariableNameForColumn($objColumn) %>_Create();
<% } %>
// Create/Setup ListBoxes (if applicable) via Unique ReverseReferences and ManyToMany References
<% foreach ($objTable->ReverseReferenceArray as $objReverseReference) { %>
<% if ($objReverseReference->Unique) { %>
$this-><%= $objCodeGen->FormControlVariableNameForUniqueReverseReference($objReverseReference) %>_Create();
<% } %>
<% } %>
<% foreach ($objTable->ManyToManyReferenceArray as $objManyToManyReference) { %>
$this-><%= $objCodeGen->FormControlVariableNameForManyToManyReference($objManyToManyReference) %>_Create();
<% } %>
// Create/Setup Button Action controls
$this->btnSave_Create();
$this->btnCancel_Create();
$this->btnDelete_Create();
}
// Protected Create Methods
<% foreach ($objTable->ColumnArray as $objColumn) { %><%
// Use the "control_create_" subtemplates to generate the code
// required to create/setup the control.
$mixArguments = array(
'objColumn' => $objColumn,
'strObjectName' => $objCodeGen->VariableNameFromTable($objTable->Name),
'strClassName' => $objTable->ClassName,
'strControlId' => $objCodeGen->FormControlVariableNameForColumn($objColumn)
);
// Figure out WHICH "control_create_" to use
if ($objColumn->Identity) {
$strTemplateFilename = 'identity';
} else if ($objColumn->Timestamp) {
$strTemplateFilename = 'identity';
} else if ($objColumn->Reference) {
if ($objColumn->Reference->IsType)
$strTemplateFilename = 'type';
else
$strTemplateFilename = 'reference';
} else if(ereg('_fck$', $objColumn->Name)) {
$strTemplateFilename = 'fck';
} else if(ereg('_img$', $objColumn->Name)) {
$strTemplateFilename = 'img';
} else if(ereg('_audio$', $objColumn->Name)) {
$strTemplateFilename = 'audio';
} else {
$strTemplateFilename = $objColumn->VariableType;
}
// Get the subtemplate and evaluate
return $objCodeGen->EvaluateSubTemplate(sprintf('control_create_%s.tpl', $strTemplateFilename), $mixArguments) . "\n\n";
%><% } %>
<% foreach ($objTable->ReverseReferenceArray as $objReverseReference) { %><%
if ($objReverseReference->Unique) {
// Use the "control_create_" subtemplates to generate the code
// required to create/setup the control.
$mixArguments = array(
'objReverseReference' => $objReverseReference,
'objTable' => $objTable,
'strObjectName' => $objCodeGen->VariableNameFromTable($objTable->Name),
'strClassName' => $objTable->ClassName,
'strControlId' => $objCodeGen->FormControlVariableNameForUniqueReverseReference($objReverseReference)
);
// Get the subtemplate and evaluate
return $objCodeGen->EvaluateSubTemplate('control_create_unique_reversereference.tpl', $mixArguments) . "\n\n";
} else
return null;
%><% } %>
<% foreach ($objTable->ManyToManyReferenceArray as $objManyToManyReference) { %><%
// Use the "control_create_manytomany_reference" subtemplate to generate the code
// required to create/setup the control.
$mixArguments = array(
'objManyToManyReference' => $objManyToManyReference,
'objTable' => $objTable,
'strObjectName' => $objCodeGen->VariableNameFromTable($objTable->Name),
'strClassName' => $objTable->ClassName,
'strControlId' => $objCodeGen->FormControlVariableNameForManyToManyReference($objManyToManyReference)
);
// Get the subtemplate and evaluate
return $objCodeGen->EvaluateSubTemplate('control_create_manytomany_reference.tpl', $mixArguments) . "\n\n";
%><% } %>
// Setup btnSave
protected function btnSave_Create() {
$this->btnSave = new QButton($this);
$this->btnSave->Text = QApplication::Translate('Save');
$this->btnSave->AddAction(new QClickEvent(), new QServerAction('btnSave_Click'));
$this->btnSave->PrimaryButton = true;
$this->btnSave->CausesValidation = true;
}
// Setup btnCancel
protected function btnCancel_Create() {
$this->btnCancel = new QButton($this);
$this->btnCancel->Text = QApplication::Translate('Cancel');
$this->btnCancel->AddAction(new QClickEvent(), new QServerAction('btnCancel_Click'));
$this->btnCancel->CausesValidation = false;
}
// Setup btnDelete
protected function btnDelete_Create() {
$this->btnDelete = new QButton($this);
$this->btnDelete->Text = QApplication::Translate('Delete');
$this->btnDelete->AddAction(new QClickEvent(), new QConfirmAction(sprintf(QApplication::Translate('Are you SURE you want to DELETE this %s?'), '<%= $objTable->ClassName %>')));
$this->btnDelete->AddAction(new QClickEvent(), new QServerAction('btnDelete_Click'));
$this->btnDelete->CausesValidation = false;
if (!$this->blnEditMode)
$this->btnDelete->Visible = false;
}
// Protected Update Methods
protected function Update<%= $objTable->ClassName; %>Fields() {
<% foreach ($objTable->ColumnArray as $objColumn) { %><%
if ((!$objColumn->Identity) && (!$objColumn->Timestamp)) {
// Use the "control_create_" subtemplates to generate the code
// required to create/setup the control.
$mixArguments = array(
'objColumn' => $objColumn,
'strObjectName' => $objCodeGen->VariableNameFromTable($objTable->Name),
'strClassName' => $objTable->ClassName,
'strControlId' => $objCodeGen->FormControlVariableNameForColumn($objColumn)
);
// Figure out WHICH "control_create_" to use
if ($objColumn->Reference) {
if ($objColumn->Reference->IsType)
$strTemplateFilename = 'type';
else
$strTemplateFilename = 'reference';
} else if(ereg('_img$', $objColumn->Name)) {
$strTemplateFilename = 'img';
} else if(ereg('_audio$', $objColumn->Name)) {
$strTemplateFilename = 'audio';
} else switch ($objColumn->VariableType) {
case QType::Boolean:
$strTemplateFilename = 'checkbox';
break;
case QType::DateTime:
$strTemplateFilename = 'calendar';
break;
default:
$strTemplateFilename = 'textbox';
break;
}
// Get the subtemplate and evaluate
return $objCodeGen->EvaluateSubTemplate(sprintf('control_update_%s.tpl', $strTemplateFilename), $mixArguments) . "\n";
} else
return null;
%><% } %>
<% foreach ($objTable->ReverseReferenceArray as $objReverseReference) { %><%
if ($objReverseReference->Unique) {
// Use the "control_update_unique_reversereference" subtemplate to generate the code
// required to create/setup the control.
$mixArguments = array(
'objReverseReference' => $objReverseReference,
'strObjectName' => $objCodeGen->VariableNameFromTable($objTable->Name),
'strClassName' => $objTable->ClassName,
'strControlId' => $objCodeGen->FormControlVariableNameForUniqueReverseReference($objReverseReference)
);
// Get the subtemplate and evaluate
return $objCodeGen->EvaluateSubTemplate('control_update_unique_reversereference.tpl', $mixArguments) . "\n";
} else
return null;
%><% } %>
}
<% foreach ($objTable->ManyToManyReferenceArray as $objManyToManyReference) { %><%
// Use the "control_update_manytomany_reference" subtemplate to generate the code
// required to create/setup the control.
$mixArguments = array(
'objManyToManyReference' => $objManyToManyReference,
'strObjectName' => $objCodeGen->VariableNameFromTable($objTable->Name),
'strClassName' => $objTable->ClassName,
'strControlId' => $objCodeGen->FormControlVariableNameForManyToManyReference($objManyToManyReference)
);
// Get the subtemplate and evaluate
return $objCodeGen->EvaluateSubTemplate('control_update_manytomany_reference.tpl', $mixArguments) . "\n";
%><% } %>
// Control ServerActions
protected function btnSave_Click($strFormId, $strControlId, $strParameter) {
$this->Update<%= $objTable->ClassName; %>Fields();
$this-><%= $objCodeGen->VariableNameFromTable($objTable->Name); %>->Save();
<% foreach ($objTable->ManyToManyReferenceArray as $objManyToManyReference) { %>
$this-><%= $objCodeGen->FormControlVariableNameForManyToManyReference($objManyToManyReference); %>_Update();
<% } %>
$this->RedirectToListPage
Saturday, April 5, 2008, 9:50 AM PDT
Thanks, Igor that is great!!
This is more then a great starting point to get things rolling :)
I would like to help make this work in the current version of qcodo. I already made the magic columns work with the current version.
I would also love to see the fckeditor and audio implementation. If you don't mind sharing that too, it would really save time :)
--
Currently I'm trying to compare your changes with the original files with winmerge.
But I wasn't able to find the file you are overriding (db_orm_edit_form_base.tpl) yet.
I tried to download the version of qcodo that you are using here to start out, but I cannot find it, I don't see any of the previous versions online..
Probably you can send me the full package to tronics AT gmx.at
As soon as I get this working on my machine, I can make it work in the current version.
Regards,
tronics
It would be great if you could make this work in new version on Qcodo, because I really have no time for this now, and I'm missing new features of Qcodo :)
I'll make asap a “clean” copy of the my customized qcodo package and I'll send to you. Sorry I cannot share with you my currently working app as it is, because of the confidentiality issues.
May be you didn't searched in the right place. The files that are overridden are in includes/qcodo/_core/codegen/templates .
Thanks you for your response Igor!
I'm looking forward to the package. I only need the old qcodo version (like it was in the download) and separately the changed templates. So I can test, see the changes and apply and modify them on the new qcodo version.
Or if you don't have the time for that - please just post the other templates here for fck and audio/file. I shall be able to work that out too.
--
I cannot not find the equivalent for db_orm_edit_form_base.tpl (no problem finding the place control_update_**.tpl).
Thought I have found equivalent code pieces in the current version but that were not the right ones..
Thanks.
Regards,
tronics
I sent you an email with the files you requested.
I hope that you will figure it out.
Igor, this is extremely interesting. Would you be willing to work with us to integrate your work into a release of QCubed?
QCubed is a community effort to take QCodo further. Join us! <http://qcu.be>