ILIAS  trunk Revision v11.0_alpha-1811-gd2d5443e411
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilPollResultsRenderer Class Reference
+ Collaboration diagram for ilPollResultsRenderer:

Public Member Functions

 __construct (int $ref_id, Refinery $refinery, DataFactory $data_factory, UIFactory $ui_factory, UIRenderer $ui_renderer, ilLanguage $lng)
 
 render (ilTemplate $tpl, ilPollResultsHandler $results, int $presentation_mode)
 

Protected Member Functions

 renderStackedChart (ilTemplate $tpl, ilPollResultsHandler $results)
 
 renderBarChart (ilTemplate $tpl, ilPollResultsHandler $results)
 
 htmlSpecialCharsAsEntities (string $string)
 

Protected Attributes

const float SINGLE_BAR_WIDTH = 0.65
 
const string SINGLE_BAR_COLOR = '#4C6586'
 
const float STACKED_BAR_WIDTH = 0.95
 
const array STACKED_BAR_COLORS
 
int $ref_id
 
Refinery $refinery
 
DataFactory $data_factory
 
UIFactory $ui_factory
 
UIRenderer $ui_renderer
 
ilLanguage $lng
 

Detailed Description

Definition at line 28 of file class.ilPollResultsRenderer.php.

Constructor & Destructor Documentation

◆ __construct()

ilPollResultsRenderer::__construct ( int  $ref_id,
Refinery  $refinery,
DataFactory  $data_factory,
UIFactory  $ui_factory,
UIRenderer  $ui_renderer,
ilLanguage  $lng 
)

Definition at line 51 of file class.ilPollResultsRenderer.php.

References $data_factory, $lng, $ref_id, $refinery, $ui_factory, $ui_renderer, ILIAS\Repository\lng(), and ILIAS\Repository\refinery().

58  {
59  $this->ref_id = $ref_id;
60  $this->refinery = $refinery;
61  $this->data_factory = $data_factory;
62  $this->ui_factory = $ui_factory;
63  $this->ui_renderer = $ui_renderer;
64  $this->lng = $lng;
65  }
+ Here is the call graph for this function:

Member Function Documentation

◆ htmlSpecialCharsAsEntities()

ilPollResultsRenderer::htmlSpecialCharsAsEntities ( string  $string)
protected

Definition at line 155 of file class.ilPollResultsRenderer.php.

References ILIAS\Repository\refinery().

Referenced by renderBarChart(), and renderStackedChart().

155  : string
156  {
157  return $this->refinery->encode()->htmlSpecialCharsAsEntities()->transform(nl2br($string));
158  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ render()

ilPollResultsRenderer::render ( ilTemplate  $tpl,
ilPollResultsHandler  $results,
int  $presentation_mode 
)

Definition at line 67 of file class.ilPollResultsRenderer.php.

References renderBarChart(), renderStackedChart(), and ilObjPoll\SHOW_RESULTS_AS_STACKED_CHART.

71  : void {
72  if ($presentation_mode === ilObjPoll::SHOW_RESULTS_AS_STACKED_CHART) {
73  $this->renderStackedChart($tpl, $results);
74  } else {
75  $this->renderBarChart($tpl, $results);
76  }
77  }
const int SHOW_RESULTS_AS_STACKED_CHART
renderStackedChart(ilTemplate $tpl, ilPollResultsHandler $results)
renderBarChart(ilTemplate $tpl, ilPollResultsHandler $results)
+ Here is the call graph for this function:

◆ renderBarChart()

ilPollResultsRenderer::renderBarChart ( ilTemplate  $tpl,
ilPollResultsHandler  $results 
)
protected

Definition at line 129 of file class.ilPollResultsRenderer.php.

References $id, ilPollResultsHandler\getAnswerPercentage(), ilPollResultsHandler\getAnswerText(), ilPollResultsHandler\getAnswerTotal(), ilPollResultsHandler\getOrderedAnswerIds(), htmlSpecialCharsAsEntities(), ILIAS\Repository\lng(), and HTML_Template_IT\setVariable().

Referenced by render().

132  : void {
133  $votes_label = $this->lng->txt('poll_chart_votes');
134  $c_dimension = $this->data_factory->dimension()->cardinal();
135  $dataset = $this->data_factory->dataset([$votes_label => $c_dimension]);
136 
137  foreach ($results->getOrderedAnswerIds() as $id) {
138  $label = $this->htmlSpecialCharsAsEntities($results->getAnswerText($id));
139  $total_votes = $results->getAnswerTotal($id);
140  $tooltip = $total_votes . ' (' . round($results->getAnswerPercentage($id)) . '%)';
141  $dataset = $dataset->withPoint($label, [$votes_label => $total_votes])
142  ->withAlternativeInformation($label, [$votes_label => $tooltip]);
143  }
144 
145  $bar_config = new BarConfig();
146  $bar_config = $bar_config->withColor($this->data_factory->color(self::SINGLE_BAR_COLOR))
147  ->withRelativeWidth(self::SINGLE_BAR_WIDTH);
148  $chart = $this->ui_factory->chart()->bar()->horizontal('', $dataset)
149  ->withTitleVisible(false)
150  ->withLegendVisible(false)
151  ->withBarConfigs([$votes_label => $bar_config]);
152  $tpl->setVariable('CHART', $this->ui_renderer->render($chart));
153  }
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ renderStackedChart()

ilPollResultsRenderer::renderStackedChart ( ilTemplate  $tpl,
ilPollResultsHandler  $results 
)
protected

Definition at line 79 of file class.ilPollResultsRenderer.php.

References $id, ilPollResultsHandler\getAnswerPercentage(), ilPollResultsHandler\getAnswerText(), ilPollResultsHandler\getAnswerTotal(), ilPollResultsHandler\getOrderedAnswerIds(), htmlSpecialCharsAsEntities(), ILIAS\Repository\lng(), and HTML_Template_IT\setVariable().

Referenced by render().

82  : void {
83  $votes_label = $this->lng->txt('poll_chart_votes');
84  $c_dimension = $this->data_factory->dimension()->cardinal();
85 
86  $dimensions = [];
87  $data_values = [];
88  $bar_configs = [];
89  $tooltips = [];
90  $color_index = 0;
91  foreach ($results->getOrderedAnswerIds() as $id) {
92  $label = $this->htmlSpecialCharsAsEntities($results->getAnswerText($id));
93  $total_votes = $results->getAnswerTotal($id);
94  $tooltip = $total_votes . ' (' . round($results->getAnswerPercentage($id)) . '%)';
95  $bar_config = new BarConfig();
96 
97  $dimensions[$label] = $c_dimension;
98  $data_values[$label] = $total_votes;
99  $bar_configs[$label] = $bar_config->withColor(
100  $this->data_factory->color(self::STACKED_BAR_COLORS[$color_index])
101  )->withRelativeWidth(self::STACKED_BAR_WIDTH);
102  $tooltips[$label] = $tooltip;
103 
104  $color_index = ($color_index + 1) >= count(self::STACKED_BAR_COLORS) ? 0 : ($color_index + 1);
105  }
106 
107  $dimension_group = $this->data_factory->dimension()->group();
108  $dataset = $this->data_factory->dataset(
109  $dimensions,
110  ['stacked' => $this->data_factory->dimension()->group(...array_keys($dimensions))]
111  )->withPoint(
112  $votes_label,
113  $data_values
114  )->withAlternativeInformation(
115  $votes_label,
116  $tooltips
117  );
118 
119  $group_config = new GroupConfig();
120  $group_config = $group_config->withStacked(true);
121  $chart = $this->ui_factory->chart()->bar()->horizontal('', $dataset)
122  ->withTitleVisible(false)
123  ->withLegendVisible(true)
124  ->withBarConfigs($bar_configs)
125  ->withGroupConfigs(['stacked' => $group_config]);
126  $tpl->setVariable('CHART', $this->ui_renderer->render($chart));
127  }
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $data_factory

DataFactory ilPollResultsRenderer::$data_factory
protected

Definition at line 46 of file class.ilPollResultsRenderer.php.

Referenced by __construct().

◆ $lng

ilLanguage ilPollResultsRenderer::$lng
protected

Definition at line 49 of file class.ilPollResultsRenderer.php.

Referenced by __construct().

◆ $ref_id

int ilPollResultsRenderer::$ref_id
protected

Definition at line 44 of file class.ilPollResultsRenderer.php.

Referenced by __construct().

◆ $refinery

Refinery ilPollResultsRenderer::$refinery
protected

Definition at line 45 of file class.ilPollResultsRenderer.php.

Referenced by __construct().

◆ $ui_factory

UIFactory ilPollResultsRenderer::$ui_factory
protected

Definition at line 47 of file class.ilPollResultsRenderer.php.

Referenced by __construct().

◆ $ui_renderer

UIRenderer ilPollResultsRenderer::$ui_renderer
protected

Definition at line 48 of file class.ilPollResultsRenderer.php.

Referenced by __construct().

◆ SINGLE_BAR_COLOR

const string ilPollResultsRenderer::SINGLE_BAR_COLOR = '#4C6586'
protected

Definition at line 31 of file class.ilPollResultsRenderer.php.

◆ SINGLE_BAR_WIDTH

const float ilPollResultsRenderer::SINGLE_BAR_WIDTH = 0.65
protected

Definition at line 30 of file class.ilPollResultsRenderer.php.

◆ STACKED_BAR_COLORS

const array ilPollResultsRenderer::STACKED_BAR_COLORS
protected
Initial value:
= [
'#35485F',
'#F06B05',
'#374E1D',
'#A18BB6',
'#2C2C2C',
'#3D9FAE',
'#663D00',
'#F75E82'
]

Definition at line 33 of file class.ilPollResultsRenderer.php.

◆ STACKED_BAR_WIDTH

const float ilPollResultsRenderer::STACKED_BAR_WIDTH = 0.95
protected

Definition at line 32 of file class.ilPollResultsRenderer.php.


The documentation for this class was generated from the following file: