Fixing the calculation of values. default tip
authorviric@mandarina
Sun, 28 Dec 2008 23:12:28 +0000
changeset 8 971cc5994467
parent 7 c7ff1a59ed84
Fixing the calculation of values.
config/config.php
models/opiniarbo_model.php
views/context.php
--- a/config/config.php	Sun Dec 28 21:15:17 2008 +0000
+++ b/config/config.php	Sun Dec 28 23:12:28 2008 +0000
@@ -11,7 +11,7 @@
 |	http://example.com/
 |
 */
-$config['base_url']	= "http://mandarina/~viric/ci/";
+$config['base_url']	= "/~viric/ci/";
 
 /*
 |--------------------------------------------------------------------------
--- a/models/opiniarbo_model.php	Sun Dec 28 21:15:17 2008 +0000
+++ b/models/opiniarbo_model.php	Sun Dec 28 23:12:28 2008 +0000
@@ -249,27 +249,31 @@
         $this->db->select('asertoj.id,values.id as vid,values.value,values.influence');
         $this->db->from('values');
         $this->db->join('asertoj','values.assertion = asertoj.id');
+        $this->db->where('values.user', $user);
         $this->db->where('asertoj.parent',$parent);
-        $this->db->where('values.user', $user);
         $query = $this->db->get();
 
         $val = NULL;
-        if ($parent != NULL)
+        if ($query->num_rows() > 0)
         {
-            if ($query->num_rows() > 0)
-            {
-                $qresult = $query->result_array();
+            $qresult = $query->result_array();
 
-                $sum_influence = 0;
+            $sum_influence = 0.;
 
-                foreach($qresult as $row)
-                {
-                    $sum_influence += abs($row['influence']);
-                }
+            foreach($qresult as $row)
+            {
+                $sum_influence += abs($row['influence']);
+            }
 
-                // Calculate the calc_value
-                $val = 0;
-                foreach($qresult as $row)
+            // Calculate the calc_value
+            $val = 0;
+
+            foreach($qresult as $row)
+            {
+                // for $parent == NULL we only need the recursive call.
+                // the $row['influence'] will have no meaning in a head assertion,
+                // so we avoid the division_by_zero error writting a special case.
+                if ($parent != NULL)
                 {
                     if ($row['influence'] >= 0)
                         $val += $row['influence'] * $this->get_user_calc_value($user,
@@ -278,8 +282,13 @@
                         $val += $row['influence'] * ($this->get_user_calc_value($user,
                             $row['id'], $row['value']) - 1) / $sum_influence;
                 }
+                else
+                    $this->get_user_calc_value($user, $row['id'], $row['value']);
             }
+        }
 
+        if ($parent != NULL)
+        {
             // Set the NULL calc_value to those without subassertions,
             // and the proper value to those with subassertions.
             $query2 = $this->db->where('assertion', $parent);
--- a/views/context.php	Sun Dec 28 21:15:17 2008 +0000
+++ b/views/context.php	Sun Dec 28 23:12:28 2008 +0000
@@ -1,2 +1,2 @@
 <h3><?=lang("context_str");?></h3>
-<pre><?=$context?></pre>
+<?=$context?>