From 769fe98f8e2e751e26d3c6c1dda20d271497446c Mon Sep 17 00:00:00 2001 From: rylon Date: Fri, 21 Mar 2014 14:19:52 +0100 Subject: [PATCH] @uvote cleaned api and split it into several logical purpose orientated files --- uVote/api/api_uvote.php | 61 +++++++-------------- uVote/api/votes/comments.php | 22 ++++++++ uVote/api/votes/graphs.php | 27 +++++++++ uVote/api/votes/should_be_in_backend.php | 13 +++++ uVote/api/votes/votes.php | 70 ++---------------------- 5 files changed, 88 insertions(+), 105 deletions(-) create mode 100644 uVote/api/votes/comments.php create mode 100644 uVote/api/votes/graphs.php create mode 100644 uVote/api/votes/should_be_in_backend.php diff --git a/uVote/api/api_uvote.php b/uVote/api/api_uvote.php index fc6b640..7af1c13 100644 --- a/uVote/api/api_uvote.php +++ b/uVote/api/api_uvote.php @@ -1,60 +1,41 @@ id, utf8_encode($c_txt), $c_src));} + + public static function write_commentrate($c_ID, $val){ + if(!\SYSTEM\SECURITY\Security::isLoggedIn()){ + throw new ERROR("You need to be logged in.");} + return \DBD\UVOTE_DATA_USER_COMMENTRATE_INSERT::Q1(array($c_ID, \SYSTEM\SECURITY\Security::getUser()->id, $val, $c_ID, \SYSTEM\SECURITY\Security::getUser()->id, $val));} +} diff --git a/uVote/api/votes/graphs.php b/uVote/api/votes/graphs.php new file mode 100644 index 0000000..1e36272 --- /dev/null +++ b/uVote/api/votes/graphs.php @@ -0,0 +1,27 @@ +next()){ + $result[] = array( 0 => $row['day'], + 'match' => $row['class_match'] > 0 ? round($row['class_match'] / ($row['class_match']+$row['class_mismatch']),2) : 0, + 'mismatch' => $row['class_match'] > 0 ? round($row['class_mismatch'] / ($row['class_match']+$row['class_mismatch']),2) : 0); + } + return $returnasjson ? SYSTEM\LOG\JsonResult::toString($result) : $result; + } + + public static function graph_bt_to_user_overall_by_time ($timespan = 84600,$returnasjson = true){ + $result = array(); + $res = \DBD\UVOTE_DATA_GRAPH_BT_TO_USER_OVERALL_BY_TIME::QQ(array($timespan, \SYSTEM\SECURITY\Security::getUser()->id, \SYSTEM\SECURITY\Security::getUser()->id)); + while ($row = $res->next()){ + $result[] = array( 0 => $row['day'], + 'class_match' => $row['class_match'] / ($row['class_match']+$row['class_mismatch']+1), + 'class_mismatch' => $row['class_mismatch'] / ($row['class_match']+$row['class_mismatch']+1)); + } + return $returnasjson ? SYSTEM\LOG\JsonResult::toString($result) : $result; + } + +} diff --git a/uVote/api/votes/should_be_in_backend.php b/uVote/api/votes/should_be_in_backend.php new file mode 100644 index 0000000..d382206 --- /dev/null +++ b/uVote/api/votes/should_be_in_backend.php @@ -0,0 +1,13 @@ +next()){ - $result[] = array( 0 => $row['day'], - 'match' => $row['class_match'] > 0 ? round($row['class_match'] / ($row['class_match']+$row['class_mismatch']),2) : 0, - 'mismatch' => $row['class_match'] > 0 ? round($row['class_mismatch'] / ($row['class_match']+$row['class_mismatch']),2) : 0); - } - return $returnasjson ? SYSTEM\LOG\JsonResult::toString($result) : $result; - } - - public static function get_graph_bt_to_user_overall_by_time ($timespan = 84600,$returnasjson = true){ - $result = array(); - $res = \DBD\UVOTE_DATA_GRAPH_BT_TO_USER_OVERALL_BY_TIME::QQ(array($timespan, \SYSTEM\SECURITY\Security::getUser()->id, \SYSTEM\SECURITY\Security::getUser()->id)); - while ($row = $res->next()){ - $result[] = array( 0 => $row['day'], - 'class_match' => $row['class_match'] / ($row['class_match']+$row['class_mismatch']+1), - 'class_mismatch' => $row['class_mismatch'] / ($row['class_match']+$row['class_mismatch']+1)); - } - return $returnasjson ? SYSTEM\LOG\JsonResult::toString($result) : $result; - } - public static function getAllVotesOfGroup($groupid){ return \DBD\UVOTE_GENERATE_VOTELIST::QA(array($groupid));} public static function getAllExpVotesOfGroup($groupid){ - return \DBD\UVOTE_GENERATE_VOTELIST_EXP::QA(array($groupid));} - - public static function getUserComments($poll_ID, $c_choice){ - return \DBD\UVOTE_GENERATE_COMMENTS_PER_POLL::QA(array($poll_ID, $c_choice));} + return \DBD\UVOTE_GENERATE_VOTELIST_EXP::QA(array($groupid));} public static function countAllPolls(){ $res = \DBD\UVOTE_DATA_COUNT_VOTES::QQ(); - return $res;} - - public static function insertPartyChoice($poll_ID, $party, $votes_pro, $votes_contra, $nr_attending, $total, $choice){ - return \DBD\UVOTE_GENERATE_VOTELIST::QI(array($poll_ID, $party, $votes_pro, $votes_contra, $nr_attending, $total, $choice));} - - public static function insertUserComment($c_choice, $poll_ID, $user_ID, $c_txt, $c_src, $timestamp){ - return \DBD\UVOTE_DATA_USER_COMMENT_INSERT::QI(array($c_choice, $poll_ID, $user_ID, $c_txt, $c_src, $timestamp));} - /*public static function getVoteOfGroup($poll_ID){ - $con = new \SYSTEM\DB\Connection(new \DBD\uVote()); - $res = $con->prepare( 'selVoteByGrp', - 'SELECT * FROM `uvote_votes` WHERE `ID` = ? LIMIT 1;', - array($poll_ID)); - $result = $res->next(); - return $result; - }*/ + return $res;} public static function get_user_choice_per_poll($poll_ID, $user_ID){ return \DBD\UVOTE_DATA_USER_CHOICE_PER_POLL::Q1(array($poll_ID, $user_ID)); @@ -122,10 +82,7 @@ class votes { return \DBD\UVOTE_DATA_BT_PER_POLL::Q1(array($poll_ID));} public static function get_user_count(){ - return \DBD\UVOTE_DATA_USER_COUNT_USERS::Q1(array());} - - public static function get_commentrate($c_ID, $val){ - return \DBD\UVOTE_DATA_USER_COMMENTRATE_PER_COMMENT::Q1(array($c_ID, $val));} + return \DBD\UVOTE_DATA_USER_COUNT_USERS::Q1(array());} public static function get_count_user_votes_per_poll($poll_ID){ return \DBD\UVOTE_DATA_USER_COUNT_CHOICE_PER_POLL::Q1(array($poll_ID));} @@ -194,28 +151,11 @@ class votes { public static function write_data($location, $birthyear, $gender, $children){ if(!\SYSTEM\SECURITY\Security::isLoggedIn()){ throw new ERROR("You need to be logged in.");} - return \DBD\UVOTE_DATA_USER_ADD_DATA_INSERT::Q1(array(\SYSTEM\SECURITY\Security::getUser()->id, $location, $birthyear, $gender, $children, \SYSTEM\SECURITY\Security::getUser()->id, $location, $birthyear, $gender, $children));} - - public static function write_comment($poll_ID, $c_choice, $c_txt, $c_src){ - if(!\SYSTEM\SECURITY\Security::isLoggedIn()){ - throw new ERROR("You need to be logged in.");} - return \DBD\UVOTE_DATA_USER_COMMENT_INSERT::Q1(array($c_choice, $poll_ID, \SYSTEM\SECURITY\Security::getUser()->id, utf8_encode($c_txt), $c_src));} - - public static function write_commentrate($c_ID, $val){ - if(!\SYSTEM\SECURITY\Security::isLoggedIn()){ - throw new ERROR("You need to be logged in.");} - return \DBD\UVOTE_DATA_USER_COMMENTRATE_INSERT::Q1(array($c_ID, \SYSTEM\SECURITY\Security::getUser()->id, $val, $c_ID, \SYSTEM\SECURITY\Security::getUser()->id, $val));} + return \DBD\UVOTE_DATA_USER_ADD_DATA_INSERT::Q1(array(\SYSTEM\SECURITY\Security::getUser()->id, $location, $birthyear, $gender, $children, \SYSTEM\SECURITY\Security::getUser()->id, $location, $birthyear, $gender, $children));} public static function get_add_data(){ return \DBD\UVOTE_DATA_USER_ADD_DATA::Q1(array(\SYSTEM\SECURITY\Security::getUser()->id)); - } - public static function write_poll($ID, $title, $iframe_link ){ - if ($ID == -1){ - return \DBD\UVOTE_DATA_NEW_POLL::QI(array($title, $iframe_link)); - } - return \DBD\UVOTE_DATA_UPDATE_POLL::QI(array($title, $iframe_link, $ID)); - } - + } public static function write_feedback($feedback){ $feedback = json_decode($feedback);