Blame view

src/app/backend/controllers/RequestController.php 4.22 KB
ef60cd4d   Administrator   first commit
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
62
63
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
  <?php
  namespace controllers;
  
  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  
  class RequestController extends \Phalcon\Mvc\Controller
  {
  
      function indexAction()
      {
  
  
          $data = \orderRequest::find(array("order" => 'id'));
          $this->view->setVars([
              'data' => $data,
          ]);
      }
  
  
  
      function setAction()
      {
         if($this->request->getPost()){
              $model =  new \orderRequest();
              $model->url  = $this->request->getPost('url', 'string');
              $model->name   = $this->request->getPost('name', 'string');
              $model->email   = $this->request->getPost('email', 'email');
              $model->phone   = $this->request->getPost('phone', 'string');
              $model->comment  = $this->request->getPost('comment', 'string');
              $model->save();
          } else {
              echo "doesn't have any request ";
          }
          die();
      }
  
  
      function addAction()
      {
          $model = array();
          $fieldsModel = \fields::find(array("type='services_sales'","order" => 'id'));
          if($this->request->get()){
              $id = $this->request->get('message_id', 'string');
  
              if(!empty($id)){
                  $model = \message::findFirst("id = '$id'");
              }
  
          }
  
          if( $this->request->isPost() )
          {
              $model = new \orderRequest();
              $model->url  = $this->request->getPost('url', 'string');
              $model->name   = $this->request->getPost('name', 'string');
              $model->email   = $this->request->getPost('email', 'email');
              $model->phone   = $this->request->getPost('phone', 'string');
              $model->comment  = $this->request->getPost('comment', 'string');
              $model->services = implode (',' , $this->request->getPost('services'));
              if( $model->save() )
              {
                  $this->flash->success( 'Сохранение прошло успешно' );
                  return $this->response->redirect([ 'for' => 'index_request' ]);
              }
              else
              {
                  $this->flash->error( 'Произошла ошибка во время сохранения.' );
              }
          }
          $this->view->pick( 'request/addEdit' );
          $this->view->setVars([
              'data' => $model,
              'fields' =>$fieldsModel
          ]);
  
      }
  
      function deleteAction($id)
      {
          $model = \orderRequest::findFirst("id = '$id'");
          if($model instanceof \orderRequest) {
              if($model->delete()){
                  $this->flash->error( 'Данные успешно удалены' );
                  return $this->response->redirect([ 'for' => 'index_request' ]);
              } else {
                  $this->flash->error( 'Произошла ошибка при попытке удаления' );
                  return $this->response->redirect([ 'for' => 'index_request' ]);
              }
          }
  
      }
  
      function updateAction($id)
      {
          $model = \orderRequest::findFirst("id = '$id'");
          $fieldsModel = \fields::find(array("type='services_sales'","order" => 'id'));
          if( $this->request->isPost() )
          {
              $model->url  = $this->request->getPost('url', 'string');
              $model->name   = $this->request->getPost('name', 'string');
              $model->email   = $this->request->getPost('email', 'email');
              $model->phone   = $this->request->getPost('phone', 'string');
              $model->comment = $this->request->getPost('comment', 'string');
              $model->services = implode (',' , $this->request->getPost('services'));
              if( $model->save() )
              {
                  $this->flash->success( 'Сохранение прошло успешно' );
                  return $this->response->redirect([ 'for' => 'index_request' ]);
              }
              else
              {
                  $this->flash->error( 'Произошла ошибка во время сохранения.' );
              }
          }
  
          $this->view->pick( 'request/addEdit' );
          $this->view->setVars([
              'data' => $model,
              'fields' =>$fieldsModel
          ]);
      }
  }