Commit 52d7dc0b8d584cf011038d2467ec5507a9a3783e
Merge branch 'discount' of gitlab.artweb.com.ua:Alex/semena
Showing
2 changed files
with
60 additions
and
7 deletions
Show diff stats
src/app/backend/controllers/DiscountController.php
| ... | ... | @@ -116,6 +116,7 @@ class DiscountController extends Controller |
| 116 | 116 | return $this->response->redirect([ 'for' => 'admin_login' ]); |
| 117 | 117 | |
| 118 | 118 | } |
| 119 | + | |
| 119 | 120 | $this->models->getDiscount()->deleteData($id); |
| 120 | 121 | |
| 121 | 122 | return $this->response->redirect([ 'for' => 'discount_index' ]); |
| ... | ... | @@ -210,4 +211,29 @@ class DiscountController extends Controller |
| 210 | 211 | ]); |
| 211 | 212 | |
| 212 | 213 | } |
| 214 | + | |
| 215 | + public function switchAction($id) { | |
| 216 | + | |
| 217 | + if( !$this->session->get('isAdminAuth') ) { | |
| 218 | + | |
| 219 | + return $this->response->redirect([ 'for' => 'admin_login' ]); | |
| 220 | + | |
| 221 | + } | |
| 222 | + | |
| 223 | + $status = $this->models->getDiscount()->getStatus($id); | |
| 224 | + | |
| 225 | + if ($status == 1) { | |
| 226 | + | |
| 227 | + $this->models->getDiscount()->updateData(['status' => 0], $id); | |
| 228 | + | |
| 229 | + } | |
| 230 | + elseif ($status == 0) { | |
| 231 | + | |
| 232 | + $this->models->getDiscount()->updateData(['status' => 1], $id); | |
| 233 | + | |
| 234 | + } | |
| 235 | + | |
| 236 | + return $this->response->redirect([ 'for' => 'discount_index' ]); | |
| 237 | + | |
| 238 | + } | |
| 213 | 239 | } |
| 214 | 240 | \ No newline at end of file | ... | ... |
src/lib/models/discount.php
| ... | ... | @@ -33,7 +33,7 @@ class discount extends \db |
| 33 | 33 | |
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | - * Get discount with `id`=$id | |
| 36 | + * Get discount | |
| 37 | 37 | * @param $id |
| 38 | 38 | * @return array |
| 39 | 39 | */ |
| ... | ... | @@ -53,6 +53,28 @@ class discount extends \db |
| 53 | 53 | ); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | + /** | |
| 57 | + * Get discount indication status | |
| 58 | + * @param $id | |
| 59 | + * @return array | |
| 60 | + */ | |
| 61 | + public function getStatus($id) { | |
| 62 | + | |
| 63 | + return $this->get( | |
| 64 | + ' | |
| 65 | + SELECT status | |
| 66 | + FROM public.discount | |
| 67 | + WHERE | |
| 68 | + id = :id | |
| 69 | + ', | |
| 70 | + [ | |
| 71 | + 'id' => $id | |
| 72 | + ], | |
| 73 | + -1 | |
| 74 | + ); | |
| 75 | + | |
| 76 | + } | |
| 77 | + | |
| 56 | 78 | |
| 57 | 79 | /** |
| 58 | 80 | * Get actual discount |
| ... | ... | @@ -79,7 +101,7 @@ class discount extends \db |
| 79 | 101 | |
| 80 | 102 | |
| 81 | 103 | /** |
| 82 | - * Delete discount with `id`=$id | |
| 104 | + * Delete discount | |
| 83 | 105 | * @param $id |
| 84 | 106 | * @return bool |
| 85 | 107 | */ |
| ... | ... | @@ -115,7 +137,8 @@ class discount extends \db |
| 115 | 137 | discount, |
| 116 | 138 | description, |
| 117 | 139 | start_date, |
| 118 | - end_date | |
| 140 | + end_date, | |
| 141 | + status | |
| 119 | 142 | ) |
| 120 | 143 | VALUES |
| 121 | 144 | ( |
| ... | ... | @@ -123,7 +146,8 @@ class discount extends \db |
| 123 | 146 | :discount, |
| 124 | 147 | :description, |
| 125 | 148 | :start_date, |
| 126 | - :end_date | |
| 149 | + :end_date, | |
| 150 | + :status | |
| 127 | 151 | ) |
| 128 | 152 | RETURNING id |
| 129 | 153 | ', |
| ... | ... | @@ -132,7 +156,8 @@ class discount extends \db |
| 132 | 156 | 'discount' => $data['discount'], |
| 133 | 157 | 'description' => $data['description'], |
| 134 | 158 | 'start_date' => $data['start_date'], |
| 135 | - 'end_date' => $data['end_date'] | |
| 159 | + 'end_date' => $data['end_date'], | |
| 160 | + 'status' => $data['status'] | |
| 136 | 161 | ], |
| 137 | 162 | -1 |
| 138 | 163 | ); |
| ... | ... | @@ -141,7 +166,7 @@ class discount extends \db |
| 141 | 166 | } |
| 142 | 167 | |
| 143 | 168 | /** |
| 144 | - * Update discount with `id`=$id | |
| 169 | + * Update discount | |
| 145 | 170 | * @param $data |
| 146 | 171 | * @param $id |
| 147 | 172 | * @return bool |
| ... | ... | @@ -158,7 +183,8 @@ class discount extends \db |
| 158 | 183 | discount = :discount, |
| 159 | 184 | description = :description, |
| 160 | 185 | start_date = :start_date, |
| 161 | - end_date = :end_date | |
| 186 | + end_date = :end_date, | |
| 187 | + status = :status | |
| 162 | 188 | WHERE |
| 163 | 189 | id = :id |
| 164 | 190 | ', |
| ... | ... | @@ -168,6 +194,7 @@ class discount extends \db |
| 168 | 194 | 'description' => $data['description'], |
| 169 | 195 | 'start_date' => $data['start_date'], |
| 170 | 196 | 'end_date' => $data['end_date'], |
| 197 | + 'status' => $data['status'], | |
| 171 | 198 | 'id' => $id |
| 172 | 199 | ] |
| 173 | 200 | ); | ... | ... |