models/opiniarbo_model.php
changeset 4 fcb273554da6
parent 3 f3e55c2386a1
child 5 cb13c07e7e5d
equal deleted inserted replaced
3:f3e55c2386a1 4:fcb273554da6
   205         return $query->result();
   205         return $query->result();
   206     }
   206     }
   207 
   207 
   208     function recalc_user_influences($user,$parent)
   208     function recalc_user_influences($user,$parent)
   209     {
   209     {
   210         $this->db->select('values.id,values.influence');
   210         $this->db->select('values.id as vid,asertoj.id,values.influence');
   211         $this->db->from('values');
   211         $this->db->from('values');
   212         $this->db->join('asertoj','values.assertion = asertoj.id');
   212         $this->db->join('asertoj','values.assertion = asertoj.id');
   213         $this->db->where('asertoj.parent',$parent);
   213         $this->db->where('asertoj.parent',$parent);
   214         $this->db->where('values.user', $user);
   214         $this->db->where('values.user', $user);
   215         $query = $this->db->get();
   215         $query = $this->db->get();
   233             foreach($qresult as $row)
   233             foreach($qresult as $row)
   234             {
   234             {
   235                 if ($parent != NULL)
   235                 if ($parent != NULL)
   236                 {
   236                 {
   237                     $newinfluence = $row['influence'] / $sum_influence;
   237                     $newinfluence = $row['influence'] / $sum_influence;
   238                     $query2 = $this->db->where('id', $row['id']);
   238                     $query2 = $this->db->where('id', $row['vid']);
   239                     $query2->update('values', array(
   239                     $query2->update('values', array(
   240                                 'influence' => $newinfluence));
   240                                 'influence' => $newinfluence));
   241                 }
   241                 }
   242                 $this->recalc_user_influences($user,$row['id']);
   242                 $this->recalc_user_influences($user,$row['id']);
   243             }
   243             }
   244         }
   244         }
   245     }
   245     }
   246 
   246 
   247     function get_user_calc_value($user, $parent, $orig_value)
   247     function get_user_calc_value($user, $parent, $orig_value)
   248     {
   248     {
   249         $this->db->select('values.id,values.value,values.influence');
   249         $this->db->select('asertoj.id,values.id as vid,values.value,values.influence');
   250         $this->db->from('values');
   250         $this->db->from('values');
   251         $this->db->join('asertoj','values.assertion = asertoj.id');
   251         $this->db->join('asertoj','values.assertion = asertoj.id');
   252         $this->db->where('asertoj.parent',$parent);
   252         $this->db->where('asertoj.parent',$parent);
   253         $this->db->where('values.user', $user);
   253         $this->db->where('values.user', $user);
   254         $query = $this->db->get();
   254         $query = $this->db->get();
   276 
   276 
   277         // Set the NULL calc_value to those without subassertions,
   277         // Set the NULL calc_value to those without subassertions,
   278         // and the proper value to those with subassertions.
   278         // and the proper value to those with subassertions.
   279         if ($parent != NULL)
   279         if ($parent != NULL)
   280         {
   280         {
   281             $query2 = $this->db->where('id', $parent);
   281             $query2 = $this->db->where('assertion', $parent);
   282             $query2->update('values', array(
   282             $query2 = $this->db->where('user', $user);
   283                         'calc_value' => $val, 'user' => $user));
   283             $query2->update('values', array('calc_value' => $val));
   284         }
   284         }
   285 
   285 
   286         if ($val == NULL)
   286         if ($val == NULL)
   287             return $orig_value;
   287             return $orig_value;
   288         else
   288         else