Exemplo n.º 1
0
 /**
  * @param Mana_Db_Model_Formula_Context $context
  * @param Mana_Db_Model_Formula_Node_Multiply $formula
  * @throws Mana_Db_Exception_Formula
  * @throws Exception
  * @return Mana_Db_Model_Formula_Expr
  */
 protected function _selectMultiply($context, $formula)
 {
     if ($context->getIsAggregate()) {
         throw new Mana_Db_Exception_Formula($this->__("You can only use aggregate function on aggregate fields"));
     }
     /* @var $formulaHelper Mana_Db_Helper_Formula */
     $formulaHelper = Mage::helper('mana_db/formula');
     $a = $this->_select($context, $formula->a);
     $b = $this->_select($context, $formula->b);
     $this->binaryCast($a, $b);
     switch ($formula->operator) {
         case Mana_Db_Model_Formula_Node_Multiply::MULTIPLY:
             if ($formulaHelper->getType($a->getType()) == 'string') {
                 throw new Mana_Db_Exception_Formula($this->__("'%s' operator is not supported on fields of %s type", '*', 'string'));
             } else {
                 return $this->expr()->setExpr("{$a->getExpr()} * {$b->getExpr()}")->setType($a->getType());
             }
         case Mana_Db_Model_Formula_Node_Multiply::DIVIDE:
             if ($formulaHelper->getType($a->getType()) == 'string') {
                 throw new Mana_Db_Exception_Formula($this->__("'%s' operator is not supported on fields of %s type", '/', 'string'));
             } else {
                 return $this->expr()->setExpr("{$a->getExpr()} / {$b->getExpr()}")->setType($a->getType());
             }
         default:
             throw new Exception('Not implemented');
     }
 }