Patch to limit testing results in AppDB

Chris Morgan cmorgan at alum.wpi.edu
Wed Jan 25 22:39:01 CST 2006


Oooh a new appdb hacker.  Welcome :-)


>      // Show the Test results for a application version
>      function ShowVersionsTestingTable($iVersionId, $iCurrentTest, $link)
>      {

The maximum number of versions to show should be a parameter to this function.

> -        $hResult = query_appdb("SELECT *
> +    global $showAll;

We don't want to use globals.  Looking at $_REQUEST['showAll'] should work.

> +
> +    $hResult = query_appdb("SELECT *
> +                                FROM testResults
> +                                WHERE versionId = '".$iVersionId."'
> +                                ORDER BY testedDate DESC;");
> +    if(mysql_num_rows($hResult) <= 5 || is_string($showAll))  {
> +        $hResult = query_appdb("SELECT *
>                                  FROM testResults
>                                  WHERE versionId = '".$iVersionId."'
>                                  ORDER BY testedDate DESC;");
> +    }
> +    else{
> +        $hResult = query_appdb("SELECT *
> +                                FROM testResults
> +                                WHERE versionId = '".$iVersionId."'
> +                                ORDER BY testedDate DESC LIMIT 0,5;");
> +    }

This is simplier if you do:

$sQuery = "select * from testResults WHERE versionId = '".$iVersionId."' ORDER 
BY testedDate DESC";

if(!$showAll)
     $sQuery.=" LIMIT 0,"$maxEntries;

It saves a db query and reduces duplicate code.

>          if(!$hResult || mysql_num_rows($hResult) == 0)
>               return;
>          echo '<p><span class="title">Testing Results</span><br />',"\n";
> @@ -379,7 +394,9 @@
>              if ($oTest->iTestingId == $iCurrentTest)
>                  echo '    <td align="center"
> class="color2"><b>Current</b></td>',"\n";
>              else
> -                echo '    <td align="center" class="color2">[<a
> href="'.$link.$oTest->iTestingId.'">Show</a>]</td>',"\n";
> +                echo '    <td align="center" class="color2">[<a
> href="'.$link.$oTest->iTestingId;
> +        if(is_string($showAll)) echo
> '&showAll='.$showAll.'">Show</a>]</td>',"\n";
> +        else echo '">Show</a>]</td>',"\n";
>              echo '    <td>',"\n";
>              echo '<a href="'.BASE.'distributionView.php
> ?iDistributionId='.$oTest->iDistributionId.'">',"\n";
>              echo $oDistribution->sName.'</a>',"\n";
> @@ -393,6 +410,20 @@
>          }
>
>          echo '</table>',"\n";
> +
> +    if(mysql_num_rows($hResult) >= 5 AND !is_string($showAll)) {
> +        echo '<form method=get action="'.$PHP_SELF.'">';
> +        echo '<input name="versionId" type=hidden value="',$iVersionId,'"
> />';
> +        echo '<input class="button" name="showAll" type=submit value="Show
> All Tests" />';
> +        echo '</form>';
> +    }
> +    if(is_string($showAll)) {
> +        echo '<form method=get action="'.$PHP_SELF.'">';
> +        echo '<input name="versionId" type=hidden value="',$iVersionId,'"
> />';
> +        echo '<input class="button" name="hideAll" type=submit
> value="Limit to 5 Tests" />';
> +        echo '</form>';
> +        unset($showAll);
> +    }
>

The common code should be factored out of these conditionals.  The only line 
that differs appears to be the one that generates the form button.


Oh, and can you attach the patch to the email?  It came through as inlined 
here which makes it difficult to save to a file, although maybe I just don't 
know what I'm doing with kmail.

Chris



More information about the wine-devel mailing list