0

Is there any way I can set a formatter on models that will convert negative numbers to positive numbers for all numeric fields in the model? I started out by trying to make a propel formatter but I'm not sure what code should go in format and formatOne. I have the following code.

class NegativeFormatter extends PropelFormatter
{
  public function format(PropelPDO $stmt)
  {
    parent::format($stmt);
  }

  public function formatOne(PropelPDO $stmt)
  {
    parent::formatOne($stmt);
  }

  public function isObjectFormatter()
  {
    return true;
  }
}
Chris McKnight
  • 8,540
  • 4
  • 29
  • 31

2 Answers2

0

Use the absolute value function.

Lusitanian
  • 11,012
  • 1
  • 41
  • 38
  • I am already doing that for a few of the fields...but I would have to do that for all 30 or so fields – Chris McKnight Jun 28 '12 at 01:51
  • Ah, I thought you meant you didn't know how to achieve the modification of the numeric value :P I'm not familiar with Propel, so you'll have to keep searching. Good luck! – Lusitanian Jun 28 '12 at 02:25
  • Yeah. Haven't found anything yet except for the propel documentation about formatters – Chris McKnight Jun 28 '12 at 04:22
0

I ended up just doing it manually for now when doing the calculations.

Chris McKnight
  • 8,540
  • 4
  • 29
  • 31