vtiger Forum Index vtiger
The Honest Open Source CRM
 

Code explanation
Click here to go to the original topic

 
       vtiger Forum Index -> Developer Forum - 5.0.2
Previous topic :: Next topic  
Author Message
guntersammet



Joined: 18 Dec 2006
Posts: 1

Posted: Wed Jan 24, 2007 5:15 pm    Post subject: Code explanation  

Hi all:
I'm pretty new to vtiger. Working on a new custom field type (picklist with associated value). Just stumbled over this piece of code (function getDetailBlockInformation in DetailViewUtils.php) and I am not sure if I am missing something:

Code:
   for($i=0; $i<$noofrows; $i++)
   {
      $fieldtablename = $adb->query_result($result,$i,"tablename");
      $fieldcolname = $adb->query_result($result,$i,"columnname");
      $uitype = $adb->query_result($result,$i,"uitype");
      $fieldname = $adb->query_result($result,$i,"fieldname");
      $fieldlabel = $adb->query_result($result,$i,"fieldlabel");
      $maxlength = $adb->query_result($result,$i,"maximumlength");
      $block = $adb->query_result($result,$i,"block");
      $generatedtype = $adb->query_result($result,$i,"generatedtype");
      $tabid = $adb->query_result($result,$i,"tabid");
      $custfld = getDetailViewOutputHtml($uitype, $fieldname, $fieldlabel, $col_fields,$generatedtype,$tabid);
      if(is_array($custfld))
      {
         $label_data[$block][] = array($custfld[0]=>array("value"=>$custfld[1],"ui"=>$custfld[2],"options"=>$custfld["options"],"secid"=>$custfld["secid"],"link"=>$custfld["link"],"cursymb"=>$custfld["cursymb"],"salut"=>$custfld["salut"],"cntimage"=>$custfld["cntimage"],"isadmin"=>$custfld["isadmin"],"tablename"=>$fieldtablename,"fldname"=>$fieldname));
      }
      $i++;
      if($i<$noofrows)
      {
         $fieldtablename = $adb->query_result($result,$i,"tablename");
         $fieldcolname = $adb->query_result($result,$i,"columnname");
         $uitype = $adb->query_result($result,$i,"uitype");
         $fieldname = $adb->query_result($result,$i,"fieldname");
         $fieldlabel = $adb->query_result($result,$i,"fieldlabel");
         $maxlength = $adb->query_result($result,$i,"maximumlength");
         $block = $adb->query_result($result,$i,"block");
         $generatedtype = $adb->query_result($result,$i,"generatedtype");
         $tabid = $adb->query_result($result,$i,"tabid");

         $custfld = getDetailViewOutputHtml($uitype, $fieldname, $fieldlabel, $col_fields,$generatedtype,$tabid);
         if(is_array($custfld))
         {
            $label_data[$block][] = array($custfld[0]=>array("value"=>$custfld[1],"ui"=>$custfld[2],"options"=>$custfld["options"],"secid"=>$custfld["secid"],"link"=>$custfld["link"],"cursymb"=>$custfld["cursymb"],"salut"=>$custfld["salut"],"cntimage"=>$custfld["cntimage"],"isadmin"=>$custfld["isadmin"],"tablename"=>$fieldtablename,"fldname"=>$fieldname));
         }
      }

   }


if I refactor this to the following:

Code:
   for($i=0; $i<$noofrows; $i++)
   {
      $fieldtablename = $adb->query_result($result,$i,"tablename");
      $fieldcolname = $adb->query_result($result,$i,"columnname");
      $uitype = $adb->query_result($result,$i,"uitype");
      $fieldname = $adb->query_result($result,$i,"fieldname");
      $fieldlabel = $adb->query_result($result,$i,"fieldlabel");
      $maxlength = $adb->query_result($result,$i,"maximumlength");
      $block = $adb->query_result($result,$i,"block");
      $generatedtype = $adb->query_result($result,$i,"generatedtype");
      $tabid = $adb->query_result($result,$i,"tabid");
      $custfld = getDetailViewOutputHtml($uitype, $fieldname, $fieldlabel, $col_fields,$generatedtype,$tabid);
      if(is_array($custfld))
      {
         $label_data[$block][] = array($custfld[0]=>array("value"=>$custfld[1],"ui"=>$custfld[2],"options"=>$custfld["options"],"secid"=>$custfld["secid"],"link"=>$custfld["link"],"cursymb"=>$custfld["cursymb"],"salut"=>$custfld["salut"],"cntimage"=>$custfld["cntimage"],"isadmin"=>$custfld["isadmin"],"tablename"=>$fieldtablename,"fldname"=>$fieldname));
      }
   }


wouldn't that have the same functionality?

I have to modify this and I'd like to avoid having to put if then else in both places. However, I am afraid that I break something somewhere else.

Anybody out there that could shed some light into this?
TIA

Gunter[/code]
Back to top  
BrianLaughlin



Joined: 13 Dec 2005
Posts: 801

Posted: Wed Jan 24, 2007 7:51 pm    Post subject: Code explanation<br /><a href="viewtopic.php?t  

Hi Gunter,

Thanks for the refactoring. You may want to consider sending this post to the mailing list. Usually more of the devs will respond there.

Great job.
Back to top  
 
       vtiger Forum Index -> Developer Forum - 5.0.2
Page 1 of 1


Powered by phpBB Search Engine Indexer
Powered by phpBB 2.0.15 © 2001, 2002 phpBB Group