He afegit opinions per usuari.
authorviric@mandarina
Fri, 26 Dec 2008 01:01:11 +0000
changeset 2 7c6c888b2fed
parent 1 f08a11b5d207
child 3 f3e55c2386a1
He afegit opinions per usuari.
controllers/opiniarbo.php
views/arbo.php
--- a/controllers/opiniarbo.php	Thu Dec 25 21:39:19 2008 +0000
+++ b/controllers/opiniarbo.php	Fri Dec 26 01:01:11 2008 +0000
@@ -19,27 +19,51 @@
         if ($mainassert == -1)
         {
             // Managing heads
-            $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('context', 'Context', 'required|min_length[0]');
+            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->form_validation->run())
+                // 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'))
             {
-                $dbdata['assert'] = $this->input->post('text');
-                $dbdata['value'] = $this->input->post('value')/20.+0.5;
-                $dbdata['context'] = $this->input->post('context');
-                $this->opiniarbo_model->insert_assertion($this->aulib->getSessionId(),
-                    $dbdata);
-                $this->opiniarbo_model->recalculate();
+                $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 * 10;
+                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);
         }
         else
@@ -47,21 +71,44 @@
             // Assert chosen
             $parserdata['mainassert'] = $mainassert;
 
-            $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', 'callback__influence_check');
-            $this->form_validation->set_rules('context', 'Context', 'required|min_length[0]');
+            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');
 
-            if ($this->form_validation->run())
+                // 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'))
             {
-                $dbdata['assert'] = $this->input->post('text');
-                $dbdata['value'] = $this->input->post('value')/20. + 0.5;
-                $dbdata['influence'] = $this->input->post('influence')/10.;
-                $dbdata['context'] = $this->input->post('context');
-                $dbdata['parent'] = $mainassert;
-                $this->opiniarbo_model->insert_assertion($this->aulib->getSessionId(),
-                    $dbdata);
-                $this->opiniarbo_model->recalculate();
+                $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'];
--- a/views/arbo.php	Thu Dec 25 21:39:19 2008 +0000
+++ b/views/arbo.php	Fri Dec 26 01:01:11 2008 +0000
@@ -103,9 +103,10 @@
 <th>Aserto
 <th>Ŝanĝi
 {subasserts}
-<?php form_open('opiniarbo/index/{mainassert}'); ?>
+<?php echo form_open('opiniarbo/index/{mainassert}'); ?>
 <input type="hidden" name="mainassert" id="mainassert" value="{parent}">
 <input type="hidden" name="id" id="id" value="{id}">
+<input type="hidden" name="vid" id="vid" value="{vid}">
 <tr>
 <td>{id}
 <td><input type="text" name="value" id="value" value="{value}" maxlength="5" size="3" />
@@ -132,7 +133,7 @@
 <h3>Kunteksto</h3>
 <p><textarea rows="10" cols="50" name="context" id="context"></textarea></p>
 
-<p><input type="submit" name="modify" value="Aldoni"/></p>
+<p><input type="submit" name="add" value="Aldoni"/></p>
 </form>
 
 <p><br />Page rendered in {elapsed_time} seconds</p>