0
|
1 |
<?php
|
|
2 |
|
|
3 |
class Opiniarbo extends Controller {
|
|
4 |
|
3
|
5 |
private $mainassert;
|
|
6 |
private $userid;
|
|
7 |
private $userid2;
|
|
8 |
|
1
|
9 |
function Opiniarbo()
|
0
|
10 |
{
|
1
|
11 |
parent::Controller();
|
|
12 |
$this->load->library('form_validation');
|
0
|
13 |
$this->load->library('aulib');
|
|
14 |
$this->load->library('parser');
|
|
15 |
$this->load->helper('form');
|
1
|
16 |
$this->load->model('opiniarbo_model');
|
|
17 |
}
|
0
|
18 |
|
1
|
19 |
function index()
|
|
20 |
{
|
3
|
21 |
// NEW INDEX
|
|
22 |
// Show users
|
|
23 |
$this->mainassert = $this->uri->segment(3, 0);
|
|
24 |
$this->userid = $this->aulib->getSessionId();
|
|
25 |
$this->userid2 = $this->uri->segment(4, 0);
|
2
|
26 |
|
3
|
27 |
// If a form told to update userid2, do it
|
|
28 |
if ($this->input->post('other_user'))
|
|
29 |
{
|
|
30 |
$this->userid2 = $this->input->post('other_user');
|
|
31 |
}
|
|
32 |
$this->load->view('page_head');
|
|
33 |
$this->_show_users();
|
|
34 |
if ($this->userid == 0)
|
|
35 |
{
|
|
36 |
// No user logged in
|
|
37 |
}
|
|
38 |
else if ($this->mainassert == 0)
|
|
39 |
{
|
|
40 |
$this->_process_new_assertion(NULL);
|
|
41 |
$this->_show_assertions(NULL, "Bazaj asertoj");
|
|
42 |
$this->_form_new_assertion(NULL, "Nova baza aserto");
|
1
|
43 |
}
|
|
44 |
else
|
|
45 |
{
|
3
|
46 |
$this->_process_new_assertion($this->mainassert);
|
|
47 |
$this->_show_preassertions($this->mainassert);
|
|
48 |
$this->_show_assertion($this->mainassert);
|
|
49 |
$this->_show_assertions($this->mainassert, "Subasertoj");
|
|
50 |
$this->_form_new_assertion($this->mainassert, "Nova subaserto");
|
1
|
51 |
}
|
3
|
52 |
$this->load->view('page_bottom');
|
1
|
53 |
}
|
|
54 |
|
|
55 |
function recalculate()
|
|
56 |
{
|
|
57 |
$this->opiniarbo_model->recalculate();
|
|
58 |
echo "OK";
|
|
59 |
}
|
|
60 |
|
|
61 |
function _value_check($str)
|
|
62 |
{
|
|
63 |
if (strlen($str) > 0 && $str <= 10.0 && $str >= -10.0)
|
|
64 |
return TRUE;
|
|
65 |
$this->form_validation->set_message("_value_check", "Skribu valoron inter -10 kaj 10");
|
|
66 |
return FALSE;
|
|
67 |
}
|
|
68 |
|
|
69 |
function _influence_check($str)
|
|
70 |
{
|
|
71 |
if (strlen($str) > 0 && $str <= 10.0 && $str >= -10.0)
|
|
72 |
return TRUE;
|
|
73 |
$this->form_validation->set_message("_influence_check", "Skribu influon inter -10 kaj 10");
|
|
74 |
return FALSE;
|
0
|
75 |
}
|
3
|
76 |
|
|
77 |
function _show_users()
|
|
78 |
{
|
|
79 |
$viewdata['assertionid'] = $this->mainassert;
|
|
80 |
$viewdata['other_user'] = $this->userid2;
|
|
81 |
$viewdata['other_user_name'] = $this->opiniarbo_model->get_user_name($this->userid2);
|
|
82 |
$viewdata['other_users'] = array_merge(array(array('id' => 0, 'name' => 'Neniu')),
|
|
83 |
$this->opiniarbo_model->get_other_users($this->userid));
|
|
84 |
$viewdata['loginlink'] = $this->aulib->getLoginLink();
|
|
85 |
$this->load->view('users', $viewdata);
|
|
86 |
}
|
|
87 |
|
|
88 |
function _show_preassertions($id)
|
|
89 |
{
|
|
90 |
$viewdata['title'] = "Antaŭasertoj";
|
|
91 |
$viewdata['assertionid'] = $this->mainassert;
|
|
92 |
$viewdata['other_user'] = $this->userid2;
|
|
93 |
$viewdata['user_name'] = $this->opiniarbo_model->get_user_name($this->userid);
|
|
94 |
$viewdata['other_user_name'] = $this->opiniarbo_model->get_user_name($this->userid2);
|
|
95 |
|
|
96 |
// Show the assertions
|
|
97 |
$viewdata['assertions'] = $this->opiniarbo_model->get_preassertions($this->userid, $this->userid2, $id);
|
|
98 |
|
|
99 |
if (count($viewdata['assertions']) > 0 )
|
|
100 |
{
|
|
101 |
foreach($viewdata['assertions'] as &$row)
|
|
102 |
{
|
|
103 |
if (isset($row['value1']))
|
|
104 |
$row['value1'] = ($row['value1'] - 0.5) * 20;
|
|
105 |
if (isset($row['calc_value1']))
|
|
106 |
$row['calc_value1'] = ($row['calc_value1'] - 0.5)*20;
|
|
107 |
if (isset($row['value2']))
|
|
108 |
$row['value2'] = ($row['value2'] - 0.5) * 20;
|
|
109 |
if (isset($row['calc_value2']))
|
|
110 |
$row['calc_value2'] = ($row['calc_value2'] - 0.5)*20;
|
|
111 |
if ($row['parent'] != NULL)
|
|
112 |
$viewdata['show_influences'] = TRUE;
|
|
113 |
}
|
|
114 |
$this->load->view('assertions', $viewdata);
|
|
115 |
}
|
|
116 |
}
|
|
117 |
|
|
118 |
function _show_assertion($id)
|
|
119 |
{
|
|
120 |
$viewdata['title'] = "Ĉefa asserto";
|
|
121 |
$viewdata['assertionid'] = $this->mainassert;
|
|
122 |
$viewdata['other_user'] = $this->userid2;
|
|
123 |
$viewdata['user_name'] = $this->opiniarbo_model->get_user_name($this->userid);
|
|
124 |
$viewdata['other_user_name'] = $this->opiniarbo_model->get_user_name($this->userid2);
|
|
125 |
$viewdata['assertions'] = array($this->opiniarbo_model->get_assertion($this->userid, $this->userid2, $id));
|
|
126 |
foreach($viewdata['assertions'] as &$row)
|
|
127 |
{
|
|
128 |
if (isset($row['value1']))
|
|
129 |
$row['value1'] = ($row['value1'] - 0.5) * 20;
|
|
130 |
if (isset($row['calc_value1']))
|
|
131 |
$row['calc_value1'] = ($row['calc_value1'] - 0.5)*20;
|
|
132 |
if (isset($row['value2']))
|
|
133 |
$row['value2'] = ($row['value2'] - 0.5) * 20;
|
|
134 |
if (isset($row['calc_value2']))
|
|
135 |
$row['calc_value2'] = ($row['calc_value2'] - 0.5)*20;
|
|
136 |
}
|
|
137 |
$viewdata['context'] = $viewdata['assertions'][0]['context'];
|
|
138 |
if ($viewdata['assertions'][0]['parent'] != NULL)
|
|
139 |
$viewdata['show_influences'] = TRUE;
|
|
140 |
$this->load->view('assertions', $viewdata);
|
|
141 |
$this->load->view('context', $viewdata);
|
|
142 |
}
|
|
143 |
|
|
144 |
function _show_assertions($parent, $title)
|
|
145 |
{
|
|
146 |
if ($parent != NULL)
|
|
147 |
{
|
|
148 |
$viewdata['show_influences'] = TRUE;
|
|
149 |
}
|
|
150 |
$viewdata['title'] = $title;
|
|
151 |
$viewdata['assertionid'] = $this->mainassert;
|
|
152 |
$viewdata['other_user'] = $this->userid2;
|
|
153 |
$viewdata['user_name'] = $this->opiniarbo_model->get_user_name($this->userid);
|
|
154 |
$viewdata['other_user_name'] = $this->opiniarbo_model->get_user_name($this->userid2);
|
|
155 |
|
|
156 |
// Show the assertions
|
|
157 |
$viewdata['assertions'] = $this->opiniarbo_model->get_assertions($this->userid, $this->userid2, $parent);
|
|
158 |
|
|
159 |
if (count($viewdata['assertions']) > 0 )
|
|
160 |
{
|
|
161 |
foreach($viewdata['assertions'] as &$row)
|
|
162 |
{
|
|
163 |
if (isset($row['value1']))
|
|
164 |
$row['value1'] = ($row['value1'] - 0.5) * 20;
|
|
165 |
if (isset($row['influence1']))
|
|
166 |
$row['influence1'] = $row['influence1']*10;
|
|
167 |
if (isset($row['calc_value1']))
|
|
168 |
$row['calc_value1'] = ($row['calc_value1'] - 0.5)*20;
|
|
169 |
if (isset($row['value2']))
|
|
170 |
$row['value2'] = ($row['value2'] - 0.5) * 20;
|
|
171 |
if (isset($row['influence2']))
|
|
172 |
$row['influence2'] = $row['influence2']*10;
|
|
173 |
if (isset($row['calc_value2']))
|
|
174 |
$row['calc_value2'] = ($row['calc_value2'] - 0.5)*20;
|
|
175 |
}
|
|
176 |
$this->load->view('assertions', $viewdata);
|
|
177 |
}
|
|
178 |
}
|
|
179 |
|
|
180 |
function _process_new_assertion($parent)
|
|
181 |
{
|
|
182 |
if ($this->input->post('add'))
|
|
183 |
{
|
|
184 |
$this->form_validation->set_rules('text', 'Aserta teksto', 'required|min_length[1]');
|
|
185 |
$this->form_validation->set_rules('value', 'Valoro', 'callback__value_check');
|
|
186 |
if ($this->input->post('parent'))
|
|
187 |
$this->form_validation->set_rules('influence', 'Influo', 'required');
|
|
188 |
|
|
189 |
// Add the subassertion if possible
|
|
190 |
if ($this->form_validation->run())
|
|
191 |
{
|
|
192 |
$dbdata['assert'] = $this->input->post('text');
|
|
193 |
$dbdata['value'] = $this->input->post('value')/20. + 0.5;
|
|
194 |
if ($this->input->post('parent'))
|
|
195 |
$dbdata['influence'] = $this->input->post('influence')/10.;
|
|
196 |
if ($this->input->post('context'))
|
|
197 |
$dbdata['context'] = $this->input->post('context');
|
|
198 |
$dbdata['parent'] = $this->mainassert;
|
|
199 |
$this->opiniarbo_model->insert_assertion($this->aulib->getSessionId(),
|
|
200 |
$dbdata);
|
|
201 |
$this->opiniarbo_model->recalculate($this->aulib->getSessionId());
|
|
202 |
}
|
|
203 |
}
|
|
204 |
else if ($this->input->post('modify'))
|
|
205 |
{
|
|
206 |
$this->form_validation->set_rules('id', 'Aserto ID', 'required');
|
|
207 |
$this->form_validation->set_rules('vid', 'Valoro ID', 'required');
|
|
208 |
$this->form_validation->set_rules('value', 'Valoro', 'callback__value_check');
|
|
209 |
if ($this->input->post('parent'))
|
|
210 |
$this->form_validation->set_rules('influence', 'Influo', 'required');
|
|
211 |
|
|
212 |
// Modify the values if possible
|
|
213 |
if ($this->form_validation->run())
|
|
214 |
{
|
|
215 |
$dbdata['assertid'] = $this->input->post('id');
|
|
216 |
$dbdata['valueid'] = $this->input->post('vid');
|
|
217 |
$dbdata['value'] = $this->input->post('value')/20.+0.5;
|
|
218 |
if ($this->input->post('parent'))
|
|
219 |
$dbdata['influence'] = $this->input->post('influence')/10;
|
|
220 |
$this->opiniarbo_model->modify_values($this->aulib->getSessionId(),
|
|
221 |
$dbdata);
|
|
222 |
$this->opiniarbo_model->recalculate($this->aulib->getSessionId());
|
|
223 |
}
|
|
224 |
}
|
|
225 |
else if ($this->input->post('delete'))
|
|
226 |
{
|
|
227 |
$this->form_validation->set_rules('vid', 'Valoro ID', 'required');
|
|
228 |
if ($this->form_validation->run())
|
|
229 |
{
|
|
230 |
$dbdata['valueid'] = $this->input->post('vid');
|
|
231 |
$this->opiniarbo_model->remove_value($this->aulib->getSessionId(),
|
|
232 |
$dbdata);
|
|
233 |
$this->opiniarbo_model->recalculate($this->aulib->getSessionId());
|
|
234 |
}
|
|
235 |
}
|
|
236 |
else if ($this->input->post('addvalue'))
|
|
237 |
{
|
|
238 |
$this->form_validation->set_rules('id', 'Valoro', 'required');
|
|
239 |
if ($this->form_validation->run())
|
|
240 |
{
|
|
241 |
$dbdata['assertid'] = $this->input->post('id');
|
|
242 |
$dbdata['value'] = $this->input->post('value')/20.+0.5;
|
|
243 |
if ($this->input->post('parent'))
|
|
244 |
$dbdata['influence'] = $this->input->post('influence')/10;
|
|
245 |
$this->opiniarbo_model->add_value($this->aulib->getSessionId(),
|
|
246 |
$dbdata);
|
|
247 |
$this->opiniarbo_model->recalculate($this->aulib->getSessionId());
|
|
248 |
}
|
|
249 |
}
|
|
250 |
}
|
|
251 |
|
|
252 |
function _form_new_assertion($parent, $title)
|
|
253 |
{
|
|
254 |
if ($parent != NULL)
|
|
255 |
{
|
|
256 |
$viewdata['parent_assertion_id'] = $parent;
|
|
257 |
}
|
|
258 |
$viewdata['title'] = $title;
|
|
259 |
$viewdata['assertionid'] = $this->mainassert;
|
|
260 |
$viewdata['other_user'] = $this->userid2;
|
|
261 |
$this->load->view('new_assertion', $viewdata);
|
|
262 |
}
|
0
|
263 |
}
|