Blame view

src/app/backend/controllers/GroupsController.php 4.21 KB
dce46e80   Alex Savenko   first push project
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  <?php

  

  namespace controllers;

  

  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  

  class GroupsController extends \Phalcon\Mvc\Controller

  {

      function indexAction()

      {

          if( !$this->session->get('isAdminAuth') )

          {

              return $this->response->redirect([ 'for' => 'admin_login' ]);

          }

  

          $params         = $this->dispatcher->getParams();

          $page           = !empty( $params['page']  ) ? $params['page'] : 1;

          $data = $this->models->getUsersGroup()->getAllData($page);

          $total = $this->models->getUsersGroup()->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' => 'users_group_index_paged', 'page' => $page ],

                      'index_page'        => 'users_group_index'

                  ], true

              );

          }

          $this->view->setVars([

              'info' => $data,

              'paginate' => !empty($paginate['output']) ? $paginate['output'] : '' ,

          ]);

      }

  

      function deleteAction($id)

      {

          if( !$this->session->get('isAdminAuth') )

          {

              return $this->response->redirect([ 'for' => 'admin_login' ]);

          }

  

          $this->models->getUsersGroup()->deleteData($id);

  

          return $this->response->redirect([ 'for' => 'users_group_index' ]);

      }

  

      function updateAction($id)

      {

  

          if( !$this->session->get('isAdminAuth') )

          {

              return $this->response->redirect([ 'for' => 'admin_login' ]);

          }

  

          if( $this->request->isPost() )

          {

  

b87f1f95   Alex Savenko   add discount to m...
62
63
              $data['name']       = $this->request->getPost('name', 'string', NULL );

              $data['discount']   = $this->request->getPost('discount', 'int', NULL );

dce46e80   Alex Savenko   first push project
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
  

  

  

              if( !empty( $data ) )

              {

                  if( $this->models->getUsersGroup()->UpdateData( $data, $id ) )

                  {

                      $this->flash->success( 'Сохранение прошло успешно' );

                      return $this->response->redirect([ 'for' => 'users_group_index' ]);

                  }

                  else

                  {

                      $this->flash->error( 'Произошла ошибка во время обновления. Повторите попытку позже' );

                  }

              }

          }

  

          $data = $this->models->getUsersGroup()->getOneData($id);

          $this->view->pick( 'groups/addEdit' );

  

          $this->view->setVars([

              'page' => $data

          ]);

  

      }

  

      function addAction()

      {

          if( !$this->session->get('isAdminAuth') )

          {

              return $this->response->redirect([ 'for' => 'admin_login' ]);

          }

  

          if( $this->request->isPost() )

          {

  

              $data['name']       = $this->request->getPost('name', 'string', NULL );

b87f1f95   Alex Savenko   add discount to m...
101
              $data['discount']   = $this->request->getPost('discount', 'int', NULL );

dce46e80   Alex Savenko   first push project
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
  

  

              if( !empty( $data ) && !isset($this->models->getUsersGroup()->getOneDataByName($data['name'])['0']) )

              {

                  if( $this->models->getUsersGroup()->addData( $data ) )

                  {

                      $this->flash->success( 'Сохранение прошло успешно' );

                      return $this->response->redirect([ 'for' => 'users_group_index' ]);

                  }

                  else

                  {

                      $this->flash->error( 'Произошла ошибка во время добавления. Повторите попытку позже' );

                  }

              }

              else {

                  $this->flash->error('Такая группа пользователей уже существует');

              }

          }

  

          $this->view->pick( 'groups/addEdit' );

  

      }

  }