/** * Renders a $variable for an $output * * @param string $variable Variable to render * @param string $output 'html': HTML rendering, 'text': TEXT rendering * @param boolean $rounded Round column values ? * @return string|null */ public function renderColumn($variable, $output = 'html', $rounded = false) { $html = $output == 'html'; switch ($variable) { case 'rate': case 'original_rate': case 'tax_amount': $ret = $this->renderItemRate($variable, $html, $rounded); break; case 'first_rate': case 'first_original_rate': case 'first_tax_amount': if (property_exists($this, $variable)) { $ret = cbpaidMoney::getInstance()->renderPrice($this->{$variable}, $this->currency, $html, $rounded); } else { $ret = null; } break; case 'validity_period': if ($this->start_date && $this->stop_date && $this->start_date != '0000-00-00 00:00:00' && $this->stop_date != '0000-00-00 00:00:00') { $startDate = cbFormatDate($this->start_date, 0, false); $stopDate = cbFormatDate($this->stop_date, 0, false); $ret = htmlspecialchars($startDate); if ($startDate != $stopDate) { $ret .= ($html ? ' - ' : ' - ') . htmlspecialchars($stopDate); } } else { $ret = null; } break; case 'tax_rule_id': if ($this->tax_rule_id && is_callable(array('cbpaidTaxRule', 'getInstance'))) { $ret = cbpaidTaxRule::getInstance((int) $this->tax_rule_id)->getShortCode(); } else { $ret = null; } break; case 'ordering': if ($this->payment_item_id) { $paymItem = $this->_paymentBasket->getPaymentItem($this->payment_item_id); if ($paymItem) { $ret = htmlspecialchars($paymItem->ordering); } else { $ret = null; } } else { $ret = null; } break; case 'discount_amount': case 'first_discount_amount': $ret = null; break; case 'quantity': case 'artnum': case 'description': case 'discount_text': default: $ret = htmlspecialchars($this->get($variable)); break; } return $ret; }
/** * Renders a $variable for an $output * * @param string $variable * @param string $output * @param boolean $rounded * @return string|null */ public function renderColumn($variable, $output = 'html', $rounded = false) { $html = $output == 'html'; switch ($variable) { case 'rate': $ret = $this->renderItemRate($html); break; case 'discount_amount': case 'tax_amount': $ret = $this->renderJustItemRates($variable, $html, $rounded); break; case 'first_rate': case 'first_discount_amount': case 'first_tax_amount': $ret = cbpaidMoney::getInstance()->renderPrice($this->{$variable}, $this->currency, $html, $rounded); break; case 'quantity': // removes insignifiant zeros after ., as well as the . itself if no decimals: $matches = null; $matched = preg_match("/^(.+?)[.]?[0]*\$/", $this->get($variable), $matches); $ret = $matched ? $matches[1] : null; break; case 'validity_period': if ($this->start_date && $this->stop_date && $this->start_date != '0000-00-00 00:00:00' && $this->stop_date != '0000-00-00 00:00:00') { $showTime = false; $startDate = cbFormatDate($this->start_date, 1, $showTime); $stopDate = cbFormatDate($this->stop_date, 1, $showTime); $ret = htmlspecialchars($startDate); if ($stopDate && $startDate != $stopDate) { $ret .= ($html ? ' - ' : ' - ') . htmlspecialchars($stopDate); } if ($this->second_stop_date && $this->second_stop_date != '0000-00-00 00:00:00') { $secondStartDate = cbFormatDate($this->_db->getUtcDateTime(cbpaidTimes::getInstance()->strToTime($this->stop_date) + 1), 1, $showTime); $secondStopDate = cbFormatDate($this->second_stop_date, 1, $showTime); $retsecond = htmlspecialchars($secondStartDate) . ($html ? ' - ' : ' - ') . htmlspecialchars($secondStopDate); $ret = sprintf($html ? CBPTXT::Th("%s, then %s") : CBPTXT::T("%s, then %s"), $ret, $retsecond); } } else { $ret = null; } break; case 'tax_rule_id': if ($this->tax_rule_id && is_callable(array('cbpaidTaxRule', 'getInstance'))) { $ret = cbpaidTaxRule::getInstance((int) $this->tax_rule_id)->getShortCode(); } else { $ret = null; } break; case 'original_rate': case 'first_original_rate': $ret = null; break; case 'ordering': case 'artnum': case 'description': case 'discount_text': default: $value = $this->get($variable); if ($value !== null) { $ret = htmlspecialchars($this->get($variable)); } else { $ret = null; } break; } return $ret; }
/** * Integration when a new payment item is added to a basket * * @param string $event * @param cbpaidSomething $something * @param cbpaidPaymentBasket|null $paymentBasket * @param cbpaidPaymentItem $paymentItem */ public function onCPayPaymentItemEvent( $event, /** @noinspection PhpUnusedParameterInspection */ $something, /** @noinspection PhpUnusedParameterInspection */ $paymentBasket, $paymentItem ) { if ( $event == 'addSomethingToBasket' ) { $tax_rule = (int) $paymentItem->getPlanParam( 'tax_rule_id', 0, null ); if ( $tax_rule == 0 ) { $tax_rule = (int) cbpaidTaxRule::getDefaultTaxRuleId(); } $paymentItem->tax_rule_id = $tax_rule; } }