File app/FavoriteFiddles.php added (mode: 100644) (index 0000000..8aec2b9) |
|
1 |
|
<?php |
|
2 |
|
|
|
3 |
|
namespace SICSF; |
|
4 |
|
|
|
5 |
|
use Illuminate\Database\Eloquent\Model; |
|
6 |
|
|
|
7 |
|
class FavoriteFiddles extends Model |
|
8 |
|
{ |
|
9 |
|
protected $table = "FavoriteFiddles"; |
|
10 |
|
protected $primaryKey = NULL; |
|
11 |
|
public $incrementing = FALSE; |
|
12 |
|
protected $keyType = NULL; |
|
13 |
|
public $timestamps = FALSE; |
|
14 |
|
|
|
15 |
|
public static function GetFavoriteFiddles($username) { |
|
16 |
|
return \DB::table("FavoriteFiddles") |
|
17 |
|
->join("Fiddles", "FavoriteFiddles.FiddleID", "=", "Fiddles.ID") |
|
18 |
|
->select("Fiddles.Title", "FavoriteFiddles.*") |
|
19 |
|
->get(); |
|
20 |
|
} |
|
21 |
|
|
|
22 |
|
public static function GetFavoriteFiddlesCount($username) { |
|
23 |
|
return self::where("Username", $username)->count(); |
|
24 |
|
} |
|
25 |
|
|
|
26 |
|
public static function DeleteFavoriteFiddle($id, $username = "") { |
|
27 |
|
if (empty($username)) { |
|
28 |
|
self::where("FiddleID", $id)->delete(); |
|
29 |
|
} |
|
30 |
|
else { |
|
31 |
|
self::where([ |
|
32 |
|
["FiddleID", "=", $id], |
|
33 |
|
["Username", "=", $username] |
|
34 |
|
])->delete(); |
|
35 |
|
} |
|
36 |
|
} |
|
37 |
|
|
|
38 |
|
public static function IsFavoriteFiddle($username, $id) { |
|
39 |
|
return (self::where([ |
|
40 |
|
["Username", "=", $username], |
|
41 |
|
["FiddeID", "=", $id] |
|
42 |
|
])->count() === 1); |
|
43 |
|
} |
|
44 |
|
|
|
45 |
|
public static function AddFavoriteFiddle($data) { |
|
46 |
|
self::insert([ |
|
47 |
|
"FiddleID" => $data["FiddleID"], |
|
48 |
|
"Username" => $data["Username"], |
|
49 |
|
"FavoritingDate" => date_timestamp_get(date_create()) |
|
50 |
|
]); |
|
51 |
|
} |
|
52 |
|
} |
File app/Fiddles.php added (mode: 100644) (index 0000000..749a655) |
|
1 |
|
<?php |
|
2 |
|
|
|
3 |
|
namespace SICSF; |
|
4 |
|
|
|
5 |
|
use Illuminate\Database\Eloquent\Model; |
|
6 |
|
use SICSF\FavoriteFiddles; |
|
7 |
|
|
|
8 |
|
class Fiddles extends Model |
|
9 |
|
{ |
|
10 |
|
protected $primaryKey = "ID"; |
|
11 |
|
public $incrementing = FALSE; |
|
12 |
|
protected $keyType = "string"; |
|
13 |
|
public $timestamps = FALSE; |
|
14 |
|
|
|
15 |
|
public static function GetPublicFiddles($username) { |
|
16 |
|
return self::where([ |
|
17 |
|
["Username", "=", $username], |
|
18 |
|
["Privacy", "=", "Public"] |
|
19 |
|
])->select("ID", "Title", "Date")->get(); |
|
20 |
|
} |
|
21 |
|
|
|
22 |
|
public static function GetPrivateFiddles($username) { |
|
23 |
|
return self::where([ |
|
24 |
|
["Username", "=", $username], |
|
25 |
|
["Privacy", "=", "Private"] |
|
26 |
|
])->select("ID", "Title", "Date")->get(); |
|
27 |
|
} |
|
28 |
|
|
|
29 |
|
public static function GetFiddlesCount($username) { |
|
30 |
|
return self::where("Username", $username)->count(); |
|
31 |
|
} |
|
32 |
|
|
|
33 |
|
public static function GetPublicFiddlesCount($username) { |
|
34 |
|
return self::where([ |
|
35 |
|
["Username", "=", $username], |
|
36 |
|
["Privacy", "=", "Public"] |
|
37 |
|
])->count(); |
|
38 |
|
} |
|
39 |
|
|
|
40 |
|
public static function GetPrivateFiddlesCount($username) { |
|
41 |
|
return self::where([ |
|
42 |
|
["Username", "=", $username], |
|
43 |
|
["Privacy", "=", "Private"] |
|
44 |
|
])->count(); |
|
45 |
|
} |
|
46 |
|
|
|
47 |
|
public static function FiddleExists($id) { |
|
48 |
|
return (self::where("ID", $id)->first() !== NULL); |
|
49 |
|
} |
|
50 |
|
|
|
51 |
|
public static function GetFiddle($id) { |
|
52 |
|
return self::where("ID", $id)->first(); |
|
53 |
|
} |
|
54 |
|
|
|
55 |
|
public static function AddFiddle($username, $data) { |
|
56 |
|
self::insert([ |
|
57 |
|
"Username" => $username, |
|
58 |
|
"ID" => md5($data["Code"]) . "-" . bin2hex(random_bytes(16)), |
|
59 |
|
"Title" => $data["Title"], |
|
60 |
|
"Code" => $data["Code"], |
|
61 |
|
"Privacy" => $data["Privacy"], |
|
62 |
|
"Date" => date_timestamp_get(date_create()) |
|
63 |
|
]); |
|
64 |
|
} |
|
65 |
|
|
|
66 |
|
public static function GetAllFiddles($offset) { |
|
67 |
|
if ($offset === -1) { |
|
68 |
|
return self::where([ |
|
69 |
|
["Privacy", "=", "Public"] |
|
70 |
|
])->select("ID", "Title", "Date", "Username")->get(); |
|
71 |
|
} |
|
72 |
|
else { |
|
73 |
|
return self::where([ |
|
74 |
|
["Privacy", "=", "Public"] |
|
75 |
|
])->select("ID", "Title", "Date", "Username") |
|
76 |
|
->offset($offset * 20) |
|
77 |
|
->limit(20) |
|
78 |
|
->get(); |
|
79 |
|
} |
|
80 |
|
} |
|
81 |
|
|
|
82 |
|
public static function UpdateFiddle($data) { |
|
83 |
|
self::transaction(function() use ($data) { |
|
84 |
|
self::where("ID", $data["ID"])->update([ |
|
85 |
|
"Title" => $data["Title"], |
|
86 |
|
"Code" => $data["Code"], |
|
87 |
|
"Privacy" => $data["Privacy"] |
|
88 |
|
]); |
|
89 |
|
|
|
90 |
|
if ($data["Privacy"] === "Private") { |
|
91 |
|
FavoriteFiddles::DeleteFavoriteFiddle($data["ID"]); |
|
92 |
|
} |
|
93 |
|
}); |
|
94 |
|
} |
|
95 |
|
|
|
96 |
|
public static function DeleteFiddle($id) { |
|
97 |
|
self::transaction(function() use ($id) { |
|
98 |
|
self::where("ID", $id)->delete(); |
|
99 |
|
FavoriteFiddles::DeleteFavoriteFiddle($id); |
|
100 |
|
}); |
|
101 |
|
} |
|
102 |
|
|
|
103 |
|
public static function GetAllFiddlesCount() { |
|
104 |
|
return self::where("Privacy", "Public")->count(); |
|
105 |
|
} |
|
106 |
|
|
|
107 |
|
public static function GetFiddleTitle($id) { |
|
108 |
|
return self::where("ID", $id)->select("Title")->first(); |
|
109 |
|
} |
|
110 |
|
} |
File app/Users.php added (mode: 100644) (index 0000000..fc0d8e8) |
|
1 |
|
<?php |
|
2 |
|
|
|
3 |
|
namespace SICSF; |
|
4 |
|
|
|
5 |
|
use Illuminate\Database\Eloquent\Model; |
|
6 |
|
|
|
7 |
|
class Users extends Model |
|
8 |
|
{ |
|
9 |
|
protected $primaryKey = "Username"; |
|
10 |
|
public $incrementing = FALSE; |
|
11 |
|
protected $keyType = "string"; |
|
12 |
|
public $timestamps = FALSE; |
|
13 |
|
|
|
14 |
|
public static function EmailExists($email) { |
|
15 |
|
return (self::where("Email", $email)->count() === 1); |
|
16 |
|
} |
|
17 |
|
|
|
18 |
|
public static function UsernameExists($username) { |
|
19 |
|
return (self::where("Username", $username)->count() === 1); |
|
20 |
|
} |
|
21 |
|
|
|
22 |
|
public static function AddUser($data) { |
|
23 |
|
$Hash = NULL; |
|
24 |
|
while (($Hash = password_hash($data["Password"], PASSWORD_BCRYPT)) === FALSE) {} |
|
25 |
|
|
|
26 |
|
self::insert([ |
|
27 |
|
"Username" => $data["Username"], |
|
28 |
|
"Email" => $data["Email"], |
|
29 |
|
"Password" => $Hash, |
|
30 |
|
"RegisterationDate" => date_timestamp_get(date_create()), |
|
31 |
|
"IsConfirmed" => FALSE |
|
32 |
|
]); |
|
33 |
|
} |
|
34 |
|
|
|
35 |
|
public static function UserExists($data) { |
|
36 |
|
$Row = self::where("Email", $data["Email"])->first(); |
|
37 |
|
$Hash = $Row->Password; |
|
38 |
|
$Password = $data["Password"]; |
|
39 |
|
return password_verify($Password, $Hash); |
|
40 |
|
} |
|
41 |
|
|
|
42 |
|
public static function GetUserByEmail($email) { |
|
43 |
|
return self::where("Email", $email)->first(); |
|
44 |
|
} |
|
45 |
|
|
|
46 |
|
public static function GetUserByUsername($username) { |
|
47 |
|
return self::where("Username", $username)->first(); |
|
48 |
|
} |
|
49 |
|
|
|
50 |
|
public static function IsConfirmed($username) { |
|
51 |
|
$Row = self::where([ |
|
52 |
|
["Username", "=", $username], |
|
53 |
|
["IsConfirmed", "=", 1] |
|
54 |
|
])->first(); |
|
55 |
|
return ($Row->IsConfirmed == TRUE); |
|
56 |
|
} |
|
57 |
|
|
|
58 |
|
public static function GetAllUsers() { |
|
59 |
|
return self::select("Username", "RegisterationDate")->orderBy("RegisterationDate", "asc")->get(); |
|
60 |
|
} |
|
61 |
|
} |
File app/UsersSettings.php added (mode: 100644) (index 0000000..ef05090) |
|
1 |
|
<?php |
|
2 |
|
|
|
3 |
|
namespace SICSF; |
|
4 |
|
|
|
5 |
|
use Illuminate\Database\Eloquent\Model; |
|
6 |
|
|
|
7 |
|
class UsersSettings extends Model |
|
8 |
|
{ |
|
9 |
|
protected $table = "UsersSettings"; |
|
10 |
|
protected $primaryKey = NULL; |
|
11 |
|
public $incrementing = FALSE; |
|
12 |
|
protected $keyType = NULL; |
|
13 |
|
public $timestamps = FALSE; |
|
14 |
|
|
|
15 |
|
public static function GetUserSettings($username) { |
|
16 |
|
$SettingsObject = new \stdClass(); |
|
17 |
|
$Settings = self::where("Username", $username) |
|
18 |
|
->select("Property", "Value") |
|
19 |
|
->get(); |
|
20 |
|
|
|
21 |
|
foreach ($Settings as $Setting) { |
|
22 |
|
$SettingsObject->{$Setting->Property} = $Setting->Value; |
|
23 |
|
} |
|
24 |
|
return $SettingsObject; |
|
25 |
|
} |
|
26 |
|
|
|
27 |
|
public static function SetUserSettings($username, $data) { |
|
28 |
|
foreach ($data as $property => $value) { |
|
29 |
|
$PropertyExist = (self::where([ |
|
30 |
|
["Username", "=", $username], |
|
31 |
|
["Property", "=", $property] |
|
32 |
|
])->count() === 1); |
|
33 |
|
|
|
34 |
|
if ($PropertyExist) { |
|
35 |
|
self::where([ |
|
36 |
|
["Username", "=", $username], |
|
37 |
|
["Property", "=", $property] |
|
38 |
|
])->update([ |
|
39 |
|
"Value" => $value |
|
40 |
|
]); |
|
41 |
|
} |
|
42 |
|
else { |
|
43 |
|
self::insert([ |
|
44 |
|
"Username" => $username, |
|
45 |
|
"Property" => $property, |
|
46 |
|
"Value" => $value |
|
47 |
|
]); |
|
48 |
|
} |
|
49 |
|
} |
|
50 |
|
} |
|
51 |
|
|
|
52 |
|
|
|
53 |
|
} |