public static function renderNonEditableStatically($model, $attribute) { if ($model instanceof RedBeanModel && $model->isAttributeFormattedAsProbability($attribute)) { $resolvedValue = NumberUtil::divisionForZero($model->{$attribute}, 100); return Yii::app()->numberFormatter->formatPercentage($resolvedValue); } else { return Yii::app()->numberFormatter->formatDecimal((int) $model->{$attribute}); } }
/** * Renders the attribute from the model. * @return The element's content. */ protected function renderControlNonEditable() { if ($this->model instanceof RedBeanModel && $this->model->isAttributeFormattedAsProbability($this->attribute)) { $resolvedValue = NumberUtil::divisionForZero($this->model->{$this->attribute}, 100); return Yii::app()->numberFormatter->formatPercentage($resolvedValue); } else { return Yii::app()->numberFormatter->formatDecimal((int) $this->model->{$this->attribute}); } }
public function renderDataCellContent($data, $row) { assert('$data instanceof ReportResultsRowData'); if (null === ($displayAttributeKey = $data::resolveKeyByAttributeName($this->attribute))) { return $data->{$this->attribute}; } $displayAttributes = $data->getDisplayAttributes(); $displayAttribute = $displayAttributes[$displayAttributeKey]; $realAttributeName = $displayAttribute->getResolvedAttribute(); if ($data->getModel($this->attribute) instanceof RedBeanModel && $data->getModel($this->attribute)->isAttributeFormattedAsProbability($realAttributeName)) { $resolvedValue = NumberUtil::divisionForZero($data->{$this->attribute}, 100); return Yii::app()->numberFormatter->formatPercentage($resolvedValue); } else { return $this->renderValue($data->{$this->attribute}); } }
public static function renderNonEditableStatically($model, $attribute) { assert('$model instanceof ReportResultsRowData'); if (null === ($displayAttributeKey = $model::resolveKeyByAttributeName($attribute))) { return $model->{$attribute}; } $displayAttributes = $model->getDisplayAttributes(); $displayAttribute = $displayAttributes[$displayAttributeKey]; $realAttributeName = $displayAttribute->getResolvedAttribute(); if ($model->getModel($attribute) instanceof RedBeanModel && $model->getModel($attribute)->isAttributeFormattedAsProbability($realAttributeName)) { $resolvedValue = NumberUtil::divisionForZero($model->{$attribute}, 100); return Yii::app()->numberFormatter->formatPercentage($resolvedValue); } else { return Yii::app()->format->formatNumber((int) $model->{$attribute}); } }
/** * @return array */ public function getChartData() { $chartData = $this->resolveChartDataStructure(); $rows = $this->makeCombinedData(); foreach ($rows as $row) { $chartIndexToCompare = $row[$this->resolveIndexGroupByToUse()]; if (isset($chartData[$chartIndexToCompare])) { $uniqueOpenRate = NumberUtil::divisionForZero($row[self::UNIQUE_OPENS], $row[self::COUNT]); $uniqueClickThroughRate = NumberUtil::divisionForZero($row[self::UNIQUE_CLICKS], $row[self::COUNT]); $chartData[$chartIndexToCompare][self::UNIQUE_OPEN_RATE] = round($uniqueOpenRate * 100, 2); $chartData[$chartIndexToCompare][self::UNIQUE_CLICK_THROUGH_RATE] = round($uniqueClickThroughRate * 100, 2); } } $newChartData = array(); foreach ($chartData as $data) { $newChartData[] = $data; } return $newChartData; }
protected static function renderMetricsContent(Autoresponder $autoresponder) { $dataProvider = new AutoresponderGroupedChartDataProvider($autoresponder); $data = $dataProvider->getChartData(); $sentQuantity = Yii::app()->format->formatNumber((int) $data[MarketingChartDataProvider::SENT]); $openQuantity = Yii::app()->format->formatNumber((int) $data[MarketingChartDataProvider::UNIQUE_OPENS]); $openRate = round(NumberUtil::divisionForZero($openQuantity, $sentQuantity) * 100, 2); $clickQuantity = Yii::app()->format->formatNumber((int) $data[MarketingChartDataProvider::UNIQUE_CLICKS]); $clickRate = round(NumberUtil::divisionForZero($clickQuantity, $sentQuantity) * 100, 2); $unsubscribedQuantity = Yii::app()->format->formatNumber((int) $data[MarketingChartDataProvider::UNSUBSCRIBED]); $unsubscribedRate = round(NumberUtil::divisionForZero($unsubscribedQuantity, $sentQuantity) * 100, 2); $bouncedQuantity = Yii::app()->format->formatNumber((int) $data[MarketingChartDataProvider::BOUNCED]); $bouncedRate = round(NumberUtil::divisionForZero($bouncedQuantity, $sentQuantity) * 100, 2); $content = null; $content .= ZurmoHtml::tag('div', array('class' => 'autoresponder-stats'), Zurmo::t('MarketingModule', '{quantity} sent', array('{quantity}' => ZurmoHtml::tag('strong', array(), $sentQuantity)))); $content .= ZurmoHtml::tag('div', array('class' => 'autoresponder-stats'), Zurmo::t('MarketingModule', '{quantity} opens ({openRate}%)', array('{quantity}' => ZurmoHtml::tag('strong', array(), $openQuantity), '{openRate}' => ZurmoHtml::tag('span', array(), $openRate)))); $content .= ZurmoHtml::tag('div', array('class' => 'autoresponder-stats'), Zurmo::t('MarketingModule', '{quantity} unique clicks ({clickRate}%)', array('{quantity}' => ZurmoHtml::tag('strong', array(), $clickQuantity), '{clickRate}' => ZurmoHtml::tag('span', array(), $clickRate)))); $content .= ZurmoHtml::tag('div', array('class' => 'autoresponder-stats'), Zurmo::t('MarketingModule', '{quantity} Unsubscribed ({unsubscribedRate}%)', array('{quantity}' => ZurmoHtml::tag('strong', array(), $unsubscribedQuantity), '{unsubscribedRate}' => ZurmoHtml::tag('span', array(), $unsubscribedRate)))); $content .= ZurmoHtml::tag('div', array('class' => 'autoresponder-stats'), Zurmo::t('MarketingModule', '{quantity} Bounces ({bouncedRate}%)', array('{quantity}' => ZurmoHtml::tag('strong', array(), $bouncedQuantity), '{bouncedRate}' => ZurmoHtml::tag('span', array(), $bouncedRate)))); return $content; }