0
|
1 |
<?php
|
|
2 |
class Opiniarbo_model extends Model {
|
|
3 |
|
|
4 |
function Opiniarbo_model()
|
|
5 |
{
|
|
6 |
parent::Model();
|
|
7 |
}
|
|
8 |
|
|
9 |
function get_my_heads($user)
|
|
10 |
{
|
|
11 |
$query = $this->db->get_where('asertoj',
|
|
12 |
array('user' => $user, 'parent' => NULL));
|
|
13 |
return $query->result();
|
|
14 |
}
|
|
15 |
|
|
16 |
function get_other_heads($user)
|
|
17 |
{
|
|
18 |
$query = $this->db->get_where('asertoj',
|
|
19 |
array('user !=' => $user, 'parent' => NULL));
|
|
20 |
return $query->result();
|
|
21 |
}
|
|
22 |
|
|
23 |
function get_my_subasserts($parent, $user)
|
|
24 |
{
|
|
25 |
$query = $this->db->get_where('asertoj',
|
|
26 |
array('user' => $user,
|
|
27 |
'parent' => $parent));
|
|
28 |
return $query->result();
|
|
29 |
}
|
|
30 |
|
|
31 |
function get_other_subasserts($parent, $user)
|
|
32 |
{
|
|
33 |
$query = $this->db->get_where('asertoj',
|
|
34 |
array('user !=' => $user,
|
|
35 |
'parent' => $parent));
|
|
36 |
return $query->result();
|
|
37 |
}
|
|
38 |
|
|
39 |
function get_calc_value($assert, $orig_value)
|
|
40 |
{
|
|
41 |
$query = $this->db->get_where('asertoj',
|
|
42 |
array('parent' => $assert));
|
|
43 |
|
|
44 |
if ($query->num_rows() > 0)
|
|
45 |
{
|
|
46 |
$val = 0;
|
|
47 |
foreach($query->result() as $row)
|
|
48 |
{
|
|
49 |
$val += get_calc_value($row->id, $row->value);
|
|
50 |
}
|
|
51 |
$query2 = $this->db->where('id', $row->id);
|
|
52 |
$query2->update('asertoj', array(
|
|
53 |
'calc_value' => $val));
|
|
54 |
|
|
55 |
return $val;
|
|
56 |
}
|
|
57 |
|
|
58 |
return $orig_value;
|
|
59 |
}
|
|
60 |
|
|
61 |
function recalculate()
|
|
62 |
{
|
|
63 |
// Get all heads
|
|
64 |
get_calc_value(NULL, 0);
|
|
65 |
}
|
|
66 |
|
|
67 |
function insert_assertion()
|
|
68 |
{
|
|
69 |
if (isset($_POST['parent']))
|
|
70 |
{
|
|
71 |
$data['parent'] = $_POST['parent'];
|
|
72 |
$data['influence'] = $_POST['influence'];
|
|
73 |
}
|
|
74 |
else
|
|
75 |
{
|
|
76 |
$data['parent'] = NULL;
|
|
77 |
$data['influence'] = $_POST['influence'];
|
|
78 |
}
|
|
79 |
$data['assert'] = $_POST['assert'];
|
|
80 |
$data['context'] = $_POST['context'];
|
|
81 |
$data['value'] = float($_POST['value']);
|
|
82 |
}
|
|
83 |
}
|
|
84 |
|
|
85 |
?>
|