k_neurons fix & small warnings removed
[mirrors/Kyberia-bloodline.git] / wwwroot / backend / mysql / backend.inc
index 71c3936226d32338bb6f79b25bcd53795efe07f6..87e1d2d744bd09297fafed0b8050e5eb81d66d78 100644 (file)
@@ -75,11 +75,10 @@ function addNode($params) {
         }
 
         $parent_permissions=permissions::checkPerms($parent_id);
-       print_r($parent_permissions);
+
         if (!$parent_permissions['w']) {
                 $error=$error_messages['WRITE_PERMISSION_ERROR'];
                 logger::log('add','error','WRITE_PERMISSION_ERROR');
-                die("trralalala1");
                 return false;
         }
 
@@ -342,4 +341,52 @@ function getKNeurons($user_id,$interval) {
        return $k_array;
 }
 
+// setSynapse
+
+// Set synapse weight. 
+// If synapse does not exists, create a new one.
+// Secure.
+// Returns true on sucess, otherwise false.
+
+function setSynapse($params){
+       global $db,$node,$error,$error_messages;
+
+       // security check
+       if ((!is_numeric($params['src'])) 
+               or (!is_numeric($params['dst']))
+               or (!is_numeric($params['weight']))) {
+
+               return false;
+       }
+
+       $src=$params['src'];
+       $dst=$params['dst'];
+       $weight=$params['weight'];
+
+       // weight could be only positive
+       if ( $weight < 0) {
+               return false;
+       }
+
+       // if already exists
+       $q="select count(src) from neurons where dst ='$dst' and src = '$src'";
+       $set=$db->query($q);
+       $set->next();
+       $isrc=$set->getString('count(src)');
+
+       if ( $isrc > 0 ) {
+               $q="update neurons set synapse_weight='$weight' 
+                       where dst = '$dst' and src = '$src'";
+       } else { 
+               // FIXME no vector set
+               $q="insert into neurons values('$weight','$dst','$src',0,'synapse',
+                                               CURRENT_TIMESTAMP(),now(),NULL,$src)";
+       }
+       $set=$db->query($q);
+
+       return true;
+}
+
+
+
 }
This page took 0.115669 seconds and 4 git commands to generate.