Skip to content

Commit

Permalink
Making the baby registry dynamic with dynamic shareable links: #133
Browse files Browse the repository at this point in the history
  • Loading branch information
khalidsaadat committed Apr 3, 2022
1 parent 5f94138 commit 16000a8
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 144 deletions.
7 changes: 5 additions & 2 deletions app/controllers/BabyRegistryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ public function index(){
return header('location:/account/login');
}

// get the all the baby registries for the current logged in user
$baby_registeries = $this->model('BabyRegistry')->getAllByUserId($_SESSION['user_id']);

// Send the 'products' variable to the View for rendering it to the webpage.
$this->view('baby_registry/index');
$this->view('baby_registry/index', ['baby_registeries'=>$baby_registeries]);
}

public function add() {
Expand All @@ -88,7 +91,7 @@ public function add() {
$organizer_name = $first_name . ' ' . $last_name;
$email = $_POST['email'];
$delivery_date = $_POST['date'];
$address_id = 8; // default id until we fix it
$address_id = $_POST['change_address'];
$description = $_POST['description'];


Expand Down
7 changes: 7 additions & 0 deletions app/models/BabyRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ public function getAll(){
return $stmt->fetchAll();
}

public function getAllByUserId($user_id){
$stmt = self::$_connection->prepare("SELECT * FROM baby_registry WHERE user_id = :user_id");
$stmt->execute(['user_id'=>$user_id]);
$stmt->setFetchMode(PDO::FETCH_CLASS, 'BabyRegistry');
return $stmt->fetchAll();
}

public function find($baby_registry_id){
$stmt = self::$_connection->prepare("SELECT * FROM baby_registry WHERE baby_registry_id = :baby_registry_id");
$stmt->execute(['baby_registry_id'=>$baby_registry_id]);
Expand Down
62 changes: 31 additions & 31 deletions app/views/baby_registry/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<div class="breadcrumb__links">
<a href="./index.html">Home</a>
<a href="./shop.html">Baby Registry</a>
<span>Baby Registry Settings</span>
<span>Create Baby Registry</span>
</div>
</div>
</div>
Expand All @@ -50,7 +50,7 @@
<!-- Checkout Section Begin -->
<section class="checkout spad">
<div class="container">
<div class="checkout__form">
<div class="checkout__form authentication_form">
<form method="post">
<div class="row">
<div class="col-lg-8 col-md-6">
Expand Down Expand Up @@ -84,21 +84,12 @@
<div class="checkout__input">
<p>Expected Arrival Date<span>*</span></p>
<div class="form-group">
<label class="control-label" for="date">Date</label>
<input class="form-control" id="date" name="date" placeholder="MM/DD/YYY" type="text"/>
<input class="" id="date" name="date" placeholder="MM/DD/YYY" type="text"/>
</div>
</div>

<div class="checkout__input__checkbox">
<br>
<p>Is This Your First Baby ?</p>
<input type="radio" name = "ans" value="yes"> Yes </br>
<input type="radio" name = "ans" value="no"> No </br>

</div>

<!-- shipping address -->
<div class="row" style="margin-bottom: 20px;">
<div class="row" style="margin-bottom: 20px; margin-top: 20px;">
<div class="col-lg-12">
<div style="background: #e1e5ee; padding: 5px 10px;">
<div class="row">
Expand All @@ -107,10 +98,6 @@
Your delivery address:
</span>
</div>
<div class="col-md-2 text-right" style="font-size: 14px; cursor: pointer;" data-toggle="modal" data-target="#change-address-modal">
<span class="icon_pencil" style="cursor: pointer;"></span>
<span style="color: #2a324b;">Change</span>
</div>

</div>
<div style="padding-top: 10px;">
Expand All @@ -119,33 +106,46 @@

$primary_address = $model['primary_address'];
$p_full_address = $primary_address->street . ', ' . $primary_address->city . ', ' . $primary_address->province . ', ' . $primary_address->postal_code . ', ' . $primary_address->country;

echo "
<input type='radio' id='primary' name='address' checked='checked'> <label for='primary'>$p_full_address</label> <br>
";
}

if(isset($model['secondary_address'])) {
$secondary_address = $model['secondary_address'];
$s_full_address = $secondary_address->street . ', ' . $secondary_address->city . ', ' . $secondary_address->province . ', ' . $secondary_address->postal_code . ', ' . $secondary_address->country;
}

echo "
<input type='radio' id='p_address' name='change_address' value='$primary_address->address_id' checked='checked'> <label for='p_address'>$p_full_address</label> <br>
<input type='radio' id='s_address' name='change_address' value='$secondary_address->address_id'> <label for='s_address'>$s_full_address</label> <br>
";
?>

</div>
</div>
</div>
</div>

<!-- Change Address Modal -->
<div class="modal fade" id="change-address-modal" tabindex="-1" role="dialog" aria-labelledby="change-address-modal-label" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title font-weight" id="change-address-modal-label">Select Your Delivery Address</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="checkout__input">
<p>Add a greetings to your friends and family at the top of your registry</p>
<input type="text" name= "description" id = "description"
placeholder="E.g Thank you so much for visiting our Baby Registry.">
</div>

<button type="submit" name="create_registry" class="site-btn">Create my Baby Registry</button>


</div>

</div>
</form>
</div>
</div>
</section>
<!-- Checkout Section End -->

<?php
// global footer - do not write file extension (.php)
$this->view('include/footer');
?> </div>
<div class="modal-body">

<span style="font-size: 18px;">Your current delivery address is: </span>
Expand Down
Loading

0 comments on commit 16000a8

Please sign in to comment.