X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;f=wwwroot%2Fbackend%2Fmysql%2Fbackend.inc;h=bdc85152631c56af2cebf295cff829752571a5da;hb=9c833cbaa6b865dda14760b7f448467ec1a912d6;hp=06cea4d3b528546cea63641c005ffedc4756f10f;hpb=ea8ec237eef63c13011de76d414425ce13ce884d;p=mirrors%2FKyberia-bloodline.git diff --git a/wwwroot/backend/mysql/backend.inc b/wwwroot/backend/mysql/backend.inc index 06cea4d..bdc8515 100644 --- a/wwwroot/backend/mysql/backend.inc +++ b/wwwroot/backend/mysql/backend.inc @@ -49,7 +49,7 @@ function putNode($what,$where,$checkpermissions=true) { $nodeshell_vector = $nodeshell['node_vector']; if ($checkpermissions) { - $nodeshell_permissions = permissions::checkPermissions($nodeshell); + $nodeshell_permissions = permissions::checkPerms($nodeshell); if (!$nodeshell_permissions['w']) { $error = $error_messages['WRITE_PERMISSION_ERROR']; return false; @@ -68,11 +68,14 @@ function addNode($params) { global $db,$node,$error,$error_messages; $parent_id=$params['node_parent']; + if ($params['flag']=='registration') $params['node_creator']=UBIK_ID; + if (!is_numeric($parent_id)) { $parent_id=$node['node_id']; } - $parent_permissions=permissions::checkPermissions($parent_id); + $parent_permissions=permissions::checkPerms($parent_id); + if (!$parent_permissions['w']) { $error=$error_messages['WRITE_PERMISSION_ERROR']; logger::log('add','error','WRITE_PERMISSION_ERROR'); @@ -84,11 +87,8 @@ function addNode($params) { $kset->next(); $user_k=$kset->getString('user_k'); - if ($params['flag']=='registration') $params['node_creator']=UBIK_ID; - if (!$user_k && $params['node_creator']!=UBIK_ID) { $error=$error_messages['K_SPENT']; - return false; } @@ -326,19 +326,62 @@ function setParent($node_id,$parent_id) { return 0; } -// XXX TODO -// +// Get nodes sorted by weight_k specific to user -function get_k_neurons($user_id,$interval) { +function getKNeurons($user_id,$interval) { global $db,$node,$error,$error_messages; $q="call k_neurons('$user_id','$interval')"; $set=$db->query($q); -// $set->next(); - return $set; + + while ($set->next()) { + $k_array[]=$set->getRecord(); + } + + 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']; + // 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; } + + +}