Commit 9586c455233a3a136677cc376f1bf66512b9a1fa
1 parent
3b0b683e
base
Showing
4 changed files
with
299 additions
and
1 deletions
Show diff stats
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: Alex Savenko | |
5 | + * Date: 20.12.2016 | |
6 | + * Time: 13:35 | |
7 | + */ | |
8 | + | |
9 | +namespace controllers; | |
10 | + | |
11 | +use Phalcon\Mvc\Controller; | |
12 | + | |
13 | + | |
14 | +class DiscountController extends Controller | |
15 | +{ | |
16 | + | |
17 | + public function indexAction() { | |
18 | + | |
19 | + if( !$this->session->get('isAdminAuth') ) { | |
20 | + | |
21 | + return $this->response->redirect([ 'for' => 'admin_login' ]); | |
22 | + | |
23 | + } | |
24 | + | |
25 | + $params = $this->dispatcher->getParams(); | |
26 | + $page = !empty( $params['page'] ) ? $params['page'] : 1; | |
27 | + | |
28 | + $data = $this->models->getDiscount()->getAllData(); | |
29 | + $total = $this->models->getDiscount()->countData(); | |
30 | + | |
31 | + if( $total['0']['total'] > \config::get( 'limits/items') ) | |
32 | + { | |
33 | + $paginate = $this->common->paginate( | |
34 | + [ | |
35 | + 'page' => $page, | |
36 | + 'items_per_page' => \config::get( 'limits/admin_orders', 5), | |
37 | + 'total_items' => $total[0]['total'], | |
38 | + 'url_for' => [ 'for' => 'discount_index_paged', 'page' => $page ], | |
39 | + 'index_page' => 'discount_index' | |
40 | + ], true | |
41 | + ); | |
42 | + } | |
43 | + $this->view->setVars([ | |
44 | + 'info' => $data, | |
45 | + 'paginate' => !empty($paginate['output']) ? $paginate['output'] : '' , | |
46 | + ]); | |
47 | + | |
48 | + } | |
49 | + | |
50 | +} | |
0 | 51 | \ No newline at end of file | ... | ... |
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: Alex Savenko | |
5 | + * Date: 20.12.2016 | |
6 | + * Time: 15:46 | |
7 | + */ | |
8 | +?> | |
9 | + | |
10 | +<div id="static_page"> | |
11 | + <div class="inner"><?= $this->flash->output(); ?></div> | |
12 | +<div class="inner"> | |
13 | + <div class="sidebar_content_wrapper clearfix"> | |
14 | + <div class="sidebar_wrapper float"> | |
15 | + <div class="sidebar clearfix"> | |
16 | + <?= $this->partial('partial/sidebar') ?> | |
17 | + </div> | |
18 | + </div> | |
19 | + <div class="content_wrapper float"> | |
20 | + <div class="h_700"> | |
21 | + <div class="content_wrapper_list clearfix"> | |
22 | + <div class="table_name header_gradient">discounts</div> | |
23 | + <div class="table_add_page"><a href="<?= $this->url->get([ 'for' => 'promo_codes_add' ]) ?>" title="Добавить">Добавить</a></div> | |
24 | + | |
25 | + <div class="table_pages_wrapper"> | |
26 | + | |
27 | + <?php | |
28 | + | |
29 | + if( !empty( $info ) ) | |
30 | + { | |
31 | + $data_pages = ''; | |
32 | + | |
33 | + foreach( $info as $p ) | |
34 | + { | |
35 | + $data_pages .= | |
36 | + '<div class="one_page_edit header_gradient clearfix">'. | |
37 | + '<div class="one_page_edit_check float"></div>'. | |
38 | + '<div class="one_page_edit_name float"><a href="/promo_codes_update/'.$p['id'].'" title="">'.$p['name'].'</a></div>'. | |
39 | + '<div class="one_page_delete_ico float_right"><a href="/promo_codes_delete/'.$p['id'].'" title="Удалить" onclick="return confirm(\'Вы действительно хотите удалить информацию?\')"></a></div>'. | |
40 | + '<div class="one_page_edit_ico float_right"><a href="/promo_codes_update/'.$p['id'].'" title="Редактировать"></a></div>'. | |
41 | + '</div>'; | |
42 | + } | |
43 | + | |
44 | + | |
45 | + echo( $data_pages ); | |
46 | + } | |
47 | + | |
48 | + ?> | |
49 | + | |
50 | + </div> | |
51 | + | |
52 | + </div> | |
53 | + <div class="inner"> | |
54 | + <div class="paginate"> | |
55 | + <?=$paginate?> | |
56 | + </div> | |
57 | + </div> | |
58 | + </div> | |
59 | + | |
60 | + </div> | |
61 | + | |
62 | + </div> | |
63 | +</div> | |
64 | +</div> | ... | ... |
src/lib/models.php
... | ... | @@ -50,7 +50,8 @@ namespace |
50 | 50 | protected $_reviews = false; |
51 | 51 | protected $_modal = false; |
52 | 52 | protected $_manager_mail = false; |
53 | - protected $_promo_to_user = false; | |
53 | + protected $_promo_to_user = false; | |
54 | + protected $_discount = false; | |
54 | 55 | |
55 | 56 | |
56 | 57 | |
... | ... | @@ -531,6 +532,17 @@ namespace |
531 | 532 | return $this->_promo_codes; |
532 | 533 | } |
533 | 534 | |
535 | + public function getDiscount() | |
536 | + { | |
537 | + if( empty($this->_discount) ) | |
538 | + { | |
539 | + $this->_discount = new \models\discount(); | |
540 | + $this->_discount->setDi( $this->getDi() ); | |
541 | + } | |
542 | + | |
543 | + return $this->_discount; | |
544 | + } | |
545 | + | |
534 | 546 | public function getPayment() |
535 | 547 | { |
536 | 548 | if( empty($this->_payment) ) | ... | ... |
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: Alex Savenko | |
5 | + * Date: 20.12.2016 | |
6 | + * Time: 13:39 | |
7 | + */ | |
8 | + | |
9 | +namespace models; | |
10 | + | |
11 | + | |
12 | +class discount extends \db | |
13 | +{ | |
14 | + | |
15 | + /** | |
16 | + * Get all discounts | |
17 | + * @return array | |
18 | + */ | |
19 | + public function getAllData() | |
20 | + { | |
21 | + | |
22 | + return $this->get( | |
23 | + ' | |
24 | + SELECT * FROM | |
25 | + public.disocount | |
26 | + ' | |
27 | + , | |
28 | + [ | |
29 | + ], | |
30 | + -1 | |
31 | + ); | |
32 | + } | |
33 | + | |
34 | + | |
35 | + /** | |
36 | + * Get discount with `id`=$id | |
37 | + * @param $id | |
38 | + * @return array | |
39 | + */ | |
40 | + public function getOneData($id) | |
41 | + { | |
42 | + return $this->get( | |
43 | + ' | |
44 | + SELECT * | |
45 | + FROM public.disocount | |
46 | + WHERE | |
47 | + id = :id | |
48 | + ', | |
49 | + [ | |
50 | + 'id' => $id | |
51 | + ], | |
52 | + -1 | |
53 | + ); | |
54 | + } | |
55 | + | |
56 | + | |
57 | + /** | |
58 | + * Delete discount with `id`=$id | |
59 | + * @param $id | |
60 | + * @return bool | |
61 | + */ | |
62 | + public function deleteData($id) | |
63 | + { | |
64 | + return $this->exec( | |
65 | + ' DELETE | |
66 | + FROM | |
67 | + public.disocount | |
68 | + WHERE | |
69 | + id = :id | |
70 | + ', | |
71 | + [ | |
72 | + 'id' => $id | |
73 | + ] | |
74 | + ); | |
75 | + } | |
76 | + | |
77 | + /** | |
78 | + * Add new discount | |
79 | + * @param $data | |
80 | + * @return array | |
81 | + */ | |
82 | + public function addData($data) | |
83 | + { | |
84 | + | |
85 | + return $this->get( | |
86 | + ' | |
87 | + INSERT INTO | |
88 | + public.disocount | |
89 | + ( | |
90 | + name, | |
91 | + discount, | |
92 | + description, | |
93 | + start_date, | |
94 | + end_date | |
95 | + ) | |
96 | + VALUES | |
97 | + ( | |
98 | + :name, | |
99 | + :discount, | |
100 | + :description, | |
101 | + :start_date, | |
102 | + :end_date | |
103 | + ) | |
104 | + RETURNING id | |
105 | + ', | |
106 | + [ | |
107 | + 'name' => $data['name'], | |
108 | + 'discount' => $data['discount'], | |
109 | + 'description' => $data['description'], | |
110 | + 'start_date' => $data['start_date'], | |
111 | + 'end_date' => $data['end_date'] | |
112 | + ], | |
113 | + -1 | |
114 | + ); | |
115 | + | |
116 | + | |
117 | + } | |
118 | + | |
119 | + /** | |
120 | + * Update discount with `id`=$id | |
121 | + * @param $data | |
122 | + * @param $id | |
123 | + * @return bool | |
124 | + */ | |
125 | + public function updateData($data, $id) | |
126 | + { | |
127 | + | |
128 | + return $this->exec( | |
129 | + ' | |
130 | + UPDATE | |
131 | + public.disocount | |
132 | + SET | |
133 | + name = :name, | |
134 | + discount = :discount, | |
135 | + description = :description, | |
136 | + start_date = :start_date, | |
137 | + end_date = :end_date | |
138 | + WHERE | |
139 | + id = :id | |
140 | + ', | |
141 | + [ | |
142 | + 'name' => $data['name'], | |
143 | + 'discount' => $data['discount'], | |
144 | + 'description' => $data['description'], | |
145 | + 'start_date' => $data['start_date'], | |
146 | + 'end_date' => $data['end_date'], | |
147 | + 'id' => $id | |
148 | + ] | |
149 | + ); | |
150 | + } | |
151 | + | |
152 | + /** | |
153 | + * Count all discounts | |
154 | + * @return array | |
155 | + */ | |
156 | + public function countData() | |
157 | + { | |
158 | + return $this->get( | |
159 | + ' | |
160 | + SELECT | |
161 | + COUNT(id) AS total | |
162 | + FROM | |
163 | + public.disocount | |
164 | + ', | |
165 | + [ | |
166 | + | |
167 | + ], | |
168 | + -1 | |
169 | + ); | |
170 | + } | |
171 | + | |
172 | +} | |
0 | 173 | \ No newline at end of file | ... | ... |