0
|
1 |
<?php
|
|
2 |
|
|
3 |
class Opiniarbo extends Controller {
|
|
4 |
|
1
|
5 |
function Opiniarbo()
|
0
|
6 |
{
|
1
|
7 |
parent::Controller();
|
|
8 |
$this->load->library('form_validation');
|
0
|
9 |
$this->load->library('aulib');
|
|
10 |
$this->load->library('parser');
|
|
11 |
$this->load->helper('form');
|
1
|
12 |
$this->load->model('opiniarbo_model');
|
|
13 |
}
|
0
|
14 |
|
1
|
15 |
function index()
|
|
16 |
{
|
|
17 |
$mainassert = $this->uri->segment(3, -1);
|
|
18 |
$parserdata['logindata'] = $this->aulib->getLoginLink();
|
|
19 |
if ($mainassert == -1)
|
|
20 |
{
|
|
21 |
// Managing heads
|
2
|
22 |
if ($this->input->post('add'))
|
1
|
23 |
{
|
2
|
24 |
$this->form_validation->set_rules('text', 'Aserta teksto', 'required|min_length[1]');
|
|
25 |
$this->form_validation->set_rules('value', 'Valoro', 'callback__value_check');
|
|
26 |
|
|
27 |
// Add the new assertion if added succesfully
|
|
28 |
if ($this->form_validation->run())
|
|
29 |
{
|
|
30 |
$dbdata['assert'] = $this->input->post('text');
|
|
31 |
$dbdata['value'] = $this->input->post('value')/20.+0.5;
|
|
32 |
if ($this->input->post('context'))
|
|
33 |
$dbdata['context'] = $this->input->post('context');
|
|
34 |
$this->opiniarbo_model->insert_assertion($this->aulib->getSessionId(),
|
|
35 |
$dbdata);
|
|
36 |
$this->opiniarbo_model->recalculate($this->aulib->getSessionId());
|
|
37 |
}
|
1
|
38 |
}
|
2
|
39 |
else if ($this->input->post('modify'))
|
|
40 |
{
|
|
41 |
$this->form_validation->set_rules('id', 'Valoro', 'required');
|
|
42 |
$this->form_validation->set_rules('vid', 'Valoro', 'required');
|
|
43 |
$this->form_validation->set_rules('value', 'Valoro', 'callback__value_check');
|
|
44 |
|
|
45 |
// Add the new assertion if added succesfully
|
|
46 |
if ($this->form_validation->run())
|
|
47 |
{
|
|
48 |
$dbdata['assertid'] = $this->input->post('id');
|
|
49 |
$dbdata['valueid'] = $this->input->post('vid');
|
|
50 |
$dbdata['value'] = $this->input->post('value')/20.+0.5;
|
|
51 |
$this->opiniarbo_model->modify_values($this->aulib->getSessionId(),
|
|
52 |
$dbdata);
|
|
53 |
$this->opiniarbo_model->recalculate($this->aulib->getSessionId());
|
|
54 |
}
|
|
55 |
}
|
|
56 |
|
|
57 |
// Show the head assertions
|
1
|
58 |
$parserdata['asserts'] = $this->opiniarbo_model->get_my_heads($this->aulib->getSessionId());
|
|
59 |
foreach($parserdata['asserts'] as &$row)
|
|
60 |
{
|
2
|
61 |
if ($row['value'] != NULL)
|
|
62 |
$row['value'] = ($row['value'] - 0.5) * 20;
|
|
63 |
if ($row['calc_value'] != NULL)
|
|
64 |
$row['calc_value'] = ($row['calc_value'] - 0.5)*20;
|
1
|
65 |
}
|
2
|
66 |
$parserdata['asserts_other'] = $this->opiniarbo_model->get_other_heads($this->aulib->getSessionId());
|
1
|
67 |
$this->parser->parse('arbo_heads', $parserdata);
|
|
68 |
}
|
|
69 |
else
|
|
70 |
{
|
|
71 |
// Assert chosen
|
|
72 |
$parserdata['mainassert'] = $mainassert;
|
|
73 |
|
2
|
74 |
if ($this->input->post('add'))
|
1
|
75 |
{
|
2
|
76 |
$this->form_validation->set_rules('text', 'Aserta teksto', 'required|min_length[1]');
|
|
77 |
$this->form_validation->set_rules('value', 'Valoro', 'callback__value_check');
|
|
78 |
$this->form_validation->set_rules('influence', 'Influo', 'required');
|
|
79 |
|
|
80 |
// Add the subassertion if possible
|
|
81 |
if ($this->form_validation->run())
|
|
82 |
{
|
|
83 |
$dbdata['assert'] = $this->input->post('text');
|
|
84 |
$dbdata['value'] = $this->input->post('value')/20. + 0.5;
|
|
85 |
$dbdata['influence'] = $this->input->post('influence')/10.;
|
|
86 |
if ($this->input->post('context'))
|
|
87 |
$dbdata['context'] = $this->input->post('context');
|
|
88 |
$dbdata['parent'] = $mainassert;
|
|
89 |
$this->opiniarbo_model->insert_assertion($this->aulib->getSessionId(),
|
|
90 |
$dbdata);
|
|
91 |
$this->opiniarbo_model->recalculate($this->aulib->getSessionId());
|
|
92 |
}
|
|
93 |
}
|
|
94 |
else if ($this->input->post('modify'))
|
|
95 |
{
|
|
96 |
$this->form_validation->set_rules('id', 'Valoro', 'required');
|
|
97 |
$this->form_validation->set_rules('vid', 'Valoro', 'required');
|
|
98 |
$this->form_validation->set_rules('value', 'Valoro', 'callback__value_check');
|
|
99 |
$this->form_validation->set_rules('influence', 'Influo', 'required');
|
|
100 |
|
|
101 |
// Modify the values if possible
|
|
102 |
if ($this->form_validation->run())
|
|
103 |
{
|
|
104 |
$dbdata['assertid'] = $this->input->post('id');
|
|
105 |
$dbdata['valueid'] = $this->input->post('vid');
|
|
106 |
$dbdata['value'] = $this->input->post('value')/20.+0.5;
|
|
107 |
$dbdata['influence'] = $this->input->post('influence')/10;
|
|
108 |
$this->opiniarbo_model->modify_values($this->aulib->getSessionId(),
|
|
109 |
$dbdata);
|
|
110 |
$this->opiniarbo_model->recalculate($this->aulib->getSessionId());
|
|
111 |
}
|
1
|
112 |
}
|
|
113 |
$assertdata = $this->opiniarbo_model->get_assert($mainassert, $this->aulib->getSessionId());
|
|
114 |
$parserdata['maintext'] = $assertdata['assert'];
|
|
115 |
$parserdata['mainvalue'] = $assertdata['value'];
|
|
116 |
if ($parserdata['mainvalue'] != NULL)
|
|
117 |
$parserdata['mainvalue'] = ($parserdata['mainvalue'] - 0.5)*20;
|
|
118 |
$parserdata['maininfluence'] = $assertdata['influence'];
|
|
119 |
if ($parserdata['maininfluence'] != NULL)
|
|
120 |
$parserdata['maininfluence'] = $parserdata['maininfluence'] * 10;
|
|
121 |
$parserdata['maincontext'] = $assertdata['context'];
|
|
122 |
$parserdata['maincalc_value'] = $assertdata['calc_value'];
|
|
123 |
if ($parserdata['maincalc_value'] != NULL)
|
|
124 |
$parserdata['maincalc_value'] = ($parserdata['maincalc_value'] - 0.5)*20;
|
|
125 |
|
|
126 |
$parserdata['subasserts'] = $this->opiniarbo_model->get_subasserts($mainassert, $this->aulib->getSessionId());
|
|
127 |
foreach($parserdata['subasserts'] as &$row)
|
|
128 |
{
|
|
129 |
if ($row['value'] != NULL)
|
|
130 |
$row['value'] = ($row['value'] - 0.5) * 20;
|
|
131 |
if ($row['influence'] != NULL)
|
|
132 |
$row['influence'] = $row['influence'] * 10;
|
|
133 |
if ($row['calc_value'] != NULL)
|
|
134 |
$row['calc_value'] = ($row['calc_value'] - 0.5)*20;
|
|
135 |
}
|
|
136 |
|
|
137 |
$parserdata['preasserts'] = $this->opiniarbo_model->get_preasserts($mainassert, $this->aulib->getSessionId());
|
|
138 |
foreach($parserdata['preasserts'] as &$row)
|
|
139 |
{
|
|
140 |
if ($row['value'] != NULL)
|
|
141 |
$row['value'] = ($row['value'] - 0.5) * 20;
|
|
142 |
if ($row['influence'] != NULL)
|
|
143 |
$row['influence'] = $row['influence'] * 10;
|
|
144 |
if ($row['calc_value'] != NULL)
|
|
145 |
$row['calc_value'] = ($row['calc_value'] - 0.5)*20;
|
|
146 |
}
|
|
147 |
$this->parser->parse('arbo', $parserdata);
|
|
148 |
}
|
|
149 |
}
|
|
150 |
|
|
151 |
function recalculate()
|
|
152 |
{
|
|
153 |
$this->opiniarbo_model->recalculate();
|
|
154 |
echo "OK";
|
|
155 |
}
|
|
156 |
|
|
157 |
function _value_check($str)
|
|
158 |
{
|
|
159 |
if (strlen($str) > 0 && $str <= 10.0 && $str >= -10.0)
|
|
160 |
return TRUE;
|
|
161 |
$this->form_validation->set_message("_value_check", "Skribu valoron inter -10 kaj 10");
|
|
162 |
return FALSE;
|
|
163 |
}
|
|
164 |
|
|
165 |
function _influence_check($str)
|
|
166 |
{
|
|
167 |
if (strlen($str) > 0 && $str <= 10.0 && $str >= -10.0)
|
|
168 |
return TRUE;
|
|
169 |
$this->form_validation->set_message("_influence_check", "Skribu influon inter -10 kaj 10");
|
|
170 |
return FALSE;
|
0
|
171 |
}
|
|
172 |
}
|