function nodes::GetUserSubmissionsChildren() created, need to write some usefull...
[mirrors/Kyberia-bloodline.git] / wwwroot / backend / mysql / backend.inc
index d65fc9435974553856715eb24066eee25536d861..0dc22dcfe951d351c5c3610d4ad39258274dcfbf 100644 (file)
@@ -181,9 +181,9 @@ function getUserByLogin($login) {
 static function getNodeIdByName($name, $external_link=false) {
        global $db;
 
-       $qh = sprintf('select node_id from nodes where node_name = "%s"', mysql_real_escape_string($name));
+       $qh = sprintf('select node_id from nodes where node_name = "%s"', db_escape_string($name));
        if ($external_link)
-               $qh .= sprintf(' and external_link="%s"', mysql_real_escape_string($external_link));
+               $qh .= sprintf(' and external_link="%s"', db_escape_string($external_link));
 
        $set = $db->query($qh);
        $set->next();
@@ -261,7 +261,7 @@ function getChildrenNodes($orderby="desc",$offset=0,$limit=DEFAULT_LISTING_AMOUN
        $q="select users.*,nodes.* from nodes
 left join users on users.user_id=nodes.node_creator where
 node_parent='$node_handle' order by node_created $orderby LIMIT $offset,$limit";
-       echo $q;
+       #echo $q;
        $result=$db->query($q);
 
        while ($result->next()) {
@@ -273,6 +273,23 @@ node_parent='$node_handle' order by node_created $orderby LIMIT $offset,$limit";
 }
 
 
+function GetUserSubmissionsChildren($user_id,$limit=23,$offset=0,$orderby='') {
+  global $db;
+
+         $q="select users.*,nodes.* from nodes
+left join users on users.user_id=nodes.node_creator where
+node_creator='$user_id' order by node_created $orderby LIMIT $offset,$limit";
+       //$q="select * from nodes LIMIT 10,10";
+  #echo $q;
+  $result=$db->query($q);
+
+  while ($result->next()) {
+    $array[]=addBase36id($result->getRecord());
+  }
+
+  return $array;
+}
+
 function getThreadedChildrenNodes($orderby="desc",$offset=0,$limit=DEFAULT_LISTING_AMOUNT) {
        global $db, $error, $node;
        $node_handle=$node['node_id'];
@@ -341,4 +358,77 @@ 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;
+}
+
+// getSynapseWeight
+
+// If synapse does not exists, weight is 1
+// Secure.
+// Returns synapse weight (from user to node)
+
+function getSynapseWeight($user_id,$node_id){
+       global $db;
+
+       if (!is_numeric($user_id)) 
+               { return -1; }
+       if (!is_numeric($node_id)) 
+               { return -1; }
+
+       $set=$db->query("select synapse_weight from neurons where src =".
+               $user_id." and dst = ".$node_id." and link='synapse'");
+
+       $set->next();
+       $synapse_weight=$set->getString('synapse_weight');
+
+       if (! ($synapse_weight) ) { $synapse_weight = 1;}       
+
+       return $synapse_weight;
+
 }
+}
+
+?>
This page took 0.11859 seconds and 4 git commands to generate.