consolidate all repos to one for archive

This commit is contained in:
2025-01-28 13:46:42 +01:00
commit a6610fbc7a
5350 changed files with 2705721 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
<?php
class comments_controller_json
{
public function index()
{
// Iz modela pidobimo vse oglase
$comments = Comments::all();
//izpišemo $ads v JSON formatu
echo json_encode($comments);
}
public function show($id)
{
$comments = Comments::findForAd($id);
echo json_encode($comments);
}
public function store()
{
$comment = Comments::insert($_POST["ad_id"], $_SESSION["USER_ID"], $_POST["content"]);
echo json_encode($comment);
}
public function update($id)
{
}
public function delete($id)
{
// Poiščemo in izbrišemo oglas
$comment = Comments::find($id);
$comment->delete();
// Vrnemo podatke iz izbrisanega oglasa
echo json_encode($comment);
}
}

View File

@@ -0,0 +1,53 @@
<?php
class users_controller_json
{
public function index()
{
// Iz modela pidobimo vse oglase
$users = User::all();
//izpišemo $ads v JSON formatu
echo json_encode($users);
}
public function show($id)
{
$user = User::find($id);
echo json_encode($user);
}
public function store()
{
// Store se pokliče z POST, zato so podatki iz obrazca na voljo v $_POST
$id = User::insert($_POST["username"], $_POST["password"]);
$user = User::find($id);
// Vrnemo vstavljen oglas
echo json_encode($user);
}
public function update($id)
{
// Update se pokliče z PUT, zato nima podatkov v formData ($_POST).
// Namesto tega smo jih poslali v body-u HTTP zahtevka v JSON formatu.
$data = file_get_contents('php://input'); //preberemo body iz zahtevka
$data = json_decode($data, true); //dekodiramo JSON string v PHP array
// Poiščemo in posodobimo oglas
$user = User::find($id);
$user = $user->update($data['username'], $data['email'], $data['ime'], $data['priimek'], $data['naslov'], $data['posta'], $data['telefon']);
// Vrnemo posodobljen oglas
echo json_encode($user);
}
public function delete($id)
{
// Poiščemo in izbrišemo oglas
$user = User::find($id);
$user->delete();
// Vrnemo podatke iz izbrisanega oglasa
echo json_encode($user);
}
}