This topic is locked

Custom View / Edit Lookup Wizard

2/27/2008 1:13:28 PM
PHPRunner General questions
S
spintz author

I have users, that have roles.

Certian fields in a record need to be assigned users of specific roles, so the "Edit As -> Lookup Wizard" has a WHERE clause of role == 3 or role == 7, for example.
However, when viewing, to save load times on the list page, instead of querying the database for every row, and looking up the value, I do a single query in the "List Page: Before process" event, and create a userid/name array. Then, in the View, I select custom, and lookup the values for the userid/username mapping in the array.
Now, my problem is that the Edit As, changes the $value that my View As gets. So, basically, the Edit As lookup is done first, then that value is provided to the Custom View filter. I don't think this should be the case. Or better yet, the View tab, should have an option to use the LookupWizard from the Edit As, if you want. But if I select Custom, then I should get the raw data and be able to deal with it myself. It's not intuitive that the "Edit As" filter is being applied to the value before the "View As". I've found where I can fix this in the generated code, but I'd like to see this changed in a future version. It's very confusing.

S
spintz author 2/27/2008

In the source folder for PHPRunner 4.1, open the list.php file and in the section for -

elseif (@f.strEditFormat==EDIT_FORMAT_LOOKUP_WIZARD || @f.strEditFormat==EDIT_FORMAT_RADIO) && pLookupObj.nLookupType == LT_LOOKUPTABLE##



Change the code to be this -

if(strlen($data["##@f.strName s##"]))

{

$strdata = make_db_value("##@f.strName s##",$data["##@f.strName s##"]);

##if @f.strViewFormat==FORMAT_CUSTOM##

##if NeedEncode(@f)##

$value=ProcessLargeText(GetDataInt($strdata,$data,"##@f.strName s##", "##@f.strViewFormat s##"),"field=##@f.strName uhs##".$keylink,"",MODE_LIST);

##else##

$value=GetDataInt($strdata,$data,"##@f.strName s##", "##@f.strViewFormat s##");

##endif##

##else##

$LookupSQL="SELECT ";

##if @f.EditFormatObj.pLookupObj.bCustomDisplay##

$LookupSQL.="##@f.strDisplayField s##";

##else##

$LookupSQL.="##@f.strDisplayField ws##";

##endif##

$LookupSQL.=" FROM ##@f.EditFormatObj.pLookupObj.strTable ts## WHERE ##@f.strLinkField ws## = " . $strdata;

##if EditFormatObj.pLookupObj.strWhere##

$LookupSQL.=" and (".##EditFormatObj.pLookupObj.strWhere##.")";

##endif##

LogInfo($LookupSQL);

$rsLookup = db_query($LookupSQL,$conn);

$lookupvalue=$data["##@f.strName s##"];

if($lookuprow=db_fetch_numarray($rsLookup))

$lookupvalue=$lookuprow[0];

##if NeedEncode(@f)##

$value=ProcessLargeText(GetDataInt($lookupvalue,$data,"##@f.strName s##", "##@f.strViewFormat s##"),"field=##@f.strName uhs##".$keylink,"",MODE_LIST);

##else##

$value=GetDataInt($lookupvalue,$data,"##@f.strName s##", "##@f.strViewFormat s##");

##endif##

##endif##

}

else

$value="";


This saved me hand editing the output *_list.php files everytime I built my project. I'm going to make the same changes to view.php, print.php and export.php. It'd be great to have this implemented for 4.2 or some version beyond...

Alexey admin 2/28/2008

Hi,
I see what you saying.

There is an easier way to achieve that.
Add an aliased field on the Edit SQL query tab in PHPRunner.

I.e.

select

...

role,

role as rawrole,

...

from ...



Then proceed to the Choose Fields tab and choose rolefield to appear on the Edit page and rawrole - on the View.

S
spintz author 2/28/2008

Hi,

I see what you saying.

There is an easier way to achieve that.
Add an aliased field on the Edit SQL query tab in PHPRunner.

I.e.
Then proceed to the Choose Fields tab and choose rolefield to appear on the Edit page and rawrole - on the View.


I prefer my solution over having aliased fields. It's more intuitive to have edit/view behavior different, if you want it. I've used alias fields for other things, like when I need different field behavior on Add/Edit pages.