Warning, Brick after this line.
-------------------
Well, SQL Views, and "ModelViews" as is. Sometimes you want to show some table data in other form or somewhere, but you don't want to show all fields on a related form.
OpenXava solves this with Views Annotations:
You can write on a class:
Code: Select all
@View(name="Simple", // This view is used only when “Simple†is specified
members="number, name" // Shows only number and name in the same line
)
And just number,name fields will be showed when you specify to use the view "Simple".
Your solution probably works, the problem is that goes against all database design principles.
As far as I see on the code. Right now, the core is on parent-child.php
Here there are a hardcoded array with tables and relationships or parent-child.
The code creates an array based on permissions and look for the table asked if there are permissions or not to show.
How? Using the JS function post (common.js.php).
Code: Select all
function post(url, params, update, disable, loading){
new Ajax.Request(
url, {
method: 'post',
parameters: params,
onCreate: function() {
if($(disable) != undefined) $(disable).disabled=true;
if($(loading) != undefined && update != loading) $(loading).update('<div style="direction: ltr;"><img src="loading.gif"> <?php echo $Translation['Loading ...']; ?></div>');
},
onSuccess: function(resp) {
if($(update) != undefined) $(update).update(resp.responseText);
},
onComplete: function() {
if($(disable) != undefined) $(disable).disabled=false;
if($(loading) != undefined && loading != update) $(loading).update('');
}
}
);
}
How is used this function? As I epxlained in previous post:
Code: Select all
post(
"parent-children.php",
{
ChildTable: "direccionentidad",
ChildLookupField: "entidad_id",
SelectedID: "<?php echo {$SelectedID}; ?>",
Page: 1,
SortBy: "",
SortDirection: "",
Operation: "get-records"
},
"di-info"
);
You specify the childtable, lookup field, actual ID of parent and an operation, and where you want to "print" ("di-info" div)
get-records operation is responsible to return the detail view as is (show-childrens return the complete Childs frame, and calls recursivelly to itself for get-records)
get-records builds SQL based on the hardcoded parent/childs array and prepare some data to pass to loadView (incCommon.php)
Code: Select all
/**
* Loads a given view from the templates folder, passing the given data to it
* @param $view the name of a php file (without extension) to be loaded from the 'templates' folder
* @param $the_data_to_pass_to_the_view (optional) associative array containing the data to pass to the view
* @return the output of the parsed view as a string
*/
function loadView($view, $the_data_to_pass_to_the_view=false){
global $Translation;
$view = dirname(__FILE__)."/templates/$view.php";
if(!is_file($view)) return false;
if(is_array($the_data_to_pass_to_the_view)){
foreach($the_data_to_pass_to_the_view as $k => $v)
$$k = $v;
}
unset($the_data_to_pass_to_the_view, $k, $v);
ob_start();
@include($view);
$out=ob_get_contents();
ob_end_clean();
return $out;
}
loadView calls this template (normally, children-relatedtable.php) and with the data passed builds all.
Template, creates JS functions to retrieve data and manage behaviour of the generated detail-view, like get records, create new one and so on, calling to, again, to parent-children.php and with a composed name like ($table.$lookupfield)GetRecords({ Verb: '' }) where verb could be new, reload and so on...
Summarizing, this is all.
My idea is to create a "clone" of parent-child.php, that "ignores" the hardcode array, and works with data passed.
For example
Code: Select all
post(
"aux-detail-view.php",
{
ViewName: "MyView",
ChildTable: "direccionentidad",
ChildLookupField: "entidad_id",
SelectedID: "<?php echo {$SelectedID}; ?>",
Page: 1,
SortBy: "",
SortDirection: "",
Operation: "get-records"
ParamsArray: "",
Query: ""
},
"target-div"
);
Ideally, that could understand a new data array
Code: Select all
'data' => array(
'parent-table' => '',
'parent-primary-key' => '',
'child-primary-key' => '',
'child-primary-key-index' => 0,
'tab-label' => 'D',
'table-icon' => '',
'display-refresh' => true,
'display-add-new' => true,
'forced-where' => '',
'display-fields' => array(5 => 'Nombre', 6 => 'Dirección por defecto'),
'display-field-names' => array(5 => 'nombreDireccion', 6 => 'direccion_defecto', ),
'sortable-fields' => array(),
'records-per-page' => 10,
'default-sort-by' => false,
'default-sort-direction' => 'asc',
'open-detail-view-on-click' => true,
'display-page-selector' => true,
'show-page-progress' => true,
'template' => '',
'template-printable' => '',
'query' => ""
)
Obviously, is needed a "generic" children-view.php template too, because templates are hardcoded on the table too, and calls parent-children.php too. And JScode takes into consideration the name of the table, and should be the ViewName. Then, is needed a new one, independent of the table, because will be passed as param, calling this new "aux-detail-view.php".
A lot of work.
I hope I explained.
Note: I though this was simpler to do, and can't understand how anybody need it before.