Skip to content

Commit

Permalink
Baby registry now stores the user id for shareable link: #133
Browse files Browse the repository at this point in the history
  • Loading branch information
khalidsaadat committed Apr 4, 2022
1 parent 49725f2 commit df15aed
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion app/controllers/BabyRegistryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public function add() {

$new_registry = $this->model('BabyRegistry'); // create registry model

$new_registry->user_id = $_SESSION['user_id'];
$new_registry->name = $name;
$new_registry->email = $email;
$new_registry->delivery_date = $delivery_date;
Expand All @@ -106,7 +107,8 @@ public function add() {

$new_registry->insert();

$this->view('baby_registry/add');
// $this->view('baby_registry/add');
return header('location:/babyregistry');
}


Expand Down
7 changes: 4 additions & 3 deletions app/models/BabyRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function getAll(){
}

public function getAllByUserId($user_id){
$stmt = self::$_connection->prepare("SELECT * FROM baby_registry WHERE user_id = :user_id");
$stmt = self::$_connection->prepare("SELECT * FROM baby_registry WHERE user_id = :user_id ORDER BY delivery_date DESC");
$stmt->execute(['user_id'=>$user_id]);
$stmt->setFetchMode(PDO::FETCH_CLASS, 'BabyRegistry');
return $stmt->fetchAll();
Expand All @@ -35,8 +35,9 @@ public function findByName($name) {
}

public function insert(){
$stmt = self::$_connection->prepare("INSERT INTO baby_registry(name ,delivery_date, organizer_name, address_id, description) VALUES(:name, :delivery_date, :organizer_name, :address_id, :description)");
$stmt->execute(['name'=>$this->name,
$stmt = self::$_connection->prepare("INSERT INTO baby_registry(user_id, name ,delivery_date, organizer_name, address_id, description) VALUES(:user_id, :name, :delivery_date, :organizer_name, :address_id, :description)");
$stmt->execute(['user_id'=>$this->user_id,
'name'=>$this->name,
'delivery_date'=>$this->delivery_date,
'organizer_name'=>$this->organizer_name,
'address_id'=>$this->address_id,
Expand Down
1 change: 1 addition & 0 deletions app/views/baby_registry/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
</div>

<hr>

<div style="display: flex; align-items: center;">
<img src="/assets/icons/settings.png" height="14" style="vertical-align:middle; padding-right: 5px;"><span style="font-size: 11px;">SETTINGS</span>
<span style="padding-left: 10px; padding-right: 10px;"></span>
Expand Down

0 comments on commit df15aed

Please sign in to comment.