help to migrate a working application to qcubed 2.0
Hello.
I have started an experimental migration to 2.0.
In my development i had a good and rapid path starting from the generated panel for my tables in the drafts->panel folder, the "Dashboard".
After I applied my personalization in panel or logic in metacontrols ...
The only step I used were:
1 - create a directory (example Address)
2 - copy in this directory from the \drafts\panels\ the generated panels for Address table AddressEditPanel.class.php, AddressEditPanel.tpl.php, AddressListPanel.class.php, AddressListPanel.tpl.php)
3 - copy also in this directory from \drafts\panels\ index.php
4 - apply some modification in index to remove listbox and have list panel displayed.
the result is index.php ( with my developed added check on logged in user removed ):
<?php
// Include prepend.inc to load Qcubed
// magia 2009
require('../includes/prepend.inc.php');
// require('../../includes/prepend.inc.php');
// Security check for ALLOW_REMOTE_ADMIN
// To allow access REGARDLESS of ALLOW_REMOTE_ADMIN, simply remove the line below
QApplication::CheckRemoteAdmin();
// Let's "magically" determine the list of genereated Class Panel Drafts by
// just traversing through this directory, looking for "*ListPanel.class.php" and "*EditPanel.class.php"
// Obviously, if you are wanting to make your own dashbaord, you should change this and use more
// hard-coded means to determine which classes' paneldrafts you want to include/use in your dashboard.
$objDirectory = opendir(dirname(__FILE__));
$strClassNameArray = array();
while ($strFile = readdir($objDirectory)) {
if ($intPosition = strpos($strFile, 'ListPanel.class.php')) {
$strClassName = substr($strFile, 0, $intPosition);
$strClassNameArray[$strClassName] = $strClassName . 'ListPanel';
require($strClassName . 'ListPanel.class.php');
require($strClassName . 'EditPanel.class.php');
}
}
class Dashboard extends QForm {
// AutoleasingEditPanel.class.php
// AutoleasingListPanel.class.php
protected $lstClassNames;
protected $pnlTitle;
protected $pnlList;
protected $pnlEdit;
protected function Form_Create() {
$this->pnlTitle = new QPanel($this);
$this->pnlTitle->Text = 'AJAX Dashboard';
$this->pnlList = new QPanel($this, 'pnlList');
$this->pnlList->AutoRenderChildren = true;
$this->pnlEdit = new QPanel($this, 'pnlEdit');
$this->pnlEdit->AutoRenderChildren = true;
$this->pnlEdit->Visible = false;
$this->pnlList->RemoveChildControls(true);
$this->pnlEdit->RemoveChildControls(true);
$this->pnlEdit->Visible = false;
// magia 2009 - set autoconsistent - valido in ogni directory
global $strClassNameArray;
global $strClassName;
/* magia 2009 immmediate form with list and edit panel in this directory
*/
/* magia 2009 comment out
$this->lstClassNames = new QListBox($this);
$this->lstClassNames->AddItem('- Select One -', null);
// Use the strClassNameArray as magically determined above to aggregate the listbox of classes
// Obviously, this should be modified if you want to make a custom dashboard
global $strClassNameArray;
foreach ($strClassNameArray as $strKey => $strValue)
$this->lstClassNames->AddItem($strKey, $strValue);
$this->lstClassNames->AddAction(new QChangeEvent(), new QAjaxAction('lstClassNames_Change'));
$this->objDefaultWaitIcon = new QWaitIcon($this);
end magia 2009
*/
/* call to output list panel */
// $this->lstClassNames_Change();
$this->pnlList->RemoveChildControls(true);
$this->pnlEdit->RemoveChildControls(true);
$this->pnlEdit->Visible = false;
$this->pnlTitle->Text = $strClassName;
$objNewPanel = new $strClassNameArray[$strClassName]($this->pnlList, 'SetEditPane', 'CloseEditPane');
}
/**
* This Form_Validate event handler allows you to specify any custom Form Validation rules.
* It will also Blink() on all invalid controls, as well as Focus() on the top-most invalid control.
*/
protected function Form_Validate() {
// By default, we report that Custom Validations passed
$blnToReturn = true;
// Custom Validation Rules
// TODO: Be sure to set $blnToReturn to false if any custom validation fails!
$blnFocused = false;
foreach ($this->GetErrorControls() as $objControl) {
// Set Focus to the top-most invalid control
if (!$blnFocused) {
$objControl->Focus();
$blnFocused = true;
}
// Blink on ALL invalid controls
$objControl->Blink();
}
return $blnToReturn;
}
/* magia 2009 comment out
protected function lstClassNames_Change() {
// Get rid of all child controls for list and edit panels
$this->pnlList->RemoveChildControls(true);
$this->pnlEdit->RemoveChildControls(true);
$this->pnlEdit->Visible = false;
if ($strClassName = $this->lstClassNames->SelectedValue) {
// We've selected a Class Name
$objNewPanel = new $strClassName($this->pnlList, 'SetEditPane', 'CloseEditPane');
$this->pnlTitle->Text = $this->lstClassNames->SelectedName;
} else {
$this->pnlTitle->Text = 'AJAX Dashboard';
}
}
end magia 2009
*/
/*
public function SetListPane(QPanel $objPanel) {
$this->pnlList->RemoveChildControls(true);
$objPanel->SetParentControl($this->pnlList);
}
*/
public function CloseEditPane($blnUpdatesMade) {
// Close the Edit Pane
$this->pnlEdit->RemoveChildControls(true);
$this->pnlEdit->Visible = false;
// If updates were made, let's "brute force" the updates to the screen by just refreshing the list pane altogether
if ($blnUpdatesMade)
$this->pnlList->Refresh();
}
public function SetEditPane(QPanel $objPanel = null) {
$this->pnlEdit->RemoveChildControls(true);
if ($objPanel) {
$objPanel->SetParentControl($this->pnlEdit);
$this->pnlEdit->Visible = true;
} else {
$this->pnlEdit->Visible = false;
}
}
}
Dashboard::Run('Dashboard');
?>
?>and index.tpl.php
<?php $strPageTitle = str_replace('/gebenefitsmall/', 'Postel Gestione Benefit ', dirname($_SERVER['PHP_SELF'])); ?>
<?php require(__INCLUDES__ . '/header.inc.php'); ?>
<?php $this->RenderBegin(); ?>
<div id="titleBar">
<!-- magia 2009 change next line to return to initial menu -->
<h2 id="right"><a href="<?php _p(__VIRTUAL_DIRECTORY__);?>/index.php">« <?php _t('Go to "menu iniziale"'); ?></a></h2>
<h2>Panel Drafts</h2>
<h1><?php $this->pnlTitle->Render(); ?></h1>
</div>
<!--
<div id="dashboard">
<div id="left">
<p><strong>Select a Class to View/Edit</strong></p>
<p><?php //$this->lstClassNames->Render('FontSize=10px','Width=100px'); ?></p>
<p><?php //$this->objDefaultWaitIcon->Render(); ?></p>
</div>
-->
<div id="right">
<?php $this->pnlEdit->Render(); ?>
<?php $this->pnlList->Render(); ?>
</div>
</div>
<?php $this->RenderEnd(); ?>
<?php require(__INCLUDES__ . '/footer.inc.php'); ?>The same approach with the similar modification in path and other introduced with version 2.0.0 works
ported index.php
<?php
header("Location: ./panel_drafts.php");
?>ported panel_drafts.php
<?php
require_once('../qcubed.inc.php');
// Security check for ALLOW_REMOTE_ADMIN
// To allow access REGARDLESS of ALLOW_REMOTE_ADMIN, simply remove the line below
QApplication::CheckRemoteAdmin();
// Let's "magically" determine the list of genereated Class Panel Drafts by
// just traversing through this directory, looking for "*ListPanel.class.php" and "*EditPanel.class.php"
// Obviously, if you are wanting to make your own dashbaord, you should change this and use more
// hard-coded means to determine which classes' paneldrafts you want to include/use in your dashboard.
// $objDirectory = opendir(__DOCROOT__ . __PANEL_DRAFTS__);
$objDirectory = opendir(dirname(__FILE__));
$strClassNameArray = array();
while ($strFile = readdir($objDirectory)) {
if ($intPosition = strpos($strFile, 'ListPanel.class.php')) {
$strClassName = substr($strFile, 0, $intPosition);
$strClassNameArray[$strClassName] = $strClassName . 'ListPanel';
// require(__DOCROOT__ . __PANEL_DRAFTS__ . '/' . $strClassName . 'ListPanel.class.php');
// require(__DOCROOT__ . __PANEL_DRAFTS__ . '/' . $strClassName . 'EditPanel.class.php');
require( $strClassName . 'ListPanel.class.php');
require( $strClassName . 'EditPanel.class.php');
}
}
class Dashboard extends QForm {
protected $lstClassNames;
protected $lblTitle;
protected $pnlList;
protected $pnlEdit;
protected function Form_Create() {
$this->lblTitle = new QLabel($this);
$this->lblTitle->Text = 'AJAX Dashboard';
$this->pnlList = new QPanel($this, 'pnlList');
$this->pnlList->AutoRenderChildren = true;
$this->pnlEdit = new QPanel($this, 'pnlEdit');
$this->pnlEdit->AutoRenderChildren = true;
$this->pnlEdit->Visible = false;
/* magia 2009 comment out
$this->lstClassNames = new QListBox($this);
$this->lstClassNames->AddItem('- Select One -', null);
// Use the strClassNameArray as magically determined above to aggregate the listbox of classes
// Obviously, this should be modified if you want to make a custom dashboard
global $strClassNameArray;
foreach ($strClassNameArray as $strKey => $strValue)
$this->lstClassNames->AddItem($strKey, $strValue);
$this->lstClassNames->AddAction(new QChangeEvent(), new QAjaxAction('lstClassNames_Change'));
$this->objDefaultWaitIcon = new QWaitIcon($this);
end magia 2009 */
/* call to output list panel */
global $strClassNameArray;
global $strClassName;
// $this->lstClassNames_Change();
$this->pnlList->RemoveChildControls(true);
$this->pnlEdit->RemoveChildControls(true);
$this->pnlEdit->Visible = false;
$this->lblTitle->Text = $strClassName;
$objNewPanel = new $strClassNameArray[$strClassName]($this->pnlList, 'SetEditPane', 'CloseEditPane');
}
/**
* This Form_Validate event handler allows you to specify any custom Form Validation rules.
* It will also Blink() on all invalid controls, as well as Focus() on the top-most invalid control.
*/
protected function Form_Validate() {
// By default, we report that Custom Validations passed
$blnToReturn = true;
// Custom Validation Rules
// TODO: Be sure to set $blnToReturn to false if any custom validation fails!
$blnFocused = false;
foreach ($this->GetErrorControls() as $objControl) {
// Set Focus to the top-most invalid control
if (!$blnFocused) {
$objControl->Focus();
$blnFocused = true;
}
// Blink on ALL invalid controls
$objControl->Blink();
}
return $blnToReturn;
}
/* commented out by magia 2009
protected function lstClassNames_Change($strFormId, $strControlId, $strParameter) {
// Get rid of all child controls for list and edit panels
$this->pnlList->RemoveChildControls(true);
$this->pnlEdit->RemoveChildControls(true);
$this->pnlEdit->Visible = false;
if ($strClassName = $this->lstClassNames->SelectedValue) {
// We've selected a Class Name
$objNewPanel = new $strClassName($this->pnlList, 'SetEditPane', 'CloseEditPane');
$this->lblTitle->Text = $this->lstClassNames->SelectedName;
} else {
$this->lblTitle->Text = 'AJAX Dashboard';
}
}
end of commented out
*/
/* public function SetListPane(QPanel $objPanel) {
$this->pnlList->RemoveChildControls(true);
$objPanel->SetParentControl($this->pnlList);
}*/
public function CloseEditPane($blnUpdatesMade) {
// Close the Edit Pane
$this->pnlEdit->RemoveChildControls(true);
$this->pnlEdit->Visible = false;
// If updates were made, let's "brute force" the updates to the screen by just refreshing the list pane altogether
if ($blnUpdatesMade)
$this->pnlList->Refresh();
}
public function SetEditPane(QPanel $objPanel = null) {
$this->pnlEdit->RemoveChildControls(true);
if ($objPanel) {
$objPanel->SetParentControl($this->pnlEdit);
$this->pnlEdit->Visible = true;
} else {
$this->pnlEdit->Visible = false;
}
}
}
Dashboard::Run('Dashboard');
?>ported panel_drafts.tpl.php
<?php $strPageTitle="Panel Drafts" ?>
<?php require(__CONFIGURATION__ . '/header.inc.php'); ?>
<?php $this->RenderBegin(); ?>
<div id="pageTitle"><?php $this->lblTitle->Render(); ?></div><div id="formDraftLink"><a href="<?php _p(__VIRTUAL_DIRECTORY__ . __FORM_DRAFTS__) ?>/index.php">« <?php _t('Go to "Form Drafts"'); ?></a></div>
<div id="dashboard">
<div id="right">
<?php $this->pnlList->Render(); ?>
<?php $this->pnlEdit->Render(); ?>
</div>
</div>
<br clear="all" style="clear:both" />
<?php $this->RenderEnd(); ?>
<?php require(__CONFIGURATION__ . '/footer.inc.php'); ?>hope this can help some Qcubed fan ... , Gianni

Gianni,
Do I understand you correctly - you were able to migrate your existing application to QCubed 2.0 without problems? If so, that's awesome! If not, let us know how we can help.
Cheers,
Alex
At moment simple modification to take care of the revised structure.
The structure of application was designed to minimize code.
So after initial login I retain user info in session and select a menu depending on user
type (basic, normal, administrator).
from menu we can go to handle application tables (benefit - risources - benefit assigned to resources).
For every application table there is a directory where are the related list and edit panel (with my personalization) and my "generic" index.php and index.tpl.php
( a modified version of index.php and index.tpl.php present in drafts\panels).
In this post I listed the work required to have the same generic logic in version 2.
And at moment the first ported directorys (auto - resources - azienda ) work.
To retain the filter logic I set off filters
/*************************************************************************
/ to use old Magia filter
/ uncomment line ($this->dtgRisorses->ShowFilter = false;)
**************************************************************************/
$this->dtgRisorses->ShowFilter = false;
demo application at 1.0.RC2 version can be joined
demo gebenefit
you can login whith user:rouge - password:rouge
porting work in progress