From 9586c455233a3a136677cc376f1bf66512b9a1fa Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 20 Dec 2016 15:48:40 +0200 Subject: [PATCH] base --- src/app/backend/controllers/DiscountController.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/app/backend/views/discount/index.php | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib/models.php | 14 +++++++++++++- src/lib/models/discount.php | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 299 insertions(+), 1 deletion(-) create mode 100644 src/app/backend/controllers/DiscountController.php create mode 100644 src/app/backend/views/discount/index.php create mode 100644 src/lib/models/discount.php diff --git a/src/app/backend/controllers/DiscountController.php b/src/app/backend/controllers/DiscountController.php new file mode 100644 index 0000000..839a34d --- /dev/null +++ b/src/app/backend/controllers/DiscountController.php @@ -0,0 +1,50 @@ +session->get('isAdminAuth') ) { + + return $this->response->redirect([ 'for' => 'admin_login' ]); + + } + + $params = $this->dispatcher->getParams(); + $page = !empty( $params['page'] ) ? $params['page'] : 1; + + $data = $this->models->getDiscount()->getAllData(); + $total = $this->models->getDiscount()->countData(); + + if( $total['0']['total'] > \config::get( 'limits/items') ) + { + $paginate = $this->common->paginate( + [ + 'page' => $page, + 'items_per_page' => \config::get( 'limits/admin_orders', 5), + 'total_items' => $total[0]['total'], + 'url_for' => [ 'for' => 'discount_index_paged', 'page' => $page ], + 'index_page' => 'discount_index' + ], true + ); + } + $this->view->setVars([ + 'info' => $data, + 'paginate' => !empty($paginate['output']) ? $paginate['output'] : '' , + ]); + + } + +} \ No newline at end of file diff --git a/src/app/backend/views/discount/index.php b/src/app/backend/views/discount/index.php new file mode 100644 index 0000000..966c6f1 --- /dev/null +++ b/src/app/backend/views/discount/index.php @@ -0,0 +1,64 @@ + + +
+
flash->output(); ?>
+
+ + +
+
+ diff --git a/src/lib/models.php b/src/lib/models.php index 318f8dc..611ec5c 100644 --- a/src/lib/models.php +++ b/src/lib/models.php @@ -50,7 +50,8 @@ namespace protected $_reviews = false; protected $_modal = false; protected $_manager_mail = false; - protected $_promo_to_user = false; + protected $_promo_to_user = false; + protected $_discount = false; @@ -531,6 +532,17 @@ namespace return $this->_promo_codes; } + public function getDiscount() + { + if( empty($this->_discount) ) + { + $this->_discount = new \models\discount(); + $this->_discount->setDi( $this->getDi() ); + } + + return $this->_discount; + } + public function getPayment() { if( empty($this->_payment) ) diff --git a/src/lib/models/discount.php b/src/lib/models/discount.php new file mode 100644 index 0000000..7d0cedd --- /dev/null +++ b/src/lib/models/discount.php @@ -0,0 +1,172 @@ +get( + ' + SELECT * FROM + public.disocount + ' + , + [ + ], + -1 + ); + } + + + /** + * Get discount with `id`=$id + * @param $id + * @return array + */ + public function getOneData($id) + { + return $this->get( + ' + SELECT * + FROM public.disocount + WHERE + id = :id + ', + [ + 'id' => $id + ], + -1 + ); + } + + + /** + * Delete discount with `id`=$id + * @param $id + * @return bool + */ + public function deleteData($id) + { + return $this->exec( + ' DELETE + FROM + public.disocount + WHERE + id = :id + ', + [ + 'id' => $id + ] + ); + } + + /** + * Add new discount + * @param $data + * @return array + */ + public function addData($data) + { + + return $this->get( + ' + INSERT INTO + public.disocount + ( + name, + discount, + description, + start_date, + end_date + ) + VALUES + ( + :name, + :discount, + :description, + :start_date, + :end_date + ) + RETURNING id + ', + [ + 'name' => $data['name'], + 'discount' => $data['discount'], + 'description' => $data['description'], + 'start_date' => $data['start_date'], + 'end_date' => $data['end_date'] + ], + -1 + ); + + + } + + /** + * Update discount with `id`=$id + * @param $data + * @param $id + * @return bool + */ + public function updateData($data, $id) + { + + return $this->exec( + ' + UPDATE + public.disocount + SET + name = :name, + discount = :discount, + description = :description, + start_date = :start_date, + end_date = :end_date + WHERE + id = :id + ', + [ + 'name' => $data['name'], + 'discount' => $data['discount'], + 'description' => $data['description'], + 'start_date' => $data['start_date'], + 'end_date' => $data['end_date'], + 'id' => $id + ] + ); + } + + /** + * Count all discounts + * @return array + */ + public function countData() + { + return $this->get( + ' + SELECT + COUNT(id) AS total + FROM + public.disocount + ', + [ + + ], + -1 + ); + } + +} \ No newline at end of file -- libgit2 0.21.4