# HG changeset patch # User viric@mandarina # Date 1230483473 0 # Node ID f3e55c2386a1fae9c2c957b09b557d1a99a737f8 # Parent 7c6c888b2fed5e57264aacb6271867b7acd33bd1 Made multiuser. diff -r 7c6c888b2fed -r f3e55c2386a1 controllers/.opiniarbo.php.swp Binary file controllers/.opiniarbo.php.swp has changed diff -r 7c6c888b2fed -r f3e55c2386a1 controllers/opiniarbo.php --- a/controllers/opiniarbo.php Fri Dec 26 01:01:11 2008 +0000 +++ b/controllers/opiniarbo.php Sun Dec 28 16:57:53 2008 +0000 @@ -2,6 +2,10 @@ class Opiniarbo extends Controller { + private $mainassert; + private $userid; + private $userid2; + function Opiniarbo() { parent::Controller(); @@ -14,138 +18,38 @@ function index() { - $mainassert = $this->uri->segment(3, -1); - $parserdata['logindata'] = $this->aulib->getLoginLink(); - if ($mainassert == -1) - { - // Managing heads - if ($this->input->post('add')) - { - $this->form_validation->set_rules('text', 'Aserta teksto', 'required|min_length[1]'); - $this->form_validation->set_rules('value', 'Valoro', 'callback__value_check'); + // NEW INDEX + // Show users + $this->mainassert = $this->uri->segment(3, 0); + $this->userid = $this->aulib->getSessionId(); + $this->userid2 = $this->uri->segment(4, 0); - // Add the new assertion if added succesfully - if ($this->form_validation->run()) - { - $dbdata['assert'] = $this->input->post('text'); - $dbdata['value'] = $this->input->post('value')/20.+0.5; - if ($this->input->post('context')) - $dbdata['context'] = $this->input->post('context'); - $this->opiniarbo_model->insert_assertion($this->aulib->getSessionId(), - $dbdata); - $this->opiniarbo_model->recalculate($this->aulib->getSessionId()); - } - } - else if ($this->input->post('modify')) - { - $this->form_validation->set_rules('id', 'Valoro', 'required'); - $this->form_validation->set_rules('vid', 'Valoro', 'required'); - $this->form_validation->set_rules('value', 'Valoro', 'callback__value_check'); - - // Add the new assertion if added succesfully - if ($this->form_validation->run()) - { - $dbdata['assertid'] = $this->input->post('id'); - $dbdata['valueid'] = $this->input->post('vid'); - $dbdata['value'] = $this->input->post('value')/20.+0.5; - $this->opiniarbo_model->modify_values($this->aulib->getSessionId(), - $dbdata); - $this->opiniarbo_model->recalculate($this->aulib->getSessionId()); - } - } - - // Show the head assertions - $parserdata['asserts'] = $this->opiniarbo_model->get_my_heads($this->aulib->getSessionId()); - foreach($parserdata['asserts'] as &$row) - { - if ($row['value'] != NULL) - $row['value'] = ($row['value'] - 0.5) * 20; - if ($row['calc_value'] != NULL) - $row['calc_value'] = ($row['calc_value'] - 0.5)*20; - } - $parserdata['asserts_other'] = $this->opiniarbo_model->get_other_heads($this->aulib->getSessionId()); - $this->parser->parse('arbo_heads', $parserdata); + // If a form told to update userid2, do it + if ($this->input->post('other_user')) + { + $this->userid2 = $this->input->post('other_user'); + } + $this->load->view('page_head'); + $this->_show_users(); + if ($this->userid == 0) + { + // No user logged in + } + else if ($this->mainassert == 0) + { + $this->_process_new_assertion(NULL); + $this->_show_assertions(NULL, "Bazaj asertoj"); + $this->_form_new_assertion(NULL, "Nova baza aserto"); } else { - // Assert chosen - $parserdata['mainassert'] = $mainassert; - - if ($this->input->post('add')) - { - $this->form_validation->set_rules('text', 'Aserta teksto', 'required|min_length[1]'); - $this->form_validation->set_rules('value', 'Valoro', 'callback__value_check'); - $this->form_validation->set_rules('influence', 'Influo', 'required'); - - // Add the subassertion if possible - if ($this->form_validation->run()) - { - $dbdata['assert'] = $this->input->post('text'); - $dbdata['value'] = $this->input->post('value')/20. + 0.5; - $dbdata['influence'] = $this->input->post('influence')/10.; - if ($this->input->post('context')) - $dbdata['context'] = $this->input->post('context'); - $dbdata['parent'] = $mainassert; - $this->opiniarbo_model->insert_assertion($this->aulib->getSessionId(), - $dbdata); - $this->opiniarbo_model->recalculate($this->aulib->getSessionId()); - } - } - else if ($this->input->post('modify')) - { - $this->form_validation->set_rules('id', 'Valoro', 'required'); - $this->form_validation->set_rules('vid', 'Valoro', 'required'); - $this->form_validation->set_rules('value', 'Valoro', 'callback__value_check'); - $this->form_validation->set_rules('influence', 'Influo', 'required'); - - // Modify the values if possible - if ($this->form_validation->run()) - { - $dbdata['assertid'] = $this->input->post('id'); - $dbdata['valueid'] = $this->input->post('vid'); - $dbdata['value'] = $this->input->post('value')/20.+0.5; - $dbdata['influence'] = $this->input->post('influence')/10; - $this->opiniarbo_model->modify_values($this->aulib->getSessionId(), - $dbdata); - $this->opiniarbo_model->recalculate($this->aulib->getSessionId()); - } - } - $assertdata = $this->opiniarbo_model->get_assert($mainassert, $this->aulib->getSessionId()); - $parserdata['maintext'] = $assertdata['assert']; - $parserdata['mainvalue'] = $assertdata['value']; - if ($parserdata['mainvalue'] != NULL) - $parserdata['mainvalue'] = ($parserdata['mainvalue'] - 0.5)*20; - $parserdata['maininfluence'] = $assertdata['influence']; - if ($parserdata['maininfluence'] != NULL) - $parserdata['maininfluence'] = $parserdata['maininfluence'] * 10; - $parserdata['maincontext'] = $assertdata['context']; - $parserdata['maincalc_value'] = $assertdata['calc_value']; - if ($parserdata['maincalc_value'] != NULL) - $parserdata['maincalc_value'] = ($parserdata['maincalc_value'] - 0.5)*20; - - $parserdata['subasserts'] = $this->opiniarbo_model->get_subasserts($mainassert, $this->aulib->getSessionId()); - foreach($parserdata['subasserts'] as &$row) - { - if ($row['value'] != NULL) - $row['value'] = ($row['value'] - 0.5) * 20; - if ($row['influence'] != NULL) - $row['influence'] = $row['influence'] * 10; - if ($row['calc_value'] != NULL) - $row['calc_value'] = ($row['calc_value'] - 0.5)*20; - } - - $parserdata['preasserts'] = $this->opiniarbo_model->get_preasserts($mainassert, $this->aulib->getSessionId()); - foreach($parserdata['preasserts'] as &$row) - { - if ($row['value'] != NULL) - $row['value'] = ($row['value'] - 0.5) * 20; - if ($row['influence'] != NULL) - $row['influence'] = $row['influence'] * 10; - if ($row['calc_value'] != NULL) - $row['calc_value'] = ($row['calc_value'] - 0.5)*20; - } - $this->parser->parse('arbo', $parserdata); + $this->_process_new_assertion($this->mainassert); + $this->_show_preassertions($this->mainassert); + $this->_show_assertion($this->mainassert); + $this->_show_assertions($this->mainassert, "Subasertoj"); + $this->_form_new_assertion($this->mainassert, "Nova subaserto"); } + $this->load->view('page_bottom'); } function recalculate() @@ -169,4 +73,191 @@ $this->form_validation->set_message("_influence_check", "Skribu influon inter -10 kaj 10"); return FALSE; } + + function _show_users() + { + $viewdata['assertionid'] = $this->mainassert; + $viewdata['other_user'] = $this->userid2; + $viewdata['other_user_name'] = $this->opiniarbo_model->get_user_name($this->userid2); + $viewdata['other_users'] = array_merge(array(array('id' => 0, 'name' => 'Neniu')), + $this->opiniarbo_model->get_other_users($this->userid)); + $viewdata['loginlink'] = $this->aulib->getLoginLink(); + $this->load->view('users', $viewdata); + } + + function _show_preassertions($id) + { + $viewdata['title'] = "Antaŭasertoj"; + $viewdata['assertionid'] = $this->mainassert; + $viewdata['other_user'] = $this->userid2; + $viewdata['user_name'] = $this->opiniarbo_model->get_user_name($this->userid); + $viewdata['other_user_name'] = $this->opiniarbo_model->get_user_name($this->userid2); + + // Show the assertions + $viewdata['assertions'] = $this->opiniarbo_model->get_preassertions($this->userid, $this->userid2, $id); + + if (count($viewdata['assertions']) > 0 ) + { + foreach($viewdata['assertions'] as &$row) + { + if (isset($row['value1'])) + $row['value1'] = ($row['value1'] - 0.5) * 20; + if (isset($row['calc_value1'])) + $row['calc_value1'] = ($row['calc_value1'] - 0.5)*20; + if (isset($row['value2'])) + $row['value2'] = ($row['value2'] - 0.5) * 20; + if (isset($row['calc_value2'])) + $row['calc_value2'] = ($row['calc_value2'] - 0.5)*20; + if ($row['parent'] != NULL) + $viewdata['show_influences'] = TRUE; + } + $this->load->view('assertions', $viewdata); + } + } + + function _show_assertion($id) + { + $viewdata['title'] = "Ĉefa asserto"; + $viewdata['assertionid'] = $this->mainassert; + $viewdata['other_user'] = $this->userid2; + $viewdata['user_name'] = $this->opiniarbo_model->get_user_name($this->userid); + $viewdata['other_user_name'] = $this->opiniarbo_model->get_user_name($this->userid2); + $viewdata['assertions'] = array($this->opiniarbo_model->get_assertion($this->userid, $this->userid2, $id)); + foreach($viewdata['assertions'] as &$row) + { + if (isset($row['value1'])) + $row['value1'] = ($row['value1'] - 0.5) * 20; + if (isset($row['calc_value1'])) + $row['calc_value1'] = ($row['calc_value1'] - 0.5)*20; + if (isset($row['value2'])) + $row['value2'] = ($row['value2'] - 0.5) * 20; + if (isset($row['calc_value2'])) + $row['calc_value2'] = ($row['calc_value2'] - 0.5)*20; + } + $viewdata['context'] = $viewdata['assertions'][0]['context']; + if ($viewdata['assertions'][0]['parent'] != NULL) + $viewdata['show_influences'] = TRUE; + $this->load->view('assertions', $viewdata); + $this->load->view('context', $viewdata); + } + + function _show_assertions($parent, $title) + { + if ($parent != NULL) + { + $viewdata['show_influences'] = TRUE; + } + $viewdata['title'] = $title; + $viewdata['assertionid'] = $this->mainassert; + $viewdata['other_user'] = $this->userid2; + $viewdata['user_name'] = $this->opiniarbo_model->get_user_name($this->userid); + $viewdata['other_user_name'] = $this->opiniarbo_model->get_user_name($this->userid2); + + // Show the assertions + $viewdata['assertions'] = $this->opiniarbo_model->get_assertions($this->userid, $this->userid2, $parent); + + if (count($viewdata['assertions']) > 0 ) + { + foreach($viewdata['assertions'] as &$row) + { + if (isset($row['value1'])) + $row['value1'] = ($row['value1'] - 0.5) * 20; + if (isset($row['influence1'])) + $row['influence1'] = $row['influence1']*10; + if (isset($row['calc_value1'])) + $row['calc_value1'] = ($row['calc_value1'] - 0.5)*20; + if (isset($row['value2'])) + $row['value2'] = ($row['value2'] - 0.5) * 20; + if (isset($row['influence2'])) + $row['influence2'] = $row['influence2']*10; + if (isset($row['calc_value2'])) + $row['calc_value2'] = ($row['calc_value2'] - 0.5)*20; + } + $this->load->view('assertions', $viewdata); + } + } + + function _process_new_assertion($parent) + { + if ($this->input->post('add')) + { + $this->form_validation->set_rules('text', 'Aserta teksto', 'required|min_length[1]'); + $this->form_validation->set_rules('value', 'Valoro', 'callback__value_check'); + if ($this->input->post('parent')) + $this->form_validation->set_rules('influence', 'Influo', 'required'); + + // Add the subassertion if possible + if ($this->form_validation->run()) + { + $dbdata['assert'] = $this->input->post('text'); + $dbdata['value'] = $this->input->post('value')/20. + 0.5; + if ($this->input->post('parent')) + $dbdata['influence'] = $this->input->post('influence')/10.; + if ($this->input->post('context')) + $dbdata['context'] = $this->input->post('context'); + $dbdata['parent'] = $this->mainassert; + $this->opiniarbo_model->insert_assertion($this->aulib->getSessionId(), + $dbdata); + $this->opiniarbo_model->recalculate($this->aulib->getSessionId()); + } + } + else if ($this->input->post('modify')) + { + $this->form_validation->set_rules('id', 'Aserto ID', 'required'); + $this->form_validation->set_rules('vid', 'Valoro ID', 'required'); + $this->form_validation->set_rules('value', 'Valoro', 'callback__value_check'); + if ($this->input->post('parent')) + $this->form_validation->set_rules('influence', 'Influo', 'required'); + + // Modify the values if possible + if ($this->form_validation->run()) + { + $dbdata['assertid'] = $this->input->post('id'); + $dbdata['valueid'] = $this->input->post('vid'); + $dbdata['value'] = $this->input->post('value')/20.+0.5; + if ($this->input->post('parent')) + $dbdata['influence'] = $this->input->post('influence')/10; + $this->opiniarbo_model->modify_values($this->aulib->getSessionId(), + $dbdata); + $this->opiniarbo_model->recalculate($this->aulib->getSessionId()); + } + } + else if ($this->input->post('delete')) + { + $this->form_validation->set_rules('vid', 'Valoro ID', 'required'); + if ($this->form_validation->run()) + { + $dbdata['valueid'] = $this->input->post('vid'); + $this->opiniarbo_model->remove_value($this->aulib->getSessionId(), + $dbdata); + $this->opiniarbo_model->recalculate($this->aulib->getSessionId()); + } + } + else if ($this->input->post('addvalue')) + { + $this->form_validation->set_rules('id', 'Valoro', 'required'); + if ($this->form_validation->run()) + { + $dbdata['assertid'] = $this->input->post('id'); + $dbdata['value'] = $this->input->post('value')/20.+0.5; + if ($this->input->post('parent')) + $dbdata['influence'] = $this->input->post('influence')/10; + $this->opiniarbo_model->add_value($this->aulib->getSessionId(), + $dbdata); + $this->opiniarbo_model->recalculate($this->aulib->getSessionId()); + } + } + } + + function _form_new_assertion($parent, $title) + { + if ($parent != NULL) + { + $viewdata['parent_assertion_id'] = $parent; + } + $viewdata['title'] = $title; + $viewdata['assertionid'] = $this->mainassert; + $viewdata['other_user'] = $this->userid2; + $this->load->view('new_assertion', $viewdata); + } } diff -r 7c6c888b2fed -r f3e55c2386a1 libraries/aulib.php --- a/libraries/aulib.php Fri Dec 26 01:01:11 2008 +0000 +++ b/libraries/aulib.php Sun Dec 28 16:57:53 2008 +0000 @@ -133,6 +133,14 @@ } /* + * Return TRUE if user has specified role + */ + function getUserName($userid) + { + return $this->obj->aumodel->userInfo($userid, 'name'); + } + + /* * Show "deny access" page */ function denyAccess() diff -r 7c6c888b2fed -r f3e55c2386a1 models/.opiniarbo.php.swp Binary file models/.opiniarbo.php.swp has changed diff -r 7c6c888b2fed -r f3e55c2386a1 models/opiniarbo.php --- a/models/opiniarbo.php Fri Dec 26 01:01:11 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +0,0 @@ -db->get_where('asertoj', - array('user' => $user, 'parent' => NULL)); - return $query->result(); - } - - function get_other_heads($user) - { - $query = $this->db->get_where('asertoj', - array('user !=' => $user, 'parent' => NULL)); - return $query->result(); - } - - function get_my_subasserts($parent, $user) - { - $query = $this->db->get_where('asertoj', - array('user' => $user, - 'parent' => $parent)); - return $query->result(); - } - - function get_other_subasserts($parent, $user) - { - $query = $this->db->get_where('asertoj', - array('user !=' => $user, - 'parent' => $parent)); - return $query->result(); - } - - function get_calc_value($assert, $orig_value) - { - $query = $this->db->get_where('asertoj', - array('parent' => $assert)); - - if ($query->num_rows() > 0) - { - $val = 0; - foreach($query->result() as $row) - { - $val += get_calc_value($row->id, $row->value); - } - $query2 = $this->db->where('id', $row->id); - $query2->update('asertoj', array( - 'calc_value' => $val)); - - return $val; - } - - return $orig_value; - } - - function recalculate() - { - // Get all heads - get_calc_value(NULL, 0); - } - - function insert_assertion() - { - if (isset($_POST['parent'])) - { - $data['parent'] = $_POST['parent']; - $data['influence'] = $_POST['influence']; - } - else - { - $data['parent'] = NULL; - $data['influence'] = $_POST['influence']; - } - $data['assert'] = $_POST['assert']; - $data['context'] = $_POST['context']; - $data['value'] = float($_POST['value']); - } -} - -?> diff -r 7c6c888b2fed -r f3e55c2386a1 models/opiniarbo_model.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/models/opiniarbo_model.php Sun Dec 28 16:57:53 2008 +0000 @@ -0,0 +1,352 @@ +db->select('id,name'); + $this->db->from('auser'); + $this->db->where('id', $userid); + $query = $this->db->get(); + + return $query->row()->name; + } + + function get_other_users($userid) + { + $this->db->select('id,name'); + $this->db->from('auser'); + $this->db->where('id !=', $userid); + $query = $this->db->get(); + + return $query->result_array(); + } + + function get_assertions($userid1, $userid2, $parent) + { + $heads = array(); + // contains: id, assert, value1, value2, calc_value1, calc_value2 + $user1_heads = $this->get_my_heads_values($userid1, $parent); + if ($userid2 != 0) + $user2_heads = $this->get_my_heads_values($userid2, $parent); + else + $user2_heads = array(); + foreach($user1_heads as $row1) + { + $found = FALSE; + foreach($user2_heads as $row2) + { + if($row2['id'] == $row1['id']) + { + $value2 = $row2['value']; + if ($parent != NULL) + $influence2 = $row['influence']; + $calc_value2 = $row2['calc_value']; + $found = TRUE; + break; + } + } + if ($found) + { + $heads[$row1['id']] = array('id' => $row1['id'], + 'vid' => $row1['vid'], + 'text' => $row1['assert'], + 'value1' => $row1['value'], + 'parent' => $row1['parent'], + 'value2' => $value2); + if ($parent != NULL) + { + $heads[$row1['id']] += array('influence1' => $row1['influence']); + $heads[$row1['id']] += array('influence2' => $influence2); + } + if ($row1['calc_value'] != NULL) + $heads[$row1['id']] += array('calc_value1' => $row1['calc_value']); + if ($calc_value2 != NULL) + $heads[$row1['id']] += array('calc_value2' => $calc_value2); + + } + else + { + $heads[$row1['id']] = array('id' => $row1['id'], + 'vid' => $row1['vid'], + 'text' => $row1['assert'], + 'parent' => $row1['parent'], + 'value1' => $row1['value']); + if ($parent != NULL) + { + $heads[$row1['id']] += array('influence1' => $row1['influence']); + } + if ($row1['calc_value'] != NULL) + $heads[$row1['id']] += array('calc_value1' => $row1['calc_value']); + } + } + foreach($user2_heads as $row2) + { + if (!isset($heads[$row2['id']])) + { + $heads[$row2['id']] = array('id' => $row2['id'], + 'text' => $row2['assert'], + 'parent' => $row2['parent'], + 'value2' => $row2['value']); + if ($row2['calc_value'] != NULL) + $heads[$row2['id']] += array('calc_value2' => $row2['calc_value']); + if ($parent != NULL) + { + $heads[$row2['id']] += array('influence2' => $row2['influence']); + } + + } + } + return $heads; + } + + function get_my_heads_values($user, $parent) + { + $this->db->select('asertoj.id,asertoj.assert,asertoj.parent,values.value,values.influence,' + .'values.calc_value, values.id as vid'); + $this->db->from('asertoj'); + $this->db->join('values', 'values.assertion = asertoj.id'); + $this->db->where('values.user', $user); + $this->db->where('asertoj.parent', $parent); + + $query = $this->db->get(); + return $query->result_array(); + } + + function get_assertion($userid1, $userid2, $id) + { + $this->db->select('assert,context,parent'); + $this->db->from('asertoj'); + $this->db->where('id', $id); + $query = $this->db->get(); + $qresult = $query->row_array(); + + $result['id'] = $id; + $result['text'] = $qresult['assert']; + $result['context'] = $qresult['context']; + $result['parent'] = $qresult['parent']; + + $this->db->select('id,value,calc_value,influence'); + $this->db->from('values'); + $this->db->where('assertion', $id); + $this->db->where('user', $userid1); + $query = $this->db->get(); + if ($query->num_rows() > 0) + { + $qresult = $query->row_array(); + $result['vid'] = $qresult['id']; + if ($qresult['value'] != NULL) + $result['value1'] = $qresult['value']; + if ($qresult['influence'] != NULL) + $result['influence1'] = $qresult['influence']; + if ($qresult['calc_value'] != NULL) + $result['calc_value1'] = $qresult['calc_value']; + } + + $this->db->select('value,calc_value,influence'); + $this->db->from('values'); + $this->db->where('assertion', $id); + $this->db->where('user', $userid2); + $query = $this->db->get(); + if ($query->num_rows() > 0) + { + $qresult = $query->row_array(); + if ($qresult['value'] != NULL) + $result['value2'] = $qresult['value']; + if ($qresult['influence'] != NULL) + $result['influence2'] = $qresult['influence']; + if ($qresult['calc_value'] != NULL) + $result['calc_value2'] = $qresult['calc_value']; + } + + return $result; + } + + function get_subasserts($parent, $user) + { + $this->db->select('asertoj.id,asertoj.assert,values.value,' + .'values.calc_value,values.influence, values.id as vid'); + $this->db->from('asertoj'); + $this->db->join('values', 'values.assertion = asertoj.id'); + $this->db->where('values.user', $user); + $this->db->where('asertoj.parent', $parent); + + $query = $this->db->get(); + return $query->result_array(); + } + + function get_preassertions($userid1, $userid2, $id) + { + $result = array(); + do + { + $assertion = $this->get_assertion($userid1, $userid2, $id); + $id = $assertion['parent']; + $result[] = $assertion; + } while($id != NULL); + + // We already show the main assert, so don't need in the preasserts + unset($result[0]); + + return array_reverse($result); + } + + function get_other_subasserts($parent, $user) + { + $query = $this->db->get_where('asertoj', + array('user !=' => $user, + 'parent' => $parent)); + return $query->result(); + } + + function recalc_user_influences($user,$parent) + { + $this->db->select('values.id,values.influence'); + $this->db->from('values'); + $this->db->join('asertoj','values.assertion = asertoj.id'); + $this->db->where('asertoj.parent',$parent); + $this->db->where('values.user', $user); + $query = $this->db->get(); + + // Remap the influences + if ($query->num_rows() > 0) + { + $qresult = $query->result_array(); + + $sum_influence = 0; + + if ($parent != NULL) + { + foreach($qresult as $row) + { + $sum_influence += abs($row['influence']); + } + } + + // Remap as needed between a total of -10 and 10 + foreach($qresult as $row) + { + if ($parent != NULL) + { + $newinfluence = $row['influence'] / $sum_influence; + $query2 = $this->db->where('id', $row['id']); + $query2->update('values', array( + 'influence' => $newinfluence)); + } + $this->recalc_user_influences($user,$row['id']); + } + } + } + + function get_user_calc_value($user, $parent, $orig_value) + { + $this->db->select('values.id,values.value,values.influence'); + $this->db->from('values'); + $this->db->join('asertoj','values.assertion = asertoj.id'); + $this->db->where('asertoj.parent',$parent); + $this->db->where('values.user', $user); + $query = $this->db->get(); + + if ($query->num_rows() > 0) + { + $qresult = $query->result_array(); + + // Calculate the calc_value + $val = 0; + foreach($qresult as $row) + { + if ($row['influence'] >= 0) + $val += $row['influence'] * $this->get_user_calc_value($user, + $row['id'], $row['value']); + else + $val += $row['influence'] * ($this->get_user_calc_value($user, + $row['id'], $row['value']) - 1); + } + } + else + { + $val = NULL; + } + + // Set the NULL calc_value to those without subassertions, + // and the proper value to those with subassertions. + if ($parent != NULL) + { + $query2 = $this->db->where('id', $parent); + $query2->update('values', array( + 'calc_value' => $val, 'user' => $user)); + } + + if ($val == NULL) + return $orig_value; + else + return $val; + } + + function recalculate($user) + { + // Get all heads calculated + $this->recalc_user_influences($user, NULL); + $this->get_user_calc_value($user, NULL, 0); + } + + function insert_assertion($user, $inputdata) + { + $assertdata = array('assert' => $inputdata['assert']); + // concat the 'context', if provided. + if (isset($inputdata['context'])) + $assertdata += array('context' => $inputdata['context']); + // concat the 'parent', if provided. + if (isset($inputdata['parent'])) + $assertdata += array('parent' => $inputdata['parent']); + $this->db->insert('asertoj', $assertdata); + $this->db->select('LAST_INSERT_ID()'); + $query = $this->db->get(); + $lastid = array_values($query->row_array()); + $lastid = $lastid[0]; + + $valuesdata = array('assertion' => $lastid, + 'value' => $inputdata['value'], + 'user' => $user); + // concat the 'influence', if provided. + if (isset($inputdata['influence'])) + $valuesdata += array('influence' => $inputdata['influence']); + $this->db->insert('values', $valuesdata); + } + + function modify_values($user, $inputdata) + { + print_r($inputdata); + $valuesdata = array('value' => $inputdata['value']); + if (isset($inputdata['influence'])) + $valuesdata = array_merge($valuesdata,array('influence' => $inputdata['influence'])); + + $this->db->where('id', $inputdata['valueid']); + $this->db->update('values', $valuesdata); + } + + function remove_value($user, $inputdata) + { + $this->db->where('id', $inputdata['valueid']); + $this->db->delete('values'); + } + + function add_value($user, $inputdata) + { + $valuesdata = array('value' => $inputdata['value']); + $valuesdata += array('assertion' => $inputdata['assertid']); + $valuesdata += array('user' => $user); + if (isset($inputdata['influence'])) + $valuesdata += array('influence' => $inputdata['influence']); + + $this->db->insert('values', $valuesdata); + } +} + +?> diff -r 7c6c888b2fed -r f3e55c2386a1 views/arbo.php --- a/views/arbo.php Fri Dec 26 01:01:11 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,142 +0,0 @@ - - -Opiniarbo - - - - - - - -

Opiniarbo

- -

Uzantoj

- -{logindata} - -

Antaŭasertoj

- - - - - - -
Id -Valoro -Influo -Kalkulita -Teksto -{preasserts} -
{id} -{value} -{influence} -{calc_value} - -{/preasserts} -
- -

Ĉefaserto

- - - - -
Id -Valoro -Influo -Kalkulita -Aserto -
{mainassert} -{mainvalue} -{maininfluence} -{maincalc_value} -{maintext} -
- -

Kunteksto

-

{maincontext}

- -

Subasertoj

- - - - -
Id -Valoro -Influo -Kalkulita -Aserto -Ŝanĝi -{subasserts} - - - - -
{id} - - -{calc_value} - - - -{/subasserts} -
- -

Nova subaserto

- - - - - - - -

Kunteksto

-

- -

- - -


Page rendered in {elapsed_time} seconds

- - - diff -r 7c6c888b2fed -r f3e55c2386a1 views/assertions.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/views/assertions.php Sun Dec 28 16:57:53 2008 +0000 @@ -0,0 +1,99 @@ +$title"; +?> + + + + +";?> +"; + echo "
+ + + +
Id + +Influo + +Valoro +Kalkulita + +Influo + +Valoro +Kalkulita +Teksto +Ŝanĝi + + +
{$assertion['id']}"; + if(isset($assertion['value1'])) + { + $value1 = $assertion['value1']; + // We suppose any value1 comes with vid + echo ""; + } + else + $value1 = ""; + if (isset($show_influences)) + { + if (isset($assertion['parent'])) + { + if(isset($assertion['influence1'])) + $influence1 = $assertion['influence1']; + else + $influence1 = ""; + echo ""; + } + else + echo ""; + } + + echo ""; + + if (isset($assertion['calc_value1'])) + echo "{$assertion['calc_value1']}"; + else + echo ""; + + if (isset($show_influences)) + { + if (isset($assertion['parent'])) + { + if(isset($assertion['influence2'])) + $influence2 = $assertion['influence2']; + else + $influence2 = ""; + echo "{$influence2}"; + } + else + echo ""; + } + + if (isset($assertion['value2'])) + echo "{$assertion['value2']}"; + else + echo ""; + + if (isset($assertion['calc_value2'])) + echo "{$assertion['value2']}"; + else + echo ""; + echo "" . anchor("opiniarbo/index/{$assertion['id']}/{$other_user}", + $assertion['text']); +?> + + + + + + + + + +
diff -r 7c6c888b2fed -r f3e55c2386a1 views/context.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/views/context.php Sun Dec 28 16:57:53 2008 +0000 @@ -0,0 +1,2 @@ +

Kunteksto

+
diff -r 7c6c888b2fed -r f3e55c2386a1 views/new_assertion.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/views/new_assertion.php Sun Dec 28 16:57:53 2008 +0000 @@ -0,0 +1,21 @@ +$title"; +?> + + + + + + + +

Kunteksto

+

+ +

+ diff -r 7c6c888b2fed -r f3e55c2386a1 views/page_bottom.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/views/page_bottom.php Sun Dec 28 16:57:53 2008 +0000 @@ -0,0 +1,4 @@ +


Page rendered in {elapsed_time} seconds

+ + + diff -r 7c6c888b2fed -r f3e55c2386a1 views/page_head.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/views/page_head.php Sun Dec 28 16:57:53 2008 +0000 @@ -0,0 +1,47 @@ + + +Opiniarbo + + + + + + + diff -r 7c6c888b2fed -r f3e55c2386a1 views/users.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/views/users.php Sun Dec 28 16:57:53 2008 +0000 @@ -0,0 +1,17 @@ +

Uzantoj

+ + +

Komparite kun

+ + + + + +