Made multilanguage. Catalan and Russian.
authorviric@mandarina
Sun, 28 Dec 2008 20:48:10 +0000
changeset 5 cb13c07e7e5d
parent 4 fcb273554da6
child 6 8fc19b7bd2dc
Made multilanguage. Catalan and Russian.
config/config.php
controllers/opiniarbo.php
language/kataluna/arbo_lang.php
language/rusa/arbo_lang.php
models/opiniarbo_model.php
views/assertions.php
views/context.php
views/new_assertion.php
views/users.php
--- a/config/config.php	Sun Dec 28 17:20:55 2008 +0000
+++ b/config/config.php	Sun Dec 28 20:48:10 2008 +0000
@@ -11,7 +11,7 @@
 |	http://example.com/
 |
 */
-$config['base_url']	= "http://localhost/~viric/ci/";
+$config['base_url']	= "http://mandarina/~viric/ci/";
 
 /*
 |--------------------------------------------------------------------------
--- a/controllers/opiniarbo.php	Sun Dec 28 17:20:55 2008 +0000
+++ b/controllers/opiniarbo.php	Sun Dec 28 20:48:10 2008 +0000
@@ -13,6 +13,8 @@
         $this->load->library('aulib');
 		$this->load->library('parser');
 		$this->load->helper('form');
+		$this->load->language('arbo','rusa');
+		$this->load->helper('language');
 		$this->load->model('opiniarbo_model');
     }
 
@@ -38,16 +40,16 @@
         else if ($this->mainassert == 0)
         {
             $this->_process_new_assertion(NULL);
-            $this->_show_assertions(NULL, "Bazaj asertoj");
-            $this->_form_new_assertion(NULL, "Nova baza aserto");
+            $this->_show_assertions(NULL, lang("headassertions_str"));
+            $this->_form_new_assertion(NULL, lang("newheadassertion_str"));
         }
         else
         {
             $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->_show_assertions($this->mainassert, lang("subassertions_str"));
+            $this->_form_new_assertion($this->mainassert, lang("newsubassertion_str"));
         }
         $this->load->view('page_bottom');
     }
@@ -79,7 +81,7 @@
         $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')),
+        $viewdata['other_users'] = array_merge(array(array('id' => 0, 'name' => lang('noone_str'))),
             $this->opiniarbo_model->get_other_users($this->userid));
         $viewdata['loginlink'] = $this->aulib->getLoginLink();
         $this->load->view('users', $viewdata);
@@ -117,7 +119,7 @@
 
     function _show_assertion($id)
     {
-        $viewdata['title'] = "Ĉefa asserto";
+        $viewdata['title'] = lang("mainassertion_str");
         $viewdata['assertionid'] = $this->mainassert;
         $viewdata['other_user'] = $this->userid2;
         $viewdata['user_name'] = $this->opiniarbo_model->get_user_name($this->userid);
@@ -162,14 +164,10 @@
             {
                 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;
             }
@@ -184,7 +182,7 @@
             $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');
+                $this->form_validation->set_rules('influence', 'Influo', 'callback__influence_check');
 
             // Add the subassertion if possible
             if ($this->form_validation->run())
@@ -192,10 +190,11 @@
                 $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.;
+                    $dbdata['influence'] = $this->input->post('influence');
                 if ($this->input->post('context'))
                     $dbdata['context'] = $this->input->post('context');
-                $dbdata['parent'] = $this->mainassert;
+                if ($this->mainassert != 0)
+                    $dbdata['parent'] = $this->mainassert;
                 $this->opiniarbo_model->insert_assertion($this->aulib->getSessionId(),
                     $dbdata);
                 $this->opiniarbo_model->recalculate($this->aulib->getSessionId());
@@ -207,7 +206,7 @@
             $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');
+                $this->form_validation->set_rules('influence', 'Influo', 'callback__influence_check');
 
             // Modify the values if possible
             if ($this->form_validation->run())
@@ -216,7 +215,7 @@
                 $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;
+                    $dbdata['influence'] = $this->input->post('influence');
                 $this->opiniarbo_model->modify_values($this->aulib->getSessionId(),
                     $dbdata);
                 $this->opiniarbo_model->recalculate($this->aulib->getSessionId());
@@ -241,7 +240,7 @@
                 $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;
+                    $dbdata['influence'] = $this->input->post('influence');
                 $this->opiniarbo_model->add_value($this->aulib->getSessionId(),
                         $dbdata);
                 $this->opiniarbo_model->recalculate($this->aulib->getSessionId());
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/language/kataluna/arbo_lang.php	Sun Dec 28 20:48:10 2008 +0000
@@ -0,0 +1,23 @@
+<?php
+$lang['context_str'] = "Contexte";
+$lang['subassertions_str'] = "Subafirmacions";
+$lang['headassertions_str'] = "Afirmacions inicials";
+$lang['mainassertion_str'] = "Afirmació principal";
+$lang['value_str'] = "Valor";
+$lang['influence_str'] = "Influència";
+$lang['calculated_str'] = "Calculat";
+$lang['assertion_str'] = "Afirmació";
+$lang['change_str'] = "Canviar";
+$lang['addvalue_str'] = "Opinar";
+$lang['delete_str'] = "Eliminar";
+$lang['newheadassertion_str'] = "Nova afirmació inicial";
+$lang['newsubassertion_str'] = "Nova subafirmació";
+$lang['askassertion_str'] = "Afirmació:";
+$lang['askvalue_str'] = "Valor [-10 en contra, 10 a favor]:";
+$lang['askinfluence_str'] = "Influència [-10 en contra, 10 a favor]:";
+$lang['add_str'] = "Afegir";
+$lang['compared_with_str'] = "Comparat amb";
+$lang['compare_with_str'] = "Comparar amb";
+$lang['users_str'] = "Usuaris";
+$lang['showheadassertions_str'] = "Mostrar les afirmacions inicials";
+$lang['noone_str'] = "Ningú";
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/language/rusa/arbo_lang.php	Sun Dec 28 20:48:10 2008 +0000
@@ -0,0 +1,24 @@
+<?php
+$lang['context_str'] = "Контекст";
+$lang['subassertions_str'] = "Под-утверждения";
+$lang['headassertions_str'] = "Начальные утверждения";
+$lang['mainassertion_str'] = "Данное утверждение";
+$lang['value_str'] = "Значение";
+$lang['influence_str'] = "Влияние";
+$lang['calculated_str'] = "Счёт значения";
+$lang['assertion_str'] = "Утверждение";
+$lang['change_str'] = "Изменить";
+$lang['addvalue_str'] = "Оценить";
+$lang['delete_str'] = "Удалить";
+$lang['newheadassertion_str'] = "Новое начальное утверждение";
+$lang['newsubassertion_str'] = "Новое под-утверждение";
+$lang['askassertion_str'] = "Утверждение:";
+$lang['askvalue_str'] = "Значение [-10 против, 10 за]:";
+$lang['askinfluence_str'] = "Влияние [-10 против, 10 за]:";
+$lang['add_str'] = "Добавить";
+$lang['compared_with_str'] = "Сравнения с";
+$lang['compare_with_str'] = "Сравнить с";
+$lang['users_str'] = "Пользователи";
+$lang['showheadassertions_str'] = "Показывать начальные утверждения";
+$lang['noone_str'] = "Некем";
+$lang['id_str'] = "Ид.";
--- a/models/opiniarbo_model.php	Sun Dec 28 17:20:55 2008 +0000
+++ b/models/opiniarbo_model.php	Sun Dec 28 20:48:10 2008 +0000
@@ -9,7 +9,7 @@
     function get_user_name($userid)
     {
         if ($userid == 0)
-            return "Neniu";
+            return lang("noone_str");
         $this->db->select('id,name');
         $this->db->from('auser');
         $this->db->where('id', $userid);
@@ -253,31 +253,35 @@
         $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.
+        $val = NULL;
         if ($parent != NULL)
         {
+            if ($query->num_rows() > 0)
+            {
+                $qresult = $query->result_array();
+
+                $sum_influence = 0;
+
+                foreach($qresult as $row)
+                {
+                    $sum_influence += abs($row['influence']);
+                }
+
+                // 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']) / $sum_influence;
+                    else
+                        $val += $row['influence'] * ($this->get_user_calc_value($user,
+                            $row['id'], $row['value']) - 1) / $sum_influence;
+                }
+            }
+
+            // Set the NULL calc_value to those without subassertions,
+            // and the proper value to those with subassertions.
             $query2 = $this->db->where('assertion', $parent);
             $query2 = $this->db->where('user', $user);
             $query2->update('values', array('calc_value' => $val));
@@ -292,7 +296,7 @@
     function recalculate($user)
     {
         // Get all heads calculated
-        $this->recalc_user_influences($user, NULL);
+        //$this->recalc_user_influences($user, NULL);
         $this->get_user_calc_value($user, NULL, 0);
     }
 
@@ -322,7 +326,6 @@
 
     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']));
--- a/views/assertions.php	Sun Dec 28 17:20:55 2008 +0000
+++ b/views/assertions.php	Sun Dec 28 20:48:10 2008 +0000
@@ -13,19 +13,19 @@
 <th colspan="<?=$colspan?>"><?=$user_name?>
 <th colspan="<?=$colspan?>"><?=$other_user_name?>
 <tr>
-<th>Id
+<th><?=lang("id_str");?>
 <?php if(isset($show_influences)):?>
-<th>Influo
+<th><?=lang("influence_str")?>
 <?php endif;?>
-<th>Valoro
-<th>Kalkulita
+<th><?=lang("value_str")?>
+<th><?=lang("calculated_str")?>
 <?php if(isset($show_influences)):?>
-<th>Influo
+<th><?=lang("influence_str")?>
 <?php endif;?>
-<th>Valoro
-<th>Kalkulita
-<th>Teksto
-<th>Ŝanĝi
+<th><?=lang("value_str")?>
+<th><?=lang("calculated_str")?>
+<th><?=lang("assertion_str")?>
+<th><?=lang("change_str")?>
 <?php foreach($assertions as $assertion):?>
 <?=form_open("opiniarbo/index/$assertionid/$other_user");?>
 <tr>
@@ -36,7 +36,7 @@
     echo "<td>{$assertion['id']}";
     if(isset($assertion['value1']))
     {
-        $value1 = $assertion['value1'];
+        $value1 = sprintf("%2.2f", $assertion['value1']);
         // We suppose any value1 comes with vid
         echo "<input type=\"hidden\" name=\"vid\" id=\"vid\" value=\"{$assertion['vid']}\">";
     }
@@ -47,18 +47,18 @@
         if (isset($assertion['parent']))
         {
             if(isset($assertion['influence1']))
-                $influence1 = $assertion['influence1'];
+                $influence1 = sprintf("%2.2f", $assertion['influence1']);
             else
                 $influence1 = "";
             echo "<td><input type=\"text\" name=\"influence\" id=\"influence\" value=\"".
-               sprintf("%2.2f", $influence1)."\" maxlength=\"5\" size=\"3\" />";
+               $influence1."\" maxlength=\"5\" size=\"3\" />";
         }
         else
             echo "<td>";
     }
 
     echo "<td><input type=\"text\" name=\"value\" id=\"value\" value=\"".
-        sprintf("%2.2f", $value1)."\" maxlength=\"5\" size=\"3\" />";
+        $value1."\" maxlength=\"5\" size=\"3\" />";
 
     if (isset($assertion['calc_value1']))
         echo "<td>".sprintf("%2.2f", $assertion['calc_value1']);
@@ -70,10 +70,10 @@
         if (isset($assertion['parent']))
         {
             if(isset($assertion['influence2']))
-                $influence2 = $assertion['influence2'];
+                $influence2 = sprintf("%2.2f", $assertion['influence2']);
             else
                 $influence2 = "";
-            echo "<td>".sprintf("%2.2f", $influence2);
+            echo "<td>".$influence2;
         }
         else
             echo "<td>";
@@ -93,10 +93,10 @@
 ?>
 <td>
 <?php  if(isset($assertion['value1'])):?>
-    <input type="submit" name="modify" value="Ŝanĝi"/>
-    <input type="submit" name="delete" value="Forigi"/>
+    <input type="submit" name="modify" value="<?=lang("change_str");?>"/>
+    <input type="submit" name="delete" value="<?=lang("delete_str");?>"/>
 <?php  else:?>
-    <input type="submit" name="addvalue" value="Taksi"/>
+    <input type="submit" name="addvalue" value="<?=lang("addvalue_str");?>"/>
 <?php  endif;?>
 </form>
 <?php endforeach;?>
--- a/views/context.php	Sun Dec 28 17:20:55 2008 +0000
+++ b/views/context.php	Sun Dec 28 20:48:10 2008 +0000
@@ -1,2 +1,2 @@
-<h3>Kunteksto</h3>
+<h3><?=lang("context_str");?></h3>
 <pre><?=$context?></pre>
--- a/views/new_assertion.php	Sun Dec 28 17:20:55 2008 +0000
+++ b/views/new_assertion.php	Sun Dec 28 20:48:10 2008 +0000
@@ -7,15 +7,15 @@
 <?=form_open("opiniarbo/index/$assertionid/$other_user");?>
 <input type="hidden" name="parent" id="parent" value="<?=$assertionid?>">
 <ul>
-<li>Aserto: <input type="text" name="text" id="text" maxlength="500" size="100" />
-<li>Valoro de aserto [-10 falsa, 10 vera]: <input type="text" name="value" id="value" maxlength="5" size="3" />
+<li><?=lang("askassertion_str");?> <input type="text" name="text" id="text" maxlength="500" size="100" />
+<li><?=lang("askvalue_str");?> <input type="text" name="value" id="value" maxlength="5" size="3" />
 <?php if(isset($parent_assertion_id)):?>
-<li>Influo al la patra aserto [-10 mala plena influo, 10 plena influo]: <input type="text" name="influence" id="influence" maxlength="5" size="3" />
+<li><?=lang("askinfluence_str");?> <input type="text" name="influence" id="influence" maxlength="5" size="3" />
 <?php endif;?>
 </ul>
 
-<h3>Kunteksto</h3>
+<h3><?=lang("context_str");?></h3>
 <p><textarea rows="10" cols="50" name="context" id="context"></textarea></p>
 
-<p><input type="submit" name="add" value="Aldoni"/></p>
+<p><input type="submit" name="add" value="<?=lang("add_str");?>"/></p>
 </form>
--- a/views/users.php	Sun Dec 28 17:20:55 2008 +0000
+++ b/views/users.php	Sun Dec 28 20:48:10 2008 +0000
@@ -1,7 +1,7 @@
-<h2>Uzantoj</h2>
+<h2><?=lang("users_str");?></h2>
 <?=$loginlink?>
 
-<h3>Komparite kun <?=$other_user_name?></h3>
+<h3><?=lang("compared_with_str");?> <?=$other_user_name?></h3>
 
 <?=form_open("opiniarbo/index/$assertionid/$other_user"); ?>
     <select name="other_user">
@@ -11,7 +11,7 @@
     else
         echo "<option value=\"{$user['id']}\" selected>{$user['name']}</option>";
     endforeach;?>
-    <input type="submit" name="compare" value="Kompari kun">
+    <input type="submit" name="compare" value="<?=lang("compare_with_str");?>">
 </form>
 
-<?=anchor("opiniarbo/index/0/$other_user",'Montri la bazajn asertojn');
+<?=anchor("opiniarbo/index/0/$other_user",lang("showheadassertions_str"));