Ignore:
Timestamp:
02/12/24 14:17:23 (11 months ago)
Author:
bube-ristovska <ristovska725@…>
Branches:
main
Children:
2bd3041
Parents:
92df8cd
Message:

Finalized phase 5

Location:
app/Http/Controllers
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • app/Http/Controllers/OfficerController.php

    r92df8cd r7e9dadd  
    1717            return view('login');
    1818        }
    19         $results = DB::select('select * from policeman join people on policeman.pe_id = people.pe_id;');
     19        if(Session::get('is_policeman')){
     20            $police_station = DB::select('select * from police_station where p_id=:p_id;',['p_id'=>  Session::get('p_id')]);
     21        } else {
     22            $police_station = DB::select('select * from police_station where pe_id=:pe_id;',['pe_id'=>  Session::get('pe_id')]);
     23        }
     24        $results = DB::select('select * from policeman join people on policeman.pe_id = people.pe_id where p_id=:p_id;',['p_id'=>  $police_station[0]->p_id]);
     25//        $results = DB::select('select * from policeman join people on policeman.pe_id = people.pe_id;');
     26
    2027        return view('employees', [
    21             'employees' => $results
     28            'employees' => $results,
     29            'p_address'=>$police_station[0]->p_address
    2230        ]);
    2331    }
     
    3644        ]);
    3745
     46
     47        $police_station = DB::select('select * from police_station where pe_id=:pe_id;',['pe_id'=>  Session::get('pe_id')]);
     48
    3849        $pe_id = DB::select('select pe_id from people where embg = :embg;', ['embg' => $policeman["embg"]]);
    39         DB::insert('INSERT INTO policeman (pe_id, badge_no, p_date_of_employment, rank, p_id, p_password) VALUES (?, ?, ?, ?, ?, ?)', [$pe_id[0]->pe_id, $policeman["badge_no"], Carbon::now()->format('Y-m-d'), $policeman["rank"], $policeSTATION,$policeman["password"]]);
    40         return view('register-policeman');
     50        DB::insert('INSERT INTO policeman (pe_id, badge_no, p_date_of_employment, rank, p_id, p_password) VALUES (?, ?, ?, ?, ?, ?)', [$pe_id[0]->pe_id, $policeman["badge_no"], Carbon::now()->format('Y-m-d'), $policeman["rank"], $police_station[0]->p_id,$policeman["password"]]);
     51        return redirect()->back()->with('message',"Додадено");
    4152    }
    4253
  • app/Http/Controllers/PeopleController.php

    r92df8cd r7e9dadd  
    2323            return view('login');
    2424        }
     25//        $credentials = request()->validate([
     26//            'embg' => 'required'
     27//        ]);
     28//        $embg = $credentials['embg'];
     29//
     30//        $peoples = DB::select('SELECT * FROM people WHERE embg ~ :embg', ['embg' =>  '^' . $embg]);
     31
    2532        $credentials = request()->validate([
    26             'embg' => 'required'
     33            'embg' => 'nullable', // Assuming embg is not always required
     34            'gender' => 'nullable',
     35            'age' => 'nullable',
    2736        ]);
    28         $embg = $credentials['embg'];
     37        $query = 'SELECT * FROM people WHERE true';
    2938
    30         $peoples = DB::select('SELECT * FROM people WHERE embg ~ :embg', ['embg' =>  '^' . $embg]);
     39        $embg = '^' . $credentials['embg'];
     40        if ($credentials['embg']) {
     41            $query .= " AND embg LIKE '{$credentials['embg']}%'";
     42        }
    3143
    32         return view('filter', [
    33             'peoples' => $peoples
    34         ]);
     44        // Check if $credentials['gender'] is an array and handle accordingly
     45        if (isset($credentials['gender']) && (is_array($credentials['gender']) && count($credentials['gender']) > 0)) {
     46            $genderConditions = implode(" OR ", array_map(function ($gender) {
     47                return "gender = '{$gender}'";
     48            }, $credentials['gender']));
     49
     50            $query .= " AND ({$genderConditions})";
     51        } elseif (isset($credentials['gender']) && !is_array($credentials['gender'])) {
     52            $query .= " AND gender = '{$credentials['gender']}'";
     53        }
     54
     55        // Check if $credentials['age'] is an array and handle accordingly
     56        if (isset($credentials['age']) && is_array($credentials['age']) && count($credentials['age']) > 0) {
     57            $ageConditions = [];
     58
     59            foreach ($credentials['age'] as $ageRange) {
     60                // Extract minimum and maximum ages from the range
     61                list($minAge, $maxAge) = explode('-', $ageRange);
     62
     63                // Add condition for the age range
     64                $ageConditions[] = "EXTRACT(YEAR FROM AGE(current_date, date_of_birth)) BETWEEN {$minAge} AND {$maxAge}";
     65            }
     66
     67            $query .= " AND (" . implode(" OR ", $ageConditions) . ")";
     68        }
     69        // Use a raw SQL query with the built conditions
     70
     71        $peoples = DB::select($query);
     72        return view('filter', ['peoples' => $peoples]);
    3573    }
    3674    public function getPerson(Request $request)
  • app/Http/Controllers/SessionsController.php

    r92df8cd r7e9dadd  
    4646                Session::put('pe_id', $exists[0]->pe_id);
    4747            }
    48             return redirect()->intended('/');
     48            return view('welcome');
    4949        }
    5050
Note: See TracChangeset for help on using the changeset viewer.