mirror of
https://github.com/claradex/nativegallery.git
synced 2025-02-21 19:22:24 +03:00
contests api
This commit is contained in:
parent
2e5c8ffbb0
commit
020ec19124
6 changed files with 151 additions and 47 deletions
31
app/Controllers/Api/Admin/Contests/Create.php
Normal file
31
app/Controllers/Api/Admin/Contests/Create.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controllers\Api\Admin\Contests;
|
||||
|
||||
|
||||
|
||||
use App\Services\{Auth, Router, GenerateRandomStr, DB, Json, EXIF};
|
||||
use App\Models\{User, Vote, Photo};
|
||||
|
||||
|
||||
class Create
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$openprdate = strtotime($_POST['openpretendsdate']);
|
||||
$closeprdate = strtotime($_POST['closepretendsdate']);
|
||||
$opendate = strtotime($_POST['opendate']);
|
||||
$closedate = strtotime($_POST['closedate']);
|
||||
|
||||
if ($_POST['startContestNow'] === "1") {
|
||||
$opendate = $closeprdate;
|
||||
}
|
||||
DB::query('INSERT INTO contests VALUES (\'0\', :themeid, :openprdate, :closeprdate, :opendate, :closedate, 0)', array(':themeid' => $_POST['themeid'], ':openprdate' => $openprdate, ':closeprdate'=>$closeprdate, ':opendate' => $opendate, ':closedate'=>$closedate));
|
||||
echo json_encode(
|
||||
array(
|
||||
'errorcode' => 0,
|
||||
'error' => 0
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
28
app/Controllers/Api/Admin/Contests/CreateTheme.php
Normal file
28
app/Controllers/Api/Admin/Contests/CreateTheme.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controllers\Api\Admin\Contests;
|
||||
|
||||
|
||||
|
||||
use App\Services\{Auth, Router, GenerateRandomStr, DB, Json, EXIF};
|
||||
use App\Models\{User, Vote, Photo};
|
||||
|
||||
|
||||
class CreateTheme
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
if ($_POST['active'] === "1") {
|
||||
$status = 1;
|
||||
} else {
|
||||
$status = 0;
|
||||
}
|
||||
DB::query('INSERT INTO contests_themes VALUES (\'0\', :title, :status)', array(':title' => $_POST['body'], ':status' => $status));
|
||||
echo json_encode(
|
||||
array(
|
||||
'errorcode' => 0,
|
||||
'error' => 0
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -2,69 +2,96 @@
|
|||
|
||||
namespace App\Controllers\Api\Images;
|
||||
|
||||
|
||||
|
||||
use App\Services\{Auth, Router, GenerateRandomStr, DB, Json, EXIF};
|
||||
use App\Models\{User, Vote};
|
||||
|
||||
|
||||
class Rate
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
if (isset($_GET['vote']) && isset($_GET['pid'])) {
|
||||
if (Vote::photo(Auth::userid(), $_GET['pid']) === -1) {
|
||||
DB::query('INSERT INTO photos_rates VALUES (\'0\', :id, :pid, :type, 0)', array(':id'=>Auth::userid(), ':pid' => $_GET['pid'], ':type'=>$_GET['vote']));
|
||||
if (Vote::photo(Auth::userid(), $_GET['pid']) != $_GET['vote']) {
|
||||
DB::query('DELETE FROM photos_rates WHERE user_id=:id AND photo_id=:pid AND type=:type', array(':id'=>Auth::userid(), ':pid' => $_GET['pid'], ':type'=>Vote::photo(Auth::userid(), $_GET['pid'])));
|
||||
$userId = Auth::userid();
|
||||
$photoId = $_GET['pid'];
|
||||
$voteType = (int) $_GET['vote'];
|
||||
$contest = (isset($_GET['action']) && $_GET['action'] === 'vote-konk') ? 1 : 0;
|
||||
|
||||
if ($contest === 1) {
|
||||
if (Vote::photoContest($userId, $photoId) === -1) {
|
||||
DB::query(
|
||||
'INSERT INTO photos_rates (id, user_id, photo_id, type, contest) VALUES (NULL, :id, :pid, :type, 1)',
|
||||
[':id' => $userId, ':pid' => $photoId, ':type' => $voteType]
|
||||
);
|
||||
if (Vote::photoContest($userId, $photoId) != $voteType) {
|
||||
DB::query(
|
||||
'DELETE FROM photos_rates WHERE user_id=:id AND photo_id=:pid AND type=:type AND contest=1',
|
||||
[':id' => $userId, ':pid' => $photoId, ':type' => Vote::photo($userId, $photoId)]
|
||||
);
|
||||
}
|
||||
} else if (Vote::photo(Auth::userid(), $_GET['pid']) === (int)$_GET['vote']) {
|
||||
DB::query('DELETE FROM photos_rates WHERE user_id=:id AND photo_id=:pid', array(':id'=>Auth::userid(), ':pid' => $_GET['pid']));
|
||||
} elseif (Vote::photoContest($userId, $photoId) === $voteType) {
|
||||
DB::query(
|
||||
'DELETE FROM photos_rates WHERE user_id=:id AND photo_id=:pid AND contest=1',
|
||||
[':id' => $userId, ':pid' => $photoId]
|
||||
);
|
||||
} else {
|
||||
DB::query('UPDATE photos_rates SET type=:type WHERE user_id=:id AND photo_id=:pid', array(':id'=>Auth::userid(), ':pid' => $_GET['pid'], ':type'=>$_GET['vote']));
|
||||
|
||||
DB::query(
|
||||
'UPDATE photos_rates SET type=:type WHERE user_id=:id AND photo_id=:pid AND contest=1',
|
||||
[':id' => $userId, ':pid' => $photoId, ':type' => $voteType]
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (Vote::photo($userId, $photoId) === -1) {
|
||||
DB::query(
|
||||
'INSERT INTO photos_rates (id, user_id, photo_id, type, contest) VALUES (NULL, :id, :pid, :type, 0)',
|
||||
[':id' => $userId, ':pid' => $photoId, ':type' => $voteType]
|
||||
);
|
||||
if (Vote::photo($userId, $photoId) != $voteType) {
|
||||
DB::query(
|
||||
'DELETE FROM photos_rates WHERE user_id=:id AND photo_id=:pid AND type=:type AND contest=0',
|
||||
[':id' => $userId, ':pid' => $photoId, ':type' => Vote::photo($userId, $photoId)]
|
||||
);
|
||||
}
|
||||
} elseif (Vote::photo($userId, $photoId) === $voteType) {
|
||||
DB::query(
|
||||
'DELETE FROM photos_rates WHERE user_id=:id AND photo_id=:pid AND contest=0',
|
||||
[':id' => $userId, ':pid' => $photoId]
|
||||
);
|
||||
} else {
|
||||
DB::query(
|
||||
'UPDATE photos_rates SET type=:type WHERE user_id=:id AND photo_id=:pid AND contest=0',
|
||||
[':id' => $userId, ':pid' => $photoId, ':type' => $voteType]
|
||||
);
|
||||
}
|
||||
}
|
||||
$votes = DB::query('SELECT * FROM photos_rates WHERE photo_id=:id ORDER BY id DESC', array(':id' => $_GET['pid']));
|
||||
|
||||
$votes = DB::query('SELECT * FROM photos_rates WHERE photo_id=:id ORDER BY id DESC', [':id' => $photoId]);
|
||||
$formattedVotesPos = [];
|
||||
$formattedVotesNeg = [];
|
||||
|
||||
foreach ($votes as $vote) {
|
||||
$user = new User($vote['user_id']);
|
||||
if ($vote['type'] === 0) {
|
||||
$type = 0;
|
||||
$formattedVotesNeg[] = [$vote['user_id'], $user->i('username'), $type];
|
||||
$formattedVotesNeg[] = [$vote['user_id'], $user->i('username'), 0];
|
||||
} elseif ($vote['type'] === 1) {
|
||||
$type = 1;
|
||||
$formattedVotesPos[] = [$vote['user_id'], $user->i('username'), $type];
|
||||
$formattedVotesPos[] = [$vote['user_id'], $user->i('username'), 1];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (Vote::photo(Auth::userid(), $_GET['pid']) === 0) {
|
||||
$negbtn = true;
|
||||
$posbtn = false;
|
||||
} else if (Vote::photo(Auth::userid(), $_GET['pid']) === 1) {
|
||||
$negbtn = false;
|
||||
$posbtn = true;
|
||||
} else {
|
||||
$negbtn = false;
|
||||
$posbtn = false;
|
||||
}
|
||||
$currentVote = Vote::photo($userId, $photoId);
|
||||
$contCurrentVote = Vote::photoContest($userId, $photoId);
|
||||
$result = [
|
||||
'buttons' => [$negbtn, $posbtn],
|
||||
'buttons' => [
|
||||
'negbtn' => $currentVote === 0,
|
||||
'posbtn' => $currentVote === 1,
|
||||
'negbtn_contest' => $contCurrentVote === 0,
|
||||
'posbtn_contest' => $contCurrentVote === 1,
|
||||
],
|
||||
'errors' => '',
|
||||
'rating' => Vote::count($_GET['pid'])
|
||||
'rating' => Vote::count($photoId),
|
||||
'votes' => [
|
||||
1 => $formattedVotesPos,
|
||||
0 => $formattedVotesNeg
|
||||
]
|
||||
];
|
||||
$votes = [];
|
||||
$votes[1] = $formattedVotesPos;
|
||||
$votes[0] = $formattedVotesNeg;
|
||||
|
||||
if (!empty($votes)) {
|
||||
$result['votes'] = $votes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||
|
|
|
@ -37,7 +37,7 @@ class Upload
|
|||
} else {
|
||||
$moderated = 1;
|
||||
}
|
||||
DB::query('INSERT INTO photos VALUES (\'0\', :userid, :postbody, :photourl, :time, :timeup, :exif, 0, :moderated, :place, 0, :gallery, :entityid, 0, :content)', array(':postbody' => $postbody, ':userid' => Auth::userid(), ':time' => mktime(0, 0, 0, $_POST['month'], $_POST['day'], $_POST['year']), ':content' => $content, ':photourl' => self::$photourl, ':exif' => $exif, ':place' => $_POST['place'], ':timeup' => time(), ':moderated' => $moderated, ':gallery'=>$_POST['gallery'], ':entityid'=>self::$entitydata_id));
|
||||
DB::query('INSERT INTO photos VALUES (\'0\', :userid, :postbody, :photourl, :time, :timeup, :exif, 0, :moderated, :place, 0, :gallery, :entityid, 0, 0, :content)', array(':postbody' => $postbody, ':userid' => Auth::userid(), ':time' => mktime(0, 0, 0, $_POST['month'], $_POST['day'], $_POST['year']), ':content' => $content, ':photourl' => self::$photourl, ':exif' => $exif, ':place' => $_POST['place'], ':timeup' => time(), ':moderated' => $moderated, ':gallery'=>$_POST['gallery'], ':entityid'=>self::$entitydata_id));
|
||||
if (($moderated === 1) && (self::$subsnotify != 'disabled')) {
|
||||
$followers = DB::query('SELECT * FROM followers WHERE user_id=:uid', array(':uid' => Auth::userid()));
|
||||
foreach ($followers as $f) {
|
||||
|
|
|
@ -31,6 +31,8 @@ use \App\Controllers\Api\Admin\GetVehicleInputs as AdminGetVehicleInputs;
|
|||
use \App\Controllers\Api\Admin\GeoDB\Create as AdminGeoDBCreate;
|
||||
use \App\Controllers\Api\Admin\GeoDB\Load as AdminGeoDBLoad;
|
||||
use \App\Controllers\Api\Admin\GeoDB\Delete as AdminGeoDBDelete;
|
||||
use \App\Controllers\Api\Admin\Contests\CreateTheme as AdminContestsCreateTheme;
|
||||
use \App\Controllers\Api\Admin\Contests\Create as AdminContestsCreate;
|
||||
|
||||
class ApiController
|
||||
{
|
||||
|
@ -108,6 +110,12 @@ class ApiController
|
|||
public static function admingetvehicleinputs() {
|
||||
return new AdminGetVehicleInputs();
|
||||
}
|
||||
public static function admincontestscreatetheme() {
|
||||
return new AdminContestsCreateTheme();
|
||||
}
|
||||
public static function admincontestscreate() {
|
||||
return new AdminContestsCreate();
|
||||
}
|
||||
public static function admingeodbcreate() {
|
||||
return new AdminGeoDBCreate();
|
||||
}
|
||||
|
|
|
@ -17,5 +17,15 @@ class ContestsController
|
|||
Page::set('Contests/VotingIndex');
|
||||
|
||||
}
|
||||
public static function waiting()
|
||||
{
|
||||
Page::set('Contests/VotingWaiting');
|
||||
|
||||
}
|
||||
public static function sendpretend()
|
||||
{
|
||||
Page::set('Contests/VotingSendPretend');
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue