82 lines
4.0 KiB
PHP
82 lines
4.0 KiB
PHP
<?php
|
|
class api_go_trainer extends \SYSTEM\API\api_system {
|
|
public static function call_guides_action_new($title, $cat, $text) {
|
|
if(!\SYSTEM\SECURITY\Security::isLoggedIn()){
|
|
return;
|
|
}
|
|
else{
|
|
$con = new \SYSTEM\DB\Connection();
|
|
$res = $con->prepare( 'selGuide',
|
|
'SELECT * FROM `go_trainer_guides` WHERE `title` = ?;',
|
|
array($title));
|
|
$res = $con->prepare( 'insertVote',
|
|
'INSERT INTO `go_trainer_guides` (`id`, `cat`, `parent_type`, `parent_id`, `title`, `author`, `body`, `created`, `last_edit`) '
|
|
. ' VALUES (NULL, ?, 0, 0, ?, ?, ?, NOW(), NOW());
|
|
',
|
|
array($cat, $title, \SYSTEM\SECURITY\Security::getUser()->id, $text));
|
|
return JsonResult::ok();
|
|
}
|
|
}
|
|
public static function call_guides_action_rate($rating, $guide) {
|
|
if(!\SYSTEM\SECURITY\Security::isLoggedIn()){
|
|
return;
|
|
}
|
|
else{
|
|
$rated = \SQL\GO_TRAINER_GET_HASRATED::Q1(array(\SYSTEM\SECURITY\Security::getUser()->id, $guide));
|
|
if ($rating == $rated['rating']){
|
|
return JsonResult::fail();
|
|
}
|
|
if ($rated){
|
|
$con = new \SYSTEM\DB\Connection();
|
|
$res = $con->prepare( 'updateRate',
|
|
'UPDATE go_trainer_rating SET rating=?, `timestamp`=NOW() WHERE id=?;',
|
|
array($rating, $rated['id']));
|
|
return JsonResult::ok();
|
|
}
|
|
$con = new \SYSTEM\DB\Connection();
|
|
$res = $con->prepare( 'selRate',
|
|
'SELECT * FROM `go_trainer_rating` WHERE `user_id` = ?;',
|
|
array(\SYSTEM\SECURITY\Security::getUser()->id));
|
|
$res = $con->prepare( 'insertRate',
|
|
'INSERT INTO `go_trainer_rating` (`id`, `user_id`, `rating`, `relation_type`, `relation_id`, `timestamp`)'
|
|
. ' VALUES (NULL, ?, ?, 1, ?, NOW());',
|
|
array(\SYSTEM\SECURITY\Security::getUser()->id, $rating, $guide));
|
|
return JsonResult::ok();
|
|
}
|
|
}
|
|
public static function call_guides_action_comment($text, $guide) {
|
|
if(!\SYSTEM\SECURITY\Security::isLoggedIn()){
|
|
return;
|
|
}
|
|
else{
|
|
$con = new \SYSTEM\DB\Connection();
|
|
$res = $con->prepare( 'selGuide',
|
|
'SELECT * FROM `go_trainer_guides` WHERE `id` = ?;',
|
|
array($guide));
|
|
$res = $con->prepare( 'insertComment',
|
|
'INSERT INTO `go_trainer_guides` (`id`, `cat`, `parent_type`, `parent_id`, `title`, `author`, `body`, `created`, `last_edit`) '
|
|
. ' VALUES (NULL, ?, 1, ?, ?, ?, ?, NOW(), NOW());
|
|
',
|
|
array('', $guide, '', \SYSTEM\SECURITY\Security::getUser()->id, $text));
|
|
return JsonResult::ok();
|
|
}
|
|
}
|
|
public static function call_guides_action_search ($searchstring){
|
|
$result = lists::generate_guidelist($searchstring);
|
|
return $result;
|
|
}
|
|
public static function call_guides_action_save_profile_picture ($url){
|
|
if(!\SYSTEM\SECURITY\Security::isLoggedIn()){
|
|
return;
|
|
}
|
|
else{
|
|
$con = new \SYSTEM\DB\Connection();
|
|
$res = $con->prepare( 'updateProfilePic',
|
|
'INSERT INTO go_trainer_trainer (system_user_id, profile_picture_url, last_edit) VALUES(?, ?, NOW()) ON DUPLICATE KEY UPDATE profile_picture_url = ?;',
|
|
array(\SYSTEM\SECURITY\Security::getUser()->id, $url, $url));
|
|
return JsonResult::ok();
|
|
}
|
|
}
|
|
|
|
}
|