bug 1221: Put the assurance method independent logic in one place
authorMichael Tänzer <neo@nhng.de>
Mon, 21 Apr 2014 22:17:12 +0000 (00:17 +0200)
committerMichael Tänzer <neo@nhng.de>
Mon, 21 Apr 2014 22:17:12 +0000 (00:17 +0200)
Signed-off-by: Michael Tänzer <neo@nhng.de>
includes/notary.inc.php

index a8ec208..49dc09d 100644 (file)
         */
        function calc_awarded($row)
        {
-               $awarded = intval($row['awarded']);
-               if (intval($row['points']) < $awarded)
-                       $points = $awarded;      // if 'sum of added points' > 100, awarded shows correct value
-               else
-                       $points = intval($row['points']);       // on very old assurances, awarded is '0' instead of correct value
+               // Back in the old days there was no `awarded` column => is now zero,
+               // there the `points` column contained that data
+               $points = max(intval($row['awarded']), intval($row['points']));
+
+               // Set negative points to zero, yes there are such things in the database
+               $points = max($points, 0);
+
                switch ($row['method'])
                {
                        case 'Thawte Points Transfer':    // revoke all Thawte-points     (as per arbitration)
                        default:                                // should never happen ... ;-)
                                $points = 0;
                }
-               if ($points < 0)                                // ignore negative points (bug needs to be fixed)
-                       $points = 0;
+
                return $points;
        }