Record info retrieval breaking new record input (solved)

A place for users and developers of the Xataface to discuss and receive support.

Record info retrieval breaking new record input (solved)

Postby casanovax7 » Mon Oct 01, 2012 5:03 pm

I have gone around and around trying to figure out what I need to do to make my code work.

I have the following in the delegate class file of my table in order for me to retrieve the image size of an uploaded image:

Code: Select all
function field__displaysize(){
    $app =& Dataface_Application::getInstance();
    $query =& $app->getQuery();
    $imgurlrec =& $app->getRecord();
    $imgurlfield =& $imgurlrec->getValue('img_url');
    $imgurl = 'http://thisisatest.com/input2/tables/img/img_url/'.$imgurlfield;
    list($width,$height,$type,$attr) = getimagesize($imgurl);
    $displaysize = 'width='.$width.', height='.$height;
    return $displaysize;
}


But after adding that code, I cannot add new records. The error log tells me:

Code: Select all
[02-Oct-2012 00:03:10 UTC] PHP Strict Standards:  Only variables should be assigned by reference in /home1/everaft8/public_html/xata/Dataface/Record.php on line 1365
[02-Oct-2012 00:03:18 UTC] PHP Fatal error:  Call to a member function getValue() on a non-object in /home1/everaft8/public_html/input2/tables/img/img.php on line 22


If I take that code out, I can add new records, no problem...

I know I am doing something that is probably very obvious to REAL coders - could somebody please tell me what I am doing wrong? I suspect I am doing something improper to get the value of the 'img_url' field... Thanks in advance!
Last edited by casanovax7 on Thu Oct 04, 2012 2:22 pm, edited 1 time in total.
casanovax7
 
Posts: 20
Joined: Wed Sep 05, 2012 3:36 pm

Re: Record info retrieval breaking new record input

Postby shannah » Mon Oct 01, 2012 6:18 pm

The error is because $imgurlrec is null.

If you are trying to create a calculated field, then you should be receiving the Dataface_Record as the first argument of the method, rather than using the Dataface_Application::getRecord() method (which just returns the record that was specified by the current HTTP request).

E.g.
Code: Select all
function field__displaysize(Dataface_Record $imgurlrec ){
    $imgurlfield = $imgurlrec->getValue('img_url');
    $imgurl = 'http://thisisatest.com/input2/tables/img/img_url/'.$imgurlfield;
    list($width,$height,$type,$attr) = getimagesize($imgurl);
    $displaysize = 'width='.$width.', height='.$height;
    return $displaysize;
}


-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Record info retrieval breaking new record input

Postby casanovax7 » Tue Oct 02, 2012 9:23 am

You are seriously so awesome. And I really appreciate the assistance. One more thing that I wanted to do...

I want to be able to get a drop-down list for each image. In a similar (incorrect) way that I had done before to get the previous code, I had scrapped together something that worked fine if I never needed to save new records:

Code: Select all
function valuelist__locationtable(){
    $app =& Dataface_Application::getInstance();
    $query =& $app->getQuery();
    $imgrecord =& $app->getRecord();
    $vend =& $imgrecord->getValue('img_vendor');
    $sql = ("select SF_ID, Location_Name from vend_01 where Vendor_Account__c='$vend'");
    $res = mysql_query($sql);
    $out = array();
    while ($row = mysql_fetch_assoc($res) ) $out[$row['SF_ID']] = $row['Location_Name'];
    return $out;
}


The idea is that I get a valuelist of Location Names (Location_Name) that stores the related record id (SF_ID) for each image (this allows me to assign images to specific locations that live on another table). It's fine thus far, but obviously it doesn't work when trying to add new records, as my previous code did not... I tried to do something similar to the code you gave me:

Code: Select all
function valuelist__locationtable(Dataface_Record $imgrec){
    $vend = $imgrec->getValue('img_vendor');
    $sql = ("select SF_ID, Location_Name from vend_01 where Vendor_Account__c='$vend'");
    $res = mysql_query($sql);
    $out = array();
    while ($row = mysql_fetch_assoc($res) ) $out[$row['SF_ID']] = $row['Location_Name'];
    return $out;
}


Since it didn't work I'm assuming I am completely off the mark on something... Thanks again for all your help!
casanovax7
 
Posts: 20
Joined: Wed Sep 05, 2012 3:36 pm

Re: Record info retrieval breaking new record input

Postby shannah » Tue Oct 02, 2012 9:54 am

Valuelists really are meant to be static across requests. Therefore it can't really be used for what you want.

The depselect widget was designed to fill this void, but *sigh* it requires XF 2.0 which isn't released yet.
http://xataface.com/dox/modules/depselect/latest/

If you look in the forum, many users have also implemented this behaviour in a one-off fashion. All require some measure of Javascript to work. The idea. You listen for changes in one widget, and use ajax to load options into your valuelist. You might be able to get some ideas by the implementation of the depselect module:

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Record info retrieval breaking new record input

Postby casanovax7 » Tue Oct 02, 2012 10:07 am

Does it make a difference if I say that a static valuelist isn't a problem? What I mean is, I actually don't need the valuelist to automatically populate when new information is input into the form. Essentially, all I need is the function to do a query when the record is viewed, and then display those results as a valuelist... Like I said, this code actually does work for me (it even works when the img_vendor field is blank - I can still edit and save with no errors):

Code: Select all
function valuelist__locationtable(){
    $app =& Dataface_Application::getInstance();
    $query =& $app->getQuery();
    $imgrecord =& $app->getRecord();
    $vend =& $imgrecord->getValue('img_vendor');
    $sql = ("select SF_ID, Location_Name from vend_01 where Vendor_Account__c='$vend'");
    $res = mysql_query($sql);
    $out = array();
    while ($row = mysql_fetch_assoc($res) ) $out[$row['SF_ID']] = $row['Location_Name'];
    return $out;
}


It just doesn't work when I try to add a new record... Is there any way for me to exclude a field from the add new record form? :D
casanovax7
 
Posts: 20
Joined: Wed Sep 05, 2012 3:36 pm

Re: Record info retrieval breaking new record input

Postby casanovax7 » Tue Oct 02, 2012 11:05 am

OK; I apologize for the back and forth on this. Anyways, I think I figured it out; at least, thus far things seem to work now. I changed the delegate class valuelist function to the following:

Code: Select all
function valuelist__locationtable(){
    $app =& Dataface_Application::getInstance();
    $query =& $app->getQuery();

    $sql = 'None';

    $action = $query['-action'];
    switch ($action){
        case 'edit':

            $imgrecord =& $app->getRecord();
            $vend =& $imgrecord->getValue('img_vendor');
            if ( $imgrecord){
                    $sql = "select SF_ID, Location_Name from vend_01 where Vendor_Account__c='$vend'";
                }
            break;
    }
   
    $res = mysql_query($sql);
    $out = array();
    while ($row = mysql_fetch_assoc($res) ) $out[$row['SF_ID']] = $row['Location_Name'];
    return $out;
}


Now it performs the same function as before, storing the SF_ID but displaying the Location_Name in the valuelist; but when going to add a new record the valuelist is empty (which is what I wanted) and doesn't err out.

Thanks for all your time and hard work on this INVALUABLE TOOL!
casanovax7
 
Posts: 20
Joined: Wed Sep 05, 2012 3:36 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 23 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved